Commit Graph
234 Commits
Author SHA1 Message Date
Waiman Long 71439ed5a5 hrtimer: Fix trace oddity
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit 5d6446f409da00e5a389125ddb5ce09f5bc404c9
Author: Thomas Gleixner <tglx@kernel.org>
Date:   Mon, 19 Jan 2026 11:38:34 +0100

    hrtimer: Fix trace oddity

    It turns out that __run_hrtimer() will trace like:

              <idle>-0     [032] d.h2. 20705.474563: hrtimer_cancel:       hrtimer=0xff2db8f77f8226e8
              <idle>-0     [032] d.h1. 20705.474563: hrtimer_expire_entry: hrtimer=0xff2db8f77f8226e8 now=20699452001850 function=tick_nohz_handler/0x0

    Which is a bit nonsensical, the timer doesn't get canceled on
    expiration. The cause is the use of the incorrect debug helper.

    Fixes: c6a2a17702 ("hrtimer: Add tracepoint for hrtimers")
    Reported-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://patch.msgid.link/20260121143208.219595606@infradead.org

Signed-off-by: Waiman Long <longman@redhat.com>
2026-03-09 23:09:34 -04:00
Waiman Long 35041e9ccf hrtimer: Fix softirq base check in update_needs_ipi()
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit 05dc4a9fc8b36d4c99d76bbc02aa9ec0132de4c2
Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Date:   Wed, 7 Jan 2026 11:39:24 +0100

    hrtimer: Fix softirq base check in update_needs_ipi()

    The 'clockid' field is not the correct way to check for a softirq base.

    Fix the check to correctly compare the base type instead of the clockid.

    Fixes: 1e7f7fbcd4 ("hrtimer: Avoid more SMP function calls in clock_was_set()")
    Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://patch.msgid.link/20260107-hrtimer-clock-base-check-v1-1-afb5dbce94a1@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2026-03-09 23:09:33 -04:00
Waiman Long 2462518834 time: Fix spelling mistakes in comments
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit 391253b25f078d2fe5657a1dedd360396d186407
Author: Haofeng Li <lihaofeng@kylinos.cn>
Date:   Wed, 10 Sep 2025 17:37:03 +0800

    time: Fix spelling mistakes in comments

    Correct several typos found in comments across various files in the
    kernel/time directory.

    No functional changes are introduced by these corrections.

    Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Signed-off-by: Waiman Long <longman@redhat.com>
2026-02-28 14:50:43 -05:00
Waiman Long ef475da724 hrtimer: Reorder branches in hrtimer_clockid_to_base()
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit 3c3af563b31766f67106c7549ad084a08ef613f2
Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Date:   Thu, 21 Aug 2025 15:28:16 +0200

    hrtimer: Reorder branches in hrtimer_clockid_to_base()

    Align the ordering to the one used for hrtimer_bases.

    Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/20250821-hrtimer-cleanup-get_time-v2-9-3ae822e5bfbd@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2026-02-28 14:50:42 -05:00
Waiman Long 75081225e7 hrtimer: Remove hrtimer_clock_base:: Get_time
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit 009eb5da29a91016e3ebb988e6401e79411be7a1
Author: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Date:   Thu, 21 Aug 2025 15:28:15 +0200

    hrtimer: Remove hrtimer_clock_base:: Get_time

    The get_time() callbacks always need to match the bases clockid.
    Instead of maintaining that association twice in hrtimer_bases,
    use a helper.

    Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/all/20250821-hrtimer-cleanup-get_time-v2-8-3ae822e5bfbd@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2026-02-28 14:50:42 -05:00
Waiman Long d8ebe55f63 hrtimers: Unconditionally update target CPU base after offline timer migration
JIRA: https://issues.redhat.com/browse/RHEL-152433

commit e895f8e29119c8c966ea794af9e9100b10becb88
Author: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Date:   Tue, 5 Aug 2025 16:10:25 +0800

    hrtimers: Unconditionally update target CPU base after offline timer migration

    When testing softirq based hrtimers on an ARM32 board, with high resolution
    mode and NOHZ inactive, softirq based hrtimers fail to expire after being
    moved away from an offline CPU:

    CPU0                            CPU1
                                    hrtimer_start(..., HRTIMER_MODE_SOFT);
    cpu_down(CPU1)                  ...
                                    hrtimers_cpu_dying()
                                      // Migrate timers to CPU0
                                      smp_call_function_single(CPU0, returgger_next_event);
      retrigger_next_event()
        if (!highres && !nohz)
            return;

    As retrigger_next_event() is a NOOP when both high resolution timers and
    NOHZ are inactive CPU0's hrtimer_cpu_base::softirq_expires_next is not
    updated and the migrated softirq timers never expire unless there is a
    softirq based hrtimer queued on CPU0 later.

    Fix this by removing the hrtimer_hres_active() and tick_nohz_active() check
    in retrigger_next_event(), which enforces a full update of the CPU base.
    As this is not a fast path the extra cost does not matter.

    [ tglx: Massaged change log ]

    Fixes: 5c0930ccaa ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
    Co-developed-by: Frederic Weisbecker <frederic@kernel.org>
    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
    Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/20250805081025.54235-1-wangxiongfeng2@huawei.com

