1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _linux_POSIX_TIMERS_TYPES_H
3#define _linux_POSIX_TIMERS_TYPES_H
4
5#include <linux/mutex_types.h>
6#include <linux/timerqueue_types.h>
7#include <linux/types.h>
8
9/*
10 * Bit fields within a clockid:
11 *
12 * The most significant 29 bits hold either a pid or a file descriptor.
13 *
14 * Bit 2 indicates whether a cpu clock refers to a thread or a process.
15 *
16 * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
17 *
18 * A clockid is invalid if bits 2, 1, and 0 are all set.
19 */
20#define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
21#define CPUCLOCK_PERTHREAD(clock) \
22	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
23
24#define CPUCLOCK_PERTHREAD_MASK	4
25#define CPUCLOCK_WHICH(clock)	((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
26#define CPUCLOCK_CLOCK_MASK	3
27#define CPUCLOCK_PROF		0
28#define CPUCLOCK_VIRT		1
29#define CPUCLOCK_SCHED		2
30#define CPUCLOCK_MAX		3
31#define CLOCKFD			CPUCLOCK_MAX
32#define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
33
34#ifdef CONFIG_POSIX_TIMERS
35
36/**
37 * posix_cputimer_base - Container per posix CPU clock
38 * @nextevt:		Earliest-expiration cache
39 * @tqhead:		timerqueue head for cpu_timers
40 */
41struct posix_cputimer_base {
42	u64			nextevt;
43	struct timerqueue_head	tqhead;
44};
45
46/**
47 * posix_cputimers - Container for posix CPU timer related data
48 * @bases:		Base container for posix CPU clocks
49 * @timers_active:	Timers are queued.
50 * @expiry_active:	Timer expiry is active. Used for
51 *			process wide timers to avoid multiple
52 *			task trying to handle expiry concurrently
53 *
54 * Used in task_struct and signal_struct
55 */
56struct posix_cputimers {
57	struct posix_cputimer_base	bases[CPUCLOCK_MAX];
58	unsigned int			timers_active;
59	unsigned int			expiry_active;
60};
61
62/**
63 * posix_cputimers_work - Container for task work based posix CPU timer expiry
64 * @work:	The task work to be scheduled
65 * @mutex:	Mutex held around expiry in context of this task work
66 * @scheduled:  @work has been scheduled already, no further processing
67 */
68struct posix_cputimers_work {
69	struct callback_head	work;
70	struct mutex		mutex;
71	unsigned int		scheduled;
72};
73
74#else /* CONFIG_POSIX_TIMERS */
75
76struct posix_cputimers { };
77
78#endif /* CONFIG_POSIX_TIMERS */
79
80#endif /* _linux_POSIX_TIMERS_TYPES_H */
81