Skip to contentSkip to conversation

CPUSpeed 1.1 released (finally)

DISCUSSION Carl Thompson 4 participants 6 messages Nov 8, 2003 – Dec 1, 2003

lore
Share & tools
lore
#0 lore raw

I have finally gotten around to releasing CPUSpeed v1.1 (formerly named cpufreq but that was too confusing). CPUSpeed is yet another program (actually the first, I think?) to control CPU speed based on idle, AC connection and CPU temperature using the CPUFreq userspace governor.

Some Features:
* Dynamically adjusts CPU speed and voltage based on demand for CPU (idle/work ratio threshold is user-configurable)
* Automatically detects available processor speeds
* For normal operation, no configuration or options are necessary. Just run it!
* One binary works on both Linux 2.4 with the 'proc' interface and Linux 2.6 with the 'sysfs' interface. No need to recompile if you switch kernels!
* Can reduce CPU speed and voltage if AC power is disconnected from the computer (requires ACPI)
* Can reduce CPU speed and voltage if CPU temperature gets too high (Requires ACPI, temperature is user-configurable)
* Can be told to lock CPU at minimum or maximum frequency via signals
* "nice()'d" processes will not increase CPU speed
* Crash-proof frequency switching even if you have a very tempermental CPU (some AMD mobile Athlons in particular)
* More that I'm forgetting.

This latest version of CPUSpeed can be found at its new web site:

http://carlthompson.net/software/cpuspeed

My apologies to all those who have patiently waited for months for me to release this version! Future versions will be more timely...

Thank you,
Carl E. Thompson

#1 lore raw
Quoted 4 lines · Carl Thompson

I have finally gotten around to releasing CPUSpeed v1.1 (formerly named cpufreq but that was too confusing). CPUSpeed is yet another program (actually the first, I think?) to control CPU speed based on idle, AC connection and CPU temperature using the CPUFreq userspace governor.

Really really nice!
However one minor nitpick: It's not allowed to call fopen() from a signal handler....... I'll try to work up a patch for this and send it

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq

#2 lore raw
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines · Carl Thompson

I have finally gotten around to releasing CPUSpeed v1.1 (formerly named cpufreq but that was too confusing). CPUSpeed is yet another program (actually the first, I think?) to control CPU speed based on idle, AC connection and CPU temperature using the CPUFreq userspace governor.

Really really nice!
However one minor nitpick: It's not allowed to call fopen() from a signal handler....... I'll try to work up a patch for this and send it

patch attached; it also converts usleep to nanosleep which I've been told is the much better API for this sort of thing anyway.

It turns out that the code never really actually set an alarm, but really just raise()'d the signal instead of doing a function call....

cpuspeed.cc +10 -7
diff -purN cpuspeed-1.1/cpuspeed.cc cpuspeed/cpuspeed.cc
@@ -440,9 +440,12 @@ main(unsigned argc, char * argv[])
         USERSPACE = SYSFS_USERSPACE;
     }
 
-    unsigned interval = 20; // 2 seconds
+    struct timespec interval;
     bool daemonize = false;
 
+    interval.tv_sec = 20;
+    interval.tv_nsec = 0;
+
     // parse argv
     for(unsigned i = 1; i < argc; i++)
     {
@@ -453,7 +456,7 @@ main(unsigned argc, char * argv[])
             if (argc <= i + 1)
                 die(false, "The -i option must be followed by an interval in tenths of a second\n");
 
-            interval = get_int(argv[++i]);
+            interval.tv_sec = get_int(argv[++i]);
             errprintf("Interval is %u\n", interval);
 
         }
@@ -562,15 +565,15 @@ main(unsigned argc, char * argv[])
     // block all of our signals during each signal handler to avoid possible
     // race condition (not that it would really matter)
     sigemptyset(&signal_action.sa_mask);
-    sigaddset(&signal_action.sa_mask, SIGALRM);
+//    sigaddset(&signal_action.sa_mask, SIGALRM);
     sigaddset(&signal_action.sa_mask, SIGUSR1);
     sigaddset(&signal_action.sa_mask, SIGUSR2);
     sigaddset(&signal_action.sa_mask, SIGHUP);
     signal_action.sa_flags = 0;
 
     // set the SIGALRM handler to our function