Signed-off-by: Waiman Long <longman@redhat.com>
2026-02-28 14:50:38 -05:00
Waiman Long c9b63ab73c hrtimer: Add missing ACCESS_PRIVATE() for hrtimer::function
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 2424e146bee00ddb4d4f79d3224f54634ca8d2bc
Author: Nam Cao <namcao@linutronix.de>
Date:   Tue, 8 Apr 2025 12:38:54 +0200

    hrtimer: Add missing ACCESS_PRIVATE() for hrtimer::function

    The "function" field of struct hrtimer has been changed to private, but
    two instances have not been converted to use ACCESS_PRIVATE().

    Convert them to use ACCESS_PRIVATE().

    Fixes: 04257da0c99c ("hrtimers: Make callback function pointer private")
    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/20250408103854.1851093-1-namcao@linutronix.de
    Closes: https://lore.kernel.org/oe-kbuild-all/202504071931.vOVl13tt-lkp@intel.com/
    Closes: https://lore.kernel.org/oe-kbuild-all/202504072155.5UAZjYGU-lkp@intel.com/

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:39 -05:00
Waiman Long 27a3762c08 tracing/timers: Rename the hrtimer_init event to hrtimer_setup
JIRA: https://issues.redhat.com/browse/RHEL-114122
Conflicts:
  The tools/perf/tests/shell/trace_btf_enum.sh dropped to avoid conflict
  with perf v6.17 rebase MR which includes a version of upstream
  commit fc4a0ae7e19e ("perf test trace: Stop tracing hrtimer_setup
  event in trace enum test") that removes hrtimer_setup/init from
  trace_btf_enum.sh anyway.

commit 244132c4e5777fe0a4544ef23afba0d9a50e5ec5
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:21 +0100

    tracing/timers: Rename the hrtimer_init event to hrtimer_setup

    The function hrtimer_init() doesn't exist anymore. It was replaced by
    hrtimer_setup().

    Thus, rename the hrtimer_init trace event to hrtimer_setup to keep it
    consistent.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/cba84c3d853c5258aa3a262363a6eac08e2c7afc.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:39 -05:00
Waiman Long cbe4ab2dcf hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 59c9edafc0f3843c3e616eb8136a310c7c552595
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:20 +0100

    hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack()

    All the hrtimer_init*() functions have been renamed to hrtimer_setup*().
    Rename debug_init_on_stack() to debug_setup_on_stack() as well, to keep the
    names consistent.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/073cf6162779a2f5b12624677d4c49ee7eccc1ed.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:39 -05:00
Waiman Long 461147abb1 hrtimers: Rename debug_init() to debug_setup()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit e9ef2093ad9edec8d8a060e14891952570c82b8b
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:19 +0100

    hrtimers: Rename debug_init() to debug_setup()

    All the hrtimer_init*() functions have been renamed to hrtimer_setup*().
    Rename debug_init() to debug_setup() as well, to keep the names consistent.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/4b730c1f79648b16a1c5413f928fdc2e138dfc43.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long 3bfd321ca4 hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit fcea1ccf2476ca793b0ca3f80ca23f5a28cbb0b3
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:18 +0100

    hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper()

    All the hrtimer_init*() functions have been renamed to hrtimer_setup*().
    Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper() as well, to
    keep the names consistent.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/807694aedad9353421c4a7347629a30c5c31026f.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long 8e39882770 hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 1cc24f2e766c5a6606b834a677bd58991c1b9781
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:17 +0100

    hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns()

    The struct hrtimer::function field can only be changed using
    hrtimer_setup*() or hrtimer_update_function(), and both already null-check
    'function'. Therefore, null-checking 'function' in hrtimer_start_range_ns()
    is not necessary.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/4661c571ee87980c340ccc318fc1a473c0c8f6bc.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long c7dd2e62e7 hrtimers: Make callback function pointer private
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 04257da0c99c9d4ff7c5bb93046482e1f7d34938
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:16 +0100

    hrtimers: Make callback function pointer private

    Make the struct hrtimer::function field private, to prevent users from
    changing this field in an unsafe way. hrtimer_update_function() should be
    used if the callback function needs to be changed.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/7d0e6e0c5c59a64a9bea940051aac05d750bc0c2.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long 8cd7cc83cc hrtimers: Merge __hrtimer_init() into __hrtimer_setup()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 87d82cff3829733fa6838492a9215303ad98a61c
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:12 +0100

    hrtimers: Merge __hrtimer_init() into __hrtimer_setup()

    __hrtimer_init() is only called by __hrtimer_setup(). Simplify by merging
    __hrtimer_init() into __hrtimer_setup().

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/8a0a847a35f711f66b2d05b57255aa44e7e61279.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long f9b5f2e831 hrtimers: Switch to use __htimer_setup()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 50177a8b2ec756a03f635444538da928dc5ac488
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:11 +0100

    hrtimers: Switch to use __htimer_setup()

    __hrtimer_init_sleeper() calls __hrtimer_init() and also sets up the
    callback function. But there is already __hrtimer_setup() which does both
    actions.

    Switch to use __hrtimer_setup() to simplify the code.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/d9a45a51b6a8aa0045310d63f73753bf6b33f385.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long c7cb83c8d5 hrtimers: Delete hrtimer_init()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 9779489a31d77a7b9cb6f20d2d2caced4e29dbe6
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:55:10 +0100

    hrtimers: Delete hrtimer_init()

    hrtimer_init() is now unused. Delete it.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/all/003722f60c7a2a4f8d4ed24fb741aa313b7e5136.1738746927.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:38 -05:00
Waiman Long 85b8815885 hrtimers: Replace hrtimer_clock_to_base_table with switch-case
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 4441b976dfeff0d3579e8da3c0283300c618a553
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Fri, 14 Feb 2025 15:43:33 +0200

    hrtimers: Replace hrtimer_clock_to_base_table with switch-case

    Clang and GCC complain about overlapped initialisers in the
    hrtimer_clock_to_base_table definition. With `make W=1` and CONFIG_WERROR=y
    (which is default nowadays) this breaks the build:

      CC      kernel/time/hrtimer.o
    kernel/time/hrtimer.c:124:21: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides]
      124 |         [CLOCK_REALTIME]        = HRTIMER_BASE_REALTIME,

    kernel/time/hrtimer.c:122:27: note: previous initialization is here
      122 |         [0 ... MAX_CLOCKS - 1]  = HRTIMER_MAX_CLOCK_BASES,

    (and similar for CLOCK_MONOTONIC, CLOCK_BOOTTIME, and CLOCK_TAI).

    hrtimer_clockid_to_base(), which uses the table, is only used in
    __hrtimer_init(), which is not a hotpath.

    Therefore replace the table lookup with a switch case in
    hrtimer_clockid_to_base() to avoid this warning.

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/20250214134424.3367619-1-andriy.shevchenko@linux.intel.com

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:30 -05:00
Waiman Long 06f45ae779 hrtimers: Force migrate away hrtimers queued after CPUHP_AP_HRTIMERS_DYING
JIRA: https://issues.redhat.com/browse/RHEL-114122
CVE: CVE-2025-21816

commit 53dac345395c0d2493cbc2f4c85fe38aef5b63f5
Author: Frederic Weisbecker <frederic@kernel.org>
Date:   Sat, 18 Jan 2025 00:24:33 +0100

    hrtimers: Force migrate away hrtimers queued after CPUHP_AP_HRTIMERS_DYING

    hrtimers are migrated away from the dying CPU to any online target at
    the CPUHP_AP_HRTIMERS_DYING stage in order not to delay bandwidth timers
    handling tasks involved in the CPU hotplug forward progress.

    However wakeups can still be performed by the outgoing CPU after
    CPUHP_AP_HRTIMERS_DYING. Those can result again in bandwidth timers being
    armed. Depending on several considerations (crystal ball power management
    based election, earliest timer already enqueued, timer migration enabled or
    not), the target may eventually be the current CPU even if offline. If that
    happens, the timer is eventually ignored.

    The most notable example is RCU which had to deal with each and every of
    those wake-ups by deferring them to an online CPU, along with related
    workarounds:

    _ e787644caf (rcu: Defer RCU kthreads wakeup when CPU is dying)
    _ 9139f93209 (rcu/nocb: Fix RT throttling hrtimer armed from offline CPU)
    _ f7345ccc62 (rcu/nocb: Fix rcuog wake-up from offline softirq)

    The problem isn't confined to RCU though as the stop machine kthread
    (which runs CPUHP_AP_HRTIMERS_DYING) reports its completion at the end
    of its work through cpu_stop_signal_done() and performs a wake up that
    eventually arms the deadline server timer:

       WARNING: CPU: 94 PID: 588 at kernel/time/hrtimer.c:1086 hrtimer_start_range_ns+0x289/0x2d0
       CPU: 94 UID: 0 PID: 588 Comm: migration/94 Not tainted
       Stopper: multi_cpu_stop+0x0/0x120 <- stop_machine_cpuslocked+0x66/0xc0
       RIP: 0010:hrtimer_start_range_ns+0x289/0x2d0
       Call Trace:
       <TASK>
         start_dl_timer
         enqueue_dl_entity
         dl_server_start
         enqueue_task_fair
         enqueue_task
         ttwu_do_activate
         try_to_wake_up
         complete
         cpu_stopper_thread

    Instead of providing yet another bandaid to work around the situation, fix
    it in the hrtimers infrastructure instead: always migrate away a timer to
    an online target whenever it is enqueued from an offline CPU.

    This will also allow to revert all the above RCU disgraceful hacks.

    Fixes: 5c0930ccaa ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
    Reported-by: Vlad Poenaru <vlad.wing@gmail.com>
    Reported-by: Usama Arif <usamaarif642@gmail.com>
    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: stable@vger.kernel.org
    Tested-by: Paul E. McKenney <paulmck@kernel.org>
    Link: https://lore.kernel.org/all/20250117232433.24027-1-frederic@kernel.org
    Closes: 20241213203739.1519801-1-usamaarif642@gmail.com

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:30 -05:00
Waiman Long 6943c63639 hrtimers: Mark is_migration_base() with __always_inline
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 27af31e44949fa85550176520ef7086a0d00fd7b
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Thu, 16 Jan 2025 18:07:45 +0200

    hrtimers: Mark is_migration_base() with __always_inline

    When is_migration_base() is unused, it prevents kernel builds
    with clang, `make W=1` and CONFIG_WERROR=y:

    kernel/time/hrtimer.c:156:20: error: unused function 'is_migration_base' [-Werror,-Wunused-function]
      156 | static inline bool is_migration_base(struct hrtimer_clock_base *base)
          |                    ^~~~~~~~~~~~~~~~~

    Fix this by marking it with __always_inline.

    [ tglx: Use __always_inline instead of __maybe_unused and move it into the
            usage sites conditional ]

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/20250116160745.243358-1-andriy.shevchenko@linux.intel.com

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:30 -05:00
Waiman Long bea446045d hrtimers: Update the return type of enqueue_hrtimer()
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit da7100d3bf7d6f5c49ef493ea963766898e9b069
Author: Richard Clark <richard.xnu.clark@gmail.com>
Date:   Tue, 24 Dec 2024 15:57:03 +0800

    hrtimers: Update the return type of enqueue_hrtimer()

    The return type should be 'bool' instead of 'int' according to the calling
    context in the kernel, and its internal implementation, i.e. :

            return timerqueue_add();

    which is a bool-return function.

    [ tglx: Adjust function arguments ]

    Signed-off-by: Richard Clark <richard.xnu.clark@gmail.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/Z2ppT7me13dtxm1a@MBC02GN1V4Q05P

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:29 -05:00
Waiman Long 862297c1b9 hrtimers: Handle CPU state correctly on hotplug
JIRA: https://issues.redhat.com/browse/RHEL-114122
CVE: CVE-2024-57951

