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#include <linux/timex.h>
8#include <linux/alarmtimer.h>
9
10union cpu_time_count {
11 cputime_t cpu;
12 unsigned long long sched;
13};
14
15struct cpu_timer_list {
16 struct list_head entry;
17 union cpu_time_count expires, incr;
18 struct task_struct *task;
19 int firing;
20};
21
22
23
24
25
26
27
28
29
30
31
32
33#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
34#define CPUCLOCK_PERTHREAD(clock) \
35 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
36
37#define CPUCLOCK_PERTHREAD_MASK 4
38#define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
39#define CPUCLOCK_CLOCK_MASK 3
40#define CPUCLOCK_PROF 0
41#define CPUCLOCK_VIRT 1
42#define CPUCLOCK_SCHED 2
43#define CPUCLOCK_MAX 3
44#define CLOCKFD CPUCLOCK_MAX
45#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
46
47#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
48 ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
49#define MAKE_THREAD_CPUCLOCK(tid, clock) \
50 MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
51
52#define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD)
53#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
54
55
56struct k_itimer {
57 struct list_head list;
58 spinlock_t it_lock;
59 clockid_t it_clock;
60 timer_t it_id;
61 int it_overrun;
62 int it_overrun_last;
63 int it_requeue_pending;
64#define REQUEUE_PENDING 1
65 int it_sigev_notify;
66 struct signal_struct *it_signal;
67 union {
68 struct pid *it_pid;
69 struct task_struct *it_process;
70 };
71 struct sigqueue *sigq;
72 union {
73 struct {
74 struct hrtimer timer;
75 ktime_t interval;
76 } real;
77 struct cpu_timer_list cpu;
78 struct {
79 unsigned int clock;
80 unsigned int node;
81 unsigned long incr;
82 unsigned long expires;
83 } mmtimer;
84 struct alarm alarmtimer;
85 struct rcu_head rcu;
86 } it;
87};
88
89struct k_clock {
90 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
91 int (*clock_set) (const clockid_t which_clock,
92 const struct timespec *tp);
93 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
94 int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
95 int (*timer_create) (struct k_itimer *timer);
96 int (*nsleep) (const clockid_t which_clock, int flags,
97 struct timespec *, struct timespec __user *);
98 long (*nsleep_restart) (struct restart_block *restart_block);
99 int (*timer_set) (struct k_itimer * timr, int flags,
100 struct itimerspec * new_setting,
101 struct itimerspec * old_setting);
102 int (*timer_del) (struct k_itimer * timr);
103#define TIMER_RETRY 1
104 void (*timer_get) (struct k_itimer * timr,
105 struct itimerspec * cur_setting);
106};
107
108extern struct k_clock clock_posix_cpu;
109extern struct k_clock clock_posix_dynamic;
110
111void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
112
113
114int posix_timer_event(struct k_itimer *timr, int si_private);
115
116void posix_cpu_timer_schedule(struct k_itimer *timer);
117
118void run_posix_cpu_timers(struct task_struct *task);
119void posix_cpu_timers_exit(struct task_struct *task);
120void posix_cpu_timers_exit_group(struct task_struct *task);
121
122void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
123 cputime_t *newval, cputime_t *oldval);
124
125long clock_nanosleep_restart(struct restart_block *restart_block);
126
127void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
128
129#endif
130