Skip to content

Spinlocks and hartlocks#87

Open
auctumnus wants to merge 32 commits into
UMN-Kernel-Object:remexre/tasksfrom
auctumnus:remexre/tasks
Open

Spinlocks and hartlocks#87
auctumnus wants to merge 32 commits into
UMN-Kernel-Object:remexre/tasksfrom
auctumnus:remexre/tasks

Conversation

@auctumnus
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread src/kernel/include/arch/riscv64/insns.h Outdated
Comment thread src/kernel/spinlock.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

Comment thread src/kernel/spinlock.c Outdated
#include <insns.h>
#include <types.h>

// TODO: move this over to insns.h?
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 7 times, most recently from ba047e3 to e277ac4 Compare February 28, 2026 19:21
Signed-off-by: Amy Ringo <me@remexre.com>
These functions are for mapping IO memory.

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: 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>
Closes UMN-Kernel-Object#90.

Note that this depends on GCC 15 (UMN-Kernel-Object#82) as well. GCC 16 will let us
simplify the -march line to -march=rva23s64, but it's not released at
the time of writing.

Signed-off-by: Amy Ringo <me@remexre.com>
This makes it easier to test concurrency-related code.

Signed-off-by: Amy Ringo <me@remexre.com>
auctumnus 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>
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
Copy Markdown
Author

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

@remexre remexre force-pushed the remexre/tasks branch 4 times, most recently from c62a624 to 3709edb Compare March 28, 2026 17:47
@remexre remexre force-pushed the remexre/tasks branch 2 times, most recently from 23f6481 to 832ace2 Compare April 9, 2026 01:31
@remexre remexre force-pushed the remexre/tasks branch 2 times, most recently from 4350e50 to de6543d Compare April 25, 2026 19:27
@remexre remexre force-pushed the remexre/tasks branch 2 times, most recently from 83d562a to 315ff7a Compare April 26, 2026 08:47
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