Skip to content

Spinlocks#87

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

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

Conversation

@auctumnus
Copy link

This PR adds spinlock functionality.

Somewhat supersedes part of #33.

remexre and others added 10 commits January 18, 2026 14:29
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Amy Ringo <me@remexre.com>
Signed-off-by: Autumn <auctumnus@pm.me>
Signed-off-by: Autumn <auctumnus@pm.me>
@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

Signed-off-by: Autumn <auctumnus@pm.me>
Co-authored-by: remexre <me@remexre.com>
Signed-off-by: autumn <auctumnus@pm.me>
@remexre remexre force-pushed the remexre/tasks branch 5 times, most recently from 55d95e6 to 241654e Compare February 14, 2026 09:05
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