summaryrefslogtreecommitdiffstats
path: root/src/include/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/kernel')
-rw-r--r--src/include/kernel/cpu.H4
-rw-r--r--src/include/kernel/futexmgr.H89
-rw-r--r--src/include/kernel/syscalls.H15
-rw-r--r--src/include/kernel/usermutex.H18
4 files changed, 97 insertions, 29 deletions
diff --git a/src/include/kernel/cpu.H b/src/include/kernel/cpu.H
index 87e769743..0f36dd941 100644
--- a/src/include/kernel/cpu.H
+++ b/src/include/kernel/cpu.H
@@ -9,7 +9,7 @@
#include <kernel/types.h>
#include <arch/ppc.H>
#include <builtins.h>
-#include <sys/mutex.h>
+#include <sys/sync.h>
// Thread ID support only, Power7 (4 threads).
#define KERNEL_MAX_SUPPORTED_CPUS (4 * 8 * 4) // Sockets, cores, threads.
@@ -36,7 +36,7 @@ struct cpu_t
task_t* idle_task;
/** XSCOM mutex to serialize access per CPU */
- mutex_t xscom_mutex;
+ mutex_t * xscom_mutex;
};
/** @fn getCpuId
diff --git a/src/include/kernel/futexmgr.H b/src/include/kernel/futexmgr.H
new file mode 100644
index 000000000..824175136
--- /dev/null
+++ b/src/include/kernel/futexmgr.H
@@ -0,0 +1,89 @@
+#ifndef FUTEXMGR
+#define FUTEXMGR
+
+/**
+ * @file futexmgr.H
+ * @brief Declaration for kernel side futex management
+ */
+
+#include <stdint.h>
+#include <util/locked/list.H>
+#include <kernel/spinlock.H>
+
+struct task_t;
+
+
+/**
+ * @class FutexManager
+ * Kernel internal management of fuxtexs
+ */
+class FutexManager
+{
+ public:
+
+ /**
+ * Put the current processes on a wait queue
+ * @param[in] i_task pointer to the current task structure
+ * @param[in] i_addr Futex address
+ * @param[in] i_val Value that *i_addr should contain
+ * @returns [0 | error code] if *i_addr != i_val returns EWOULDBLOCK
+ */
+ static uint64_t wait(task_t * i_task, uint64_t * i_addr, uint64_t i_val);
+
+ /**
+ * Wakeup threads
+ * @param[in] i_addr pointer to a futex
+ * @param[in] i_count The max number of threads to wake
+ * @returns The number of threads awoken
+ */
+ static uint64_t wake(uint64_t * i_addr, uint64_t i_count);
+
+ protected:
+
+ /**
+ * Ctor
+ */
+ FutexManager() {};
+
+ /**
+ * Dtor
+ */
+ ~FutexManager() {};
+
+ private: // functions
+
+ /**
+ * Put the current processes on a wait queue
+ * @param[in] i_task pointer to the current task structure
+ * @param[in] i_addr Futex address
+ * @param[in] i_val Value that *i_addr should contain
+ * @returns [0 | error code] if *i_addr != i_val returns EWOULDBLOCK
+ */
+ uint64_t _wait(task_t * i_task, uint64_t * i_addr, uint64_t i_val);
+
+ /**
+ * Wakeup threads
+ * @param[in] i_addr pointer to a futex
+ * @param[in] i_count The max number of threads to wake
+ * @returns The number of threads awoken
+ */
+ uint64_t _wake(uint64_t * i_addr, uint64_t i_count);
+
+ private: // data
+
+ struct _FutexWait_t
+ {
+ _FutexWait_t * next; ///< next _FutexWait_t in list
+ _FutexWait_t * prev; ///< prev _FutexWait_t in list
+ uint64_t * key; ///< search key is futex address
+ task_t* task; ///< task on wait list
+ };
+
+ typedef Util::Locked::List<_FutexWait_t, uint64_t *> FutexList_t;
+
+ Spinlock iv_lock; ///< lock
+ FutexList_t iv_list; ///< List of waiting tasks for all futexes
+};
+
+#endif
+
diff --git a/src/include/kernel/syscalls.H b/src/include/kernel/syscalls.H
index 1b87c5019..26e2bdf75 100644
--- a/src/include/kernel/syscalls.H
+++ b/src/include/kernel/syscalls.H
@@ -24,15 +24,6 @@ namespace Systemcalls
/** task_end() */
TASK_END,
- /** mutex_create() */
- MUTEX_CREATE,
- /** mutex_destroy() */
- MUTEX_DESTROY,
- /** mutex_lock() */
- MUTEX_LOCK_CONTESTED,
- /** mutex_unlock() */
- MUTEX_UNLOCK_CONTESTED,
-
/** msgq_create() */
MSGQ_CREATE,
/** msgq_destroy() */
@@ -59,6 +50,12 @@ namespace Systemcalls
/** nanosleep() */
TIME_NANOSLEEP,
+ /** futex_wait() */
+ FUTEX_WAIT,
+
+ /** futex_wake() */
+ FUTEX_WAKE,
+
SYSCALL_MAX
};
diff --git a/src/include/kernel/usermutex.H b/src/include/kernel/usermutex.H
deleted file mode 100644
index c9f631579..000000000
--- a/src/include/kernel/usermutex.H
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __KERNEL_USERMUTEX_H
-#define __KERNEL_USERMUTEX_H
-
-#include <util/locked/queue.H>
-#include <kernel/spinlock.H>
-#include <kernel/task.H>
-
-struct UserMutex
-{
- uint64_t value;
- bool unlock_pend;
- Spinlock lock;
- Util::Locked::Queue<task_t> waiting;
-
- UserMutex() : value(0), unlock_pend(false) {};
-};
-
-#endif
OpenPOWER on IntegriCloud