hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/hrtimer.h
....@@ -1,6 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
2
- * include/linux/hrtimer.h
3
- *
43 * hrtimers - High-resolution kernel timers
54 *
65 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
....@@ -9,8 +8,6 @@
98 * data type definitions, declarations, prototypes
109 *
1110 * Started by: Thomas Gleixner and Ingo Molnar
12
- *
13
- * For licencing details see kernel-base/COPYING
1411 */
1512 #ifndef _LINUX_HRTIMER_H
1613 #define _LINUX_HRTIMER_H
....@@ -20,6 +17,7 @@
2017 #include <linux/init.h>
2118 #include <linux/list.h>
2219 #include <linux/percpu.h>
20
+#include <linux/seqlock.h>
2321 #include <linux/timer.h>
2422 #include <linux/timerqueue.h>
2523 #include <linux/android_kabi.h>
....@@ -36,12 +34,15 @@
3634 * when starting the timer)
3735 * HRTIMER_MODE_SOFT - Timer callback function will be executed in
3836 * soft irq context
37
+ * HRTIMER_MODE_HARD - Timer callback function will be executed in
38
+ * hard irq context even on PREEMPT_RT.
3939 */
4040 enum hrtimer_mode {
4141 HRTIMER_MODE_ABS = 0x00,
4242 HRTIMER_MODE_REL = 0x01,
4343 HRTIMER_MODE_PINNED = 0x02,
4444 HRTIMER_MODE_SOFT = 0x04,
45
+ HRTIMER_MODE_HARD = 0x08,
4546
4647 HRTIMER_MODE_ABS_PINNED = HRTIMER_MODE_ABS | HRTIMER_MODE_PINNED,
4748 HRTIMER_MODE_REL_PINNED = HRTIMER_MODE_REL | HRTIMER_MODE_PINNED,
....@@ -52,6 +53,11 @@
5253 HRTIMER_MODE_ABS_PINNED_SOFT = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_SOFT,
5354 HRTIMER_MODE_REL_PINNED_SOFT = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_SOFT,
5455
56
+ HRTIMER_MODE_ABS_HARD = HRTIMER_MODE_ABS | HRTIMER_MODE_HARD,
57
+ HRTIMER_MODE_REL_HARD = HRTIMER_MODE_REL | HRTIMER_MODE_HARD,
58
+
59
+ HRTIMER_MODE_ABS_PINNED_HARD = HRTIMER_MODE_ABS_PINNED | HRTIMER_MODE_HARD,
60
+ HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD,
5561 };
5662
5763 /*
....@@ -105,6 +111,8 @@
105111 * @state: state information (See bit values above)
106112 * @is_rel: Set if the timer was armed relative
107113 * @is_soft: Set if hrtimer will be expired in soft interrupt context.
114
+ * @is_hard: Set if hrtimer will be expired in hard interrupt context
115
+ * even on RT.
108116 *
109117 * The hrtimer structure must be initialized by hrtimer_init()
110118 */
....@@ -116,6 +124,7 @@
116124 u8 state;
117125 u8 is_rel;
118126 u8 is_soft;
127
+ u8 is_hard;
119128
120129 ANDROID_KABI_RESERVE(1);
121130 };
....@@ -154,7 +163,7 @@
154163 struct hrtimer_cpu_base *cpu_base;
155164 unsigned int index;
156165 clockid_t clockid;
157
- seqcount_t seq;
166
+ seqcount_raw_spinlock_t seq;
158167 struct hrtimer *running;
159168 struct timerqueue_head active;
160169 ktime_t (*get_time)(void);
....@@ -189,6 +198,10 @@
189198 * @nr_retries: Total number of hrtimer interrupt retries
190199 * @nr_hangs: Total number of hrtimer interrupt hangs
191200 * @max_hang_time: Maximum time spent in hrtimer_interrupt
201
+ * @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are
202
+ * expired
203
+ * @timer_waiters: A hrtimer_cancel() invocation waits for the timer
204
+ * callback to finish.
192205 * @expires_next: absolute time of the next event, is required for remote
193206 * hrtimer enqueue; it is the total first expiry time (hard
194207 * and soft hrtimer are taken into account)
....@@ -215,6 +228,10 @@
215228 unsigned short nr_retries;
216229 unsigned short nr_hangs;
217230 unsigned int max_hang_time;
231
+#endif
232
+#ifdef CONFIG_PREEMPT_RT
233
+ spinlock_t softirq_expiry_lock;
234
+ atomic_t timer_waiters;
218235 #endif
219236 ktime_t expires_next;
220237 struct hrtimer *next_timer;
....@@ -304,15 +321,11 @@
304321
305322 extern void hrtimer_interrupt(struct clock_event_device *dev);
306323
307
-extern void clock_was_set_delayed(void);
308
-
309324 extern unsigned int hrtimer_resolution;
310325
311326 #else
312327
313328 #define hrtimer_resolution (unsigned int)LOW_RES_NSEC
314
-
315
-static inline void clock_was_set_delayed(void) { }
316329
317330 #endif
318331
....@@ -337,7 +350,6 @@
337350 timer->base->get_time());
338351 }
339352
340
-extern void clock_was_set(void);
341353 #ifdef CONFIG_TIMERFD
342354 extern void timerfd_clock_was_set(void);
343355 #else
....@@ -347,16 +359,29 @@
347359
348360 DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
349361
362
+#ifdef CONFIG_PREEMPT_RT
363
+void hrtimer_cancel_wait_running(const struct hrtimer *timer);
364
+#else
365
+static inline void hrtimer_cancel_wait_running(struct hrtimer *timer)
366
+{
367
+ cpu_relax();
368
+}
369
+#endif
350370
351371 /* Exported timer functions: */
352372
353373 /* Initialize timers: */
354374 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
355375 enum hrtimer_mode mode);
376
+extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id,
377
+ enum hrtimer_mode mode);
356378
357379 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
358380 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
359381 enum hrtimer_mode mode);
382
+extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
383
+ clockid_t clock_id,
384
+ enum hrtimer_mode mode);
360385
361386 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
362387 #else
....@@ -366,6 +391,14 @@
366391 {
367392 hrtimer_init(timer, which_clock, mode);
368393 }
394
+
395
+static inline void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
396
+ clockid_t clock_id,
397
+ enum hrtimer_mode mode)
398
+{
399
+ hrtimer_init_sleeper(sl, clock_id, mode);
400
+}
401
+
369402 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
370403 #endif
371404
....@@ -400,6 +433,9 @@
400433 delta = ktime_to_ns(ktime_sub(hard, soft));
401434 hrtimer_start_range_ns(timer, soft, delta, mode);
402435 }
436
+
437
+void hrtimer_sleeper_start_expires(struct hrtimer_sleeper *sl,
438
+ enum hrtimer_mode mode);
403439
404440 static inline void hrtimer_restart(struct hrtimer *timer)
405441 {
....@@ -471,15 +507,11 @@
471507 /* Precise sleep: */
472508
473509 extern int nanosleep_copyout(struct restart_block *, struct timespec64 *);
474
-extern long hrtimer_nanosleep(const struct timespec64 *rqtp,
475
- const enum hrtimer_mode mode,
510
+extern long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,
476511 const clockid_t clockid);
477512
478
-extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
479
- struct task_struct *tsk);
480
-
481513 extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta,
482
- const enum hrtimer_mode mode);
514
+ const enum hrtimer_mode mode);
483515 extern int schedule_hrtimeout_range_clock(ktime_t *expires,
484516 u64 delta,
485517 const enum hrtimer_mode mode,