@@ -17,6 +17,27 @@ void __weak arch_do_signal_or_restart(struct pt_regs *regs) { }
1717#define EXIT_TO_USER_MODE_WORK_LOOP (EXIT_TO_USER_MODE_WORK)
1818#endif
1919
20+ /* TIF bits, which prevent a time slice extension. */
21+ #ifdef CONFIG_PREEMPT_RT
22+ /*
23+ * Since rseq slice ext has a direct correlation to the worst case
24+ * scheduling latency (schedule is delayed after all), only have it affect
25+ * LAZY reschedules on PREEMPT_RT for now.
26+ *
27+ * However, since this delay is only applicable to userspace, a value
28+ * for rseq_slice_extension_nsec that is strictly less than the worst case
29+ * kernel space preempt_disable() region, should mean the scheduling latency
30+ * is not affected, even for !LAZY.
31+ *
32+ * However, since this value depends on the hardware at hand, it cannot be
33+ * pre-determined in any sensible way. Hence punt on this problem for now.
34+ */
35+ # define TIF_SLICE_EXT_SCHED (_TIF_NEED_RESCHED_LAZY)
36+ #else
37+ # define TIF_SLICE_EXT_SCHED (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
38+ #endif
39+ #define TIF_SLICE_EXT_DENY (EXIT_TO_USER_MODE_WORK & ~TIF_SLICE_EXT_SCHED)
40+
2041static __always_inline unsigned long __exit_to_user_mode_loop (struct pt_regs * regs ,
2142 unsigned long ti_work )
2243{
@@ -28,8 +49,10 @@ static __always_inline unsigned long __exit_to_user_mode_loop(struct pt_regs *re
2849
2950 local_irq_enable_exit_to_user (ti_work );
3051
31- if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY ))
32- schedule ();
52+ if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY )) {
53+ if (!rseq_grant_slice_extension (ti_work & TIF_SLICE_EXT_DENY ))
54+ schedule ();
55+ }
3356
3457 if (ti_work & _TIF_UPROBE )
3558 uprobe_notify_resume (regs );
0 commit comments