hrtimer: select housekeeping CPU during migration

Message ID 20240211135213.2518068-1-costa.shul@redhat.com
State New
Headers
Series hrtimer: select housekeeping CPU during migration |

Commit Message

Costa Shulyupin Feb. 11, 2024, 1:52 p.m. UTC
  because during CPU deactivation a timer can migrate
to isolated CPU and break CPU isolation.

For reference see function get_nohz_timer_target,
which selects CPU for new timers from housekeeping_cpumask(HK_TYPE_TIMER)

Inspired by Waiman Long <longman@redhat.com>

Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Waiman Long Feb. 11, 2024, 4:37 p.m. UTC | #1
On 2/11/24 08:52, Costa Shulyupin wrote:
> because during CPU deactivation a timer can migrate
> to isolated CPU and break CPU isolation.
>
> For reference see function get_nohz_timer_target,
> which selects CPU for new timers from housekeeping_cpumask(HK_TYPE_TIMER)
>
> Inspired by Waiman Long <longman@redhat.com>
>
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>

Nit: It is unusual to begin the commit log with "because".

Other than that, the patch looks good to me.

Reviewed-by:  Waiman Long <longman@redhat.com>

> ---
>   kernel/time/hrtimer.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index f82997cf53b6..460d916e24b7 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2227,7 +2227,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
>   int hrtimers_cpu_dying(unsigned int dying_cpu)
>   {
>   	struct hrtimer_cpu_base *old_base, *new_base;
> -	int i, ncpu = cpumask_first(cpu_active_mask);
> +	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
>   	pr_debug("ncpu=%d, dying_cpu=%d\n", ncpu, dying_cpu);
>   
>   	tick_cancel_sched_timer(dying_cpu);
  
Frederic Weisbecker Feb. 12, 2024, 3:23 p.m. UTC | #2
Le Sun, Feb 11, 2024 at 03:52:13PM +0200, Costa Shulyupin a écrit :
> because during CPU deactivation a timer can migrate
> to isolated CPU and break CPU isolation.
> 
> For reference see function get_nohz_timer_target,
> which selects CPU for new timers from housekeeping_cpumask(HK_TYPE_TIMER)
> 
> Inspired by Waiman Long <longman@redhat.com>
> 
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
  
Thomas Gleixner Feb. 13, 2024, 12:36 p.m. UTC | #3
On Sun, Feb 11 2024 at 15:52, Costa Shulyupin wrote:
> because during CPU deactivation a timer can migrate
> to isolated CPU and break CPU isolation.

That's not a sentence.

> For reference see function get_nohz_timer_target,

get_nohz_timer_target()

> which selects CPU for new timers from
> housekeeping_cpumask(HK_TYPE_TIMER)

But what is the point of this statement?

> Inspired by Waiman Long <longman@redhat.com>

Can you please use a proper tag, i.e. Suggested-by and not invent some
random free form text just because?

> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
> ---
>  kernel/time/hrtimer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index f82997cf53b6..460d916e24b7 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2227,7 +2227,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
>  int hrtimers_cpu_dying(unsigned int dying_cpu)
>  {
>  	struct hrtimer_cpu_base *old_base, *new_base;
> -	int i, ncpu = cpumask_first(cpu_active_mask);
> +	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
>  	pr_debug("ncpu=%d, dying_cpu=%d\n", ncpu, dying_cpu);
>  
>  	tick_cancel_sched_timer(dying_cpu);

Q: Against which tree is this supposed to apply?

A: Against some private tree of yours which added the pr_debug() in a
   previous commit.

Can you please read and follow Documentation/process/ and provide
patches which actually can be applied without fixing them up manually?

Thanks,

        tglx
  

Patch

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index f82997cf53b6..460d916e24b7 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2227,7 +2227,7 @@  static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
 int hrtimers_cpu_dying(unsigned int dying_cpu)
 {
 	struct hrtimer_cpu_base *old_base, *new_base;
-	int i, ncpu = cpumask_first(cpu_active_mask);
+	int i, ncpu = cpumask_any_and(cpu_active_mask, housekeeping(HK_TYPE_TIMER));
 	pr_debug("ncpu=%d, dying_cpu=%d\n", ncpu, dying_cpu);
 
 	tick_cancel_sched_timer(dying_cpu);