]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/posix-timers.h
posix-timers: Move posix-timer internals to core
[karo-tx-linux.git] / include / linux / posix-timers.h
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
10 struct siginfo;
11
12 struct cpu_timer_list {
13         struct list_head entry;
14         u64 expires, incr;
15         struct task_struct *task;
16         int firing;
17 };
18
19 /*
20  * Bit fields within a clockid:
21  *
22  * The most significant 29 bits hold either a pid or a file descriptor.
23  *
24  * Bit 2 indicates whether a cpu clock refers to a thread or a process.
25  *
26  * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
27  *
28  * A clockid is invalid if bits 2, 1, and 0 are all set.
29  */
30 #define CPUCLOCK_PID(clock)             ((pid_t) ~((clock) >> 3))
31 #define CPUCLOCK_PERTHREAD(clock) \
32         (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
33
34 #define CPUCLOCK_PERTHREAD_MASK 4
35 #define CPUCLOCK_WHICH(clock)   ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
36 #define CPUCLOCK_CLOCK_MASK     3
37 #define CPUCLOCK_PROF           0
38 #define CPUCLOCK_VIRT           1
39 #define CPUCLOCK_SCHED          2
40 #define CPUCLOCK_MAX            3
41 #define CLOCKFD                 CPUCLOCK_MAX
42 #define CLOCKFD_MASK            (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
43
44 #define MAKE_PROCESS_CPUCLOCK(pid, clock) \
45         ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
46 #define MAKE_THREAD_CPUCLOCK(tid, clock) \
47         MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
48
49 #define FD_TO_CLOCKID(fd)       ((~(clockid_t) (fd) << 3) | CLOCKFD)
50 #define CLOCKID_TO_FD(clk)      ((unsigned int) ~((clk) >> 3))
51
52 #define REQUEUE_PENDING 1
53
54 /**
55  * struct k_itimer - POSIX.1b interval timer structure.
56  * @list:               List head for binding the timer to signals->posix_timers
57  * @t_hash:             Entry in the posix timer hash table
58  * @it_lock:            Lock protecting the timer
59  * @it_clock:           The posix timer clock id
60  * @it_id:              The posix timer id for identifying the timer
61  * @it_overrun:         The overrun counter for pending signals
62  * @it_overrun_last:    The overrun at the time of the last delivered signal
63  * @it_requeue_pending: Indicator that timer waits for being requeued on
64  *                      signal delivery
65  * @it_sigev_notify:    The notify word of sigevent struct for signal delivery
66  * @it_signal:          Pointer to the creators signal struct
67  * @it_pid:             The pid of the process/task targeted by the signal
68  * @it_process:         The task to wakeup on clock_nanosleep (CPU timers)
69  * @sigq:               Pointer to preallocated sigqueue
70  * @it:                 Union representing the various posix timer type
71  *                      internals. Also used for rcu freeing the timer.
72  */
73 struct k_itimer {
74         struct list_head        list;
75         struct hlist_node       t_hash;
76         spinlock_t              it_lock;
77         clockid_t               it_clock;
78         timer_t                 it_id;
79         int                     it_overrun;
80         int                     it_overrun_last;
81         int                     it_requeue_pending;
82         int                     it_sigev_notify;
83         struct signal_struct    *it_signal;
84         union {
85                 struct pid              *it_pid;
86                 struct task_struct      *it_process;
87         };
88         struct sigqueue         *sigq;
89         union {
90                 struct {
91                         struct hrtimer  timer;
92                         ktime_t         interval;
93                 } real;
94                 struct cpu_timer_list   cpu;
95                 struct {
96                         struct alarm    alarmtimer;
97                         ktime_t         interval;
98                 } alarm;
99                 struct rcu_head         rcu;
100         } it;
101 };
102
103 void run_posix_cpu_timers(struct task_struct *task);
104 void posix_cpu_timers_exit(struct task_struct *task);
105 void posix_cpu_timers_exit_group(struct task_struct *task);
106 void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
107                            u64 *newval, u64 *oldval);
108
109 long clock_nanosleep_restart(struct restart_block *restart_block);
110
111 void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
112
113 void do_schedule_next_timer(struct siginfo *info);
114
115 #endif