From 6778948f9de86c3cfaf36725a7c87dcff9ba247f Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Mon, 11 Dec 2023 08:20:59 +0000 Subject: [PATCH] kernel_5.10 no rt --- kernel/include/linux/preempt.h | 190 +++++++++-------------------------------------- 1 files changed, 38 insertions(+), 152 deletions(-) diff --git a/kernel/include/linux/preempt.h b/kernel/include/linux/preempt.h index 7b5b2ed..7d9c1c0 100644 --- a/kernel/include/linux/preempt.h +++ b/kernel/include/linux/preempt.h @@ -77,37 +77,31 @@ /* preempt_count() and related functions, depends on PREEMPT_NEED_RESCHED */ #include <asm/preempt.h> -#define nmi_count() (preempt_count() & NMI_MASK) #define hardirq_count() (preempt_count() & HARDIRQ_MASK) -#ifdef CONFIG_PREEMPT_RT -# define softirq_count() (current->softirq_disable_cnt & SOFTIRQ_MASK) -#else -# define softirq_count() (preempt_count() & SOFTIRQ_MASK) -#endif -#define irq_count() (nmi_count() | hardirq_count() | softirq_count()) +#define softirq_count() (preempt_count() & SOFTIRQ_MASK) +#define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \ + | NMI_MASK)) /* - * Macros to retrieve the current execution context: + * Are we doing bottom half or hardware interrupt processing? * - * in_nmi() - We're in NMI context - * in_hardirq() - We're in hard IRQ context - * in_serving_softirq() - We're in softirq context - * in_task() - We're in task context - */ -#define in_nmi() (nmi_count()) -#define in_hardirq() (hardirq_count()) -#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET) -#define in_task() (!(in_nmi() | in_hardirq() | in_serving_softirq())) - -/* - * The following macros are deprecated and should not be used in new code: - * in_irq() - Obsolete version of in_hardirq() + * in_irq() - We're in (hard) IRQ context * in_softirq() - We have BH disabled, or are processing softirqs * in_interrupt() - We're in NMI,IRQ,SoftIRQ context or have BH disabled + * in_serving_softirq() - We're in softirq context + * in_nmi() - We're in NMI context + * in_task() - We're in task context + * + * Note: due to the BH disabled confusion: in_softirq(),in_interrupt() really + * should not be used in new code. */ #define in_irq() (hardirq_count()) #define in_softirq() (softirq_count()) #define in_interrupt() (irq_count()) +#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET) +#define in_nmi() (preempt_count() & NMI_MASK) +#define in_task() (!(preempt_count() & \ + (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET))) /* * The preempt_count offset after preempt_disable(); @@ -121,11 +115,7 @@ /* * The preempt_count offset after spin_lock() */ -#if !defined(CONFIG_PREEMPT_RT) #define PREEMPT_LOCK_OFFSET PREEMPT_DISABLE_OFFSET -#else -#define PREEMPT_LOCK_OFFSET 0 -#endif /* * The preempt_count offset needed for things like: @@ -174,31 +164,11 @@ #define preempt_count_inc() preempt_count_add(1) #define preempt_count_dec() preempt_count_sub(1) -#ifdef CONFIG_PREEMPT_LAZY -#define add_preempt_lazy_count(val) do { preempt_lazy_count() += (val); } while (0) -#define sub_preempt_lazy_count(val) do { preempt_lazy_count() -= (val); } while (0) -#define inc_preempt_lazy_count() add_preempt_lazy_count(1) -#define dec_preempt_lazy_count() sub_preempt_lazy_count(1) -#define preempt_lazy_count() (current_thread_info()->preempt_lazy_count) -#else -#define add_preempt_lazy_count(val) do { } while (0) -#define sub_preempt_lazy_count(val) do { } while (0) -#define inc_preempt_lazy_count() do { } while (0) -#define dec_preempt_lazy_count() do { } while (0) -#define preempt_lazy_count() (0) -#endif - #ifdef CONFIG_PREEMPT_COUNT #define preempt_disable() \ do { \ preempt_count_inc(); \ - barrier(); \ -} while (0) - -#define preempt_lazy_disable() \ -do { \ - inc_preempt_lazy_count(); \ barrier(); \ } while (0) @@ -208,13 +178,7 @@ preempt_count_dec(); \ } while (0) -#ifndef CONFIG_PREEMPT_RT -# define preempt_enable_no_resched() sched_preempt_enable_no_resched() -# define preempt_check_resched_rt() barrier(); -#else -# define preempt_enable_no_resched() preempt_enable() -# define preempt_check_resched_rt() preempt_check_resched() -#endif +#define preempt_enable_no_resched() sched_preempt_enable_no_resched() #define preemptible() (preempt_count() == 0 && !irqs_disabled()) @@ -239,29 +203,11 @@ __preempt_schedule(); \ } while (0) -/* - * open code preempt_check_resched() because it is not exported to modules and - * used by local_unlock() or bpf_enable_instrumentation(). - */ -#define preempt_lazy_enable() \ -do { \ - dec_preempt_lazy_count(); \ - barrier(); \ - if (should_resched(0)) \ - __preempt_schedule(); \ -} while (0) - #else /* !CONFIG_PREEMPTION */ #define preempt_enable() \ do { \ barrier(); \ preempt_count_dec(); \ -} while (0) - -#define preempt_lazy_enable() \ -do { \ - dec_preempt_lazy_count(); \ - barrier(); \ } while (0) #define preempt_enable_notrace() \ @@ -302,11 +248,7 @@ #define preempt_disable_notrace() barrier() #define preempt_enable_no_resched_notrace() barrier() #define preempt_enable_notrace() barrier() -#define preempt_check_resched_rt() barrier() #define preemptible() 0 - -#define preempt_lazy_disable() barrier() -#define preempt_lazy_enable() barrier() #endif /* CONFIG_PREEMPT_COUNT */ @@ -326,21 +268,9 @@ } while (0) #define preempt_fold_need_resched() \ do { \ - if (tif_need_resched_now()) \ + if (tif_need_resched()) \ set_preempt_need_resched(); \ } while (0) - -#ifdef CONFIG_PREEMPT_RT -# define preempt_disable_rt() preempt_disable() -# define preempt_enable_rt() preempt_enable() -# define preempt_disable_nort() barrier() -# define preempt_enable_nort() barrier() -#else -# define preempt_disable_rt() barrier() -# define preempt_enable_rt() barrier() -# define preempt_disable_nort() preempt_disable() -# define preempt_enable_nort() preempt_enable() -#endif #ifdef CONFIG_PREEMPT_NOTIFIERS @@ -392,78 +322,34 @@ #endif -#ifdef CONFIG_SMP - -/* - * Migrate-Disable and why it is undesired. +/** + * migrate_disable - Prevent migration of the current task * - * When a preempted task becomes elegible to run under the ideal model (IOW it - * becomes one of the M highest priority tasks), it might still have to wait - * for the preemptee's migrate_disable() section to complete. Thereby suffering - * a reduction in bandwidth in the exact duration of the migrate_disable() - * section. + * Maps to preempt_disable() which also disables preemption. Use + * migrate_disable() to annotate that the intent is to prevent migration, + * but not necessarily preemption. * - * Per this argument, the change from preempt_disable() to migrate_disable() - * gets us: - * - * - a higher priority tasks gains reduced wake-up latency; with preempt_disable() - * it would have had to wait for the lower priority task. - * - * - a lower priority tasks; which under preempt_disable() could've instantly - * migrated away when another CPU becomes available, is now constrained - * by the ability to push the higher priority task away, which might itself be - * in a migrate_disable() section, reducing it's available bandwidth. - * - * IOW it trades latency / moves the interference term, but it stays in the - * system, and as long as it remains unbounded, the system is not fully - * deterministic. - * - * - * The reason we have it anyway. - * - * PREEMPT_RT breaks a number of assumptions traditionally held. By forcing a - * number of primitives into becoming preemptible, they would also allow - * migration. This turns out to break a bunch of per-cpu usage. To this end, - * all these primitives employ migirate_disable() to restore this implicit - * assumption. - * - * This is a 'temporary' work-around at best. The correct solution is getting - * rid of the above assumptions and reworking the code to employ explicit - * per-cpu locking or short preempt-disable regions. - * - * The end goal must be to get rid of migrate_disable(), alternatively we need - * a schedulability theory that does not depend on abritrary migration. - * - * - * Notes on the implementation. - * - * The implementation is particularly tricky since existing code patterns - * dictate neither migrate_disable() nor migrate_enable() is allowed to block. - * This means that it cannot use cpus_read_lock() to serialize against hotplug, - * nor can it easily migrate itself into a pending affinity mask change on - * migrate_enable(). - * - * - * Note: even non-work-conserving schedulers like semi-partitioned depends on - * migration, so migrate_disable() is not only a problem for - * work-conserving schedulers. - * + * Can be invoked nested like preempt_disable() and needs the corresponding + * number of migrate_enable() invocations. */ -extern void migrate_disable(void); -extern void migrate_enable(void); - -#else - -static inline void migrate_disable(void) +static __always_inline void migrate_disable(void) { - preempt_lazy_disable(); + preempt_disable(); } -static inline void migrate_enable(void) +/** + * migrate_enable - Allow migration of the current task + * + * Counterpart to migrate_disable(). + * + * As migrate_disable() can be invoked nested, only the outermost invocation + * reenables migration. + * + * Currently mapped to preempt_enable(). + */ +static __always_inline void migrate_enable(void) { - preempt_lazy_enable(); + preempt_enable(); } - -#endif /* CONFIG_SMP */ #endif /* __LINUX_PREEMPT_H */ -- Gitblit v1.6.2