Re: [PATCH 1/2 V2] hwmon: (coretemp) Detect the thermal sensors by CPUID

From: Valdis . Kletnieks
Date: Mon May 10 2010 - 08:46:44 EST


On Mon, 10 May 2010 11:35:25 +0800, Huaxu Wan said:
>
> The thermal sensors of Intel(R) CPUs can be detected by CPUID instruction,
> indicated by CPUID.06H.EAX[0].
>
> Signed-off-by: Huaxu Wan <huaxu.wan@xxxxxxxxxxxxxxx>
> Signed-off-by: Carsten Emde <C.Emde@xxxxxxxxx>
> ---
> drivers/hwmon/coretemp.c | 24 +++++++-----------------
> 1 files changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
> index e9b7fbc..d194207 100644
> --- a/drivers/hwmon/coretemp.c
> +++ b/drivers/hwmon/coretemp.c
> @@ -440,6 +440,7 @@ static int __init coretemp_init(void)
> {
> int i, err = -ENODEV;
> struct pdev_entry *p, *n;
> + u32 eax;
>
> /* quick check if we run Intel */
> if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL)
> @@ -450,23 +451,12 @@ static int __init coretemp_init(void)
> goto exit;
>
> for_each_online_cpu(i) {
> - struct cpuinfo_x86 *c = &cpu_data(i);
> -
> - /* check if family 6, models 0xe (Pentium M DC),
> - 0xf (Core 2 DC 65nm), 0x16 (Core 2 SC 65nm),
> - 0x17 (Penryn 45nm), 0x1a (Nehalem), 0x1c (Atom),
> - 0x1e (Lynnfield) */
> - if ((c->cpuid_level < 0) || (c->x86 != 0x6) ||
> - !((c->x86_model == 0xe) || (c->x86_model == 0xf) ||
> - (c->x86_model == 0x16) || (c->x86_model == 0x17) ||
> - (c->x86_model == 0x1a) || (c->x86_model == 0x1c) ||
> - (c->x86_model == 0x1e))) {

So we remove something that checks the CPU level for a model we *expect*
to find a thermal sensor, and only throws a KERN_WARNING if we're on a
model we don't know about...

> + /* check if the CPU has thermal sensor */
> + eax = cpuid_eax(0x06);
> + if (!(eax & 0x01)) {
> + struct cpuinfo_x86 *c = &cpu_data(i);
> + printk(KERN_WARNING DRVNAME ": CPU (model=0x%x)"
> + " has no thermal sensor!\n", c->x86_model);

And replace it with a totally unprotected check that's going to fire off
a KERN_WARNING on every single CPU that Intel ever made that doesn't
include a hardware thermal sensor - including all the family 0-5,
and model < 0x0e hardware.

KERN_WARNING is for "We expected to find the hardware but it's gone off
for a walk on us". If you wanted to say "Hmm.. this CPU doesn't have one"
you probably wanted KERN_DEBUG or *maybe* KERN_INFO.

Attachment: pgp00000.pgp
Description: PGP signature