Skip to contentSkip to conversation

Allow userspace do something special on overtemp

PATCH Pavel Machek 12 participants 24 messages Aug 11, 2004 – Aug 12, 2004 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

Could it be applied?
Pavel

drivers/acpi/thermal.c renamed from linux/drivers/acpi/thermal.c +11 -11
@@ -60,7 +60,6 @@
 #define ACPI_THERMAL_NOTIFY_HOT		0xF1
 #define ACPI_THERMAL_MODE_ACTIVE	0x00
 #define ACPI_THERMAL_MODE_PASSIVE	0x01
-#define ACPI_THERMAL_PATH_POWEROFF	"/sbin/poweroff"
 
 #define ACPI_THERMAL_MAX_ACTIVE	10
 
@@ -424,24 +423,25 @@
 
 
 static int
-acpi_thermal_call_usermode (
-	char			*path)
+acpi_thermal_call_usermode(void)
 {
 	char			*argv[2] = {NULL, NULL};
 	char			*envp[3] = {NULL, NULL, NULL};
 
 	ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
 
-	if (!path)
-		return_VALUE(-EINVAL);
-
-	argv[0] = path;
-
 	/* minimal command environment */
 	envp[0] = "HOME=/";
 	envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
-	
-	call_usermodehelper(argv[0], argv, envp, 0);
+
+	argv[0] = "/sbin/overtemp";
+	if (call_usermodehelper(argv[0], argv, envp, 0)) {
+		argv[0] = "/sbin/poweroff";
+		if (call_usermodehelper(argv[0], argv, envp, 0)) {
+			/* What to do here? Should we just cut the power? */
+			printk(KERN_CRIT "attempts to poweroff failed, please power me down manually\n");
+		}
+	}
 
 	return_VALUE(0);
 }
@@ -483,7 +483,7 @@
 	printk(KERN_EMERG "Critical temperature reached (%ld C), shutting down.\n", KELVIN_TO_CELSIUS(tz->temperature));
 	acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, tz->trips.critical.flags.enabled);
 
-	acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
+	acpi_thermal_call_usermode();
 
 	return_VALUE(0);
 }
Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#1 lore raw
Quoted 5 lines · Pavel Machek

Hi!

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

why not call /sbin/hotplug ????

#2 lore raw

Hi!

Quoted 5 lines
Quoted 3 lines

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

why not call /sbin/hotplug ????

Because /sbin/hotplug may exist, but may not know how to handle overtemp. Which would be bad.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#8 lore raw
In reply to Arjan van de Ven
Quoted 8 lines · Arjan van de Ven
Quoted 5 lines · Pavel Machek

Hi!

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

why not call /sbin/hotplug ????

Good idea, then udev could create /dev/blowtorch so some other program can do ioctl(SCSI_STOP) (or just run cdrecord dev=6,6,6 -eject). Besides, it is called HOTplug for a reason.

Seriously, though, isn't hotplug supposed to handle plugging and unplugging of hardware, rather than any random events detected by the kernel?

Signature · 2 lines
Måns Rullgård
[email protected]
#3 lore raw
In reply to Pavel Machek
Quoted 5 lines · Pavel Machek

Hi!

Quoted 2 lines
Quoted 2 lines

.adds possibility to react to
critical overtemp: it tries to call /sbin/overtemp, and only if

that fails calls /sbin/poweroff.

Does /sbin/overtemp exist anyplace, or is this a proposal to create it? What might it do?

thanks,
-Len

#4 lore raw
Quoted 2 lines · Previously Len Brown

Does /sbin/overtemp exist anyplace, or is this a proposal to create it? What might it do?

Or why not use a netlink message for it?

Wichert.

Signature · 2 lines
Wichert Akkerman <[email protected]>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.
#5 lore raw
In reply to Len Brown
Quoted 5 lines · Len Brown
Quoted 3 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

.adds possibility to react to
critical overtemp: it tries to call /sbin/overtemp, and only if

that fails calls /sbin/poweroff.

Does /sbin/overtemp exist anyplace, or is this a proposal to create it? What might it do?

save some user info, suspend, standby, extreme throttling? It should be somehow configurable in userspace.

For my opinion it would be nicest if kernel just throws a thermal event to /proc/acpi/event (it already does this, but immediately shuts down) and acpid or others should decide whether shutdown/suspend/standby or whatever should be done next. I have a machine with a broken DSDT which sets the critical tp to 200°C, there always must be some HW shutdown..., or do you think this is too risky?

