Skip to content

feat(sync): futex support#123

Merged
FlareCoding merged 6 commits intomasterfrom
cursor/llama-cpp-kernel-context-0b94
Apr 3, 2026
Merged

feat(sync): futex support#123
FlareCoding merged 6 commits intomasterfrom
cursor/llama-cpp-kernel-context-0b94

Conversation

@FlareCoding
Copy link
Copy Markdown
Owner

This pull request contains changes generated by a Cursor Cloud Agent

Open in Web Open in Cursor 

cursoragent and others added 2 commits April 3, 2026 17:36
Three new Stellux syscalls (SYS_FUTEX_WAIT=1030, SYS_FUTEX_WAKE=1031,
SYS_FUTEX_WAKE_ALL=1032) providing the kernel-side foundation for
userspace synchronization primitives (mutexes, condvars, barriers).

Implementation uses a fixed 256-bucket hash table keyed by
(mm_context, uaddr). Waiters are stack-allocated in the syscall
handler. Wake batching follows the existing wait_queue.cpp pattern.

Timeout support via timer::schedule_sleep, thread kill handled
through existing force_wake_for_kill path.

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
Tests cover: EAGAIN on mismatch, wake with no waiters, basic wait/wake,
wake count limiting, timeout, killed thread unblock, wake_all, and
address independence.

Also fix futex_wait to handle kernel tasks (null mm_ctx) by reading
the futex word directly instead of going through uaccess validation.

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 3, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
The timeout test was calling futex_wait directly from the boot/idle
task, which cannot block. Moved the wait into a spawned kernel task.

Also moved timer::schedule_sleep before the bucket lock release to
close a preemption window between TASK_STATE_BLOCKED and timer arm.

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
@FlareCoding FlareCoding changed the title Llama-cpp kernel context feat(sync): futex support Apr 3, 2026
cursoragent and others added 2 commits April 3, 2026 18:09
1. Move uaccess validation before the bucket spinlock. copy_from_user
   acquires mm_ctx->lock (sleeping mutex) which must not be held under
   a spinlock. The value is re-read directly under the lock after the
   page has been faulted in.

2. Add timer::cancel_sleep after yield to prevent a stale timer from
   spuriously waking the task during a later unrelated blocking op.

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
Avoids signed wrap when count > INT32_MAX (e.g. UINT32_MAX) which
would make the comparison trivially true after waking just one task.

Co-authored-by: Albert Slepak <FlareCoding@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@FlareCoding FlareCoding merged commit 70409f8 into master Apr 3, 2026
15 checks passed
@FlareCoding FlareCoding deleted the cursor/llama-cpp-kernel-context-0b94 branch April 3, 2026 18:38
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