thread stage 7: Implement basic LWKTs, use a straight round-robin model for
[dragonfly.git] / sys / sys / thread.h
CommitLineData
2df9fa87
MD
1/*
2 * SYS/THREAD.H
3 *
4 * Implements the architecture independant portion of the LWKT
5 * subsystem.
6 *
8ad65e08 7 * $DragonFly: src/sys/sys/thread.h,v 1.3 2003/06/20 02:09:59 dillon Exp $
2df9fa87
MD
8 */
9
10#ifndef _SYS_THREAD_H_
11#define _SYS_THREAD_H_
12
13struct proc;
14struct thread;
8ad65e08 15struct globaldata;
2df9fa87
MD
16
17typedef TAILQ_HEAD(, thread) thread_list_t;
18
19struct thread {
20 TAILQ_ENTRY(thread) td_threadq;
21 struct proc *td_proc; /* (optional) associated process */
22 struct pcb *td_pcb; /* points to pcb and top of kstack */
23 int td_pri; /* 0-31, 0=highest priority */
8ad65e08 24 int td_flags; /* THF flags */
7e1d4bf4 25 char *td_kstack; /* kernel stack */
8ad65e08
MD
26 char *td_sp; /* kernel stack pointer for LWKT restore */
27 void (*td_switch)(struct thread *ntd);
28 thread_list_t *td_waitq;
2df9fa87 29#if 0
2df9fa87
MD
30 int td_bglcount; /* big giant lock count */
31#endif
32};
33
34typedef struct thread *thread_t;
35
8ad65e08
MD
36/*
37 * Thread states. Note that the RUNNING state is independant from the
38 * RUNQ/WAITQ state. That is, a thread's queueing state can be manipulated
39 * while it is running. If a thread is preempted it will always be moved
40 * back to the RUNQ if it isn't on it.
41 */
42
43#define TDF_RUNNING 0x0001 /* currently running */
44#define TDF_RUNQ 0x0002 /* on run queue */
45#define TDF_WAITQ 0x0004 /* on wait queue */
46
2df9fa87
MD
47/*
48 * Thread priorities. Typically only one thread from any given
49 * user process scheduling queue is on the LWKT run queue at a time.
50 * Remember that there is one LWKT run queue per cpu.
51 */
52
53#define THPRI_INT_HIGH 2 /* high priority interrupt */
54#define THPRI_INT_MED 4 /* medium priority interrupt */
55#define THPRI_INT_LOW 6 /* low priority interrupt */
56#define THPRI_INT_SUPPORT 10 /* kernel / high priority support */
57#define THPRI_SOFT_TIMER 12 /* kernel / timer */
58#define THPRI_SOFT_NORM 15 /* kernel / normal */
59#define THPRI_KERN_USER 20 /* kernel / block in syscall */
60#define THPRI_USER_REAL 25 /* user scheduler real time */
61#define THPRI_USER_NORM 27 /* user scheduler normal */
62#define THPRI_USER_IDLE 29 /* user scheduler idle */
63#define THPRI_IDLE_THREAD 31 /* the idle thread */
64
7e1d4bf4
MD
65#define CACHE_NTHREADS 4
66
2df9fa87
MD
67#ifdef _KERNEL
68
69extern struct vm_zone *thread_zone;
70
8ad65e08
MD
71extern void lwkt_gdinit(struct globaldata *gd);
72extern void lwkt_switch(void);
73extern void lwkt_preempt(void);
74extern void lwkt_schedule(thread_t td);
75extern void lwkt_deschedule(thread_t td);
76
2df9fa87
MD
77#endif
78
79#endif
80