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)
Fri, May 22, 8:22 AM
Unknown Object (File)
May 5 2026, 6:52 AM
Unknown Object (File)
May 3 2026, 11:54 AM
Unknown Object (File)
Apr 29 2026, 2:04 PM
Unknown Object (File)
Apr 29 2026, 2:01 PM
Unknown Object (File)
Apr 23 2026, 10:22 AM
Unknown Object (File)
Apr 21 2026, 11:01 AM
Unknown Object (File)
Apr 16 2026, 1:49 PM
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.