* [gentoo-user] Questions about cpu frequency utils scripting
@ 2015-04-21 1:05 Walter Dnes
2015-04-21 8:36 ` Emanuele Rusconi
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Walter Dnes @ 2015-04-21 1:05 UTC (permalink / raw
To: Gentoo Users List
It seems like many of the cpu speed/governor switcher utilities in
/usr/portage/sys-power don't work due to being too old. I cobbled
together a simple bash script (YES!) that sort of emulates the eselect
interface, and allows me to switch between
userspace/powersave/performance/ondemend/conservative governors. Root
permission is required, of course, to write to the /sys pseudo
filesystem. I want to add some basic error-checking and documentation
in the comments before releasing it in the wild.
The only thing I can't get working is setting specific speeds. I do
set the governor to "userspace" first. I can't think of any other
problem. Given that I can switch between performance and powersave and
ondemand/conservative, I'm not too worried about this, but I'd like to
know for completeness.
Another item I'm missing is wildcarding directories in bash. The
selected values are applied to the CPUs in a loop that goes like so...
for core in /sys/devices/system/cpu/cpu[0-9]/
do
echo "${governor[${choiceminus}]}" > ${core}cpufreq/scaling_governor
echo -n "CPU ${core:27:1} set to "
cat ${core}cpufreq/scaling_governor
done
That works fine for notebooks with say 8 cores. But what happens when
you hit 16 cores? I can't come up with one bash wildcard expression
that handles "/sys/devices/system/cpu/cpu[0-9]/" and
"/sys/devices/system/cpu/cpu[0-9][0-9]/" simultaneously. There's
probably an elegant solution right under my nose, but my Google-fu is
failing me right now. In a worst-case-scenario, I could have one loop
for "/sys/devices/system/cpu/cpu[0-9]/". Then test for the existance of
"/sys/devices/system/cpu/cpu10]/". If it exists, run a separate loop
for "/sys/devices/system/cpu/cpu[0-9][0-9]/". Ugly, but it would work.
--
Walter Dnes <waltdnes@waltdnes.org>
I don't run "desktop environments"; I run useful applications
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 1:05 [gentoo-user] Questions about cpu frequency utils scripting Walter Dnes
@ 2015-04-21 8:36 ` Emanuele Rusconi
2015-04-21 10:42 ` Alec Ten Harmsel
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Emanuele Rusconi @ 2015-04-21 8:36 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 68 bytes --]
for core in /sys/devices/system/cpu/cpu[0-9]*/
-- Emanuele Rusconi
[-- Attachment #2: Type: text/html, Size: 200 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 1:05 [gentoo-user] Questions about cpu frequency utils scripting Walter Dnes
2015-04-21 8:36 ` Emanuele Rusconi
@ 2015-04-21 10:42 ` Alec Ten Harmsel
2015-04-21 15:24 ` Walter Dnes
2015-04-21 17:02 ` Mike Gilbert
2015-04-21 19:23 ` [gentoo-user] A bash-based CPU governor/speed-control utility Walter Dnes
3 siblings, 1 reply; 8+ messages in thread
From: Alec Ten Harmsel @ 2015-04-21 10:42 UTC (permalink / raw
To: gentoo-user
On 04/20/2015 09:05 PM, Walter Dnes wrote:
>
> Another item I'm missing is wildcarding directories in bash. The
> selected values are applied to the CPUs in a loop that goes like so...
>
> for core in /sys/devices/system/cpu/cpu[0-9]/
> do
> echo "${governor[${choiceminus}]}" > ${core}cpufreq/scaling_governor
> echo -n "CPU ${core:27:1} set to "
> cat ${core}cpufreq/scaling_governor
> done
for core in `ls /sys/devices/system/cpu/ | egrep "cpu[0-9]+"`
This works great on my desktop with 12 cores.
Alec
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 10:42 ` Alec Ten Harmsel
@ 2015-04-21 15:24 ` Walter Dnes
2015-04-21 17:01 ` Alec Ten Harmsel
0 siblings, 1 reply; 8+ messages in thread
From: Walter Dnes @ 2015-04-21 15:24 UTC (permalink / raw
To: gentoo-user
On Tue, Apr 21, 2015 at 06:42:35AM -0400, Alec Ten Harmsel wrote
>
> for core in `ls /sys/devices/system/cpu/ | egrep "cpu[0-9]+"`
>
> This works great on my desktop with 12 cores.
Can you please check whether Emanuele's solution works on your system?
for core in /sys/devices/system/cpu/cpu[0-9]*/
I prefer simpler solutions.
--
Walter Dnes <waltdnes@waltdnes.org>
I don't run "desktop environments"; I run useful applications
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 15:24 ` Walter Dnes
@ 2015-04-21 17:01 ` Alec Ten Harmsel
0 siblings, 0 replies; 8+ messages in thread
From: Alec Ten Harmsel @ 2015-04-21 17:01 UTC (permalink / raw
To: gentoo-user
On 04/21/15 11:24, Walter Dnes wrote:
> On Tue, Apr 21, 2015 at 06:42:35AM -0400, Alec Ten Harmsel wrote
>> for core in `ls /sys/devices/system/cpu/ | egrep "cpu[0-9]+"`
>>
>> This works great on my desktop with 12 cores.
> Can you please check whether Emanuele's solution works on your system?
>
> for core in /sys/devices/system/cpu/cpu[0-9]*/
>
> I prefer simpler solutions.
>
That does work. I tested it this morning and it didn't work, but forgot
that I'm using zsh. Works fine with bash.
Alec
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 1:05 [gentoo-user] Questions about cpu frequency utils scripting Walter Dnes
2015-04-21 8:36 ` Emanuele Rusconi
2015-04-21 10:42 ` Alec Ten Harmsel
@ 2015-04-21 17:02 ` Mike Gilbert
2015-04-22 12:48 ` Rich Freeman
2015-04-21 19:23 ` [gentoo-user] A bash-based CPU governor/speed-control utility Walter Dnes
3 siblings, 1 reply; 8+ messages in thread
From: Mike Gilbert @ 2015-04-21 17:02 UTC (permalink / raw
To: gentoo-user
On Mon, Apr 20, 2015 at 9:05 PM, Walter Dnes <waltdnes@waltdnes.org> wrote:
> It seems like many of the cpu speed/governor switcher utilities in
> /usr/portage/sys-power don't work due to being too old.
sys-power/cpupower is probably the best option in the portage tree.
It's sources are maintained in the kernel source tree.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [gentoo-user] A bash-based CPU governor/speed-control utility
2015-04-21 1:05 [gentoo-user] Questions about cpu frequency utils scripting Walter Dnes
` (2 preceding siblings ...)
2015-04-21 17:02 ` Mike Gilbert
@ 2015-04-21 19:23 ` Walter Dnes
3 siblings, 0 replies; 8+ messages in thread
From: Walter Dnes @ 2015-04-21 19:23 UTC (permalink / raw
To: Gentoo Users List
[-- Attachment #1: Type: text/plain, Size: 1835 bytes --]
Thanks to everybody who answered my questions; I've got it working.
This mailing list seems to reject emails with executable attachments,
so I had to convert it to a .txt file before attaching the script to
this post. Instructions for making it runnable...
1) gunzip or zcat the attachment to extract cpugov.txt
2) rename it to cpugov
3) insert the line...
#!/bin/bash
...as the first line at the top of the file
4) chmod 755 cpugov
5) move it to /usr/local/bin or other appropriate subdirectory
The script understands 2 options...
cpugov list
cpugov set
The "list" option can be run by an ordinary user. It lists available
options.
The "set" option needs to write to /sys pseudo-file space, and
therefore requires root or su/sudo permissions. It lists available
options, and waits for you to enter a number and hit <ENTER> to select
that option.
If the current governor is "userspace", available speeds will be
listed as well. If you don't see speeds listed, you need to first...
cpugov set
...and select the number corresponding to "userspace". Then run cpugov
again. I don't see a major need for specific speed selection, but I
included it for completeness. The governors should handle your needs as
follows...
* powersave - runs CPUs at slowest speeds for longest battery life
* performance - runs CPUs at maximum speeds. Work gets done faster
but the battery discharges faster, too.
* conservative - this is the recommended governor. It gradually adjusts
speeds to match workload
For completeness, the remaining 2 governors are...
* ondemand - similar to conservative, but reacts faster.
* userspace - you're in charge. You get to pick-n-choose the speeds you
want when you want them.
--
Walter Dnes <waltdnes@waltdnes.org>
I don't run "desktop environments"; I run useful applications
[-- Attachment #2: cpugov.txt.gz --]
[-- Type: application/octet-stream, Size: 1592 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [gentoo-user] Questions about cpu frequency utils scripting
2015-04-21 17:02 ` Mike Gilbert
@ 2015-04-22 12:48 ` Rich Freeman
0 siblings, 0 replies; 8+ messages in thread
From: Rich Freeman @ 2015-04-22 12:48 UTC (permalink / raw
To: gentoo-user
On Tue, Apr 21, 2015 at 1:02 PM, Mike Gilbert <floppym@gentoo.org> wrote:
> On Mon, Apr 20, 2015 at 9:05 PM, Walter Dnes <waltdnes@waltdnes.org> wrote:
>> It seems like many of the cpu speed/governor switcher utilities in
>> /usr/portage/sys-power don't work due to being too old.
>
> sys-power/cpupower is probably the best option in the portage tree.
> It's sources are maintained in the kernel source tree.
>
I'm still running cpufreqd which I keep in my overlay, but upstream is
long dead and I wouldn't necessarily recommend it as a first choice.
One of these days I plan to migrate to thermald, though for the most
part I've been of a not-broken-don't-fix mindset.
--
Rich
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-04-22 12:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-21 1:05 [gentoo-user] Questions about cpu frequency utils scripting Walter Dnes
2015-04-21 8:36 ` Emanuele Rusconi
2015-04-21 10:42 ` Alec Ten Harmsel
2015-04-21 15:24 ` Walter Dnes
2015-04-21 17:01 ` Alec Ten Harmsel
2015-04-21 17:02 ` Mike Gilbert
2015-04-22 12:48 ` Rich Freeman
2015-04-21 19:23 ` [gentoo-user] A bash-based CPU governor/speed-control utility Walter Dnes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox