Skip to content

userspace: proxy: use a separate worker per core#10946

Draft
serhiy-katsyuba-intel wants to merge 2 commits into
thesofproject:mainfrom
serhiy-katsyuba-intel:userspace_multicore_crash
Draft

userspace: proxy: use a separate worker per core#10946
serhiy-katsyuba-intel wants to merge 2 commits into
thesofproject:mainfrom
serhiy-katsyuba-intel:userspace_multicore_crash

Conversation

@serhiy-katsyuba-intel

Copy link
Copy Markdown
Contributor

Previously a single userspace worker (work queue) served requests for all userspace modules, regardless of the core they ran on, and the worker thread was re-pinned to the requesting module's core on every invocation. This actually only worked in single-core tests, but on multi-core pinning failed, because a thread can only be pinned while it is not running.

Replace the single worker with a per-core worker array. Each worker thread is pinned to its core once, at creation time.

Previously a single userspace worker (work queue) served requests for
all userspace modules, regardless of the core they ran on, and the
worker thread was re-pinned to the requesting module's core on every
invocation. This actually only worked in single-core tests, but on
multi-core pinning failed, because a thread can only be pinned while
it is not running.

Replace the single worker with a per-core worker array. Each worker
thread is pinned to its core once, at creation time.

Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
The proxy now uses a separate worker per core. Each work item is
allocated, submitted and processed on the same core, so cross-core
coherency is no longer required.

Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
Copilot AI review requested due to automatic review settings June 18, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes multi-core userspace proxy handling by replacing a single shared userspace work queue (that was re-pinned per invocation) with a per-core worker array where each worker is pinned once at creation time.

Changes:

  • Introduce a per-core worker[CONFIG_CORE_COUNT] and route submissions/event usage through the current core’s worker.
  • Pin each worker thread to its core during worker creation (instead of re-pinning on each invoke).
  • Remove the need for coherent allocation for work items by keeping work processing core-local.


static int user_work_item_init(struct userspace_context *user_ctx, struct k_heap *user_heap)
{
int cpu = cpu_get_id();
int ret;

ret = user_worker_get();
ret = user_worker_get(cpu);
Comment on lines +173 to +175
work_item = sof_heap_alloc(user_heap, 0, sizeof(*work_item), 0);
if (!work_item) {
user_worker_put();
user_worker_put(cpu);

#if !IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
work_item->event = &worker.event;
work_item->event = &worker[cpu].event;
{
sof_heap_free(user_heap, user_ctx->work_item);
user_worker_put();
user_worker_put(cpu_get_id());
Comment on lines +214 to +215
int cpu = cpu_get_id();
struct k_event * const event = &worker[cpu].event;
#if !IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
/* Switch worker thread to module memory domain */
ret = k_mem_domain_add_thread(user_ctx->comp_dom, worker.thread_id);
ret = k_mem_domain_add_thread(user_ctx->comp_dom, worker[cpu].thread_id);
#endif

ret = k_work_user_submit_to_queue(&worker.work_queue, &user_ctx->work_item->work_item);
ret = k_work_user_submit_to_queue(&worker[cpu].work_queue, &user_ctx->work_item->work_item);
Comment on lines +134 to +137
k_thread_suspend(worker[cpu].thread_id);

/* Pin worker thread to the same core as the module */
k_thread_cpu_pin(worker[cpu].thread_id, cpu);

k_thread_access_grant(worker[cpu].thread_id, &worker[cpu].event);

k_thread_resume(worker[cpu].thread_id);
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.

2 participants