#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/syscall.h>
#include <sys/kassert.h>
#include <sys/kconfig.h>
#include <sys/kdebug.h>
#include <sys/kmem.h>
#include <sys/ktime.h>
#include <sys/mp.h>
#include <sys/spinlock.h>
#include <sys/thread.h>
#include <machine/trap.h>
#include <machine/pmap.h>
Go to the source code of this file.
|
void | Handle_GlobalInit () |
|
void | Thread_Init () |
|
void | Thread_InitAP () |
|
Thread * | Thread_Create (Process *proc) |
|
Thread * | Thread_KThreadCreate (void(*f)(void *), void *arg) |
|
Thread * | Thread_UThreadCreate (Thread *oldThr, uint64_t rip, uint64_t arg) |
|
static void | Thread_Destroy (Thread *thr) |
|
Thread * | Thread_Lookup (Process *proc, uint64_t tid) |
|
void | Thread_Retain (Thread *thr) |
|
void | Thread_Release (Thread *thr) |
|
uint64_t | Thread_Wait (Thread *thr, uint64_t tid) |
|
void | ThreadKThreadEntry (TrapFrame *tf) __NO_LOCK_ANALYSIS |
|
void | Thread_Dump (Thread *thr) |
|
static void | Debug_Threads (int argc, const char *argv[]) |
|
| REGISTER_DBGCMD (threads, "Display list of threads", Debug_Threads) |
|
static void | Debug_ThreadInfo (int argc, const char *argv[]) |
|
| REGISTER_DBGCMD (threadinfo, "Display current thread state", Debug_ThreadInfo) |
|
◆ Debug_ThreadInfo()
static void Debug_ThreadInfo |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
|
static |
Definition at line 384 of file thread.c.
385{
387
388 kprintf(
"Current Thread State:\n");
390}
int kprintf(const char *fmt,...)
Thread * curProc[MAX_CPUS]
void Thread_Dump(Thread *thr)
◆ Debug_Threads()
static void Debug_Threads |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
|
static |
Definition at line 354 of file thread.c.
355{
357
358
359
360 for (
int i = 0; i <
MAX_CPUS; i++) {
362 if (thr) {
365 }
366 }
368 {
371 }
373 {
376 }
377
378
379}
ThreadQueue runnableQueue
#define TAILQ_FOREACH(var, head, field)
◆ Handle_GlobalInit()
void Handle_GlobalInit |
( |
| ) |
|
Definition at line 15 of file handle.c.
16{
18}
void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
◆ REGISTER_DBGCMD() [1/2]
REGISTER_DBGCMD |
( |
threadinfo |
, |
|
|
"Display current thread state" |
, |
|
|
Debug_ThreadInfo |
|
|
) |
| |
◆ REGISTER_DBGCMD() [2/2]
REGISTER_DBGCMD |
( |
threads |
, |
|
|
"Display list of threads" |
, |
|
|
Debug_Threads |
|
|
) |
| |
◆ Thread_Create()
Definition at line 96 of file thread.c.
97{
99
100 if (!thr)
102
103 memset(thr, 0,
sizeof(*thr));
104
106
112 }
113
115
124
128
130
131
132 return thr;
133}
void Thread_InitArch(Thread *thr)
void Process_Retain(Process *proc)
void Slab_Free(Slab *slab, void *obj)
void * PAlloc_AllocPage()
void * Slab_Alloc(Slab *slab) __attribute__((malloc))
#define MEM_USERSPACE_STKLEN
#define TAILQ_INSERT_TAIL(head, elm, field)
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
void * memset(void *dst, int c, size_t len)
◆ Thread_Destroy()
static void Thread_Destroy |
( |
Thread * |
thr | ) |
|
|
static |
Definition at line 195 of file thread.c.
196{
198
199
201
202
203
208
209
211
212
214
216}
void Process_Release(Process *proc)
void PAlloc_Release(void *pg)
#define TAILQ_REMOVE(head, elm, field)
◆ Thread_Dump()
void Thread_Dump |
( |
Thread * |
thr | ) |
|
Definition at line 328 of file thread.c.
329{
330 const char *states[] = {
331 "NULL",
332 "RUNNABLE",
333 "RUNNING",
334 "WAITING",
335 "ZOMBIE"
336 };
337
338
350 }
351}
void Process_Dump(Process *proc)
◆ Thread_Init()
Definition at line 53 of file thread.c.
54{
56
59
62
66
68
69
71
72
76}
#define SCHED_STATE_RUNNING
Process * Process_Create(Process *parent, const char *title)
Thread * Thread_Create(Process *proc)
#define SPINLOCK_TYPE_NORMAL
#define SPINLOCK_TYPE_RECURSIVE
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
◆ Thread_InitAP()
◆ Thread_KThreadCreate()
Thread * Thread_KThreadCreate |
( |
void(*)(void *) |
f, |
|
|
void * |
arg |
|
) |
| |
Definition at line 136 of file thread.c.
137{
139 if (!thr)
141
143
144 return thr;
145}
void Thread_SetupKThread(Thread *thr, void(*f)(), uintptr_t arg1, uintptr_t arg2, uintptr_t arg3)
◆ Thread_Lookup()
Thread_Lookup –
Lookup a thread by TID and increment its reference count.
- Parameters
-
[in] | proc | Process within which to find a specific thread. |
[in] | tid | Thread ID of the thread to find. |
- Return values
-
NULL | if the thread isn't found. |
Definition at line 229 of file thread.c.
230{
233
238 thr = t;
239 break;
240 }
241 }
243
244 return thr;
245}
void Thread_Retain(Thread *thr)
◆ Thread_Release()
void Thread_Release |
( |
Thread * |
thr | ) |
|
Thread_Release –
Decrement the reference count for a given thread.
Definition at line 265 of file thread.c.
266{
268 if (__sync_fetch_and_sub(&thr->
refCount, 1) == 1) {
270 }
271}
static void Thread_Destroy(Thread *thr)
◆ Thread_Retain()
void Thread_Retain |
( |
Thread * |
thr | ) |
|
Thread_Retain –
Increment the reference count for a given thread.
Definition at line 253 of file thread.c.
254{
256 __sync_fetch_and_add(&thr->
refCount, 1);
257}
◆ Thread_UThreadCreate()
Definition at line 148 of file thread.c.
149{
152
153 if (!thr)
155
156 memset(thr, 0,
sizeof(*thr));
157
163 }
164
168
173
175
176
178
179
181
183
186
190
191 return thr;
192}
void Thread_SetupUThread(Thread *thr, uintptr_t rip, uintptr_t arg)
bool PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags)
◆ Thread_Wait()
Thread_Wait –
Wait for any thread (tid == TID_ANY) or a specific thread.
Definition at line 279 of file thread.c.
280{
283
285
288 if (!t) {
290 }
291
296 }
297
298
305 }
306 }
307
308 return 0;
309}
void Thread_Release(Thread *thr)
#define TAILQ_FIRST(head)
#define SYSCALL_PACK(_errcode, _val)
◆ ThreadKThreadEntry()
Definition at line 314 of file thread.c.
315{
317
319
321}
TaskStateSegment64 TSS[MAX_CPUS]
void Trap_Pop(TrapFrame *tf)
◆ curProc
Current thread executing on a given CPU.
Definition at line 41 of file sched.c.
◆ kernelProcess
◆ nextProcessID
◆ processList
◆ processSlab
◆ procLock
◆ runnableQueue
ThreadQueue runnableQueue |
|
extern |
All runnable threads.
Definition at line 37 of file sched.c.
◆ schedLock
Scheduler lock that protects all queues.
Definition at line 29 of file sched.c.
◆ threadSlab
◆ TSS
◆ waitQueue
All threads currently waiting.
Definition at line 33 of file sched.c.