Use a big-lock for kernel sychronization instead of fine-grained locking
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m21s
Build documentation / build-and-deploy (push) Successful in 54s

This commit is contained in:
2026-04-27 18:06:02 +02:00
parent 68cdd8d6d2
commit e5ebd7f3ba
56 changed files with 212 additions and 1206 deletions

View File

@@ -26,7 +26,6 @@
#define PS2KB_RINGBUFFER_MAX 2048
static struct ringbuffer ps2kb_ringbuffer;
static spin_lock_t ps2kb_ringbuffer_lock = SPIN_LOCK_INIT;
static struct proc_suspension_q ps2kb_sq;
static uint8_t shiftcode[0x100] = {
@@ -150,16 +149,11 @@ static int32_t ps2kb_keycode(void) {
static void ps2kb_irq(void* arg, void* regs, bool user, struct reschedule_ctx* rctx) {
(void)arg, (void)regs, (void)user;
uint64_t frb, fsq;
int32_t keycode = ps2kb_keycode();
if (keycode <= 0 || keycode == 0xFA)
return;
spin_lock(&ps2kb_ringbuffer_lock, &frb);
spin_lock(&ps2kb_sq.lock, &fsq);
ringbuffer_push(uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
struct list_node_link* node = ps2kb_sq.proc_list;
@@ -168,27 +162,17 @@ static void ps2kb_irq(void* arg, void* regs, bool user, struct reschedule_ctx* r
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
struct proc* resumed_proc = sq_entry->proc;
spin_unlock(&ps2kb_sq.lock, fsq);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
proc_sq_resume(resumed_proc, sq_entry, rctx);
return;
}
spin_unlock(&ps2kb_sq.lock, fsq);
spin_unlock(&ps2kb_ringbuffer_lock, frb);
}
DEFINE_DEVICE_OP(ps2kb_read_key) {
uint64_t frb, fsq;
uint8_t* chbuf = (uint8_t*)a1;
if (chbuf == NULL)
return -ST_BAD_ADDRESS_SPACE;
spin_lock(&ps2kb_ringbuffer_lock, &frb);
size_t prev_count = ps2kb_ringbuffer.count;
ringbuffer_pop(uint8_t, &ps2kb_ringbuffer, chbuf);
@@ -197,22 +181,17 @@ DEFINE_DEVICE_OP(ps2kb_read_key) {
/* didn't pop anything */
if (prev_count == new_count) {
spin_lock(&ps2kb_sq.lock, &fsq);
struct list_node_link* node = ps2kb_sq.proc_list;
spin_unlock(&ps2kb_sq.lock, fsq);
if (node != NULL) {
spin_unlock(&ps2kb_ringbuffer_lock, frb);
return -ST_PERMISSION_ERROR;
}
proc_sq_suspend(proc, &ps2kb_sq, &ps2kb_ringbuffer_lock, frb, rctx, NULL, NULL);
proc_sq_suspend(proc, &ps2kb_sq, rctx, NULL, NULL);
return ST_OK;
}
spin_unlock(&ps2kb_ringbuffer_lock, frb);
return ST_OK;
}