summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/include/arch/amd64/cdefs.h37
-rw-r--r--sys/include/sys/atomic.h32
-rw-r--r--sys/include/sys/schedvar.h1
-rw-r--r--sys/kern/kern_sched.c6
4 files changed, 74 insertions, 2 deletions
diff --git a/sys/include/arch/amd64/cdefs.h b/sys/include/arch/amd64/cdefs.h
new file mode 100644
index 0000000..98d3f0b
--- /dev/null
+++ b/sys/include/arch/amd64/cdefs.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AMD64_CDEFS_H_
+#define _AMD64_CDEFS_H_
+
+#include <sys/cdefs.h>
+
+#define md_pause() __ASMV("rep; nop")
+
+#endif /* !_AMD64_CDEFS_H_ */
diff --git a/sys/include/sys/atomic.h b/sys/include/sys/atomic.h
index 1cc0e1c..17b1b68 100644
--- a/sys/include/sys/atomic.h
+++ b/sys/include/sys/atomic.h
@@ -54,6 +54,30 @@ atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
return __sync_sub_and_fetch(p, v);
}
+static inline unsigned int
+atomic_load_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ return __atomic_load_n(p, v);
+}
+
+static inline unsigned int
+atomic_load_long_nv(volatile unsigned long *p, unsigned int v)
+{
+ return __atomic_load_n(p, v);
+}
+
+static inline void
+atomic_store_int_nv(volatile unsigned int *p, int nv, unsigned int v)
+{
+ __atomic_store_n(p, nv, v);
+}
+
+static inline void
+atomic_store_long_nv(volatile unsigned long *p, long nv, unsigned int v)
+{
+ __atomic_store_n(p, nv, v);
+}
+
/* Atomic increment (and fetch) operations */
#define atoimc_inc_long(P) atomic_add_long_nv((P), 1)
#define atomic_inc_int(P) atomic_add_int_nv((P), 1)
@@ -62,4 +86,12 @@ atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
#define atomic_dec_long(P) atomic_sub_long_nv((P), 1)
#define atomic_dec_int(P) atomic_sub_int_nv((P), 1)
+/* Atomic load operations */
+#define atomic_load_int(P) atomic_load_int_nv((P), __ATOMIC_SEQ_CST)
+#define atomic_load_long(P) atomic_load_long_nv((P), __ATOMIC_SEQ_CST)
+
+/* Atomic store operations */
+#define atomic_store_int(P, NV) atomic_store_int_nv((P), (NV), __ATOMIC_SEQ_CST)
+#define atomic_store_long(P, NV) atomic_store_long_nv((P), (NV), __ATOMIC_SEQ_CST)
+
#endif /* !_SYS_ATOMIC_H_ */
diff --git a/sys/include/sys/schedvar.h b/sys/include/sys/schedvar.h
index 81fb562..cafc9ab 100644
--- a/sys/include/sys/schedvar.h
+++ b/sys/include/sys/schedvar.h
@@ -33,6 +33,7 @@
#include <sys/cdefs.h>
#include <sys/queue.h>
#include <sys/proc.h>
+#include <machine/cdefs.h>
#if defined(_KERNEL)
#define DEFAULT_TIMESLICE_USEC 1050
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index 16daae2..ca5bfbe 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -237,8 +237,10 @@ sched_switch(struct trapframe *tf)
void
sched_enter(void)
{
- sched_oneshot(false);
- for (;;);
+ for (;;) {
+ sched_oneshot(false);
+ md_pause();
+ }
}
void