diff options
Diffstat (limited to 'kern/thread.h')
-rw-r--r-- | kern/thread.h | 87 |
1 files changed, 82 insertions, 5 deletions
diff --git a/kern/thread.h b/kern/thread.h index 7775576a..ac9ad6d8 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Richard Braun. + * Copyright (c) 2012, 2013 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,60 @@ struct task; #define THREAD_RESCHEDULE 0x1 /* Thread marked for reschedule */ /* + * Scheduling policies. + * + * The idle policy is reserved for the per-CPU idle threads. + */ +#define THREAD_SCHED_POLICY_FIFO 0 +#define THREAD_SCHED_POLICY_RR 1 +#define THREAD_SCHED_POLICY_TS 2 +#define THREAD_SCHED_POLICY_IDLE 3 +#define THREAD_NR_SCHED_POLICIES 4 + +/* + * Scheduling classes. + * + * Classes are sorted by order of priority (lower indexes first). The same + * class can apply to several policies. + * + * The idle class is reserved for the per-CPU idle threads. + */ +#define THREAD_SCHED_CLASS_RT 0 +#define THREAD_SCHED_CLASS_TS 1 +#define THREAD_SCHED_CLASS_IDLE 2 +#define THREAD_NR_SCHED_CLASSES 3 + +/* + * Real-time priority properties. + */ +#define THREAD_SCHED_RT_PRIO_MIN 0 +#define THREAD_SCHED_RT_PRIO_MAX 31 + +/* + * Scheduling context of a real-time thread. + */ +struct thread_rt_ctx { + struct list node; + unsigned short priority; + unsigned short time_slice; +}; + +/* + * Time-sharing priority properties. + */ +#define THREAD_SCHED_TS_PRIO_MIN 0 +#define THREAD_SCHED_TS_PRIO_DEFAULT 20 +#define THREAD_SCHED_TS_PRIO_MAX 39 + +/* + * Scheduling context of a time-sharing thread. + */ +struct thread_ts_ctx { + struct list node; + unsigned short weight; +}; + +/* * Thread structure. */ struct thread { @@ -48,9 +102,19 @@ struct thread { short flags; unsigned short pinned; unsigned short preempt; - struct list runq_node; - struct list task_node; + + /* Common scheduling properties */ + unsigned char sched_policy; + unsigned char sched_class; + + /* Scheduling class specific contexts */ + union { + struct thread_rt_ctx rt_ctx; + struct thread_ts_ctx ts_ctx; + }; + struct task *task; + struct list task_node; void *stack; char name[THREAD_NAME_SIZE]; void (*fn)(void *); @@ -58,6 +122,16 @@ struct thread { } __aligned(CPU_L1_SIZE); /* + * Thread creation attributes. + */ +struct thread_attr { + struct task *task; + const char *name; + unsigned char sched_policy; + unsigned short priority; +}; + +/* * Early initialization of the thread module. * * This function makes it possible to use migration and preemption control @@ -78,9 +152,12 @@ void thread_setup(void); /* * Create a thread. * - * If the given name is null, the task name is used instead. + * If the given attributes are NULL, default attributes are used. If the task + * is NULL, the caller task is selected. If the name is NULL, the task name is + * used instead. The default attributes also select the caller task and task + * name. */ -int thread_create(struct thread **threadp, struct task *task, const char *name, +int thread_create(struct thread **threadp, const struct thread_attr *attr, void (*fn)(void *), void *arg); /* |