Hwmon: Merge Pkgtemp with Coretemp
PATCH v8 1/1 Hwmon: Merge Pkgtemp with Coretemp
This patch merges the pkgtemp with coretemp driver. The sysfs interfaces for all cores in the same pkg are shown under one directory, in hwmon. It also supports CONFIG_HOTPLUG_CPU. So, the sysfs interfaces are created when each core comes online and are removed when it goes offline.
---
v1:
* Basic Merging of pkgtemp with coretemp.
* Creates one hwmon device per core.
v2:
* Fixed some Data structure related comments from v1.
* Creates one hwmon device per core.
v3:
* Creates one hwmon device per physical package.
* No appropriate support for CPU hotplug.
v4:
* Creates one hwmon device per package.
* Added appropriate support for CONFIG_HOTPLUG_CPU.
v5:
* Changed naming of sysfs based on core_id
* Changed all %d to %u appropriately
* Removed unnecessary variables crit/max_alarm
* Fixed the flow of show_temp method
* Removed unwanted print messages
* Removed per-core related code from coretemp_device_add
* Corrected the error handling in get_core_online
v6:
* Added support to bring a HT core online, when real core is offlined
* Updated the Documentation/hwmon/coretemp
* Rearranged the code to avoid forward declarations
* Added locking for coretemp_remove_core method
* Added appropriate CONFIG_SMP #ifdefs
* Made variables static in create_core_attrs method
v7:
* Removed unnecessary mutexes from create_core_data and remove_core methods
* Fixed data->valid conditions in show_temp method
* Fixed coretemp_get_pdev for non-smp config
v8:
* Fixed retrieval of phys_proc_id in probe
* Added coretemp_remove_device to handle CPU offlining properly
Documentation/hwmon/coretemp | 21 +- drivers/hwmon/coretemp.c | 678 +++++++++++++++++++++++++++++------------ 2 files changed, 493 insertions(+), 206 deletions(-)
Documentation/hwmon/coretemp +14 -7
@@ -15,8 +15,13 @@ Author: Rudolf Marek Description ----------- +This driver permits reading the DTS (Digital Temperature Sensor) embedded +inside Intel CPUs. This driver can read both the per-core and per-package +temperature using the appropriate sensors. The per-package sensor is new; +as of now, it is present only in the SandyBridge platform. The driver will +show the temperature of all cores inside a package under a single device +directory inside hwmon. -This driver permits reading temperature sensor embedded inside Intel Core CPU. Temperature is measured in degrees Celsius and measurement resolution is 1 degree C. Valid temperatures are from 0 to TjMax degrees C, because the actual value of temperature register is in fact a delta from TjMax.
@@ -27,13 +32,15 @@ mechanism will perform actions to forcibly cool down the processor. Alarm may be raised, if the temperature grows enough (more than TjMax) to trigger the Out-Of-Spec bit. Following table summarizes the exported sysfs files: -temp1_input - Core temperature (in millidegrees Celsius). -temp1_max - All cooling devices should be turned on (on Core2). -temp1_crit - Maximum junction temperature (in millidegrees Celsius). -temp1_crit_alarm - Set when Out-of-spec bit is set, never clears. +All Sysfs entries are named with their core_id (represented here by 'X'). +tempX_input - Core temperature (in millidegrees Celsius). +tempX_max - All cooling devices should be turned on (on Core2). +tempX_crit - Maximum junction temperature (in millidegrees Celsius). +tempX_crit_alarm - Set when Out-of-spec bit is set, never clears. Correct CPU operation is no longer guaranteed. -temp1_label - Contains string "Core X", where X is processor - number. +tempX_label - Contains string "Core X", where X is processor + number. For Package temp, this will be "Physical id Y", + where Y is the package number. The TjMax temperature is set to 85 degrees C if undocumented model specific register (UMSR) 0xee has bit 30 set. If not the TjMax is 100 degrees C as
drivers/hwmon/coretemp.c +479 -199
814 lines not on this page · raw message
Signature · 7 lines
1.6.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Durga,
Quoted 8 lines · Durgadoss R
This patch merges the pkgtemp with coretemp driver. The sysfs interfaces for all cores in the same pkg are shown under one directory, in hwmon. It also supports
CONFIG_HOTPLUG_CPU. So, the sysfs interfaces are created when each core comes online and are removed when it goes offline.Signed-off-by Durgadoss R <[email protected]>
[ ... ]
Quoted 3 lines
v8:
* Fixed retrieval ofphys_proc_idin probe
* Addedcoretemp_remove_deviceto handle CPU offlining properly
There is no coretemp_remove_device() in the code. You mean coretemp_device_remove(), presumably.
[ ... ]
drivers/hwmon/coretemp.c static void __devinit get_ucode_rev_on_cpu(void *edx) · line 481
Quoted 11 lines
drivers/hwmon/coretemp.c +10
-0+static struct platform_device *coretemp_get_pdev (unsigned int cpu) +{ +struct pdev_entry *p; + +mutex_lock (&pdev_list_mutex); +list_for_each_entry (p, &pdev_list, list) +if (p->cpu = cpu) { +mutex_unlock (&pdev_list_mutex); +return p->pdev; + }
I have been wondering about this. In the non-SMP case, can there ever be more than one entry ?
If so, you should not need the loop but could just use list_first_entry() instead.
[ ... ]
drivers/hwmon/coretemp.c exit: · line 711
Quoted 8 lines
drivers/hwmon/coretemp.c +1
-2-static void __cpuinit coretemp_device_remove (unsigned int cpu) +static void coretemp_device_remove (unsigned int cpu) {struct pdev_entry *p; -unsigned int i;mutex_lock (&pdev_list_mutex);list_for_each_entry (p, &pdev_list, list) {
I think this should be list_for_each_safe() since you remove p.
drivers/hwmon/coretemp.c exit: · line 718
Quoted 8 lines
drivers/hwmon/coretemp.c +5
-0+#ifdef CONFIG_SMP +if (p->phys_proc_id !=cpu_data (cpu).phys_proc_id) +continue ; +#else if (p->cpu != cpu)continue ; +#endif
#ifdef at column 0, please.
I wonder about the !SMP case. Doesn't that imply that there is only one CPU ? If so, why compare the CPU ID ?
[ ... ]
drivers/hwmon/coretemp.c exit: · line 732
Quoted 5 lines
drivers/hwmon/coretemp.c +5
-0+{ +int i; + +/* Find online cores, except pkgtemp data */ +for (i =MAX_CORE_DATA -1 ; i >=0 ; --i) {
Not that it matters, but starting at 0 and iterating upwards is more common. Is that just personal preference, or do you have a reason ? Just wondering.
drivers/hwmon/coretemp.c exit: · line 735
Quoted 3 lines
drivers/hwmon/coretemp.c +3
-0+if (pdata->core_data[i] && + !pdata->core_data[i]->is_pkg_data) { +return 1 ;
Please return a boolean.
Quoted 5 lines
drivers/hwmon/coretemp.c +5
-0+ } + } +return 0 ; +} +
[ ... ]
Quoted 18 lines
drivers/hwmon/coretemp.c +18
-0+ +static void put_core_offline (unsigned int cpu) +{ +int i, indx; +struct platform_data *pdata; +struct platform_device *pdev =coretemp_get_pdev (cpu); + +/* If the physical CPU device does not exist, just return */ +if (!pdev) +return ; + + pdata =platform_get_drvdata (pdev); + + indx =get_attr_no (cpu,0 ); + +if (pdata->core_data[indx] && pdata->core_data[indx]->cpu = cpu) +coretemp_remove_core (pdata, &pdev->dev, indx); +
drivers/hwmon/coretemp.c exit: · line 805
Quoted 10 lines
drivers/hwmon/coretemp.c +10
-0+/* Online the HT version of this core, if any */ +for_each_cpu (i,cpu_sibling_mask (cpu)) +if (i != cpu) { +get_core_online (i); +break ; + } + +/* If all cores in this pkg are offline, remove the device */ +if (!is_any_core_online (pdata)) +coretemp_device_remove (cpu);
Where do you remove the package sensor entry ?
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
First of All, Thanks for the quick reply.
Quoted 6 lines
Quoted 3 lines
v8:
* Fixed retrieval ofphys_proc_idin probe
* Addedcoretemp_remove_deviceto handle CPU offlining properlyThere is no
coretemp_remove_device()in the code. You meancoretemp_device_remove(), presumably.
oops.. my bad.. :(
Quoted 16 lines
[ ... ]
drivers/hwmon/coretemp.c static void __devinit get_ucode_rev_on_cpu(void *edx) · line 481
Quoted 11 lines
drivers/hwmon/coretemp.c +10
-0+static struct platform_device *coretemp_get_pdev (unsigned int cpu) +{ +struct pdev_entry *p; + +mutex_lock (&pdev_list_mutex); +list_for_each_entry (p, &pdev_list, list) +if (p->cpu = cpu) { +mutex_unlock (&pdev_list_mutex); +return p->pdev; + }I have been wondering about this. In the non-SMP case, can there ever be more than one entry ?
Quoted 2 lines
If so, you should not need the loop but could just use
list_first_entry()instead.
Did not know about the list_first_entry() function..shall use it hereafter..
Quoted 21 lines
[ ... ]
drivers/hwmon/coretemp.c exit: · line 711
Quoted 8 lines
drivers/hwmon/coretemp.c +1
-2-static void __cpuinit coretemp_device_remove (unsigned int cpu) +static void coretemp_device_remove (unsigned int cpu) {struct pdev_entry *p; -unsigned int i;mutex_lock (&pdev_list_mutex);list_for_each_entry (p, &pdev_list, list) {I think this should be
list_for_each_safe()since you remove p.drivers/hwmon/coretemp.c exit: · line 718
Quoted 8 lines
drivers/hwmon/coretemp.c +5
-0+#ifdef CONFIG_SMP +if (p->phys_proc_id !=cpu_data (cpu).phys_proc_id) +continue ; +#else if (p->cpu != cpu)continue ; +#endif
Quoted 2 lines
#ifdef at column 0, please.
Didn't know this rule..And checkpatch.pl did not teach me either :)
Quoted 3 lines
I wonder about the !SMP case. Doesn't that imply that there is only one CPU ? If so, why compare the CPU ID ?
Agree that there will be only one entry..Shall change it accordingly..
Quoted 10 lines
[ ... ]
drivers/hwmon/coretemp.c exit: · line 732
Quoted 5 lines
drivers/hwmon/coretemp.c +5
-0+{ +int i; + +/* Find online cores, except pkgtemp data */ +for (i =MAX_CORE_DATA -1 ; i >=0 ; --i) {Not that it matters, but starting at 0 and iterating upwards is more common. Is that just personal preference, or do you have a reason ? Just wondering.
Initially I had this code in coretemp_remove. There, the pkgtemp will be removed after all its cores are removed if we loop this way. Wanted to keep the same code here too..
But again as you said, it doesn't matter.. Should I change ??
Quoted 5 lines
drivers/hwmon/coretemp.c exit: · line 805
Quoted 3 lines
drivers/hwmon/coretemp.c +3
-0+/* If all cores in this pkg are offline, remove the device */ +if (!is_any_core_online (pdata)) +coretemp_device_remove (cpu);Where do you remove the package sensor entry ?
Coretemp_device_remove will call platform_device_unregister, Which in turn calls coretemp_remove. This will remove the pkgtemp entry and do other cleanups like removing the name attr etc..
Thanks,
Durga
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 29 lines · Durgadoss
Hi Guenter,
First of All, Thanks for the quick reply.
Quoted 6 lines
Quoted 3 lines
v8:
* Fixed retrieval ofphys_proc_idin probe
* Addedcoretemp_remove_deviceto handle CPU offlining properlyThere is no
coretemp_remove_device()in the code. You meancoretemp_device_remove(), presumably.oops.. my bad.. :(
Quoted 16 lines
[ ... ]
drivers/hwmon/coretemp.c static void __devinit get_ucode_rev_on_cpu(void *edx) · line 481
Quoted 11 lines
drivers/hwmon/coretemp.c +10
-0+static struct platform_device *coretemp_get_pdev (unsigned int cpu) +{ +struct pdev_entry *p; + +mutex_lock (&pdev_list_mutex); +list_for_each_entry (p, &pdev_list, list) +if (p->cpu = cpu) { +mutex_unlock (&pdev_list_mutex); +return p->pdev; + }I have been wondering about this. In the non-SMP case, can there ever be more than one entry ?
Quoted 5 lines
Quoted 2 lines
If so, you should not need the loop but could just use
list_first_entry()instead.Did not know about the
list_first_entry()function..shall use it hereafter..
Me not either until about an hour ago ;).
Quoted 21 lines
Quoted 21 lines
[ ... ]
drivers/hwmon/coretemp.c exit: · line 711
Quoted 8 lines
drivers/hwmon/coretemp.c +1
-2-static void __cpuinit coretemp_device_remove (unsigned int cpu) +static void coretemp_device_remove (unsigned int cpu) {struct pdev_entry *p; -unsigned int i;mutex_lock (&pdev_list_mutex);list_for_each_entry (p, &pdev_list, list) {I think this should be
list_for_each_safe()since you remove p.Quoted 8 lines
drivers/hwmon/coretemp.c +5
-0+#ifdef CONFIG_SMP +if (p->phys_proc_id !=cpu_data (cpu).phys_proc_id) +continue ; +#else if (p->cpu != cpu)continue ; +#endif
Quoted 5 lines
Quoted 2 lines
#ifdef at column 0, please.
Didn't know this rule..And checkpatch.pl did not teach me either :)
I don't even know if it is a rule, but it is common practive, which is good enough for me to make it a rule.
Strictly speaking, the rule would be to not have any ifdefs in the code in the first place. Might be worth exploring if we can get rid of the ifdefs by using a single set of defines at the top, such as
#ifdef CONFIG_SMP
#define phys_proc_id(cpu) cpu_data(cpu)->phys_proc_id
#define cpu_core_id(cpu) cpu_data(cpu)->cpu_core_id
#else
#define phys_proc_id(cpu) (cpu)
#define cpu_core_id(cpu) (cpu)
#endif
If you also unconditionally declare phys_proc_id and cpu_core_id in struct pdev_entry, that should enable us to get rid of pretty much all the ifdefs in the code.
Would be great if you could do that now, or we can do it in a subsequent patch.
Quoted 17 lines
Quoted 3 lines
I wonder about the !SMP case. Doesn't that imply that there is only one CPU ? If so, why compare the CPU ID ?
Agree that there will be only one entry..Shall change it accordingly..
Quoted 10 lines
[ ... ]
drivers/hwmon/coretemp.c exit: · line 732
Quoted 5 lines
drivers/hwmon/coretemp.c +5
-0+{ +int i; + +/* Find online cores, except pkgtemp data */ +for (i =MAX_CORE_DATA -1 ; i >=0 ; --i) {Not that it matters, but starting at 0 and iterating upwards is more common. Is that just personal preference, or do you have a reason ? Just wondering.
Quoted 4 lines
Initially I had this code in
coretemp_remove. There, the pkgtemp will be removed after all its cores are removed if we loop this way. Wanted to keep the same code here too..
Guess the same question applies there too ;).
Quoted 2 lines
But again as you said, it doesn't matter.. Should I change ??
Your call.
Quoted 10 lines
Quoted 5 lines
drivers/hwmon/coretemp.c exit: · line 805
Quoted 3 lines
drivers/hwmon/coretemp.c +3
-0+/* If all cores in this pkg are offline, remove the device */ +if (!is_any_core_online (pdata)) +coretemp_device_remove (cpu);Where do you remove the package sensor entry ?
Coretemp_device_removewill callplatform_device_unregister, Which in turn callscoretemp_remove. This will remove the pkgtemp entry and do other cleanups like removing the name attr etc..
Ok. Might make sense to add a little explanation.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Guenter,
Quoted 14 lines
Strictly speaking, the rule would be to not have any ifdefs in the code in the first place.
Might be worth exploring if we can get rid of the ifdefs by using a single set of defines
at the top, such as#ifdef
CONFIG_SMP
#definephys_proc_id(cpu)cpu_data(cpu)->phys_proc_id
#definecpu_core_id(cpu)cpu_data(cpu)->cpu_core_id
#else
#definephys_proc_id(cpu)(cpu)
#definecpu_core_id(cpu)(cpu)
#endif
Quoted 5 lines
If you also unconditionally declare
phys_proc_idandcpu_core_idin structpdev_entry,
that should enable us to get rid of pretty much all the ifdefs in the code.Would be great if you could do that now, or we can do it in a subsequent patch.
I am not thinking about a new patch for this :)
Shall do this change in the next version itself..
Thanks,
Durga
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors