Re: [PATCH 2/3] hwmon: (coretemp) Read TjMax only when refreshing the temperature

From: Guenter Roeck

Date: Fri Sep 25 2026 - 10:16:37 EST


On Thu, Sep 24, 2026 at 07:33:21PM -0700, Ricardo Neri wrote:
> show_temp() reads TjMax before checking whether the cached temperature is
> still fresh, but consumes it only when recomputing that temperature. On a
> cache hit the value is discarded.
>
> Discarding it is not free. On CPUs that report TjMax in
> MSR_IA32_TEMPERATURE_TARGET, get_tjmax() returns the value it just read
> without storing it in tdata->tjmax, so every call reads the MSR again.
> That is a cross-CPU call whenever the CPU owning the sensor is not the
> current one, and it is made while holding tdata->update_lock.
>
> Read TjMax where it is used. The value cannot go stale in the meantime:
> bits 23:16 of MSR_IA32_TEMPERATURE_TARGET are read-only, and the register
> is package-scoped, so every CPU of the package reads the same value.
>
> The temperature reported to userspace does not change.
>
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@xxxxxxxxxxxxxxx>

Applied. No need to resend this or the previous patch.

Thanks,
Guenter