Some other related thing:
Why are no thermal events thrown if active/passive trip points are reached/sub-ceeded?
The only way at the moment to figure out in userspace whether the system is actively cooled or even slowed down by throttling (passive) is by polling /proc/acpi/thermal/*/state. Isn't the purpose of thermal events exactly for this? I think about a possiblity to notify user if machine is slowed down.

Thomas

#9 lore raw
In reply to Måns Rullgård
Quoted 3 lines · Måns Rullgård

Seriously, though, isn't hotplug supposed to handle plugging and unplugging of hardware, rather than any random events detected by the kernel?

/sbin/kernel_event_notifier was named /sbin/hotplug by accident. I'm sure someone will send a patch to fix it up.

Signature · 3 lines
USB is for mice, FireWire is for men!

sUse lINUX ag, nÜRNBERG
#11 lore raw
In reply to a message not in the archive

Hi!

Quoted 3 lines

Would you mind improving this slightly, instead of returning on failure, idle on failure so the cpu cools down from lack of instruction execution? Is this easily done?

Well, but that would kill the system, right?

I do not want to do that. Hardware will kill us anyway if overheat is serious.
Pavel

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         
#7 lore raw
In reply to Len Brown

Hi!

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

.adds possibility to react to
critical overtemp: it tries to call /sbin/overtemp, and only if

that fails calls /sbin/poweroff.

Does /sbin/overtemp exist anyplace, or is this a proposal to create it? What might it do?

It does not exist anywhere, but probably will exist in SL92.

It might:
* shutdown faster (poweroff is very carefull but not too fast;
* display big red message "sorry your cpu overheated" then shutdown :-)
* do nothing (use with care if your thermal sensor is flakey)

Pavel

Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         
#6 lore raw
In reply to Thomas Renninger

Thomas Renninger <[email protected]> ha scritto:

Quoted 15 lines
Quoted 5 lines · Len Brown
Quoted 3 lines · Pavel Machek

Hi!

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

.adds possibility to react to
critical overtemp: it tries to call /sbin/overtemp, and only if

that fails calls /sbin/poweroff.

Does /sbin/overtemp exist anyplace, or is this a proposal to create it? What might it do?

Quoted 7 lines

save some user info, suspend, standby, extreme throttling? It should be somehow configurable in userspace.

For my opinion it would be nicest if kernel just throws a thermal event to /proc/acpi/event (it already does this, but immediately shuts down) and acpid or others should decide whether shutdown/suspend/standby or whatever should be done next.

I think that /sbin/overtemp is better, acpid may not know what do. Suppose that the kernel delivers the event to acpid (or hotplug) but they aren't configured to handle that, your CPU will melt...

Quoted 2 lines

I have a machine with a broken DSDT which sets the critical tp to 200°C, there always must be some HW shutdown..., or do you think this is too risky?

It's more secure to call a program that can handle that for sure (ie. /sbin/overtemp) and shutdown if it doesn't exist.

Luca

Signature · 4 lines
Home: http://kronoz.cjb.net
"New processes are created by other processes, just like new
 humans. New humans are created by other humans, of course,
 not by processes." -- Unix System Administration Handbook
#12 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek

Hi!

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

Could it be applied?
Pavel

Why invent Yet-Another-Call-To-Userland-Interface when either hotplug/dbus, netlink or an ACPI event will do?

The argument "well what if hotplug of acpid don't know what to do" is, IMO, bogus since:

* Obviously systems today are functioning
* Hardware will poweroff off on overheat anyway (not graceful, but will save hardware components)
* Teaching hotplug/apcid isn't hard
* Policy should be kept out of the kernel if at all possible

Dax

#13 lore raw

I agree with Dan.

I think I'd rather see the calls to usermode deleted instead of extended -- unless there is a reason that the general event -> acpid method can't work.

If the administrator screws up and disables shutdown on critical temp, modern hardware will throttle (in hardware), and if that too fails, it will shut itself off.

-Len

#19 lore raw
In reply to Dax Kelson

Hi!

Quoted 6 lines
Quoted 5 lines

This patch cleans up thermal.c a bit, and adds possibility to react to critical overtemp: it tries to call /sbin/overtemp, and only if that fails calls /sbin/poweroff.

Could it be applied?

Quoted 7 lines

Why invent Yet-Another-Call-To-Userland-Interface when either hotplug/dbus, netlink or an ACPI event will do?

The argument "well what if hotplug of acpid don't know what to do" is, IMO, bogus since:

* Obviously systems today are functioning

Yes, kernel is calling /sbin/poweroff, which everyone has. Switching to hotplug/dbus would immediately break those systems.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#14 lore raw
In reply to Len Brown

Hi!

Quoted 3 lines

I think I'd rather see the calls to usermode deleted instead of extended -- unless there is a reason that the general event -> acpid method can't work.

See above, switching to acpid would break all the existing setups... in stable series.

Also notice that thermal.c is so "interestingly" written that my patch does not actually make it longer by deleting useless defines etc...

Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#15 lore raw
Quoted 8 lines · Pavel Machek

Hi!

Quoted 3 lines

I think I'd rather see the calls to usermode deleted instead of extended -- unless there is a reason that the general event -> acpid method can't work.

See above, switching to acpid would break all the existing setups... in stable series.

ah, the price of progress.

I'm confident that the distros can figure out how to update the (neglected) acpid scripts at the same time as (or before) the kernel update.

If they can't, then ACPI critical shutdown will fail (maybe on some systems not such a bad thing;-) and TM1 will kick in, and if that doesn't work, TM2 will kick in, and if that doesn't work the processor will disable itself.

In practice, the only time this will happen is due to an erroneous thermal sensor reading, or when somebody loses their CPU fan; and it is the exact same path that the system would take if somebody booted with acpi=off.

Quoted 2 lines

Also notice that thermal.c is so "interestingly" written that my patch does not actually make it longer by deleting useless defines etc...

Conserving syntax is certainly laudable,
but conserving semantics is even more valuable.

I do thank you for identifying this issue and proposing change.

-Len

#21 lore raw
In reply to Len Brown

On 12 Aug 2004 11:19:05 -0400 Len Brown wrote:

| Simpler to delete the usermode call and rely on the (flexible)
| acpid event, yes?
| 
|  thermal.c |   29 +----------------------------
|  1 files changed, 1 insertion(+), 28 deletions(-)

a. Yes, it should be more flexible than just 'overtemp'.

b. For userspace, there are:

acpid - http://sourceforge.net/projects/acpid/

acpi tools, like ospmd (by Andy Grover) - in CVS at
http://sourceforge.net/projects/acpi/

What others are there?

And ospmd (at least) needs some care. Andy wanted to give it up 1 or 2 years ago, so I took it over for awhile. However, it still needs more care, so if anyone out there wants to maintain it, please speak up.

--
~Randy

#20 lore raw
In reply to Pavel Machek

Simpler to delete the usermode call and rely on the (flexible) acpid event, yes?

 thermal.c |   29 +----------------------------
 1 files changed, 1 insertion(+), 28 deletions(-)

cheers,
-Len

===== drivers/acpi/thermal.c 1.34 vs edited =====

drivers/acpi/thermal.c +0 -26
@@ -61,7 +61,6 @@
 #define ACPI_THERMAL_MODE_ACTIVE	0x00
 #define ACPI_THERMAL_MODE_PASSIVE	0x01
 #define ACPI_THERMAL_MODE_CRT   	0xff
-#define ACPI_THERMAL_PATH_POWEROFF	"/sbin/poweroff"
 
 #define ACPI_THERMAL_MAX_ACTIVE	10
 
@@ -422,30 +421,6 @@
 
 
 static int
-acpi_thermal_call_usermode (
-	char			*path)
-{
-	char			*argv[2] = {NULL, NULL};
-	char			*envp[3] = {NULL, NULL, NULL};
-
-	ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
-
-	if (!path)
-		return_VALUE(-EINVAL);
-
-	argv[0] = path;
-
-	/* minimal command environment */
-	envp[0] = "HOME=/";
-	envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
-	
-	call_usermodehelper(argv[0], argv, envp, 0);
-
-	return_VALUE(0);
-}
-
-
-static int
 acpi_thermal_critical (
 	struct acpi_thermal	*tz)
 {
@@ -468,10 +443,8 @@
 	if (result)
 		return_VALUE(result);
 
-	printk(KERN_EMERG "Critical temperature reached (%ld C), shutting

down.\n", KELVIN_TO_CELSIUS(tz->temperature));
+ printk(KERN_EMERG "Critical temperature reached (%ld C).\n",
KELVIN_TO_CELSIUS(tz->temperature));
acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL,
tz->trips.critical.flags.enabled);
-
- acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);

