On 3/4/2026 10:32 AM, Frederic Weisbecker wrote:
> Le Tue, Feb 24, 2026 at 06:04:32PM -0500, Joel Fernandes a écrit :
>> The rcu_nocb_cpu_offload() and rcu_nocb_cpu_deoffload() functions are
>> nearly duplicates.
>>
>> Therefore, extract the common logic into rcu_nocb_cpu_toggle_offload()
>> which takes an 'offload' boolean, and make both exported functions
>> simple wrappers.
>>
>> This eliminates a bunch of duplicate code at the call sites, namely
>> mutex locking, CPU hotplug locking and CPU online checks.
>>
>> Signed-off-by: Joel Fernandes <[email protected]>
>> ---
>>  kernel/rcu/tree_nocb.h | 89 ++++++++++++++++++++++--------------------
>>  1 file changed, 46 insertions(+), 43 deletions(-)
>>
>> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
>> index b3337c7231cc..5b041134d6bb 100644
>> --- a/kernel/rcu/tree_nocb.h
>> +++ b/kernel/rcu/tree_nocb.h
>> @@ -1081,30 +1081,6 @@ static int rcu_nocb_rdp_deoffload(struct rcu_data 
>> *rdp)
>>      return 0;
>>  }
>>  
>> -int rcu_nocb_cpu_deoffload(int cpu)
>> -{
>> -    struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
>> -    int ret = 0;
>> -
>> -    cpus_read_lock();
>> -    mutex_lock(&rcu_state.nocb_mutex);
>> -    if (rcu_rdp_is_offloaded(rdp)) {
>> -            if (!cpu_online(cpu)) {
>> -                    ret = rcu_nocb_rdp_deoffload(rdp);
>> -                    if (!ret)
>> -                            cpumask_clear_cpu(cpu, rcu_nocb_mask);
>> -            } else {
>> -                    pr_info("NOCB: Cannot CB-deoffload online CPU %d\n", 
>> rdp->cpu);
>> -                    ret = -EINVAL;
>> -            }
>> -    }
>> -    mutex_unlock(&rcu_state.nocb_mutex);
>> -    cpus_read_unlock();
>> -
>> -    return ret;
>> -}
>> -EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload);
>> -
>>  static bool rcu_nocb_rdp_offload_wait_cond(struct rcu_data *rdp)
>>  {
>>      unsigned long flags;
>> @@ -1149,27 +1125,54 @@ static int rcu_nocb_rdp_offload(struct rcu_data *rdp)
>>      return 0;
>>  }
>>  
>> +/* Common helper for CPU offload/deoffload operations. */
>> +static int rcu_nocb_cpu_toggle_offload(int cpu, bool offload)
>> +{
>> +    struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
>> +    bool currently_offloaded;
>> +    int ret = 0;
>> +
>> +    cpus_read_lock();
>> +    mutex_lock(&rcu_state.nocb_mutex);
>> +
>> +    currently_offloaded = rcu_rdp_is_offloaded(rdp);
> 
> Do we really need that extra variable?

No we don't need it, fixed.

> Reviewed-by: Frederic Weisbecker <[email protected]>
> 

Thanks!

-- 
Joel Fernandes


Reply via email to