commit 2f8dea1692eef2b7ba6a256246ed82c365fdc686
Author: Koichiro Den <koichiro.den@canonical.com>
Date:   Fri, 20 Dec 2024 22:44:21 +0900

    hrtimers: Handle CPU state correctly on hotplug

    Consider a scenario where a CPU transitions from CPUHP_ONLINE to halfway
    through a CPU hotunplug down to CPUHP_HRTIMERS_PREPARE, and then back to
    CPUHP_ONLINE:

    Since hrtimers_prepare_cpu() does not run, cpu_base.hres_active remains set
    to 1 throughout. However, during a CPU unplug operation, the tick and the
    clockevents are shut down at CPUHP_AP_TICK_DYING. On return to the online
    state, for instance CFS incorrectly assumes that the hrtick is already
    active, and the chance of the clockevent device to transition to oneshot
    mode is also lost forever for the CPU, unless it goes back to a lower state
    than CPUHP_HRTIMERS_PREPARE once.

    This round-trip reveals another issue; cpu_base.online is not set to 1
    after the transition, which appears as a WARN_ON_ONCE in enqueue_hrtimer().

    Aside of that, the bulk of the per CPU state is not reset either, which
    means there are dangling pointers in the worst case.

    Address this by adding a corresponding startup() callback, which resets the
    stale per CPU state and sets the online flag.

    [ tglx: Make the new callback unconditionally available, remove the online
            modification in the prepare() callback and clear the remaining
            state in the starting callback instead of the prepare callback ]

    Fixes: 5c0930ccaa ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
    Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/all/20241220134421.3809834-1-koichiro.den@canonical.com

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:28 -05:00
Waiman Long b734d02412 softirq: Use a dedicated thread for timer wakeups on PREEMPT_RT.
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 49a17639508c3b35f90ca829e60dddeeeb750e74
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Wed, 6 Nov 2024 15:51:39 +0100

    softirq: Use a dedicated thread for timer wakeups on PREEMPT_RT.

    The timer and hrtimer soft interrupts are raised in hard interrupt
    context. With threaded interrupts force enabled or on PREEMPT_RT this leads
    to waking the ksoftirqd for the processing of the soft interrupt.

    ksoftirqd runs as SCHED_OTHER task which means it will compete with other
    tasks for CPU resources.  This can introduce long delays for timer
    processing on heavy loaded systems and is not desired.

    Split the TIMER_SOFTIRQ and HRTIMER_SOFTIRQ processing into a dedicated
    timers thread and let it run at the lowest SCHED_FIFO priority.
    Wake-ups for RT tasks happen from hardirq context so only timer_list timers
    and hrtimers for "regular" tasks are processed here. The higher priority
    ensures that wakeups are performed before scheduling SCHED_OTHER tasks.

    Using a dedicated variable to store the pending softirq bits values ensure
    that the timer are not accidentally picked up by ksoftirqd and other
    threaded interrupts.

    It shouldn't be picked up by ksoftirqd since it runs at lower priority.
    However if ksoftirqd is already running while a timer fires, then ksoftird
    will be PI-boosted due to the BH-lock to ktimer's priority.

    The timer thread can pick up pending softirqs from ksoftirqd but only
    if the softirq load is high. It is not be desired that the picked up
    softirqs are processed at SCHED_FIFO priority under high softirq load
    but this can already happen by a PI-boost by a force-threaded interrupt.

    [ frederic@kernel.org: rcutorture.c fixes, storm fix by introduction of
      local_timers_pending() for tick_nohz_next_event() ]

    [ junxiao.chang@intel.com: Ensure ktimersd gets woken up even if a
      softirq is currently served. ]

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Paul E. McKenney <paulmck@kernel.org> [rcutorture]
    Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
    Link: https://lore.kernel.org/all/20241106150419.2593080-4-bigeasy@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:18 -05:00
Waiman Long c5f59c6da3 hrtimer: Use __raise_softirq_irqoff() to raise the softirq
JIRA: https://issues.redhat.com/browse/RHEL-114122

commit 7a7f5065bc1dd8c463fc55f18ad43907c16571ee
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Wed, 6 Nov 2024 15:51:37 +0100

    hrtimer: Use __raise_softirq_irqoff() to raise the softirq

    Raising the hrtimer soft interrupt is always done from hard interrupt
    context, so it can be reduced to just setting the HRTIMER soft interrupt
    flag. The soft interrupt will be invoked on return from interrupt.

    Use therefore __raise_softirq_irqoff() to raise the HRTIMER soft interrupt,
    which is a trivial optimization.

    Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
    Link: https://lore.kernel.org/all/20241106150419.2593080-2-bigeasy@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:17 -05:00
Waiman Long 87da2c0f19 Revert "softirq: Use a dedicated thread for timer wakeups."
JIRA: https://issues.redhat.com/browse/RHEL-114122
Upstream Status: RHEL only

