]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/sched.h
fef7e323f4701fe04009d1791553823854f8f3a8
[bcachefs-tools-debian] / include / linux / sched.h
1 #ifndef __TOOLS_LINUX_SCHED_H
2 #define __TOOLS_LINUX_SCHED_H
3
4 #include <pthread.h>
5 #include <time.h>
6 #include <linux/atomic.h>
7 #include <linux/bug.h>
8 #include <linux/completion.h>
9 #include <linux/jiffies.h>
10 #include <linux/rwsem.h>
11 #include <linux/time64.h>
12
13 #define TASK_RUNNING            0
14 #define TASK_INTERRUPTIBLE      1
15 #define TASK_UNINTERRUPTIBLE    2
16 #define __TASK_STOPPED          4
17 #define __TASK_TRACED           8
18 /* in tsk->exit_state */
19 #define EXIT_DEAD               16
20 #define EXIT_ZOMBIE             32
21 #define EXIT_TRACE              (EXIT_ZOMBIE | EXIT_DEAD)
22 /* in tsk->state again */
23 #define TASK_DEAD               64
24 #define TASK_WAKEKILL           128
25 #define TASK_WAKING             256
26 #define TASK_PARKED             512
27 #define TASK_NOLOAD             1024
28 #define TASK_NEW                2048
29 #define TASK_IDLE_WORKER        4096
30 #define TASK_STATE_MAX          8192
31 #define TASK_FREEZABLE          (1U << 14)
32
33 /* Convenience macros for the sake of set_task_state */
34 #define TASK_KILLABLE           (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
35 #define TASK_STOPPED            (TASK_WAKEKILL | __TASK_STOPPED)
36 #define TASK_TRACED             (TASK_WAKEKILL | __TASK_TRACED)
37
38 #define TASK_IDLE               (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
39
40 /* Convenience macros for the sake of wake_up */
41 #define TASK_NORMAL             (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
42 #define TASK_ALL                (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
43
44 #define TASK_COMM_LEN 16
45
46 #define PF_EXITING      0x00000004      /* getting shut down */
47 #define PF_EXITPIDONE   0x00000008      /* pi exit done on shut down */
48 #define PF_VCPU         0x00000010      /* I'm a virtual CPU */
49 #define PF_WQ_WORKER    0x00000020      /* I'm a workqueue worker */
50 #define PF_FORKNOEXEC   0x00000040      /* forked but didn't exec */
51 #define PF_MCE_PROCESS  0x00000080      /* process policy on mce errors */
52 #define PF_SUPERPRIV    0x00000100      /* used super-user privileges */
53 #define PF_DUMPCORE     0x00000200      /* dumped core */
54 #define PF_SIGNALED     0x00000400      /* killed by a signal */
55 #define PF_MEMALLOC     0x00000800      /* Allocating memory */
56 #define PF_NPROC_EXCEEDED 0x00001000    /* set_user noticed that RLIMIT_NPROC was exceeded */
57 #define PF_USED_MATH    0x00002000      /* if unset the fpu must be initialized before use */
58 #define PF_USED_ASYNC   0x00004000      /* used async_schedule*(), used by module init */
59 #define PF_NOFREEZE     0x00008000      /* this thread should not be frozen */
60 #define PF_FROZEN       0x00010000      /* frozen for system suspend */
61 #define PF_FSTRANS      0x00020000      /* inside a filesystem transaction */
62 #define PF_KSWAPD       0x00040000      /* I am kswapd */
63 #define PF_MEMALLOC_NOIO 0x00080000     /* Allocating memory without IO involved */
64 #define PF_LESS_THROTTLE 0x00100000     /* Throttle me less: I clean memory */
65 #define PF_KTHREAD      0x00200000      /* I am a kernel thread */
66 #define PF_RANDOMIZE    0x00400000      /* randomize virtual address space */
67 #define PF_SWAPWRITE    0x00800000      /* Allowed to write to swap */
68 #define PF_NO_SETAFFINITY 0x04000000    /* Userland is not allowed to meddle with cpus_allowed */
69 #define PF_MCE_EARLY    0x08000000      /* Early kill for mce process policy */
70 #define PF_MUTEX_TESTER 0x20000000      /* Thread belongs to the rt mutex tester */
71 #define PF_FREEZER_SKIP 0x40000000      /* Freezer should not count it as freezable */
72
73 struct task_struct {
74         pthread_t               thread;
75
76         int                     (*thread_fn)(void *);
77         void                    *thread_data;
78
79         atomic_t                usage;
80         int                     state;
81
82         /* kthread: */
83         unsigned long           kthread_flags;
84         struct completion       exited;
85
86         unsigned                flags;
87
88         bool                    on_cpu;
89         char                    comm[TASK_COMM_LEN];
90         pid_t                   pid;
91
92         struct bio_list         *bio_list;
93
94         struct signal_struct    {
95                 struct rw_semaphore exec_update_lock;
96         }                       *signal, _signal;
97 };
98
99 extern __thread struct task_struct *current;
100
101 #define __set_task_state(tsk, state_value)              \
102         do { (tsk)->state = (state_value); } while (0)
103 #define set_task_state(tsk, state_value)                \
104         smp_store_mb((tsk)->state, (state_value))
105 #define __set_current_state(state_value)                \
106         do { current->state = (state_value); } while (0)
107 #define set_current_state(state_value)                  \
108         smp_store_mb(current->state, (state_value))
109
110 #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
111
112 extern void __put_task_struct(struct task_struct *t);
113
114 static inline void put_task_struct(struct task_struct *t)
115 {
116         if (atomic_dec_and_test(&t->usage))
117                 __put_task_struct(t);
118 }
119
120 #define cond_resched()
121 #define need_resched()  0
122
123 void schedule(void);
124
125 #define MAX_SCHEDULE_TIMEOUT    LONG_MAX
126 long schedule_timeout(long timeout);
127
128 static inline void io_schedule(void)
129 {
130         schedule();
131 }
132
133 static inline long io_schedule_timeout(long timeout)
134 {
135         return schedule_timeout(timeout);
136 }
137
138 int wake_up_process(struct task_struct *);
139
140 static inline u64 ktime_get_seconds(void)
141 {
142         struct timespec ts;
143
144         clock_gettime(CLOCK_MONOTONIC, &ts);
145
146         return ts.tv_sec;
147 }
148
149 static inline u64 ktime_get_real_seconds(void)
150 {
151         struct timespec ts;
152
153         clock_gettime(CLOCK_REALTIME, &ts);
154
155         return ts.tv_sec;
156 }
157
158 static inline void ktime_get_coarse_real_ts64(struct timespec64 *ts)
159 {
160         clock_gettime(CLOCK_REALTIME_COARSE, ts);
161 }
162
163 #define current_kernel_time64() current_kernel_time()
164 #define CURRENT_TIME            (current_kernel_time())
165
166 static inline unsigned int stack_trace_save_tsk(struct task_struct *task,
167                                   unsigned long *store, unsigned int size,
168                                   unsigned int skipnr)
169 {
170         return 0;
171 }
172
173 #endif /* __TOOLS_LINUX_SCHED_H */