summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-01-23 23:57:04 +0100
committerRichard Braun <rbraun@sceen.net>2017-01-23 23:57:04 +0100
commit5548178e6c7355c250f2d938e7502040c55228a3 (patch)
tree9b0f19aeb1d1df22cdd7369c534762c509daa3ec
parente2415706c10859f3e9a3d40b9819e58b83661e4f (diff)
kern/thread: move private definitions to thread_i.h
-rw-r--r--Makefrag.am1
-rw-r--r--kern/thread.c15
-rw-r--r--kern/thread.h145
-rw-r--r--kern/thread_i.h156
-rw-r--r--kern/types.h5
5 files changed, 180 insertions, 142 deletions
diff --git a/Makefrag.am b/Makefrag.am
index 830c47b..b0a5d32 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -55,6 +55,7 @@ x15_SOURCES += \
kern/task.h \
kern/thread.c \
kern/thread.h \
+ kern/thread_i.h \
kern/types.h \
kern/work.c \
kern/work.h \
diff --git a/kern/thread.c b/kern/thread.c
index 418da9b..09159f6 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2014 Richard Braun.
+ * Copyright (c) 2012-2017 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
@@ -125,6 +125,19 @@
#define THREAD_SUSPEND_PREEMPT_LEVEL 2
/*
+ * 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
+
+/*
* Default time slice for real-time round-robin scheduling.
*/
#define THREAD_DEFAULT_RR_TIME_SLICE (HZ / 10)
diff --git a/kern/thread.h b/kern/thread.h
index 2c483ab..6279df5 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2014 Richard Braun.
+ * Copyright (c) 2012-2017 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
@@ -36,42 +36,21 @@
#include <kern/assert.h>
#include <kern/cpumap.h>
-#include <kern/list.h>
#include <kern/macros.h>
-#include <kern/param.h>
#include <kern/types.h>
-#include <machine/atomic.h>
-#include <machine/cpu.h>
#include <machine/tcb.h>
/*
- * Forward declarations.
+ * Thread structure.
*/
-struct spinlock;
-struct task;
-struct thread_runq;
-struct thread_ts_runq;
+struct thread;
/*
* Thread name buffer size.
*/
#define THREAD_NAME_SIZE 32
-/*
- * Thread flags.
- */
-#define THREAD_YIELD 0x1UL /* Must yield the processor ASAP */
-#define THREAD_DETACHED 0x2UL /* Resources automatically released on exit */
-
-/*
- * Thread states.
- *
- * Threads in the running state may not be on a run queue if they're being
- * awaken.
- */
-#define THREAD_RUNNING 0
-#define THREAD_SLEEPING 1
-#define THREAD_DEAD 2
+#include <kern/thread_i.h>
/*
* Scheduling policies.
@@ -85,34 +64,12 @@ struct thread_ts_runq;
#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 63
/*
- * Scheduling data for a real-time thread.
- */
-struct thread_rt_data {
- struct list node;
- unsigned short priority;
- unsigned short time_slice;
-};
-
-/*
* Time-sharing priority properties.
*/
#define THREAD_SCHED_TS_PRIO_MIN 0
@@ -120,77 +77,6 @@ struct thread_rt_data {
#define THREAD_SCHED_TS_PRIO_MAX 39
/*
- * Scheduling data for a time-sharing thread.
- */
-struct thread_ts_data {
- struct list group_node;
- struct list runq_node;
- struct thread_ts_runq *ts_runq;
- unsigned long round;
- unsigned short priority;
- unsigned short weight;
- unsigned short work;
-};
-
-/*
- * Maximum number of thread-specific data keys.
- */
-#define THREAD_KEYS_MAX 4
-
-/*
- * Thread structure.
- *
- * Thread members are normally protected by the lock of the run queue they're
- * associated with. Thread-local members are accessed without synchronization.
- */
-struct thread {
- struct tcb tcb;
-
- /* Flags must be changed atomically */
- unsigned long flags;
-
- /* Sleep/wakeup synchronization members */
- struct thread_runq *runq;
- unsigned short state;
-
- /* Thread-local members */
- unsigned short preempt;
- unsigned short pinned;
- unsigned short llsync_read;
-
- /* Common scheduling properties */
- unsigned char sched_policy;
- unsigned char sched_class;
-
- /* Processors on which this thread is allowed to run */
- struct cpumap cpumap;
-
- /* Scheduling class specific data */
- union {
- struct thread_rt_data rt_data;
- struct thread_ts_data ts_data;
- };
-
- /* Thread-specific data */
- void *tsd[THREAD_KEYS_MAX];
-
- /* Members related to termination */
- struct mutex join_lock;
- struct condition join_cond;
- int exited;
-
- /* Read-only members */
- struct task *task;
- struct list task_node;
- void *stack;
- char name[THREAD_NAME_SIZE];
- void (*fn)(void *);
- void *arg;
-} __aligned(CPU_L1_SIZE);
-
-#define THREAD_ATTR_DETACHED 0x1
-
-/*
* Thread creation attributes.
*/
struct thread_attr {
@@ -375,29 +261,6 @@ thread_self(void)
}
/*
- * Flag access functions.
- */
-
-static inline void
-thread_set_flag(struct thread *thread, unsigned long flag)
-{
- atomic_or_ulong(&thread->flags, flag);
-}
-
-static inline void
-thread_clear_flag(struct thread *thread, unsigned long flag)
-{
- atomic_and_ulong(&thread->flags, ~flag);
-}
-
-static inline int
-thread_test_flag(struct thread *thread, unsigned long flag)
-{
- barrier();
- return ((thread->flags & flag) != 0);
-}
-
-/*
* Main scheduler invocation call.
*
* Called on return from interrupt or when reenabling preemption.
diff --git a/kern/thread_i.h b/kern/thread_i.h
new file mode 100644
index 0000000..189c359
--- /dev/null
+++ b/kern/thread_i.h
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2017 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _KERN_THREAD_I_H
+#define _KERN_THREAD_I_H
+
+#include <kern/cpumap.h>
+#include <kern/list.h>
+#include <kern/macros.h>
+#include <kern/param.h>
+#include <kern/types.h>
+#include <machine/atomic.h>
+#include <machine/tcb.h>
+
+struct thread_runq;
+struct thread_ts_runq;
+
+/*
+ * Thread flags.
+ */
+#define THREAD_YIELD 0x1UL /* Must yield the processor ASAP */
+#define THREAD_DETACHED 0x2UL /* Resources automatically released on exit */
+
+/*
+ * Thread states.
+ *
+ * Threads in the running state may not be on a run queue if they're being
+ * awaken.
+ */
+#define THREAD_RUNNING 0
+#define THREAD_SLEEPING 1
+#define THREAD_DEAD 2
+
+/*
+ * Scheduling data for a real-time thread.
+ */
+struct thread_rt_data {
+ struct list node;
+ unsigned short priority;
+ unsigned short time_slice;
+};
+
+/*
+ * Scheduling data for a time-sharing thread.
+ */
+struct thread_ts_data {
+ struct list group_node;
+ struct list runq_node;
+ struct thread_ts_runq *ts_runq;
+ unsigned long round;
+ unsigned short priority;
+ unsigned short weight;
+ unsigned short work;
+};
+
+/*
+ * Maximum number of thread-specific data keys.
+ */
+#define THREAD_KEYS_MAX 4
+
+/*
+ * Thread structure.
+ *
+ * Thread members are normally protected by the lock of the run queue they're
+ * associated with. Thread-local members are accessed without synchronization.
+ */
+struct thread {
+ struct tcb tcb;
+
+ /* Flags must be changed atomically */
+ unsigned long flags;
+
+ /* Sleep/wakeup synchronization members */
+ struct thread_runq *runq;
+ unsigned short state;
+
+ /* Thread-local members */
+ unsigned short preempt;
+ unsigned short pinned;
+ unsigned short llsync_read;
+
+ /* Common scheduling properties */
+ unsigned char sched_policy;
+ unsigned char sched_class;
+
+ /* Processors on which this thread is allowed to run */
+ struct cpumap cpumap;
+
+ /* Scheduling class specific data */
+ union {
+ struct thread_rt_data rt_data;
+ struct thread_ts_data ts_data;
+ };
+
+ /*
+ * Thread-specific data should only be used by architecture-dependent code.
+ * For machine-independent code, new member variables should be added.
+ *
+ * TODO move those to the TCB and remove.
+ */
+ void *tsd[THREAD_KEYS_MAX];
+
+ /* Members related to termination */
+ struct mutex join_lock;
+ struct condition join_cond;
+ int exited;
+
+ /* Read-only members */
+ struct task *task;
+ struct list task_node;
+ void *stack;
+ char name[THREAD_NAME_SIZE];
+ void (*fn)(void *);
+ void *arg;
+} __aligned(CPU_L1_SIZE);
+
+#define THREAD_ATTR_DETACHED 0x1
+
+/*
+ * Flag access functions.
+ */
+
+static inline void
+thread_set_flag(struct thread *thread, unsigned long flag)
+{
+ atomic_or_ulong(&thread->flags, flag);
+}
+
+static inline void
+thread_clear_flag(struct thread *thread, unsigned long flag)
+{
+ atomic_and_ulong(&thread->flags, ~flag);
+}
+
+static inline int
+thread_test_flag(struct thread *thread, unsigned long flag)
+{
+ barrier();
+ return ((thread->flags & flag) != 0);
+}
+
+#endif /* _KERN_THREAD_I_H */
diff --git a/kern/types.h b/kern/types.h
index 5e8a7db..fa13ef7 100644
--- a/kern/types.h
+++ b/kern/types.h
@@ -21,6 +21,11 @@
#include <machine/types.h>
/*
+ * Forward declarations.
+ */
+struct task;
+
+/*
* Types defined here to avoid inclusion loops.
*/