summaryrefslogtreecommitdiff
path: root/linux/sched.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-02-05 00:13:40 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-02-05 00:13:40 -0500
commit27c0b6fbc5ffe0979436a6436187d1bf952e9a24 (patch)
tree6978012f0721c356a50fa1455bb32ddd5bbc6074 /linux/sched.c
parent7c29c458db133a8a5ad92b73c2a22561cd279da0 (diff)
use futex instead of pthread cond variable for schedule
Diffstat (limited to 'linux/sched.c')
-rw-r--r--linux/sched.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/linux/sched.c b/linux/sched.c
index cc614b12..2d61c480 100644
--- a/linux/sched.c
+++ b/linux/sched.c
@@ -1,4 +1,5 @@
+#include <linux/futex.h>
#include <string.h>
#include <sys/mman.h>
@@ -6,6 +7,7 @@
#include <linux/printk.h>
#include <linux/rcupdate.h>
#include <linux/sched.h>
+#include <linux/slab.h>
#include <linux/timer.h>
__thread struct task_struct *current;
@@ -19,28 +21,23 @@ void __put_task_struct(struct task_struct *t)
/* returns true if process was woken up, false if it was already running */
int wake_up_process(struct task_struct *p)
{
- int ret;
+ int ret = p->state != TASK_RUNNING;
- pthread_mutex_lock(&p->lock);
- ret = p->state != TASK_RUNNING;
p->state = TASK_RUNNING;
-
- pthread_cond_signal(&p->wait);
- pthread_mutex_unlock(&p->lock);
-
+ futex(&p->state, FUTEX_WAKE|FUTEX_PRIVATE_FLAG,
+ INT_MAX, NULL, NULL, 0);
return ret;
}
void schedule(void)
{
- rcu_quiescent_state();
+ int v;
- pthread_mutex_lock(&current->lock);
-
- while (current->state != TASK_RUNNING)
- pthread_cond_wait(&current->wait, &current->lock);
+ rcu_quiescent_state();
- pthread_mutex_unlock(&current->lock);
+ while ((v = current->state) != TASK_RUNNING)
+ futex(&current->state, FUTEX_WAIT|FUTEX_PRIVATE_FLAG,
+ v, NULL, NULL, 0);
}
static void process_timeout(unsigned long __data)
@@ -169,8 +166,6 @@ static void sched_init(void)
memset(p, 0, sizeof(*p));
p->state = TASK_RUNNING;
- pthread_mutex_init(&p->lock, NULL);
- pthread_cond_init(&p->wait, NULL);
atomic_set(&p->usage, 1);
init_completion(&p->exited);