[PATCH v2 1/2] watchdog/perf: Provide function for adjusting the event period
Yicong Yang
yangyicong at huawei.com
Tue May 13 00:02:12 PDT 2025
On 2025/5/13 7:07, Andrew Morton wrote:
> On Mon, 12 May 2025 21:09:18 +0800 Yicong Yang <yangyicong at huawei.com> wrote:
>
>> From: Yicong Yang <yangyicong at hisilicon.com>
>>
>> Architecture's using perf events for hard lockup detection needs to
>> convert the watchdog_thresh to the event's period, some architecture
>> for example arm64 perform this conversion using the CPU's maximum
>> frequency which will be acquired by cpufreq. However by the time
>> the lockup detector's initialized the cpufreq driver may not be
>> initialized, thus launch a watchdog with inaccurate period. Provide
>> a function hardlockup_detector_perf_adjust_period() to allowing
>> adjust the event period. Then architecture can update with more
>> accurate period if cpufreq is initialized.
>>
>> ...
>>
>> +/**
>> + * hardlockup_detector_perf_adjust_period - Adjust the event period due
>> + * to cpu frequency change
>> + * @cpu: The CPU whose event period will be adjusted
>> + * @period: The target period to be set
>> + */
>> +void hardlockup_detector_perf_adjust_period(int cpu, u64 period)
>> +{
>> + struct perf_event *event = per_cpu(watchdog_ev, cpu);
>> +
>> + if (!(watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED))
>> + return;
>
> Is this the right thing to do? Would it be better to proceed with the
> alteration of the period so that the state is correct if
> WATCHDOG_HARDLOCKUP_ENABLED is later enabled? (If that's possible).
>
This is just a check to see whether we need to proceed. WATCHDOG_HARDLOCKUP_ENABLED
will be set if:
1. hardlockup is supported
2. user doesn't disable it by cmdline/sysctl
If WATCHDOG_HARDLOCKUP_ENABLED is not set the hardlockup detector won't be initialized
as well (in watchdog_enable()), then we don't need to adjust the period as well.
>
>> + if (!event)
>> + return;
>> +
>> + if (event->attr.sample_period == period)
>> + return;
>> +
>> + if (perf_event_period(event, period))
>> + pr_err("failed to change period to %llu\n", period);
>> +}
>> +
>> /**
>> * hardlockup_detector_perf_stop - Globally stop watchdog events
>> *
>> --
>> 2.24.0
>
> .
>
More information about the linux-arm-kernel
mailing list