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