Re: [Patch v4 02/22] sched/cache: Limit the scan number of CPUs when calculating task occupancy

Chen, Yu C
2026-04-10T17:27:35Z

On 4/11/2026 1:12 AM, Tim Chen wrote:
> On Fri, 2026-04-10 at 15:29 +0800, Chen, Yu C wrote:
>> Hi Gengkun,
>>
>> On 4/9/2026 9:17 PM, Luo Gengkun wrote:
>>>
>>>
>>> On 2026/4/2 5:52, Tim Chen wrote:
>>>> From: Chen Yu <yu.c.chen@intel.com>
>>> task_struct *p, s64 delta_exec)
>>>                 pcpu_sched->runtime += delta_exec;
>>>                 rq->cpu_runtime += delta_exec;
>>>                 epoch = rq->cpu_epoch;
>>> +               cpumask_set_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
>>
>> I would refer a check before writing to avoid c2c overhead:
>> if (!cpumask_test_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus))
>> cpumask_set_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
>
>
> I think a similar check is also needed for clearing of visited CPU. It is possible that
> the visited_cpus mask has already been cleared long time back. Change

Yes, I agree, although we reach here when scanning the visited_cpus
snapshot, there could be a race condition when we are in this loop
but the CPU in visited_cpu has already been cleared.

thanks,
Chenyu

>
> + if (llc_epoch_visited_timeout && (rq->cpu_epoch - pcpu_sched->epoch) >
> + llc_epoch_visited_timeout) {
> + cpumask_clear_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
> + continue;
> + }
>
> to
>
> + if (llc_epoch_visited_timeout &&
> + cpumask_test_cpu(cpu_of(rq), &mm->sc_stat.visitied_cpus) &&
> + (rq->cpu_epoch - pcpu_sched->epoch) > llc_epoch_visited_timeout) {
> + cpumask_clear_cpu(cpu_of(rq), &mm->sc_stat.visited_cpus);
> + continue;
> + }
>
> Thanks.
>
> Tim
>
>