From 83e17e29456ec9b6d45f4d9f2634eb280c6f414f Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 19 Apr 2023 20:50:10 -0400 Subject: ticket locks --- sys/include/asm.h | 1 + sys/include/fdt.h | 2 +- sys/include/kalloc.h | 15 +++++++++++++++ sys/include/mm/kalloc.h | 15 --------------- sys/include/spinlock.h | 22 ++++++++++++---------- 5 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 sys/include/kalloc.h delete mode 100644 sys/include/mm/kalloc.h (limited to 'sys/include') diff --git a/sys/include/asm.h b/sys/include/asm.h index 86e6354..0995f88 100644 --- a/sys/include/asm.h +++ b/sys/include/asm.h @@ -50,6 +50,7 @@ read_tp(void) { uint64_t x; asm volatile("addi %0, tp, 0" : "=r"(x)); + return x; } #endif /* _ASM_H */ diff --git a/sys/include/fdt.h b/sys/include/fdt.h index ca1cea0..77c9d6e 100644 --- a/sys/include/fdt.h +++ b/sys/include/fdt.h @@ -40,7 +40,7 @@ struct fdt_node_header { char name[]; }; -void walk_fdt(struct fdt_header *header); +void fdt_walk(struct fdt_header *header); #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ #define FDT_TAGSIZE sizeof(fdt32_t) diff --git a/sys/include/kalloc.h b/sys/include/kalloc.h new file mode 100644 index 0000000..10adbda --- /dev/null +++ b/sys/include/kalloc.h @@ -0,0 +1,15 @@ +#ifndef _KALLOC_H +#define _KALLOC_H + +void *kalloc(void); + +void *kzalloc(void); + +void kfree(void *); + +void kalloc_init(void); + +void walkfree(void); + +#endif /* _KALLOC_H */ + diff --git a/sys/include/mm/kalloc.h b/sys/include/mm/kalloc.h deleted file mode 100644 index 10adbda..0000000 --- a/sys/include/mm/kalloc.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _KALLOC_H -#define _KALLOC_H - -void *kalloc(void); - -void *kzalloc(void); - -void kfree(void *); - -void kalloc_init(void); - -void walkfree(void); - -#endif /* _KALLOC_H */ - diff --git a/sys/include/spinlock.h b/sys/include/spinlock.h index ef81499..82c1585 100644 --- a/sys/include/spinlock.h +++ b/sys/include/spinlock.h @@ -1,15 +1,17 @@ -#ifndef _LOCK_H -#define _LOCK_H +#ifndef _SPINLOCK_H +#define _SPINLOCK_H -struct spinlock { - int locked; - int tp; -}; +/* fifo ticket lock implementation */ -void initlock(struct spinlock *); +typedef struct _spinlock { + int ticket; + int turn; +} spinlock_t; -void acquire(struct spinlock *); +void initlock(spinlock_t *); -void release(struct spinlock *); +void acquire(spinlock_t *); -#endif /* _LOCK_H */ +void release(spinlock_t *); + +#endif /* _SPINLOCK_H */ -- cgit v1.2.3