Skip to content

Conversation

@softwarecki
Copy link
Collaborator

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.

Copy link

Copilot AI left a 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_PROCESS and DP_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;
Copy link

Copilot AI Dec 8, 2025

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.

Copilot uses AI. Check for mistakes.

/* 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 */
Copy link

Copilot AI Dec 8, 2025

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'.

Suggested change
/* start the thread, it should immediately stop at a event */
/* start the thread, it should immediately stop at an event */

Copilot uses AI. Check for mistakes.
Comment on lines 122 to 124
events = k_event_wait_safe(task_pdata->event,
DP_EVENT_PROCESS | DP_EVENT_CANCEL,
false, K_FOREVER);
Copy link
Member

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 ?

zephyr_library_sources_ifdef(CONFIG_ZEPHYR_DP_SCHEDULER
zephyr_dp_schedule.c
zephyr_dp_schedule_proxy.c
zephyr_dp_schedule_native.c
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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>
Copy link
Collaborator

@kv2019i kv2019i left a 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.

Copy link
Collaborator

@lyakh lyakh left a 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>
@softwarecki
Copy link
Collaborator Author

k_event looks nice for this use. Couple of small nits, but nothing really blocking.

@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.

unable to copy file 'modules/sof/libmodules_sof.a'; reason: Success

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 */
Copy link
Collaborator

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.

@kv2019i kv2019i merged commit 23c4020 into thesofproject:main Dec 10, 2025
34 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants