Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 132461 - sys-power/cpufrequtils rc script fix for SMP
Summary: sys-power/cpufrequtils rc script fix for SMP
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High trivial (vote)
Assignee: Mobile Herd (OBSOLETE)
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2006-05-06 08:29 UTC by Sebastien LANGE
Modified: 2006-06-02 03:02 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch for loading the CPUs (cpufrequtils.diff,446 bytes, patch)
2006-05-06 08:31 UTC, Sebastien LANGE
Details | Diff
New cpufrequtils rc script config file (cpufrequtils,504 bytes, text/plain)
2006-05-13 06:12 UTC, Stefano Varesi
Details
New cpufrequtils rc script (cpufrequtils,1.94 KB, text/plain)
2006-05-13 06:14 UTC, Stefano Varesi
Details
New cpufrequtils rc script (cpufrequtils,2.00 KB, text/plain)
2006-05-15 02:26 UTC, Stefano Varesi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastien LANGE 2006-05-06 08:29:50 UTC
I've two CPUs on my Sun Blade 1000 and the rc script load GOVERNOR only on the first CPU then I done a patch.

Patch :

--- cpufrequtils.old    2006-05-06 17:03:28.000000000 +0200
+++ /etc/init.d/cpufrequtils    2006-05-06 16:32:15.000000000 +0200
@@ -14,6 +14,10 @@
        checkconfig || return 1
 
        ebegin "Enabling ${GOVERNOR} cpufreq governor"
-       cpufreq-set -g ${GOVERNOR}
+       nb_cpu=`cat /proc/cpuinfo | grep CPU | /bin/sed 's/CPU//' | /bin/sed 's/online//' | /bin/sed 's/\://'`
+       for NBCPU in ${nb_cpu}
+       do
+               cpufreq-set -c ${NBCPU} -g ${GOVERNOR}
+       done
        eend ${?}
 }

emerge --info :

Portage 2203-svn (default-linux/sparc/sparc64/2006.0, gcc-3.4.6, glibc-2.3.6-r3, 2.6.17-rc3 sparc64)
=================================================================
System uname: 2.6.17-rc3 sparc64 sun4u
Gentoo Base System version 1.6.14
dev-lang/python:     2.4.2
dev-util/ccache:     [Not Present]
dev-util/confcache:  [Not Present]
sys-apps/sandbox:    1.2.12
sys-devel/autoconf:  2.13, 2.59-r7
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r1
sys-devel/binutils:  2.16.1-r2
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.11-r4
ACCEPT_KEYWORDS="sparc"
AUTOCLEAN="yes"
CBUILD="sparc-unknown-linux-gnu"
CFLAGS="-O2 -mcpu=ultrasparc3 -pipe"
CHOST="sparc-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share/config /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/eselect/compiler /etc/gconf /etc/env.d"
CXXFLAGS="-O2 -mcpu=ultrasparc3 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoconfig distlocks sandbox sfperms strict"
GENTOO_MIRRORS="http://mirror.ovh.net/gentoo-distfiles/ ftp://mirror.ovh.net/gentoo-distfiles/ http://gentoo.modulix.net/gentoo/ http://ftp.club-internet.fr/pub/mirrors/gentoo "
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="sparc X alsa apache2 arts audiofile avi bash-completion berkdb bitmap-fonts bzip2 cdr cli cpudetection crypt cups curl dba dlloader dri dv dvd dvdread eds encode esd exif expat fam fbcon font-server foomaticdb fortran gcc64 gd gdbm gif glut gnome gstreamer gtk gtk2 gtkhtml hal howl idn imlib ipv6 jpeg lcms libwww mad mikmod mng motif mozilla mp3 mpeg ncurses nls nptl nptlonly ogg opengl oss pam pcre pdflib perl png python readline reflection sdl session spell spl ssl tcpd tetex tiff truetype truetype-fonts type1-fonts udev usb vorbis xml xml2 xmms xorg xprint xv xvid zlib userland_GNU kernel_linux elibc_glibc"
Unset:  ASFLAGS, CTARGET, INSTALL_MASK, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTDIR_OVERLAY
Comment 1 Sebastien LANGE 2006-05-06 08:31:49 UTC
Created attachment 86284 [details, diff]
Patch for loading the CPUs
Comment 2 Stefano Varesi 2006-05-13 06:10:56 UTC
I rewrote the rc script to consider not only the number of CPUs, but also the options that can be passed to cpufreq-set.
I've added 4 more variables to /etc/conf.d/cpufrequtils:
DRIVER : the kernel module driver for your CPU
MIN_FREQ and MAX_FREQ : the minimum and maximum CPU frequency the governor may select
FREQ : specific frequency to be set only if the governor is userspace

The new script can automatically find if it has to modprobe the specified kernel modules for the driver and the governor.
After modprobing, it applies the options to all the cpus of your machine.

To know how many cpus you have I've tried : `cat /proc/cpuinfo | grep CPU | /bin/sed 's/CPU//' | /bin/sed 's/online//' | /bin/sed 's/\://'` but it doesn't work for me (I have a Pentium 4).

I think it's better doing: `cat /proc/cpuinfo | grep processor | cut -d':' -f2 | cut -b2- | tail -n1` because it counts how many "processor : $n" lines it finds and it is architecture-independent.
Comment 3 Stefano Varesi 2006-05-13 06:12:12 UTC
Created attachment 86700 [details]
New cpufrequtils rc script config file
Comment 4 Stefano Varesi 2006-05-13 06:14:01 UTC
Created attachment 86701 [details]
New cpufrequtils rc script
Comment 5 Sebastien LANGE 2006-05-13 14:39:38 UTC
(In reply to comment #2)
> I rewrote the rc script to consider not only the number of CPUs, but also the
> options that can be passed to cpufreq-set.
> I've added 4 more variables to /etc/conf.d/cpufrequtils:
> DRIVER : the kernel module driver for your CPU
> MIN_FREQ and MAX_FREQ : the minimum and maximum CPU frequency the governor may
> select
> FREQ : specific frequency to be set only if the governor is userspace
> 
> The new script can automatically find if it has to modprobe the specified
> kernel modules for the driver and the governor.
> After modprobing, it applies the options to all the cpus of your machine.
> 
> To know how many cpus you have I've tried : `cat /proc/cpuinfo | grep CPU |
> /bin/sed 's/CPU//' | /bin/sed 's/online//' | /bin/sed 's/\://'` but it doesn't
> work for me (I have a Pentium 4).
> 
> I think it's better doing: `cat /proc/cpuinfo | grep processor | cut -d':' -f2
> | cut -b2- | tail -n1` because it counts how many "processor : $n" lines it
> finds and it is architecture-independent.
> 

With my Sparc64, I have :
cat /proc/cpuinfo :
cpu             : TI UltraSparc III (Cheetah)
fpu             : UltraSparc III integrated FPU
prom            : OBP 4.13.0 2004/01/19 18:27
type            : sun4u
ncpus probed    : 2
ncpus active    : 2
D$ parity tl1   : 0
I$ parity tl1   : 0
Cpu0Bogo        : 10.00
Cpu0ClkTck      : 000000002cb41780
Cpu1Bogo        : 10.00
Cpu1ClkTck      : 0000000001659ec8
MMU Type        : Cheetah
State:
CPU0:           online
CPU1:           online
Comment 6 Stefano Varesi 2006-05-15 02:23:49 UTC
I thought that the structure of the file /proc/cpuinfo was the same for all architectures, but I was wrong.
The better way is getting infos from sysfs, so if you want to know how many cpus you have, you must do:

$(for i in $(ls /sys/devices/system/cpu); do echo $i; done | tail -n1 | cut -b4-)

and add 1, because it starts counting from zero.
This should be really architecture independent....I hope.
Comment 7 Stefano Varesi 2006-05-15 02:26:23 UTC
Created attachment 86794 [details]
New cpufrequtils rc script
Comment 8 Stefano Varesi 2006-05-15 02:27:01 UTC
Comment on attachment 86794 [details]
New cpufrequtils rc script

Changed the way the script counts processors
Comment 9 Sebastien LANGE 2006-05-15 03:09:26 UTC
(In reply to comment #6)
> I thought that the structure of the file /proc/cpuinfo was the same for all
> architectures, but I was wrong.
> The better way is getting infos from sysfs, so if you want to know how many
> cpus you have, you must do:
> 
> $(for i in $(ls /sys/devices/system/cpu); do echo $i; done | tail -n1 | cut
> -b4-)
> 
> and add 1, because it starts counting from zero.
> This should be really architecture independent....I hope.
> 
Yes, it's good :-)
Comment 10 Henrik Brix Andersen 2006-06-01 05:00:26 UTC
I've changed the init script in sys-power/cpufrequtils-002 to work on SMP systems. 

I have based my change on the initial patch in comment #1, but adapted to use sysfs for locating the available CPUs.

I have not incorporated the proposed changes for loading kernel modules, as this is not the task of this init script (hint: use /etc/modules.autoload.d/).

If you need more sophisticated control over the cpufreq subsystem I suggest you use a daemon like cpufreqd.

Thank you for all your input on this.
Comment 11 Stefano Varesi 2006-06-02 03:02:17 UTC
Why isn't loading and unloading the task of this initscript?
There are other initscripts that take care of loading and unloading the necessary kernel modules. For example, rlocate initscript loads the rlocated module and net.eth0 loads the right module of your network interface. This is done automatically in the initscripts. In this way you can load the necessary modules on demand when you start the services and unload the modules when you stop them. If you use /etc/modules.autoload.d/, instead, you force loading every module always on boot, even if you don't start those services that need them.
So I think it is better to make the initscript doing the task of loading/unloading the needed kernel modules.