return_VALUE(0);
}

#22 lore raw
In reply to Randy.Dunlap
Quoted 9 lines · Randy.Dunlap

On 12 Aug 2004 11:19:05 -0400 Len Brown wrote:

| Simpler to delete the usermode call and rely on the (flexible)
| acpid event, yes?
| |  thermal.c |   29 +----------------------------
|  1 files changed, 1 insertion(+), 28 deletions(-)

a. Yes, it should be more flexible than just 'overtemp'.

Quoted 8 lines

b. For userspace, there are:

acpid - http://sourceforge.net/projects/acpid/

acpi tools, like ospmd (by Andy Grover) - in CVS at
http://sourceforge.net/projects/acpi/

What others are there?

powersaved - http://forge.novell.com/modules/xfmod/project/?powersave
handles APM, ACPI and cpufreq

Signature · 4 lines
seife

"Any ideas, John?"
"Well, surrounding thems out."
#16 lore raw
In reply to Len Brown

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I think I'd rather see the calls to usermode deleted instead of extended -- unless there is a reason that the general event -> acpid method can't work.

Quoted 8 lines
Quoted 2 lines

See above, switching to acpid would break all the existing setups... in stable series.

ah, the price of progress.

I'm confident that the distros can figure out how to update the (neglected) acpid scripts at the same time as (or before) the kernel update.

