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
Created attachment 86284 [details, diff] Patch for loading the CPUs
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.
Created attachment 86700 [details] New cpufrequtils rc script config file
Created attachment 86701 [details] New cpufrequtils rc script
(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
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.
Created attachment 86794 [details] New cpufrequtils rc script
Comment on attachment 86794 [details] New cpufrequtils rc script Changed the way the script counts processors
(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 :-)
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.
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.