posix-cpu-timers: Move prof/virt_ticks into caller
[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
1da177e4 65#define REQUEUE_PENDING 1
03676b41
TG
66
67/**
68 * struct k_itimer - POSIX.1b interval timer structure.
69 * @list: List head for binding the timer to signals->posix_timers
70 * @t_hash: Entry in the posix timer hash table
71 * @it_lock: Lock protecting the timer
d97bb75d 72 * @kclock: Pointer to the k_clock struct handling this timer
03676b41
TG
73 * @it_clock: The posix timer clock id
74 * @it_id: The posix timer id for identifying the timer
21e55c1f 75 * @it_active: Marker that timer is active
03676b41
TG
76 * @it_overrun: The overrun counter for pending signals
77 * @it_overrun_last: The overrun at the time of the last delivered signal
78 * @it_requeue_pending: Indicator that timer waits for being requeued on
79 * signal delivery
80 * @it_sigev_notify: The notify word of sigevent struct for signal delivery
80105cd0 81 * @it_interval: The interval for periodic timers
03676b41
TG
82 * @it_signal: Pointer to the creators signal struct
83 * @it_pid: The pid of the process/task targeted by the signal
84 * @it_process: The task to wakeup on clock_nanosleep (CPU timers)
85 * @sigq: Pointer to preallocated sigqueue
86 * @it: Union representing the various posix timer type
5d99b32a
SAS
87 * internals.
88 * @rcu: RCU head for freeing the timer.
03676b41
TG
89 */
90struct k_itimer {
91 struct list_head list;
92 struct hlist_node t_hash;
93 spinlock_t it_lock;
d97bb75d 94 const struct k_clock *kclock;
03676b41
TG
95 clockid_t it_clock;
96 timer_t it_id;
21e55c1f 97 int it_active;
78c9c4df
TG
98 s64 it_overrun;
99 s64 it_overrun_last;
03676b41
TG
100 int it_requeue_pending;
101 int it_sigev_notify;
80105cd0 102 ktime_t it_interval;
03676b41 103 struct signal_struct *it_signal;
27af4245 104 union {
03676b41
TG
105 struct pid *it_pid;
106 struct task_struct *it_process;
27af4245 107 };
03676b41 108 struct sigqueue *sigq;
1da177e4
LT
109 union {
110 struct {
03676b41 111 struct hrtimer timer;
1da177e4 112 } real;
03676b41 113 struct cpu_timer_list cpu;
9e264762 114 struct {
03676b41 115 struct alarm alarmtimer;
9e264762 116 } alarm;
1da177e4 117 } it;
5d99b32a 118 struct rcu_head rcu;
1da177e4
LT
119};
120
dce3e8fd 121void run_posix_cpu_timers(void);
2a698971
TG
122void posix_cpu_timers_exit(struct task_struct *task);
123void posix_cpu_timers_exit_group(struct task_struct *task);
2a698971 124void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
858cf3a8 125 u64 *newval, u64 *oldval);
1da177e4 126
5ab46b34 127void update_rlimit_cpu(struct task_struct *task, unsigned long rlim_new);
f06febc9 128
ae7795bc 129void posixtimer_rearm(struct kernel_siginfo *info);
1da177e4 130#endif