Revert the RT specific RHEL commit 1b7c1f0883 ("softirq: Use a
dedicated thread for timer wakeups.")  to be replaced by upstream
equivalent.

Signed-off-by: Waiman Long <longman@redhat.com>
2025-12-13 20:56:17 -05:00
Waiman Long 2185018718 treewide: Switch/rename to timer_delete[_sync]()
JIRA: https://issues.redhat.com/browse/RHEL-114125
Conflicts:
  This is a partial backport of the commit on the best effort
  basis. All the hunks that fail to merge are dropped and del_timer()
  and del_timer_sync() helpers in include/linux/timer.h are retained.

commit 8fa7292fee5c5240402371ea89ab285ec856c916
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Sat, 5 Apr 2025 10:17:26 +0200

    treewide: Switch/rename to timer_delete[_sync]()

    timer_delete[_sync]() replaces del_timer[_sync](). Convert the whole tree
    over and remove the historical wrapper inlines.

    Conversion was done with coccinelle plus manual fixups where necessary.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

Signed-off-by: Waiman Long <longman@redhat.com>
2025-09-15 23:05:39 -04:00
Waiman Long e5c82bc26e timers: Move *sleep*() and timeout functions into a separate file
JIRA: https://issues.redhat.com/browse/RHEL-114125
Conflicts:
  A merge conflict with the kernel/time/hrtimer.c hunk due to the
  presence of a later upstream commit 8fae141107d4 ("timers: Switch to
  use hrtimer_setup_sleeper_on_stack()").

commit da7bd0a9e0fce9f293b6e30c003f8f3978cee923
Author: Anna-Maria Behnsen <anna-maria@linutronix.de>
Date:   Mon, 14 Oct 2024 10:22:19 +0200

    timers: Move *sleep*() and timeout functions into a separate file

    All schedule_timeout() and *sleep*() related functions are interfaces on
    top of timer list timers and hrtimers to add a sleep to the code. As they
    are built on top of the timer list timers and hrtimers, the [hr]timer
    interfaces are already used except when queuing the timer in
    schedule_timeout(). But there exists the appropriate interface add_timer()
    which does the same job with an extra check for an already pending timer.

    Split all those functions as they are into a separate file and use
    add_timer() instead of __mod_timer() in schedule_timeout().

    While at it fix minor formatting issues and a multi line printk function
    call in schedule_timeout().

    Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Acked-by: Frederic Weisbecker <frederic@kernel.org>
    Link: https://lore.kernel.org/all/20241014-devel-anna-maria-b4-timers-flseep-v3-2-dc8b907cb62f@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-09-15 23:05:39 -04:00
Waiman Long 6578e9e5a4 can: Switch to use hrtimer_setup()
JIRA: https://issues.redhat.com/browse/RHEL-114125

commit 806e32248e22582715dbbb7664567b81b9d6928a
Author: Nam Cao <namcao@linutronix.de>
Date:   Wed, 5 Feb 2025 11:43:27 +0100

    can: Switch to use hrtimer_setup()

    hrtimer_setup() takes the callback function pointer as argument and
    initializes the timer completely.

    Replace hrtimer_init() and the open coded initialization of
    hrtimer::function with the new setup mechanism.

    Most of this patch is generated by Coccinelle. Except for the TX thrtimer
    in bcm_tx_setup() because this timer is not used and the callback function
    is never set. For this particular case, set the callback to
    hrtimer_dummy_timeout()

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/all/a3a6be42c818722ad41758457408a32163bfd9a0.1738746872.git.namcao@linutronix.de

Signed-off-by: Waiman Long <longman@redhat.com>
2025-09-15 23:05:34 -04:00
Mark Langsdorf 415763fe35 hrtimers: Delete hrtimer_init_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-88904

commit 3c2fb0152175f9f596b40763cdc1378297da60af
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:33 2024 +0100

hrtimer_init_on_stack() is now unused. Delete it.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/510ce0d2944c4a382ea51e51d03dcfb73ba0f4f7.1730386209.git.namcao@linutronix.de
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2025-08-05 15:52:06 -04:00
Mark Langsdorf b85919c378 hrtimers: Delete hrtimer_init_sleeper_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-88904

commit f3bef7aaa6c807b78e8fc6929c3226d3038fe505
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:29 2024 +0100

hrtimer_init_sleeper_on_stack() is now unused. Delete it.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/52549846635c0b3a2abf82101f539efdabcd9778.1730386209.git.namcao@linutronix.de
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2025-08-05 15:52:06 -04:00
Mark Langsdorf fd307e9001 timers: Switch to use hrtimer_setup_sleeper_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-88904
Conflicts:
	kernel/time/sleep_timeout.c - not present in
centos-stream-10, so I couldn't apply the change to
schedule_hrtimeout_range_clock()
	kernel/time/hrtimer.c - schedule_hrtimeout_range_clock()
exists in this file, so I did the replacement here

commit 8fae141107d4540a153efa0e2751a6fc12a13679
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:27 2024 +0100

hrtimer_setup_sleeper_on_stack() replaces hrtimer_init_sleeper_on_stack()
to keep the naming convention consistent.

Convert the usage sites over to it. The conversion was done with
Coccinelle.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/299c07f0f96af8ab3a7631b47b6ca22b06b20577.1730386209.git.namcao@linutronix.de
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2025-08-05 15:52:05 -04:00
Mark Langsdorf d6ad7cf949 hrtimers: Introduce hrtimer_setup_sleeper_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-88904

commit c9bd83abfeb9a9b103e689b251ccff7a01be8366
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:22 2024 +0100

The hrtimer_init*() API is replaced by hrtimer_setup*() variants to
initialize the timer including the callback function at once.

hrtimer_init_sleeper_on_stack() does not need user to setup the callback
function separately, so a new variant would not be strictly necessary.

Nonetheless, to keep the naming convention consistent, introduce
hrtimer_setup_sleeper_on_stack(). hrtimer_init_on_stack() will be removed
once all users are converted.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/7b5e18e6dd0ace9eaa211201528cb9dc23752454.1730386209.git.namcao@linutronix.de
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2025-08-05 15:52:05 -04:00
Mark Langsdorf c4281dc504 hrtimers: Introduce hrtimer_setup_on_stack()
JIRA: https://issues.redhat.com/browse/RHEL-88904

commit 444cb7db4c9f9b5d96be17c38b3e989df7bfabd5
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:21 2024 +0100

To initialize hrtimer on stack, hrtimer_init_on_stack() needs to be called
and also hrtimer::function must be set. This is error-prone and awkward to
use.

Introduce hrtimer_setup_on_stack() which does both of these things, so that
users of hrtimer can be simplified.

The new setup function also has a sanity check for the provided function
pointer. If NULL, a warning is emitted and a dummy callback installed.

hrtimer_init_on_stack() will be removed as soon as all of its users have
been converted to the new function.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/4b05e2ab3a82c517adf67fabc0f0cd8fe118b97c.1730386209.git.namcao@linutronix.de
Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
2025-08-05 15:52:05 -04:00
José Expósito 4b8789fdc3 hrtimers: Introduce hrtimer_setup() to replace hrtimer_init()
JIRA: https://issues.redhat.com/browse/RHEL-88416

commit 908a1d775422ba2e27a5e33d0c130b522419e121
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:20 2024 +0100

    hrtimers: Introduce hrtimer_setup() to replace hrtimer_init()

    To initialize hrtimer, hrtimer_init() needs to be called and also
    hrtimer::function must be set. This is error-prone and awkward to use.

    Introduce hrtimer_setup() which does both of these things, so that users of
    hrtimer can be simplified.

    The new setup function also has a sanity check for the provided function
    pointer. If NULL, a warning is emitted and a dummy callback installed.

    hrtimer_init() will be removed as soon as all of its users have been
    converted to the new function.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/5057c1ddbfd4b92033cd93d37fe38e6b069d5ba6.1730386209.git.namcao@linutronix.de

Signed-off-by: José Expósito <jexposit@redhat.com>
2025-05-29 07:19:49 +02:00
José Expósito c766516935 hrtimers: Add missing hrtimer_init() trace points
JIRA: https://issues.redhat.com/browse/RHEL-88416

commit fbf920f255315974808ce91d934fe50198294d51
Author: Nam Cao <namcao@linutronix.de>
Date:   Thu Oct 31 16:14:15 2024 +0100

    hrtimers: Add missing hrtimer_init() trace points

    hrtimer_init*_on_stack() is not covered by tracing when
    CONFIG_DEBUG_OBJECTS_TIMERS=y.

    Rework the functions similar to hrtimer_init() and hrtimer_init_sleeper()
    so that the hrtimer_init() tracepoint is unconditionally available.

    The rework makes hrtimer_init_sleeper() unused. Delete it.

    Signed-off-by: Nam Cao <namcao@linutronix.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/all/74528e8abf2bb96e8bee85ffacbf14e15cf89f0d.1730386209.git.namcao@linutronix.de

Signed-off-by: José Expósito <jexposit@redhat.com>
2025-05-29 07:19:49 +02:00
Sebastian Andrzej Siewior 1b7c1f0883 softirq: Use a dedicated thread for timer wakeups.
A timer/hrtimer softirq is raised in-IRQ context. With threaded
interrupts enabled or on PREEMPT_RT this leads to waking the ksoftirqd
for the processing of the softirq.
Once the ksoftirqd is marked as pending (or is running) it will collect
all raised softirqs. This in turn means that a softirq which would have
been processed at the end of the threaded interrupt, which runs at an
elevated priority, is now moved to ksoftirqd which runs at SCHED_OTHER
priority and competes with every regular task for CPU resources.
This introduces long delays on heavy loaded systems and is not desired
especially if the system is not overloaded by the softirqs.

Split the TIMER_SOFTIRQ and HRTIMER_SOFTIRQ processing into a dedicated
timers thread and let it run at the lowest SCHED_FIFO priority.
RT tasks are are woken up from hardirq context so only timer_list timers
and hrtimers for "regular" tasks are processed here. The higher priority
ensures that wakeups are performed before scheduling SCHED_OTHER tasks.

Using a dedicated variable to store the pending softirq bits values
ensure that the timer are not accidentally picked up by ksoftirqd and
other threaded interrupts.
It shouldn't be picked up by ksoftirqd since it runs at lower priority.
However if the timer bits are ORed while a threaded interrupt is
running, then the timer softirq would be performed at higher priority.
The new timer thread will block on the softirq lock before it starts
softirq work. This "race window" isn't closed because while timer thread
is performing the softirq it can get PI-boosted via the softirq lock by
a random force-threaded thread.
The timer thread can pick up pending softirqs from ksoftirqd but only
if the softirq load is high. It is not be desired that the picked up
softirqs are processed at SCHED_FIFO priority under high softirq load
but this can already happen by a PI-boost by a force-threaded interrupt.

Reported-by: kernel test robot <lkp@intel.com> [ static timer_threads ]
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
2024-09-30 17:28:16 +02:00
Linus Torvalds 2004cef11e Merge tag 'sched-core-2024-09-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler updates from Ingo Molnar:

 - Implement the SCHED_DEADLINE server infrastructure - Daniel Bristot
   de Oliveira's last major contribution to the kernel:

     "SCHED_DEADLINE servers can help fixing starvation issues of low
      priority tasks (e.g., SCHED_OTHER) when higher priority tasks
      monopolize CPU cycles. Today we have RT Throttling; DEADLINE
      servers should be able to replace and improve that."

   (Daniel Bristot de Oliveira, Peter Zijlstra, Joel Fernandes, Youssef
   Esmat, Huang Shijie)

 - Preparatory changes for sched_ext integration:
     - Use set_next_task(.first) where required
     - Fix up set_next_task() implementations
     - Clean up DL server vs. core sched
     - Split up put_prev_task_balance()
     - Rework pick_next_task()
     - Combine the last put_prev_task() and the first set_next_task()
     - Rework dl_server
     - Add put_prev_task(.next)

   (Peter Zijlstra, with a fix by Tejun Heo)

 - Complete the EEVDF transition and refine EEVDF scheduling:
     - Implement delayed dequeue
     - Allow shorter slices to wakeup-preempt
     - Use sched_attr::sched_runtime to set request/slice suggestion
     - Document the new feature flags
     - Remove unused and duplicate-functionality fields
     - Simplify & unify pick_next_task_fair()
     - Misc debuggability enhancements

   (Peter Zijlstra, with fixes/cleanups by Dietmar Eggemann, Valentin
   Schneider and Chuyi Zhou)

 - Initialize the vruntime of a new task when it is first enqueued,
   resulting in significant decrease in latency of newly woken tasks
   (Zhang Qiao)

 - Introduce SM_IDLE and an idle re-entry fast-path in __schedule()
   (K Prateek Nayak, Peter Zijlstra)

 - Clean up and clarify the usage of Clean up usage of rt_task()
   (Qais Yousef)

 - Preempt SCHED_IDLE entities in strict cgroup hierarchies
   (Tianchen Ding)

 - Clarify the documentation of time units for deadline scheduler
   parameters (Christian Loehle)

 - Remove the HZ_BW chicken-bit feature flag introduced a year ago,
   the original change seems to be working fine (Phil Auld)

 - Misc fixes and cleanups (Chen Yu, Dan Carpenter, Huang Shijie,
   Peilin He, Qais Yousefm and Vincent Guittot)

* tag 'sched-core-2024-09-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (64 commits)
  sched/cpufreq: Use NSEC_PER_MSEC for deadline task
  cpufreq/cppc: Use NSEC_PER_MSEC for deadline task
  sched/deadline: Clarify nanoseconds in uapi
  sched/deadline: Convert schedtool example to chrt
  sched/debug: Fix the runnable tasks output
  sched: Fix sched_delayed vs sched_core
  kernel/sched: Fix util_est accounting for DELAY_DEQUEUE
  kthread: Fix task state in kthread worker if being frozen
  sched/pelt: Use rq_clock_task() for hw_pressure
  sched/fair: Move effective_cpu_util() and effective_cpu_util() in fair.c
  sched/core: Introduce SM_IDLE and an idle re-entry fast-path in __schedule()
  sched: Add put_prev_task(.next)
  sched: Rework dl_server
  sched: Combine the last put_prev_task() and the first set_next_task()
  sched: Rework pick_next_task()
  sched: Split up put_prev_task_balance()
  sched: Clean up DL server vs core sched
  sched: Fixup set_next_task() implementations
  sched: Use set_next_task(.first) where required
  sched/fair: Properly deactivate sched_delayed task upon class change
  ...
2024-09-19 15:55:58 +02:00
Linus Torvalds 9ea925c806 Merge tag 'timers-core-2024-09-16' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Thomas Gleixner:
 "Core:

   - Overhaul of posix-timers in preparation of removing the workaround
     for periodic timers which have signal delivery ignored.

   - Remove the historical extra jiffie in msleep()

     msleep() adds an extra jiffie to the timeout value to ensure
     minimal sleep time. The timer wheel ensures minimal sleep time
     since the large rewrite to a non-cascading wheel, but the extra
     jiffie in msleep() remained unnoticed. Remove it.

   - Make the timer slack handling correct for realtime tasks.

     The procfs interface is inconsistent and does neither reflect
     reality nor conforms to the man page. Show the correct 0 slack for
     real time tasks and enforce it at the core level instead of having
     inconsistent individual checks in various timer setup functions.

   - The usual set of updates and enhancements all over the place.

  Drivers:

   - Allow the ACPI PM timer to be turned off during suspend

   - No new drivers

   - The usual updates and enhancements in various drivers"

* tag 'timers-core-2024-09-16' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (43 commits)
  ntp: Make sure RTC is synchronized when time goes backwards
  treewide: Fix wrong singular form of jiffies in comments
  cpu: Use already existing usleep_range()
  timers: Rename next_expiry_recalc() to be unique
  platform/x86:intel/pmc: Fix comment for the pmc_core_acpi_pm_timer_suspend_resume function
  clocksource/drivers/jcore: Use request_percpu_irq()
  clocksource/drivers/cadence-ttc: Add missing clk_disable_unprepare in ttc_setup_clockevent
  clocksource/drivers/asm9260: Add missing clk_disable_unprepare in asm9260_timer_init
  clocksource/drivers/qcom: Add missing iounmap() on errors in msm_dt_timer_init()
  clocksource/drivers/ingenic: Use devm_clk_get_enabled() helpers
  platform/x86:intel/pmc: Enable the ACPI PM Timer to be turned off when suspended
  clocksource: acpi_pm: Add external callback for suspend/resume
  clocksource/drivers/arm_arch_timer: Using for_each_available_child_of_node_scoped()
  dt-bindings: timer: rockchip: Add rk3576 compatible
  timers: Annotate possible non critical data race of next_expiry
  timers: Remove historical extra jiffie for timeout in msleep()
  hrtimer: Use and report correct timerslack values for realtime tasks
  hrtimer: Annotate hrtimer_cpu_base_.*_expiry() for sparse.
  timers: Add sparse annotation for timer_sync_wait_running().
  signal: Replace BUG_ON()s
  ...
2024-09-17 07:25:37 +02:00
Anna-Maria Behnsen bd7c8ff9fe treewide: Fix wrong singular form of jiffies in comments
There are several comments all over the place, which uses a wrong singular
form of jiffies.

Replace 'jiffie' by 'jiffy'. No functional change.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k
Link: https://lore.kernel.org/all/20240904-devel-anna-maria-b4-timers-flseep-v1-3-e98760256370@linutronix.de
2024-09-08 20:47:40 +02:00
Felix Moessbauer ed4fb6d7ef hrtimer: Use and report correct timerslack values for realtime tasks
The timerslack_ns setting is used to specify how much the hardware
timers should be delayed, to potentially dispatch multiple timers in a
single interrupt. This is a performance optimization. Timers of
realtime tasks (having a realtime scheduling policy) should not be
delayed.

This logic was inconsitently applied to the hrtimers, leading to delays
of realtime tasks which used timed waits for events (e.g. condition
variables). Due to the downstream override of the slack for rt tasks,
the procfs reported incorrect (non-zero) timerslack_ns values.

This is changed by setting the timer_slack_ns task attribute to 0 for
all tasks with a rt policy. By that, downstream users do not need to
specially handle rt tasks (w.r.t. the slack), and the procfs entry
shows the correct value of "0". Setting non-zero slack values (either
via procfs or PR_SET_TIMERSLACK) on tasks with a rt policy is ignored,
as stated in "man 2 PR_SET_TIMERSLACK":

  Timer slack is not applied to threads that are scheduled under a
  real-time scheduling policy (see sched_setscheduler(2)).

The special handling of timerslack on rt tasks in downstream users
is removed as well.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240814121032.368444-2-felix.moessbauer@siemens.com
2024-08-23 20:13:02 +02:00
Caleb Sander Mateos e68ac2b488 softirq: Remove unused 'action' parameter from action callback
When soft interrupt actions are called, they are passed a pointer to the
struct softirq action which contains the action's function pointer.

This pointer isn't useful, as the action callback already knows what
function it is. And since each callback handles a specific soft interrupt,
the callback also knows which soft interrupt number is running.

No soft interrupt action callback actually uses this parameter, so remove
it from the function pointer signature. This clarifies that soft interrupt
actions are global routines and makes it slightly cheaper to call them.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/all/20240815171549.3260003-1-csander@purestorage.com
2024-08-20 17:13:40 +02:00
Sebastian Andrzej Siewior 330dd6d9c0 hrtimer: Annotate hrtimer_cpu_base_.*_expiry() for sparse.
The two hrtimer_cpu_base_.*_expiry() functions are wrappers around the
locking functions and sparse complains about the missing counterpart.

Add sparse annotation to denote that this bevaviour is expected.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240812105326.2240000-3-bigeasy@linutronix.de
2024-08-14 12:44:41 +02:00
Qais Yousef ae04f69de0 sched/rt: Rename realtime_{prio, task}() to rt_or_dl_{prio, task}()
Some find the name realtime overloaded. Use rt_or_dl() as an
alternative, hopefully better, name.

Suggested-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Qais Yousef <qyousef@layalina.io>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240610192018.1567075-4-qyousef@layalina.io
2024-08-07 18:32:38 +02:00
Qais Yousef 130fd056dd sched/rt: Clean up usage of rt_task()
rt_task() checks if a task has RT priority. But depends on your
dictionary, this could mean it belongs to RT class, or is a 'realtime'
task, which includes RT and DL classes.

Since this has caused some confusion already on discussion [1], it
seemed a clean up is due.

I define the usage of rt_task() to be tasks that belong to RT class.
Make sure that it returns true only for RT class and audit the users and
replace the ones required the old behavior with the new realtime_task()
which returns true for RT and DL classes. Introduce similar
realtime_prio() to create similar distinction to rt_prio() and update
the users that required the old behavior to use the new function.

Move MAX_DL_PRIO to prio.h so it can be used in the new definitions.

Document the functions to make it more obvious what is the difference
between them. PI-boosted tasks is a factor that must be taken into
account when choosing which function to use.

Rename task_is_realtime() to realtime_task_policy() as the old name is
confusing against the new realtime_task().

No functional changes were intended.

[1] https://lore.kernel.org/lkml/20240506100509.GL40213@noisy.programming.kicks-ass.net/

Signed-off-by: Qais Yousef <qyousef@layalina.io>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Phil Auld <pauld@redhat.com>
Reviewed-by: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/20240610192018.1567075-2-qyousef@layalina.io
2024-08-07 18:32:37 +02:00
Phil Chang 5a830bbce3 hrtimer: Prevent queuing of hrtimer without a function callback
The hrtimer function callback must not be NULL. It has to be specified by
the call side but it is not validated by the hrtimer code. When a hrtimer
is queued without a function callback, the kernel crashes with a null
pointer dereference when trying to execute the callback in __run_hrtimer().

Introduce a validation before queuing the hrtimer in
hrtimer_start_range_ns().

[anna-maria: Rephrase commit message]

Signed-off-by: Phil Chang <phil.chang@mediatek.com>
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
2024-06-25 16:54:27 +02:00
Jiapeng Chong b7c8e1f8a7 hrtimer: Rename __hrtimer_hres_active() to hrtimer_hres_active()
The function hrtimer_hres_active() are defined in the hrtimer.c file, but
not called elsewhere, so rename __hrtimer_hres_active() to
hrtimer_hres_active() and remove the old hrtimer_hres_active() function.

kernel/time/hrtimer.c:653:19: warning: unused function 'hrtimer_hres_active'.

Fixes: 82ccdf062a ("hrtimer: Remove unused function")
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
Link: https://lore.kernel.org/r/20240418023000.130324-1-jiapeng.chong@linux.alibaba.com
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=8778
2024-04-22 16:13:19 +02:00
Jiapeng Chong 82ccdf062a hrtimer: Remove unused function
The function is defined, but not called anywhere:

  kernel/time/hrtimer.c:1880:20: warning: unused function '__hrtimer_peek_ahead_timers'.

Remove it.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240322070441.29646-1-jiapeng.chong@linux.alibaba.com
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=8611
2024-04-08 15:03:06 +02:00
Frederic Weisbecker 7988e5ae2b tick: Split nohz and highres features from nohz_mode
The nohz mode field tells about low resolution nohz mode or high
resolution nohz mode but it doesn't tell about high resolution non-nohz
mode.

In order to retrieve the latter state, tick_cancel_sched_timer() must
fiddle with struct hrtimer's internals to guess if the tick has been
initialized in high resolution.

Move instead the nohz mode field information into the tick flags and
provide two new bits: one to know if the tick is in nohz mode and
another one to know if the tick is in high resolution. The combination
of those two flags provides all the needed informations to determine
which of the three tick modes is running.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240225225508.11587-14-frederic@kernel.org
2024-02-26 11:37:32 +01:00
Frederic Weisbecker f04e51220a tick: Move tick cancellation up to CPUHP_AP_TICK_DYING
The tick hrtimer is cancelled right before hrtimers are migrated. This
is done from the hrtimer subsystem even though it shouldn't know about
its actual users.

Move instead the tick hrtimer cancellation to the relevant CPU hotplug
state that aims at centralizing high level tick shutdown operations so
that the related flow is easy to follow.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240225225508.11587-9-frederic@kernel.org
2024-02-26 11:37:31 +01:00
Peng Liu ffb7e01c4e tick/nohz: Remove duplicate between tick_nohz_switch_to_nohz() and tick_setup_sched_timer()
The ts->sched_timer initialization work of tick_nohz_switch_to_nohz()
is almost the same as that of tick_setup_sched_timer(), so adjust the
latter to get it reused by tick_nohz_switch_to_nohz().

This also makes the low resolution mode sched_timer benefit from the tick
skew boot option.

Signed-off-by: Peng Liu <liupeng17@lenovo.com>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240225225508.11587-2-frederic@kernel.org
2024-02-26 11:37:31 +01:00
Costa Shulyupin 56c2cb1012 hrtimer: Select housekeeping CPU during migration
During CPU-down hotplug, hrtimers may migrate to isolated CPUs,
compromising CPU isolation.

Address this issue by masking valid CPUs for hrtimers using
housekeeping_cpumask(HK_TYPE_TIMER).

Suggested-by: Waiman Long <longman@redhat.com>
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Waiman Long <longman@redhat.com>
Link: https://lore.kernel.org/r/20240222200856.569036-1-costa.shul@redhat.com
2024-02-22 22:18:21 +01:00