-    signal_action.sa_handler = alarm_handler;
-    sigaction(SIGALRM, &signal_action, 0);
+    // signal_action.sa_handler = alarm_handler;
+    // sigaction(SIGALRM, &signal_action, 0);
 
     // set the SIGUSR1 handler to our function
     signal_action.sa_handler = usr1_handler;
@@ -595,8 +598,8 @@ main(unsigned argc, char * argv[])
     // main loop
     while (1)
     {
-        raise(SIGALRM);
-        usleep(interval * 100000L);
+	alarm_handler(0);
+	nanosleep(&interval, NULL);
     }
 
     // never reached

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq

#3 lore raw

Quoting Arjan van de Ven <[email protected]>:

Quoted 4 lines
Quoted 4 lines

...

However one minor nitpick: It's not allowed to call fopen() from a signal handler....... I'll try to work up a patch for this and send it

It _is_ allowed to call fopen() from a signal handler... Perhaps what you mean is that fopen() is not a reentrant function and non-reentrant functions are usually not used in signal handlers? This is because you don't want non-reentrant functions in the main program and in the signal handlers to clobber each other. However, in this case the main program is a tight loop that does nothing except raise the ALRM signal so the use of non-reentrant functions in the signal handlers will not interfere with anything. The only issue is making sure that the signal handlers cannot interrupt each other causing the same problem, and that is why I block all of the signals in all of the signal handlers.

Quoted 2 lines

patch attached; it also converts usleep to nanosleep which I've been told is the much better API for this sort of thing anyway.

Well, the problem with usleep() is that it uses SIGALRM in some implementations... However, the glibc implementation seems to just to be a wrapper around nanosleep() and does not cause issues so I chose usleep() because the interface is simpler. However, I will switch it to nanosleep() because there may be some Linux installations that do not use glibc but some other C library that has an issue.

Quoted 2 lines

It turns out that the code never really actually set an alarm, but really just raise()'d the signal instead of doing a function call....

Your patch would allow alarm_handler() (called as a regular function) to be interrupted by the hup_handler() handler. This would actually have the opposite affect as intended because both functions use non-reentrant functions.

So the short answer is that the logic of the program will stay the same because it is not broken but I will switch to using nanosleep().

Thanks,
Carl Thompson

#4 lore raw
In reply to Carl Thompson
Quoted 2 lines

* Crash-proof frequency switching even if you have a very tempermental CPU (some AMD mobile Athlons in particular)

That's no more true those days...

Cheers,

Signature · 4 lines
Ducrot Bruno

--  Which is worse:  ignorance or apathy?
--  Don't know.  Don't care.
#5 lore raw
Quoted 4 lines · Ducrot Bruno
Quoted 2 lines

* Crash-proof frequency switching even if you have a very tempermental CPU (some AMD mobile Athlons in particular)

That's no more true those days...

(going through the archives..) I noticed the above, does that mean the "athlon giant leap bug" was fixed in the driver? if so, how? was it the below snippit from what went into 2.6.0-test6?

if so, i'd love to rip the workaround out of powernowd.. john.c

@@ -297,8 +301,14 @@

	dprintk (" voltage regulator)\n");

	latency = psb->settlingtime;

+ if (latency < 100) {
+ printk (KERN_INFO PFX "BIOS set settling time to %d microseconds."
+ "Should be at least 100. Correcting.\n", latency);
+ latency = 100;
+ }

	dprintk (KERN_INFO PFX "Settling Time: %d microseconds.\n", psb->settlingtime);
	dprintk (KERN_INFO PFX "Has %d PST tables. (Only dumping ones relevant to this CPU).\n", psb->numpst);

+ latency *= 100; /* SGTC needs to be in units of 10ns */

	p += sizeof (struct psb_s);
Signature · 3 lines
John Clemens          http://www.deater.net/john
[email protected]     ICQ: 7175925, IM: PianoManO8
      "I Hate Quotes" -- Samuel L. Clemens