summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-02-13 22:54:17 +0100
committerRichard Braun <rbraun@sceen.net>2017-02-13 22:54:17 +0100
commita26658f7ef6d92a03720fbf4d84a8e414e24dbe0 (patch)
treec1d5bb54cca63ceda328fab77f0373b55bf9760c /kern
parent23f670b418456427552590bf06e419e66a0ca747 (diff)
kern/thread: minor global priority rework
Diffstat (limited to 'kern')
-rw-r--r--kern/thread.c22
-rw-r--r--kern/thread.h35
-rw-r--r--kern/thread_i.h9
3 files changed, 36 insertions, 30 deletions
diff --git a/kern/thread.c b/kern/thread.c
index 239bbcfb..f22ff760 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -263,7 +263,7 @@ struct thread_sched_ops {
void (*put_prev)(struct thread_runq *runq, struct thread *thread);
struct thread * (*get_next)(struct thread_runq *runq);
void (*set_priority)(struct thread *thread, unsigned short priority);
- unsigned int (*get_global_priority)(const struct thread *thread);
+ unsigned int (*get_global_priority)(unsigned short priority);
void (*set_next)(struct thread_runq *runq, struct thread *thread);
void (*tick)(struct thread_runq *runq, struct thread *thread);
};
@@ -740,9 +740,9 @@ thread_sched_rt_get_next(struct thread_runq *runq)
}
static unsigned int
-thread_sched_rt_get_global_priority(const struct thread *thread)
+thread_sched_rt_get_global_priority(unsigned short priority)
{
- return THREAD_SCHED_GLOBAL_PRIO_RT + thread_priority(thread);
+ return THREAD_SCHED_GLOBAL_PRIO_RT + priority;
}
static void
@@ -1152,9 +1152,9 @@ thread_sched_fs_set_priority(struct thread *thread, unsigned short priority)
}
static unsigned int
-thread_sched_fs_get_global_priority(const struct thread *thread)
+thread_sched_fs_get_global_priority(unsigned short priority)
{
- return THREAD_SCHED_GLOBAL_PRIO_FS + thread_priority(thread);
+ return THREAD_SCHED_GLOBAL_PRIO_FS + priority;
}
static void
@@ -1508,9 +1508,9 @@ thread_sched_idle_get_next(struct thread_runq *runq)
}
static unsigned int
-thread_sched_idle_get_global_priority(const struct thread *thread)
+thread_sched_idle_get_global_priority(unsigned short priority)
{
- (void)thread;
+ (void)priority;
return THREAD_SCHED_GLOBAL_PRIO_IDLE;
}
@@ -1577,6 +1577,7 @@ thread_set_priority(struct thread *thread, unsigned short priority)
}
thread->sched_data.priority = priority;
+ thread->sched_data.global_priority = ops->get_global_priority(priority);
}
static void __init
@@ -1676,6 +1677,7 @@ thread_init_sched(struct thread *thread, unsigned short priority)
}
thread->sched_data.priority = priority;
+ thread->sched_data.global_priority = ops->get_global_priority(priority);
}
static int
@@ -2353,12 +2355,6 @@ thread_schedclass_to_str(const struct thread *thread)
}
}
-unsigned int
-thread_global_priority(const struct thread *thread)
-{
- return thread_get_sched_ops(thread)->get_global_priority(thread);
-}
-
void
thread_setscheduler(struct thread *thread, unsigned char policy,
unsigned short priority)
diff --git a/kern/thread.h b/kern/thread.h
index c5405d7f..18a43986 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -53,6 +53,19 @@ struct thread;
*/
#define THREAD_NAME_SIZE 32
+/*
+ * Common scheduling data.
+ *
+ * The global priority of a thread is meant to be compared against
+ * another global priority to determine which thread has higher priority.
+ */
+struct thread_sched_data {
+ unsigned char sched_policy;
+ unsigned char sched_class;
+ unsigned short priority;
+ unsigned int global_priority;
+};
+
#include <kern/thread_i.h>
#define THREAD_KERNEL_PREFIX PACKAGE "_"
@@ -269,29 +282,35 @@ char thread_state_to_chr(const struct thread *thread);
*/
const char * thread_schedclass_to_str(const struct thread *thread);
+static inline const struct thread_sched_data *
+thread_get_sched_data(const struct thread *thread)
+{
+ return &thread->sched_data;
+}
+
static inline unsigned char
thread_sched_policy(const struct thread *thread)
{
- return thread->sched_data.sched_policy;
+ return thread_get_sched_data(thread)->sched_policy;
}
static inline unsigned char
thread_sched_class(const struct thread *thread)
{
- return thread->sched_data.sched_class;
+ return thread_get_sched_data(thread)->sched_class;
}
static inline unsigned short
thread_priority(const struct thread *thread)
{
- return thread->sched_data.priority;
+ return thread_get_sched_data(thread)->priority;
}
-/*
- * The global priority of a thread is meant to be compared against
- * another global priority to determine which thread has higher priority.
- */
-unsigned int thread_global_priority(const struct thread *thread);
+static inline unsigned short
+thread_global_priority(const struct thread *thread)
+{
+ return thread_get_sched_data(thread)->global_priority;
+}
static inline struct thread *
thread_from_tcb(struct tcb *tcb)
diff --git a/kern/thread_i.h b/kern/thread_i.h
index eeee417c..b3d09a05 100644
--- a/kern/thread_i.h
+++ b/kern/thread_i.h
@@ -67,15 +67,6 @@ struct thread_fs_data {
};
/*
- * Common scheduling data.
- */
-struct thread_sched_data {
- unsigned char sched_policy;
- unsigned char sched_class;
- unsigned short priority;
-};
-
-/*
* Maximum number of thread-specific data keys.
*/
#define THREAD_KEYS_MAX 4