-
Notifications
You must be signed in to change notification settings - Fork 349
dp: Switch DP thread trigger from semaphore to event #10419
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
Conversation
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.
Pull request overview
This PR refactors the DP thread synchronization mechanism by replacing semaphores with events to enable more flexible task signaling. The change allows the DP thread to distinguish between different types of signals (process vs. cancel) rather than just waking up without context.
Key changes:
- Replaced semaphore-based synchronization with event-based synchronization throughout the DP scheduler
- Introduced event type enums (
DP_EVENT_PROCESSandDP_EVENT_CANCEL) to signal different conditions - Updated thread waiting logic to handle multiple event types
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/schedule/zephyr_dp_schedule.h | Defines event type enums and replaces semaphore fields with event fields in task data structure |
| src/schedule/zephyr_dp_schedule.c | Updates task initialization, cancellation, and cleanup to use events instead of semaphores |
| src/schedule/zephyr_dp_schedule_native.c | Modifies thread signaling and waiting logic to use events with multiple event type support |
| src/schedule/CMakeLists.txt | Changes build configuration to include native scheduler implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| struct scheduler_dp_data *dp_sch = NULL; | ||
| unsigned int lock_key; | ||
| enum task_state state; | ||
| uint32_t events; |
Copilot
AI
Dec 8, 2025
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 variable 'events' is declared but never used after the k_event_wait_safe() call. Consider checking the returned event flags to validate which event was received, or handling the DP_EVENT_CANCEL case appropriately if the thread needs to behave differently based on the event type.
src/schedule/zephyr_dp_schedule.c
Outdated
|
|
||
| /* start the thread, it should immediately stop at a semaphore, so clean it */ | ||
| k_sem_init(pdata->sem, 0, 1); | ||
| /* start the thread, it should immediately stop at a event */ |
Copilot
AI
Dec 8, 2025
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.
Corrected grammar from 'at a event' to 'at an event'.
| /* start the thread, it should immediately stop at a event */ | |
| /* start the thread, it should immediately stop at an event */ |
| events = k_event_wait_safe(task_pdata->event, | ||
| DP_EVENT_PROCESS | DP_EVENT_CANCEL, | ||
| false, K_FOREVER); |
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.
This will likely throw a warning now if events set but not used ? I think we have -Wall set for most files ?
src/schedule/CMakeLists.txt
Outdated
| zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER | ||
| zephyr_dp_schedule.c | ||
| zephyr_dp_schedule_proxy.c | ||
| zephyr_dp_schedule_native.c |
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.
sorry, don't understand the renaming.
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 previous name implied a proxy layer, which is misleading because the file only contains the native DP thread logic and is used even when userspace is inactive. It doesn't implement any proxy layer. Renaming improves clarity and prevents incorrect assumptions about its role. This is a cosmetic change and does not affect functionality, so it shouldn't block the 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.
@softwarecki calling one of the 2 alternatives "native" can be interpreted as the other one being "less native," i.e. possibly less supported, less preferable. I don't think that of the present 2 version the "proxy" one is more native than the "application" version. That's also the reason why I agreed to move the "application" version away from the original "native" naming. And that's also the reason I'm not accepting this renaming. Please, drop or come up with another neutral name.
Update the DP scheduler file name by replacing the proxy postfix to reflect actual content and avoid misleading semantics. The file does not implement any proxy layer, and it is also used when userspace is not active. It contains only the native DP thread. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
06be8c3 to
85d0f01
Compare
kv2019i
left a comment
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.
k_event looks nice for this use. Couple of small nits, but nothing really blocking.
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.
hard to say with certainty without trying it, but I think this is useful. But you forgot to also update the "application" variant, which would be broken after this change
Replace the DP thread trigger mechanism from semaphore to event to prepare for handling multiple types of signals within the DP thread. The previous semaphore-based approach could only wake the thread without providing context about what needs to be processed. Using an event allows signaling different conditions so the thread can identify which tasks to handle. Currently, no new event types are introduced, but this change lays the groundwork for future extensions without altering existing functionality. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
85d0f01 to
9e82b19
Compare
@kv2019i Thanks for these small suggestions. I always appreciate this kind of feedback and Im happy to apply the changes because it really improves the overall quality of the code. @lyakh I also modified the "application" variant.
Looks like CI is having a rough day again :( |
| struct k_sem *sem; /* pointer to semaphore for task scheduling */ | ||
| struct k_sem sem_struct; /* semaphore for task scheduling for kernel threads */ | ||
| struct k_event *event; /* pointer to event for task scheduling */ | ||
| struct k_event event_struct; /* event for task scheduling for kernel threads */ |
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.
alternatively to changing the "application" version in this commit too, you can add the two new members without removing the semaphore, then I'll migrate the other version later too.
Replace the DP thread trigger mechanism from semaphore to event to prepare for handling multiple types of signals within the DP thread. The previous semaphore-based approach could only wake the thread without providing context about what needs to be processed. Using an event allows signaling different conditions so the thread can identify which tasks to handle. Currently, no new event types are introduced, but this change lays the groundwork for future extensions without altering existing functionality.