Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _linux_POSIX_TIMERS_H |
2 | #define _linux_POSIX_TIMERS_H | |
3 | ||
4 | #include <linux/spinlock.h> | |
5 | #include <linux/list.h> | |
6 | #include <linux/sched.h> | |
f1f1d5eb | 7 | #include <linux/timex.h> |
1da177e4 LT |
8 | |
9 | union cpu_time_count { | |
10 | cputime_t cpu; | |
11 | unsigned long long sched; | |
12 | }; | |
13 | ||
14 | struct cpu_timer_list { | |
15 | struct list_head entry; | |
16 | union cpu_time_count expires, incr; | |
17 | struct task_struct *task; | |
18 | int firing; | |
19 | }; | |
20 | ||
81e294cb RC |
21 | /* |
22 | * Bit fields within a clockid: | |
23 | * | |
24 | * The most significant 29 bits hold either a pid or a file descriptor. | |
25 | * | |
26 | * Bit 2 indicates whether a cpu clock refers to a thread or a process. | |
27 | * | |
28 | * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. | |
29 | * | |
30 | * A clockid is invalid if bits 2, 1, and 0 are all set. | |
31 | */ | |
1da177e4 LT |
32 | #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) |
33 | #define CPUCLOCK_PERTHREAD(clock) \ | |
34 | (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) | |
35 | #define CPUCLOCK_PID_MASK 7 | |
36 | #define CPUCLOCK_PERTHREAD_MASK 4 | |
37 | #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) | |
38 | #define CPUCLOCK_CLOCK_MASK 3 | |
39 | #define CPUCLOCK_PROF 0 | |
40 | #define CPUCLOCK_VIRT 1 | |
41 | #define CPUCLOCK_SCHED 2 | |
42 | #define CPUCLOCK_MAX 3 | |
81e294cb RC |
43 | #define CLOCKFD CPUCLOCK_MAX |
44 | #define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK) | |
1da177e4 LT |
45 | |
46 | #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ | |
47 | ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) | |
48 | #define MAKE_THREAD_CPUCLOCK(tid, clock) \ | |
49 | MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) | |
50 | ||
51 | /* POSIX.1b interval timer structure. */ | |
52 | struct k_itimer { | |
53 | struct list_head list; /* free/ allocate list */ | |
54 | spinlock_t it_lock; | |
55 | clockid_t it_clock; /* which timer type */ | |
56 | timer_t it_id; /* timer id */ | |
57 | int it_overrun; /* overrun on pending signal */ | |
58 | int it_overrun_last; /* overrun on last delivered signal */ | |
2a698971 | 59 | int it_requeue_pending; /* waiting to requeue this timer */ |
1da177e4 LT |
60 | #define REQUEUE_PENDING 1 |
61 | int it_sigev_notify; /* notify word of sigevent struct */ | |
27af4245 ON |
62 | struct signal_struct *it_signal; |
63 | union { | |
64 | struct pid *it_pid; /* pid of process to send signal to */ | |
65 | struct task_struct *it_process; /* for clock_nanosleep */ | |
66 | }; | |
1da177e4 LT |
67 | struct sigqueue *sigq; /* signal queue entry. */ |
68 | union { | |
69 | struct { | |
becf8b5d TG |
70 | struct hrtimer timer; |
71 | ktime_t interval; | |
1da177e4 LT |
72 | } real; |
73 | struct cpu_timer_list cpu; | |
74 | struct { | |
75 | unsigned int clock; | |
76 | unsigned int node; | |
77 | unsigned long incr; | |
78 | unsigned long expires; | |
79 | } mmtimer; | |
80 | } it; | |
81 | }; | |
82 | ||
1da177e4 | 83 | struct k_clock { |
a924b04d | 84 | int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); |
1e6d7679 RC |
85 | int (*clock_set) (const clockid_t which_clock, |
86 | const struct timespec *tp); | |
a924b04d | 87 | int (*clock_get) (const clockid_t which_clock, struct timespec * tp); |
f1f1d5eb | 88 | int (*clock_adj) (const clockid_t which_clock, struct timex *tx); |
1da177e4 | 89 | int (*timer_create) (struct k_itimer *timer); |
2a698971 | 90 | int (*nsleep) (const clockid_t which_clock, int flags, |
97735f25 | 91 | struct timespec *, struct timespec __user *); |
1711ef38 | 92 | long (*nsleep_restart) (struct restart_block *restart_block); |
1da177e4 LT |
93 | int (*timer_set) (struct k_itimer * timr, int flags, |
94 | struct itimerspec * new_setting, | |
95 | struct itimerspec * old_setting); | |
96 | int (*timer_del) (struct k_itimer * timr); | |
97 | #define TIMER_RETRY 1 | |
98 | void (*timer_get) (struct k_itimer * timr, | |
99 | struct itimerspec * cur_setting); | |
100 | }; | |
101 | ||
1976945e TG |
102 | extern struct k_clock clock_posix_cpu; |
103 | ||
a924b04d | 104 | void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock); |
1da177e4 | 105 | |
1da177e4 LT |
106 | /* function to call to trigger timer event */ |
107 | int posix_timer_event(struct k_itimer *timr, int si_private); | |
108 | ||
2a698971 TG |
109 | void posix_cpu_timer_schedule(struct k_itimer *timer); |
110 | ||
111 | void run_posix_cpu_timers(struct task_struct *task); | |
112 | void posix_cpu_timers_exit(struct task_struct *task); | |
113 | void posix_cpu_timers_exit_group(struct task_struct *task); | |
114 | ||
115 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, | |
116 | cputime_t *newval, cputime_t *oldval); | |
1da177e4 | 117 | |
1711ef38 TA |
118 | long clock_nanosleep_restart(struct restart_block *restart_block); |
119 | ||
5ab46b34 | 120 | void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new); |
f06febc9 | 121 | |
1da177e4 | 122 | #endif |