Page MenuHomeFreeBSD

linuxkpi: Factorize duplicated code in `linux_wait_event_common()` and `linux_schedule_timeout()`
AbandonedPublic

Authored by dumbbell on Apr 13 2025, 10:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 23, 12:06 AM
Unknown Object (File)
Thu, Sep 18, 11:59 PM
Unknown Object (File)
Mon, Sep 15, 8:41 PM
Unknown Object (File)
Sep 13 2025, 12:17 PM
Unknown Object (File)
Sep 11 2025, 10:12 PM
Unknown Object (File)
Sep 9 2025, 4:44 AM
Unknown Object (File)
Sep 7 2025, 8:07 PM
Unknown Object (File)
Sep 5 2025, 10:37 AM
Subscribers

Details

Reviewers
markj
Group Reviewers
linuxkpi
Summary

There are two other functions calling linux_add_to_sleepqueue(), but the logic is slightly different. Factorizing them would make the code any cleaner.

This is part of the update of DRM drivers to Linux 6.7. This is a follow-up to D48755.

Sponsored by: The FreeBSD Foundation

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

sys/compat/linuxkpi/common/src/linux_schedule.c
310

We can just pass 0 instead of the state here. linux_add_to_sleepqueue() only cares about whether the sleep is interruptible or not, i.e., the value is only 0 or TASK_INTERRUPTIBLE. I don't think that flag is ever set in task->state.

dumbbell added inline comments.
sys/compat/linuxkpi/common/src/linux_schedule.c
310

I think it is set. Here are two examples from the i915 driver:

prepare_to_wait(&ddat->waitq, &wait, TASK_INTERRUPTIBLE);
// ...
schedule();
prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
// ...
timeout = schedule_timeout(timeout);

prepare_to_wait() calls set_task_state() which sets task->state:
https://github.com/dumbbell/freebsd-src/blob/drm-related-linuxkpi-changes/sys/compat/linuxkpi/common/src/linux_schedule.c#L267

then both schedule() and schedule_timeout() call linux_schedule_timeout().

markj added inline comments.
sys/compat/linuxkpi/common/src/linux_schedule.c
310

Thank you, I didn't realize it worked that way.

This revision is now accepted and ready to land.Apr 16 2025, 5:27 PM
dumbbell marked an inline comment as done.

I abandon this revision; see the discussion in D48755.