Skip to contentSkip to conversation

drivers/hwmon/coretemp: Fix incorrect hot-removed CPU's core sensor issue

PATCH In review Fenghua Yu 5 participants 15 messages Aug 18, 2010 – Sep 4, 2010

Subsystems (2)
lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 drivers/hwmon/coretemp: Fix incorrect hot-removed CPU's core sensor issue

From: Fenghua Yu <[email protected]>

In current coretemp driver, when a CPU in dev_list is hot-removed, although its HT sibling is still running, its core sensor is gone and not available to user level application any more.

When a CPU is hot-removed, its core sensor should be still available to upper level application as long as the hot-removed CPU's HT sibling is still running. A core sensor is invisible to user level only when all of siblings in a core are hot-removed.

This patch fixes this issue.

---
 drivers/hwmon/coretemp.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
drivers/hwmon/coretemp.c +22 -3
index c070c97..2257cc4 100644
@@ -418,7 +418,7 @@ struct pdev_entry {
 static LIST_HEAD(pdev_list);
 static DEFINE_MUTEX(pdev_list_mutex);
 
-static int __cpuinit coretemp_device_add(unsigned int cpu)
+static int coretemp_device_add(unsigned int cpu)
 {
 	int err;
 	struct platform_device *pdev;
@@ -483,15 +483,34 @@ exit:
 static void coretemp_device_remove(unsigned int cpu)
 {
 	struct pdev_entry *p, *n;
-	mutex_lock(&pdev_list_mutex);
+#ifdef CONFIG_SMP
+	int s;
+#endif
+
 	list_for_each_entry_safe(p, n, &pdev_list, list) {
 		if (p->cpu = cpu) {
+			mutex_lock(&pdev_list_mutex);
 			platform_device_unregister(p->pdev);
 			list_del(&p->list);
 			kfree(p);
+			mutex_unlock(&pdev_list_mutex);
+
+#ifdef CONFIG_SMP
+			/*
+			 * Add removed CPU's HT sibling to dev_list.
+			 * If there is no sibling available, the core sensor
+			 * is invisiable to user space any more.
+			 */
+			for_each_cpu(s, cpu_sibling_mask(cpu)) {
+				if (s != cpu) {
+					coretemp_device_add(s);
+					break;
+				}
+			}
+#endif
+			return;
 		}
 	}
-	mutex_unlock(&pdev_list_mutex);
 }
 
 static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
Signature · 7 lines
1.6.0.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author
#1 lore raw

PATCH 1/1 drivers/hwmon/coretemp: Remove warnings of unused variables

From: Fenghua Yu <[email protected]>

Remove compilation warnings of unused variables p and n in coretemp_init().

---
 drivers/hwmon/coretemp.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/hwmon/coretemp.c +0 -1
index c070c97..de81111 100644
@@ -518,7 +518,6 @@ static struct notifier_block coretemp_cpu_notifier __refdata = {
 static int __init coretemp_init(void)
 {
 	int i, err = -ENODEV;
-	struct pdev_entry *p, *n;
 
 	/* quick check if we run Intel */
 	if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL)
Signature · 7 lines
1.6.0.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw

Re: [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Hi Fenghua,

Quoted 14 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

Remove compilation warnings of unused variables p and n in coretemp_init().

---
 drivers/hwmon/coretemp.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/hwmon/coretemp.c +0 -0
index c070c97..de81111 100644

drivers/hwmon/coretemp.c static struct notifier_block coretemp_cpu_notifier __refdata = { · line 523

Quoted 7 lines
drivers/hwmon/coretemp.c +0 -1
@@ -518,7 +518,6 @@ static struct notifier_block coretemp_cpu_notifier __refdata = {
 static int __init coretemp_init(void)
 {
 	int i, err = -ENODEV;
-	struct pdev_entry *p, *n;
 
 	/* quick check if we run Intel */
 	if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL)

Thanks for the fix, but it is already in my tree:
ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-coretemp-fix-warning.patch

I'll send it to Linus as part as my next batch of hwmon fixes for 2.6.36.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw

Re: [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Quoted 7 lines · Jean Delvare

Thanks for the fix, but it is already in my tree:
ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-coretemp-fix-warning.patch

I'll send it to Linus as part as my next batch of hwmon fixes for 2.6.36.

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

-hpa

Signature · 8 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw

Re: [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Jean Delvare

Thanks for the fix, but it is already in my tree:
ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-coretemp-fix-warning.patch

Quoted 7 lines
Quoted 2 lines

I'll send it to Linus as part as my next batch of hwmon fixes for 2.6.36.

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

Meanwhile, I'm doing my best to off-load some of the hwmon work from Andrew, but that doesn't make me THE maintainer of hwmon.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw

Re: [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Quoted 8 lines · Jean Delvare

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

Meanwhile, I'm doing my best to off-load some of the hwmon work from Andrew, but that doesn't make me THE maintainer of hwmon.

OK. I was simply wondering if Fenghua should push his coretemp tree through you rather than direct to Linus.

-hpa

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#6 lore raw

Re: [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Jean Delvare

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

Quoted 6 lines
Quoted 3 lines

Meanwhile, I'm doing my best to off-load some of the hwmon work from Andrew, but that doesn't make me THE maintainer of hwmon.

OK. I was simply wondering if Fenghua should push his coretemp tree through you rather than direct to Linus.

Well, it would certainly make sense for Fenghua to send the patches to me (or better, to the lm-sensors list) and/or Andrew. I doubt Linus is willing to review random driver patches on a regular basis, especially when they don't fix anything critical.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#7 lore raw

Re: [lm-sensors] [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

In reply to Jean Delvare
Quoted 9 lines · Jean Delvare
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Jean Delvare

Thanks for the fix, but it is already in my tree:
ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-coretemp-fix-warning.patch

I'll send it to Linus as part as my next batch of hwmon fixes for 2.6.36.

Quoted 9 lines
Quoted 4 lines

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

I can step in if needed. I don't want to step on anyone's feet, though, and I would not want to be the sole maintainer, at least not yet - I just don't know the code well enough.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#8 lore raw

Re: [lm-sensors] [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Hi Guenter,

Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Jean Delvare
Quoted 4 lines · H. Peter Anvin

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

Quoted 7 lines
Quoted 3 lines

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

I can step in if needed. I don't want to step on anyone's feet, though, and I would not want to be the sole maintainer, at least not yet - I just don't know the code well enough.

Please don't say this lightly. This is a very serious matter :p

Do you realize how much work this represents? Are you ready to take the load for a long period of time?

If you are aware that being a subsystem (co-)maintainer can take several hours per week, and are ready to spend that much time on it for at least 6 months, then please let me know if you would be OK with the following:

MAINTAINERS +3 -1
@@ -2641,9 +2641,11 @@ S:	Maintained
 F:	drivers/media/video/gspca/
 
 HARDWARE MONITORING
+M:	Jean Delvare <[email protected]>
+M:	Guenter Roeck <[email protected]>
 L:	[email protected]
 W:	http://www.lm-sensors.org/
-S:	Orphan
+S:	Maintained
 F:	Documentation/hwmon/
 F:	drivers/hwmon/
 F:	include/linux/hwmon*.h

I am not working with you for such a long time, but collaboration went just fine from my perspective, so I would be very happy to co-maintain the hwmon subsystem with you.

Thanks,

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#9 lore raw

Re: [lm-sensors] [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Hi Jean,

Quoted 14 lines · Jean Delvare

Hi Guenter,

Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Jean Delvare
Quoted 4 lines · H. Peter Anvin

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

Quoted 9 lines
Quoted 3 lines

I can step in if needed. I don't want to step on anyone's feet, though, and I would not want to be the sole maintainer, at least not yet - I just don't know the code well enough.

Please don't say this lightly. This is a very serious matter :p

Do you realize how much work this represents? Are you ready to take the load for a long period of time?

I would not propose it if I didnt take it seriously.

Quoted 11 lines

If you are aware that being a subsystem (co-)maintainer can take several hours per week, and are ready to spend that much time on it for at least 6 months, then please let me know if you would be OK with the following:

MAINTAINERS +0 -0
@@ -2641,9 +2641,11 @@ S:	Maintained
 F:	drivers/media/video/gspca/
 

MAINTAINERS S: Maintained · line 2651

Quoted 10 lines
MAINTAINERS +3 -1
 HARDWARE MONITORING
+M:	Jean Delvare <[email protected]>
+M:	Guenter Roeck <[email protected]>
 L:	[email protected]
 W:	http://www.lm-sensors.org/
-S:	Orphan
+S:	Maintained
 F:	Documentation/hwmon/
 F:	drivers/hwmon/
 F:	include/linux/hwmon*.h

Yes.

Quoted 4 lines

I am not working with you for such a long time, but collaboration went just fine from my perspective, so I would be very happy to co-maintain the hwmon subsystem with you.

Same here.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#10 lore raw

Re: [lm-sensors] [PATCH] drivers/hwmon/coretemp: Remove warnings of unused variables

Quoted 51 lines · Guenter Roeck

Hi Jean,

Quoted 14 lines · Jean Delvare

Hi Guenter,

Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Jean Delvare
Quoted 4 lines · H. Peter Anvin

Hi Jean,

Are you overall hwmon maintainer now? That job is currently listed as Orphan in the MAINTAINERS file.

MAINTAINERS is correct. I do not have the time, nor the will, to be the single official maintainer of the hwmon subsystem. I would be happy to be a co-maintainer, but nobody stepped in to co-maintain with me.

Quoted 9 lines
Quoted 3 lines

I can step in if needed. I don't want to step on anyone's feet, though, and I would not want to be the sole maintainer, at least not yet - I just don't know the code well enough.

Please don't say this lightly. This is a very serious matter :p

Do you realize how much work this represents? Are you ready to take the load for a long period of time?

I would not propose it if I didnt take it seriously.

Quoted 11 lines

If you are aware that being a subsystem (co-)maintainer can take several hours per week, and are ready to spend that much time on it for at least 6 months, then please let me know if you would be OK with the following:

MAINTAINERS +0 -0
@@ -2641,9 +2641,11 @@ S:	Maintained
 F:	drivers/media/video/gspca/
 

MAINTAINERS S: Maintained · line 2651

Quoted 10 lines
MAINTAINERS +3 -1
 HARDWARE MONITORING
+M:	Jean Delvare <[email protected]>
+M:	Guenter Roeck <[email protected]>
 L:	[email protected]
 W:	http://www.lm-sensors.org/
-S:	Orphan
+S:	Maintained
 F:	Documentation/hwmon/
 F:	drivers/hwmon/
 F:	include/linux/hwmon*.h

Yes.

Quoted 5 lines
Quoted 4 lines

I am not working with you for such a long time, but collaboration went just fine from my perspective, so I would be very happy to co-maintain the hwmon subsystem with you.

Same here.

Wonderful. I'll commit the above patch upstream soon.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author
#11 lore raw

PATCH 1/1 drivers/hwmon/pkgtemp: Fix improper locking in CPU hot remove

In reply to Fenghua Yu

From: Fenghua Yu <[email protected]>

When a sibling is added to dev_list after a cpu is hot-removed, pdev_list_mutex has been locked already. But pkgtemp_device_add() tries to lock pdev_list_mutex again. This is incorrect. The patch fixes this issue.

The patch also removes __cpuinit for pkgtemp_device_add() to avoid section mismatch warning.

---
 drivers/hwmon/pkgtemp.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
drivers/hwmon/pkgtemp.c +13 -5
index 74157fc..928a016 100644
@@ -276,7 +276,7 @@ struct pdev_entry {
 static LIST_HEAD(pdev_list);
 static DEFINE_MUTEX(pdev_list_mutex);
 
-static int __cpuinit pkgtemp_device_add(unsigned int cpu)
+static int pkgtemp_device_add(unsigned int cpu)
 {
 	int err;
 	struct platform_device *pdev;
@@ -341,26 +341,34 @@ static void pkgtemp_device_remove(unsigned int cpu)
 {
 	struct pdev_entry *p, *n;
 	unsigned int i;
-	int err;
 
-	mutex_lock(&pdev_list_mutex);
 	list_for_each_entry_safe(p, n, &pdev_list, list) {
 		if (p->cpu != cpu)
 			continue;
 
+		mutex_lock(&pdev_list_mutex);
 		platform_device_unregister(p->pdev);
 		list_del(&p->list);
 		kfree(p);
+		mutex_unlock(&pdev_list_mutex);
+		/*
+		 * Select one of removed cpu's siblings to represent sensor
+		 * for this package.
+		 * If there is no more running sibling in a package, the
+		 * package sensor for this package is not available to user
+		 * space any more.
+		 */
 		for_each_cpu(i, cpu_core_mask(cpu)) {
+			int err;
+
 			if (i != cpu) {
 				err = pkgtemp_device_add(i);
 				if (!err)
 					break;
 			}
 		}
-		break;
+		return;
 	}
-	mutex_unlock(&pdev_list_mutex);
 }
 
 static int __cpuinit pkgtemp_cpu_callback(struct notifier_block *nfb,
Signature · 7 lines
1.6.0.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#12 lore raw
In reply to Fenghua Yu
Quoted 11 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In current coretemp driver, when a CPU in dev_list is hot-removed, although its HT sibling is still running, its core sensor is gone and not available to user level application any more.

When a CPU is hot-removed, its core sensor should be still available to upper level application as long as the hot-removed CPU's HT sibling is still running. A core sensor is invisible to user level only when all of siblings in a core are hot-removed.

Isn't that just a short term (ie a couple of ms or even us) race condition until the sibling is removed as well ? If so, why bother ?

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#13 lore raw
In reply to Fenghua Yu

Hi Fenghua,

Quoted 10 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In current coretemp driver, when a CPU in dev_list is hot-removed, although its HT sibling is still running, its core sensor is gone and not available to user level application any more.

When a CPU is hot-removed, its core sensor should be still available to upper level application as long as the hot-removed CPU's HT sibling is still running. A core sensor is invisible to user level only when all of siblings in a core are hot-removed.

Good point. I admit I didn't think about this scenario when fixing the duplicate HT entries. I thought both hyperthreads would go away at the same time, but since then I learned that individual HT can be removed using the sysfs "online" attributes.

That being said, I'm curious if this is really a problem in practice? Why would one disable only one hyperthread on a given core? I can't think of a real-world scenario.

I don't mean to suggest that we don't have to fix the problem. I'm simply trying to figure out how fast we need to fix it, and whether the fix is worth adding to the stable kernel series or not.

Quoted 46 lines

This patch fixes this issue.

---
 drivers/hwmon/coretemp.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
drivers/hwmon/coretemp.c +16 -2
index c070c97..2257cc4 100644
@@ -418,7 +418,7 @@ struct pdev_entry {
 static LIST_HEAD(pdev_list);
 static DEFINE_MUTEX(pdev_list_mutex);
 
-static int __cpuinit coretemp_device_add(unsigned int cpu)
+static int coretemp_device_add(unsigned int cpu)
 {
 	int err;
 	struct platform_device *pdev;
@@ -483,15 +483,34 @@ exit:
 static void coretemp_device_remove(unsigned int cpu)
 {
 	struct pdev_entry *p, *n;
-	mutex_lock(&pdev_list_mutex);
+#ifdef CONFIG_SMP
+	int s;
+#endif
+
 	list_for_each_entry_safe(p, n, &pdev_list, list) {
 		if (p->cpu = cpu) {
+			mutex_lock(&pdev_list_mutex);
 			platform_device_unregister(p->pdev);
 			list_del(&p->list);
 			kfree(p);
+			mutex_unlock(&pdev_list_mutex);
+
+#ifdef CONFIG_SMP
+			/*
+			 * Add removed CPU's HT sibling to dev_list.
+			 * If there is no sibling available, the core sensor
+			 * is invisiable to user space any more.
+			 */
+			for_each_cpu(s, cpu_sibling_mask(cpu)) {
+				if (s != cpu) {

drivers/hwmon/coretemp.c exit: · line 514

Quoted 10 lines
drivers/hwmon/coretemp.c +6 -1
+					coretemp_device_add(s);
+					break;
+				}
+			}
+#endif
+			return;
 		}
 	}
-	mutex_unlock(&pdev_list_mutex);
 }

I am not convinced by this implementation. See the following comment sequence:

* * * * *
localhost:/home/khali # sensors
coretemp-isa-0000
Adapter: ISA adapter
Core 0: +47.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0001
Adapter: ISA adapter
Core 1: +46.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0002
Adapter: ISA adapter
Core 2: +48.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0003
Adapter: ISA adapter
Core 3: +46.0°C (high = +90.0°C, crit = +100.0°C)

localhost:/home/khali # echo 0 > /sys/devices/system/cpu/cpu1/online localhost:/home/khali # sensors
coretemp-isa-0005
Adapter: ISA adapter
Core 1: +48.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Core 0: +48.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0002
Adapter: ISA adapter
Core 2: +49.0°C (high = +90.0°C, crit = +100.0°C)

coretemp-isa-0003
Adapter: ISA adapter
Core 3: +48.0°C (high = +90.0°C, crit = +100.0°C)

localhost:/home/khali #
* * * * *

As you can see, the switch of hyperthreads on Core 1 caused hwmon device coretemp-isa-0001 to be removed and be replaced with coretemp-isa-0005. There is also a change in the underlying directories, /sys/class/hwmon/hwmon1/device now points
to /sys/devices/platform/coretemp.5 instead
of /sys/devices/platform/coretemp.1. This has three drawbacks:
1* Configuration statements from /etc/sensors.conf will no longer be
applied.
2* Some monitoring applications may lose their path to the sensors.
Thankfully, libsensors uses hwmon device paths rather than physical device paths, so the effect should be limited, but other tools (e.g. the fancontrol script) tend to prefer physical device paths, so they will break.
3* If you disable several HTs at once, you have no guarantee that the
new hwmon devices will be numbered in the same order as the old hwmon devices. If you are unlucky and the number changes, then all libsensors-based applications will start reporting garbage.

I admit that these issues are not critical ones, and are rather unlikely to happen in the real world, but so is the problem you are trying to solve in the first place.

Point 1* could be easily solved by changing the way the coretemp device ID is allocated. Instead of using the CPU ID directly, we would use the smallest CPU ID amongst all the siblings. This ensures a consistent ID no matter which sibling is used.

Points 2* and 3*, however, can't be solved without reworking the driver significantly. I think we should not only skip duplicate HT entries on driver registration as my naive patch did. We should instead keep track of them, i.e. all coretemp entries should know the list of CPU entries they are backed up by, and a coretemp device would be unregistered only when this list shrinks to zero elements (all HT have been removed.)

As you said you agree to give a try to a rework of the coretemp driver to keep all related cores into the same hwmon device, I think this additional constraint might fit well in the new driver design. What do you think?

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author
#14 lore raw
Quoted 9 lines · Jean Delvare

Hi Fenghua,

Quoted 5 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>
When a CPU is hot-removed, its core sensor should be still available to upper level application as long as the hot-removed CPU's HT sibling is still running. A core sensor is invisible to user level only when all of siblings in a core are hot-removed.

Quoted 8 lines

Good point. I admit I didn't think about this scenario when fixing the duplicate HT entries. I thought both hyperthreads would go away at the same time, but since then I learned that individual HT can be removed using the sysfs "online" attributes.

That being said, I'm curious if this is really a problem in practice? Why would one disable only one hyperthread on a given core? I can't think of a real-world scenario.

Overall we need to keep state integrity for hot-removed CPU and shared core sensor. Without fixing this issue, we end up with inconsistent system info.

As for usage scenario, I can think of some:
1. Power saving. Management application may offline some threads or all thread siblings to save power. Image all of HT is disabled during run-time, less power is consumed with less performance.
2. RAS. A bad thread may be offlined which its sibling is still running. This could be becaused of logical CPU spcific state e.g. instruction TLB.

Quoted 39 lines

I don't mean to suggest that we don't have to fix the problem. I'm simply trying to figure out how fast we need to fix it, and whether the fix is worth adding to the stable kernel series or not.

As you can see, the switch of hyperthreads on Core 1 caused hwmon device coretemp-isa-0001 to be removed and be replaced with coretemp-isa-0005. There is also a change in the underlying directories, /sys/class/hwmon/hwmon1/device now points
to /sys/devices/platform/coretemp.5 instead
of /sys/devices/platform/coretemp.1. This has three drawbacks:
1* Configuration statements from /etc/sensors.conf will no longer be
applied.
2* Some monitoring applications may lose their path to the sensors.
Thankfully, libsensors uses hwmon device paths rather than physical device paths, so the effect should be limited, but other tools (e.g. the fancontrol script) tend to prefer physical device paths, so they will break.
3* If you disable several HTs at once, you have no guarantee that the
new hwmon devices will be numbered in the same order as the old hwmon devices. If you are unlucky and the number changes, then all libsensors-based applications will start reporting garbage.

I admit that these issues are not critical ones, and are rather unlikely to happen in the real world, but so is the problem you are trying to solve in the first place.

Point 1* could be easily solved by changing the way the coretemp device ID is allocated. Instead of using the CPU ID directly, we would use the smallest CPU ID amongst all the siblings. This ensures a consistent ID no matter which sibling is used.

Points 2* and 3*, however, can't be solved without reworking the driver significantly. I think we should not only skip duplicate HT entries on driver registration as my naive patch did. We should instead keep track of them, i.e. all coretemp entries should know the list of CPU entries they are backed up by, and a coretemp device would be unregistered only when this list shrinks to zero elements (all HT have been removed.)

Quoted 4 lines

As you said you agree to give a try to a rework of the coretemp driver to keep all related cores into the same hwmon device, I think this additional constraint might fit well in the new driver design. What do you think?

Yes, I agree with you on that. Since I'm rewriting coretemp/pkgtemp, this issue will be fixed in a new coding.

Thanks.

-Fenghua

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors