Re: [PATCH] hrtimer: Fix the incorrect initialization of timer->is_hard
From: cuiguoqi
Date: Mon Mar 24 2025 - 09:16:28 EST
Here,it is not set but referenced. When !PREEMPT, is_hard does not match
the actual situation.In the original logic, the actual mode selection is
mainly based on softtimer.
When the HARD/SOFT mode is not explicitly configured, the following logic
is used to select the hard/soft mode:
> bool softtimer = !!(mode & HRTIMER_MODE_SOFT); //PREEMPT_RT:flase/!PREEMPT_RT: flase
> if (IS_ENABLED(CONFIG_PREEMPT_RT) && !(mode & HRTIMER_MODE_HARD))
softtimer = true; //PREEMPT_RT:true
> base = softtimer ? HRTIMER_MAX_CLOCK_BASES/2:0;//PREEMPT_RT:soft mode/!PREEMPT_RT: hard mode
> base += hrtimer_clockid_to_base(clock_id);
> timer->base = &cpu_base->clock_base[base];
> timer->is_soft = softtimer; //PREEMPT_RT:true /!PREEMPT_RT: false
- timer->is_hard = !!(mode & HRTIMER_MODE_HARD);//PREEMPT_RT:false/!PREEMPT_RT: false
+ timer->is_hard = !softtimer; //PREEMPT_RT:false/!PREEMPT_RT: true
Thus, under !PREEMPT, the distinction in is_hard is clear.
while it does not affect the logic of the hrtimer_start_range_ns:
> if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> WARN_ON_ONCE(!(mode & HRTIMER_MODE_SOFT) ^ !timer->is_soft);
> else
> WARN_ON_ONCE(!(mode & HRTIMER_MODE_HARD) ^ !timer->is_hard);