* not everyone is running distro

* people update their kernels more often then their distros

* not everyone wants to run acpid or equivalent (I don't, for example)

* it is still change in stable series.

* it is pretty subtle change, you are not going to notice it is broken unless you actually run critical.

Quoted 5 lines

If they can't, then ACPI critical shutdown will fail (maybe on some systems not such a bad thing;-) and TM1 will kick in, and if that doesn't work, TM2 will kick in, and if that doesn't work the processor will disable itself.

hmm, yes, but it still would be nice to properly shutdown instead of fail.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
#24 lore raw
In reply to Stefan Dösinger
Quoted 4 lines · Stefan Dösinger

Hi,
Isn't this a little bit dangerous? What if acpid is not set up to handle this?

There are two levels of hardware thermal control that will kick in -- TM1 and TM2, and if they fail the hardware will turn itself off. Speaking for Intel processors only.

The reason is that the hardware needs to handle this case where the OS crashes while in ACPI mode and is unable to do any thermal control itself.

cheers,
-Len

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

#17 lore raw
In reply to Pavel Machek
Quoted 26 lines · Pavel Machek

Hi!

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

I think I'd rather see the calls to usermode deleted instead of extended -- unless there is a reason that the general event -> acpid method can't work.

Quoted 8 lines
Quoted 2 lines

See above, switching to acpid would break all the existing setups... in stable series.

ah, the price of progress.

I'm confident that the distros can figure out how to update the (neglected) acpid scripts at the same time as (or before) the kernel update.

* not everyone is running distro

* people update their kernels more often then their distros

* not everyone wants to run acpid or equivalent (I don't, for example)

* it is still change in stable series.

* it is pretty subtle change, you are not going to notice it is broken unless you actually run critical.

Quoted 8 lines
Quoted 5 lines

If they can't, then ACPI critical shutdown will fail (maybe on some systems not such a bad thing;-) and TM1 will kick in, and if that doesn't work, TM2 will kick in, and if that doesn't work the processor will disable itself.

hmm, yes, but it still would be nice to properly shutdown instead of fail.

The reality is that most of the critical temperature events are false positives, and for those that are not, the hardware will keep itself from burning even when the OS control fails.

If we confuse some self-supporting kernel types, that is too bad. If they're supporting themselves, they should read the change logs for the kernels that they download. I don't think
this is of a magnitude that it needs to wait for 2.7 to be fixed.

-Len

#18 lore raw

Hi!

Quoted 11 lines
Quoted 2 lines

hmm, yes, but it still would be nice to properly shutdown instead of fail.

The reality is that most of the critical temperature events are false positives, and for those that are not, the hardware will keep itself from burning even when the OS control fails.

If we confuse some self-supporting kernel types, that is too bad. If they're supporting themselves, they should read the change logs for the kernels that they download. I don't think
this is of a magnitude that it needs to wait for 2.7 to be fixed.

There's nothing to fix. It is not broken. It just does /sbin/poweroff; that's correct.

/sbin/poweroff is there on almost all systems; that is not case with acpid. Currently *noone* has acpid that handles critical properly, right?

So I believe that change is bad idea. /sbin/overtemp lets user configure it etc.

Ouch and btw I've done some torturing on one prototype (AMD). It had thermal at 98Celsius (specs for this cpu said 95C max), and I ended my test at 105Celsius. I do not know about TM1/TM2 etc, but in this case hardware clearly failed to do the right thing.

I do not know why acpid should be involved in this. execing binary seems safer to me -- acpid might have died (OOM? segfault?), and exec does not strike me like too ugly.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!