]>
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> | |
7 | ||
8 | union cpu_time_count { | |
9 | cputime_t cpu; | |
10 | unsigned long long sched; | |
11 | }; | |
12 | ||
13 | struct cpu_timer_list { | |
14 | struct list_head entry; | |
15 | union cpu_time_count expires, incr; | |
16 | struct task_struct *task; | |
17 | int firing; | |
18 | }; | |
19 | ||
20 | #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) | |
21 | #define CPUCLOCK_PERTHREAD(clock) \ | |
22 | (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) | |
23 | #define CPUCLOCK_PID_MASK 7 | |
24 | #define CPUCLOCK_PERTHREAD_MASK 4 | |
25 | #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) | |
26 | #define CPUCLOCK_CLOCK_MASK 3 | |
27 | #define CPUCLOCK_PROF 0 | |
28 | #define CPUCLOCK_VIRT 1 | |
29 | #define CPUCLOCK_SCHED 2 | |
30 | #define CPUCLOCK_MAX 3 | |
31 | ||
32 | #define MAKE_PROCESS_CPUCLOCK(pid, clock) \ | |
33 | ((~(clockid_t) (pid) << 3) | (clockid_t) (clock)) | |
34 | #define MAKE_THREAD_CPUCLOCK(tid, clock) \ | |
35 | MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK) | |
36 | ||
37 | /* POSIX.1b interval timer structure. */ | |
38 | struct k_itimer { | |
39 | struct list_head list; /* free/ allocate list */ | |
40 | spinlock_t it_lock; | |
41 | clockid_t it_clock; /* which timer type */ | |
42 | timer_t it_id; /* timer id */ | |
43 | int it_overrun; /* overrun on pending signal */ | |
44 | int it_overrun_last; /* overrun on last delivered signal */ | |
2a698971 | 45 | int it_requeue_pending; /* waiting to requeue this timer */ |
1da177e4 LT |
46 | #define REQUEUE_PENDING 1 |
47 | int it_sigev_notify; /* notify word of sigevent struct */ | |
48 | int it_sigev_signo; /* signo word of sigevent struct */ | |
49 | sigval_t it_sigev_value; /* value word of sigevent struct */ | |
50 | struct task_struct *it_process; /* process to send signal to */ | |
51 | struct sigqueue *sigq; /* signal queue entry. */ | |
52 | union { | |
53 | struct { | |
54 | struct timer_list timer; | |
2a698971 TG |
55 | /* clock abs_timer_list: */ |
56 | struct list_head abs_timer_entry; | |
57 | /* wall_to_monotonic used when set: */ | |
58 | struct timespec wall_to_prev; | |
1da177e4 LT |
59 | unsigned long incr; /* interval in jiffies */ |
60 | } real; | |
61 | struct cpu_timer_list cpu; | |
62 | struct { | |
63 | unsigned int clock; | |
64 | unsigned int node; | |
65 | unsigned long incr; | |
66 | unsigned long expires; | |
67 | } mmtimer; | |
68 | } it; | |
69 | }; | |
70 | ||
71 | struct k_clock_abs { | |
72 | struct list_head list; | |
73 | spinlock_t lock; | |
74 | }; | |
2a698971 | 75 | |
1da177e4 | 76 | struct k_clock { |
2a698971 | 77 | int res; /* in nanoseconds */ |
a924b04d | 78 | int (*clock_getres) (const clockid_t which_clock, struct timespec *tp); |
1da177e4 | 79 | struct k_clock_abs *abs_struct; |
a924b04d TG |
80 | int (*clock_set) (const clockid_t which_clock, struct timespec * tp); |
81 | int (*clock_get) (const clockid_t which_clock, struct timespec * tp); | |
1da177e4 | 82 | int (*timer_create) (struct k_itimer *timer); |
2a698971 | 83 | int (*nsleep) (const clockid_t which_clock, int flags, |
97735f25 | 84 | struct timespec *, struct timespec __user *); |
1da177e4 LT |
85 | int (*timer_set) (struct k_itimer * timr, int flags, |
86 | struct itimerspec * new_setting, | |
87 | struct itimerspec * old_setting); | |
88 | int (*timer_del) (struct k_itimer * timr); | |
89 | #define TIMER_RETRY 1 | |
90 | void (*timer_get) (struct k_itimer * timr, | |
91 | struct itimerspec * cur_setting); | |
92 | }; | |
93 | ||
a924b04d | 94 | void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock); |
1da177e4 | 95 | |
2a698971 | 96 | /* error handlers for timer_create, nanosleep and settime */ |
1da177e4 | 97 | int do_posix_clock_notimer_create(struct k_itimer *timer); |
97735f25 TG |
98 | int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *, |
99 | struct timespec __user *); | |
a924b04d | 100 | int do_posix_clock_nosettime(const clockid_t, struct timespec *tp); |
1da177e4 LT |
101 | |
102 | /* function to call to trigger timer event */ | |
103 | int posix_timer_event(struct k_itimer *timr, int si_private); | |
104 | ||
105 | struct now_struct { | |
106 | unsigned long jiffies; | |
107 | }; | |
108 | ||
2a698971 TG |
109 | #define posix_get_now(now) \ |
110 | do { (now)->jiffies = jiffies; } while (0) | |
111 | ||
1da177e4 LT |
112 | #define posix_time_before(timer, now) \ |
113 | time_before((timer)->expires, (now)->jiffies) | |
114 | ||
115 | #define posix_bump_timer(timr, now) \ | |
2a698971 TG |
116 | do { \ |
117 | long delta, orun; \ | |
118 | \ | |
119 | delta = (now).jiffies - (timr)->it.real.timer.expires; \ | |
120 | if (delta >= 0) { \ | |
121 | orun = 1 + (delta / (timr)->it.real.incr); \ | |
122 | (timr)->it.real.timer.expires += \ | |
123 | orun * (timr)->it.real.incr; \ | |
124 | (timr)->it_overrun += orun; \ | |
125 | } \ | |
126 | } while (0) | |
127 | ||
128 | int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *ts); | |
129 | int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *ts); | |
130 | int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *ts); | |
131 | int posix_cpu_timer_create(struct k_itimer *timer); | |
132 | int posix_cpu_nsleep(const clockid_t which_clock, int flags, | |
97735f25 | 133 | struct timespec *rqtp, struct timespec __user *rmtp); |
2a698971 TG |
134 | int posix_cpu_timer_set(struct k_itimer *timer, int flags, |
135 | struct itimerspec *new, struct itimerspec *old); | |
136 | int posix_cpu_timer_del(struct k_itimer *timer); | |
137 | void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp); | |
138 | ||
139 | void posix_cpu_timer_schedule(struct k_itimer *timer); | |
140 | ||
141 | void run_posix_cpu_timers(struct task_struct *task); | |
142 | void posix_cpu_timers_exit(struct task_struct *task); | |
143 | void posix_cpu_timers_exit_group(struct task_struct *task); | |
144 | ||
145 | void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx, | |
146 | cputime_t *newval, cputime_t *oldval); | |
1da177e4 LT |
147 | |
148 | #endif |