-
Notifications
You must be signed in to change notification settings - Fork 7.4k
System workqueue: Prevent blocking API calls #87522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bb1e9f9
eb67bb0
949b689
f0d9a3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,6 +600,14 @@ config SYSTEM_WORKQUEUE_NO_YIELD | |
cooperative and a sequence of work items is expected to complete | ||
without yielding. | ||
|
||
config SYSTEM_WORKQUEUE_NO_BLOCK | ||
bool "Select whether system work queue enforces non-blocking work items" | ||
help | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
By default, the system work queue does not enforce work items | ||
passed to it to not perform blocking operations. Selecting this | ||
enforces that blocking operations are not performed by invoking | ||
a kernel oops if such operations are attempted. | ||
|
||
endmenu | ||
|
||
menu "Barrier Operations" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,6 +523,10 @@ static inline void z_vrfy_k_thread_resume(k_tid_t thread) | |
|
||
static void unready_thread(struct k_thread *thread) | ||
{ | ||
if (IS_ENABLED(CONFIG_SYSTEM_WORKQUEUE_NO_BLOCK) && k_is_in_sys_work()) { | ||
k_oops(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks wrong to me. "Ready" and "running" aren't the same thing. A thread can be ready but lower priority than _current. Basically: my guess is that this code will oops if you try to You need to add a test for thread == _current at least, but it would probably be better to move this test to reschedule() instead. Also: probably want a panic here and not an oops. An oops in userspace will kill only the current thread, but a misuse of the system workqueue (which obviously is a kernel thread anyway) is a global failure. And finally: neither oops nor panic give any feedback to the poor user whose code blew up. Probably wants a printk() here (or to be expressed as an __ASSERT() when available). |
||
} | ||
|
||
if (z_is_thread_queued(thread)) { | ||
dequeue_thread(thread); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this warning re system workqueue is being added here when we have a section dedicated to the system workqueue that already touches on the subject?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not see this warning, it lacks the warning regarding deadlocking which is the crucial one :) I can move it to this section if we decide on continuing with this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the deadlocking issue true of any work queue though? There's nothing particularly special about the system work queue other than it tends to get used by default a lot?
I also think its worth pointing out a simple scenario where this occurs as well.
E.g. one work item is taking a semaphore a subsequent work item is giving. Work queue is now dead locked.
Blocking calls aren't inherently the issue here either I'd note, its a possible symptom but not the cause of the deadlock.
A call to i2c_transfer() for example in a work queue item is a blocking call, and may cause the work queue thread to pend. Just because it blocks doesn't inherently mean there will be a deadlock!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "which is available to any application or kernel code" part it what makes it true especially for the sys workq, given an owner of the queue would know all work passed to the queue, so can prevent deadlocks and manage latencies :)