Skip to content

Spinlocks and hartlocks#87

Open
auctumnus wants to merge 7 commits intoUMN-Kernel-Object:remexre/tasksfrom
auctumnus:remexre/tasks
Open

Spinlocks and hartlocks#87
auctumnus wants to merge 7 commits intoUMN-Kernel-Object:remexre/tasksfrom
auctumnus:remexre/tasks

Conversation

@auctumnus
Copy link

@auctumnus auctumnus commented Jan 30, 2026

This PR adds spinlock and hartlock functionality.

Somewhat supersedes part of #33.

@auctumnus auctumnus changed the title Remexre/tasks Spinlocks Jan 30, 2026
// TODO: move this over to insns.h?
#define RISCV64_CSR_SSTATUS_SIE (1 << 1)

// TODO: consider making these common across architectures somehow?
Copy link
Member

Choose a reason for hiding this comment

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

i kinda want these to be private to hartlocks, but they'd still need to be per-arch...

tbh, could you prototype them in hartlock.c and implement them in arch/riscv64/hartlock.c or smth?

Copy link
Author

Choose a reason for hiding this comment

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

private to hartlocks as in the spinlocks would take a hartlock instead?

Copy link
Author

Choose a reason for hiding this comment

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

or, well, in addition to being a spinlock, they would also take the hartlock

Comment on lines +28 to +29
// Otherwise, we might get interrupted and then attempt to re-acquire the same
// spinlock, leading to a deadlock.
Copy link
Member

Choose a reason for hiding this comment

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

i'm missing what the problematic sequence of events here is; shouldn't the atomics make this not a problem?

Copy link
Author

Choose a reason for hiding this comment

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

hmm .... i guess on second thought it shouldn't be a huge problem, i forgot that if we get interrupted we would end up dropping the lock before returning back

Copy link
Author

Choose a reason for hiding this comment

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

(e.g. if we went

  1. loop trying to acquire it while it's locked
  2. get interrupted
  3. try to acquire the same lock
    then this is fine, it's locked by a different hart which should eventually drop it)

#include <insns.h>
#include <types.h>

// TODO: move this over to insns.h?
Copy link
Member

Choose a reason for hiding this comment

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

yes; make it an enum blah : u64 too, so we get warnings if we try to use it in a too-small type

Copy link
Author

Choose a reason for hiding this comment

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

ig i didn't write down my problem here which is that nominally it's more of a struct than an enum; i.e. there are fields in sstatus that are more than 1 bit in size, and i'm unsure how to nicely represent that

@remexre remexre force-pushed the remexre/tasks branch 6 times, most recently from 241654e to cf06aaf Compare February 14, 2026 17:07
@remexre
Copy link
Member

remexre commented Feb 19, 2026

still todo:

  • hartlocks
  • bitfields
  • terrible awful ub at the end of the file

@remexre remexre force-pushed the remexre/tasks branch 10 times, most recently from 56e119a to 2b91acc Compare February 28, 2026 21:09
@auctumnus auctumnus changed the title Spinlocks Spinlocks and hartlocks Mar 14, 2026
remexre and others added 6 commits March 14, 2026 15:46
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
Co-authored-by: remexre <me@remexre.com>
Signed-off-by: autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
@auctumnus
Copy link
Author

responsible ai disclosure: i got claudeパイセン to thread struct hartlock *hartlock thru the call graph in the alloc init stuff

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