posix-cpu-timers: Remove cputime_expires
[linux-block.git] / include / linux / posix-timers.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _linux_POSIX_TIMERS_H
3#define _linux_POSIX_TIMERS_H
4
5#include <linux/spinlock.h>
6#include <linux/list.h>
9a7adcf5 7#include <linux/alarmtimer.h>
1da177e4 8
ce03f613
TG
9struct kernel_siginfo;
10struct task_struct;
55ccb616 11
1da177e4
LT
12struct cpu_timer_list {
13 struct list_head entry;
16118794 14 u64 expires;
1da177e4
LT
15 struct task_struct *task;
16 int firing;
17};
18
81e294cb
RC
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 */
1da177e4
LT
30#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
31#define CPUCLOCK_PERTHREAD(clock) \
32 (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
0606f422 33
1da177e4
LT
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
81e294cb
RC
41#define CLOCKFD CPUCLOCK_MAX
42#define CLOCKFD_MASK (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
1da177e4 43
29f1b2b0
ND
44static inline clockid_t make_process_cpuclock(const unsigned int pid,
45 const clockid_t clock)
46{
47 return ((~pid) << 3) | clock;
48}
49static inline clockid_t make_thread_cpuclock(const unsigned int tid,
50 const clockid_t clock)
51{
52 return make_process_cpuclock(tid, clock | CPUCLOCK_PERTHREAD_MASK);
53}
1da177e4 54
29f1b2b0
ND
55static inline clockid_t fd_to_clockid(const int fd)
56{
57 return make_process_cpuclock((unsigned int) fd, CLOCKFD);
58}
59
60static inline int clockid_to_fd(const clockid_t clk)
61{
62 return ~(clk >> 3);
63}
0606f422 64
2b69942f
TG
65#ifdef CONFIG_POSIX_TIMERS
66/**
67 * posix_cputimers - Container for posix CPU timer related data
11b8462f 68 * @expiries: Earliest-expiration cache array based
2b69942f
TG
69 * @cpu_timers: List heads to queue posix CPU timers
70 *
71 * Used in task_struct and signal_struct
72 */
73struct posix_cputimers {
46b88399
TG
74 u64 expiries[CPUCLOCK_MAX];
75 struct list_head cpu_timers[CPUCLOCK_MAX];
2b69942f
TG
76};
77
78static inline void posix_cputimers_init(struct posix_cputimers *pct)
79{
11b8462f 80 memset(&pct->expiries, 0, sizeof(pct->expiries));
2b69942f
TG
81 INIT_LIST_HEAD(&pct->cpu_timers[0]);
82 INIT_LIST_HEAD(&pct->cpu_timers[1]);
83 INIT_LIST_HEAD(&pct->cpu_timers[2]);
84}
85
3a245c0f
TG
86void posix_cputimers_group_init(struct posix_cputimers *pct, u64 cpu_limit);
87
88static inline void posix_cputimers_rt_watchdog(struct posix_cputimers *pct,
89 u64 runtime)
90{
11b8462f 91 pct->expiries[CPUCLOCK_SCHED] = runtime;
3a245c0f
TG
92}
93
2b69942f
TG
94/* Init task static initializer */
95#define INIT_CPU_TIMERLISTS(c) { \
96 LIST_HEAD_INIT(c.cpu_timers[0]), \
97 LIST_HEAD_INIT(c.cpu_timers[1]), \
98 LIST_HEAD_INIT(c.cpu_timers[2]), \
99}
100
101#define INIT_CPU_TIMERS(s) \
102 .posix_cputimers = { \
103 .cpu_timers = INIT_CPU_TIMERLISTS(s.posix_cputimers), \
104 },
105#else
106struct posix_cputimers { };
107#define INIT_CPU_TIMERS(s)
3a245c0f
TG
108static inline void posix_cputimers_init(struct posix_cputimers *pct) { }
109static inline void posix_cputimers_group_init(struct posix_cputimers *pct,
110 u64 cpu_limit) { }
2b69942f
TG
111#endif
112
1da177e4 113#define REQUEUE_PENDING 1
03676b41
TG
114
115/**
116 * struct k_itimer - POSIX.1b interval timer structure.
117 * @list: List head for binding the timer to signals->posix_timers
118 * @t_hash: Entry in the posix timer hash table
119 * @it_lock: Lock protecting the timer
d97bb75d 120 * @kclock: Pointer to the k_clock struct handling this timer
03676b41
TG
121 * @it_clock: The posix timer clock id
122 * @it_id: The posix timer id for identifying the timer
21e55c1f 123 * @it_active: Marker that timer is active
03676b41
TG
124 * @it_overrun: The overrun counter for pending signals
125 * @it_overrun_last: The overrun at the time of the last delivered signal
126 * @it_requeue_pending: Indicator that timer waits for being requeued on
127 * signal delivery
128 * @it_sigev_notify: The notify word of sigevent struct for signal delivery
80105cd0 129 * @it_interval: The interval for periodic timers
03676b41
TG
130 * @it_signal: Pointer to the creators signal struct
131 * @it_pid: The pid of the process/task targeted by the signal
132 * @it_process: The task to wakeup on clock_nanosleep (CPU timers)
133 * @sigq: Pointer to preallocated sigqueue
134 * @it: Union representing the various posix timer type
5d99b32a
SAS
135 * internals.
136 * @rcu: RCU head for freeing the timer.
03676b41
TG
137 */
138struct k_itimer {
139 struct list_head list;
140 struct hlist_node t_hash;
141 spinlock_t it_lock;
d97bb75d 142 const struct k_clock *kclock;
03676b41
TG
143 clockid_t it_clock;
144 timer_t it_id;
21e55c1f 145 int it_active;
78c9c4df
TG
146 s64 it_overrun;
147 s64 it_overrun_last;
03676b41
TG
148 int it_requeue_pending;
149 int it_sigev_notify;
80105cd0 150 ktime_t it_interval;
03676b41 151 struct signal_struct *it_signal;
27af4245 152 union {
03676b41
TG
153 struct pid *it_pid;
154 struct task_struct *it_process;
27af4245 155 };
03676b41 156 struct sigqueue *sigq;
1da177e4
LT
157 union {
158 struct {
03676b41 159 struct hrtimer timer;
1da177e4 160 } real;
03676b41 161 struct cpu_timer_list cpu;
9e264762 162 struct {
03676b41 163 struct alarm alarmtimer;
9e264762 164 } alarm;
1da177e4 165 } it;
5d99b32a 166 struct rcu_head rcu;
1da177e4
LT
167};
168
dce3e8fd 169void run_posix_cpu_timers(void);
2a698971
TG
170void posix_cpu_timers_exit(struct task_struct *task);
171void posix_cpu_timers_exit_group(struct task_struct *task);
2a698971 172void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
858cf3a8 173 u64 *newval, u64 *oldval);
1da177e4 174
5ab46b34 175void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
f06febc9 176
ae7795bc 177void posixtimer_rearm(struct kernel_siginfo *info);
1da177e4 178#endif