Subject: Status report: sysmon_cpufreq(9) + powerctl(8)
To: None <tech-kern@netbsd.org>
From: Juan RP <juan@xtrarom.org>
List: tech-kern
Date: 09/12/2006 21:59:44
Hi!

After two weeks of work, I have the sysmon_cpufreq(9) working
with a simple driver that will return "hardcoded" values.

I made a LKM to test the API:

http://www.xtrarom.org/~juan/sysmon_cpufreq/cpufreq_lkm/

The kernel part:

http://www.xtrarom.org/~juan/sysmon_cpufreq/cpufreq.diff

And powerctl(8), the userland part:

http://www.xtrarom.org/~juan/sysmon_cpufreq/powerctl/

Right now, powerctl can report frequencies and voltages and set a new
frequency with (-f value).

The sysmon_cpufreq.c drivers checks in kernel that the passed value
from userland is good against the array of frequencies in the
dictionary.

Example output of powerctl with cpufreq_lkm:

[juan@nocturno][~]> sudo modload cpufreq.o 
Module loaded as ID 0
[juan@nocturno][~]> modstat
Type    Id   Offset Loadaddr Size Info     Rev Module Name
MISC      0       - cd5ee000 0004 cd5ee2a8   2 cpufreq
[juan@nocturno][~]> ./sysmon_cpufreq/powerctl/powerctl 
cpu0
        current:        800 MHz [998 mV]
        frequencies:    800 1200 1400 1600 (in MHz)
        voltages:       998 1004 1120 1190 (in mV)
[juan@nocturno][~]> ./sysmon_cpufreq/powerctl/powerctl -f 1200
800 -> 1200
[juan@nocturno][~]> dmesg|grep cpufreq
cpufreq_lkm registered with sysmon_cpufreq.
cpufreq_lkm unregistered of sysmon_cpufreq.
cpufreq_lkm registered with sysmon_cpufreq.
smcf_name: cpufreq_lkm
sysmonioctl_cpufreq: prop_dictionary_copyout_ioctl.
smcf_name: cpufreq_lkm
sysmonioctl_cpufreq: prop_dictionary_copyout_ioctl.
smcf_name: cpufreq_lkm
sysmonioctl_cpufreq: prop_dictionary_copyout_ioctl.
smcf_name: cpufreq_lkm
sysmonioctl_cpufreq: prop_dictionary_copyout_ioctl.
smcf_name: cpufreq_lkm
sysmonioctl_cpufreq: copyin_ioctl done (error: 0)
sysmonioctl_cpufreq: cpufreq-new-frequency done.
sysmonioctl_cpufreq: newfreq: 1200 cfreq.cf_curfreq: 800
sysmonioctl_cpufreq: frequencies and fqlobj done.
sysmonioctl_cpufreq: mycnt: 4
sysmonioctl_cpufreq: newfreq: 1200 cf_fqlist[i]: 800
sysmonioctl_cpufreq: newfreq: 1200 cf_fqlist[i]: 1200
sysmonioctl_cpufreq: freqfound: 1
cpufreq_lkm: newfreq: 1200
sysmonioctl_cpufreq: cf_newfreq: 1200
sysmonioctl_cpufreq: releasing objects.
[juan@nocturno][~]>

There are some things that I'd like to fix before importing it into the
tree:

+ Currently sysmon_cpufreq will use the first valid driver,
   it's desirable to have more drivers working together and not
   only one.

+ SMP case. I use ci = curcpu().... but how that does work 
   in multiprocessor systems?

+ powerctl(8) is just a toy, I want to add the following options:
 
	* Daemon mode: (a la estd), change freq when the CPU load is
	   high or low.
	* Powersave mode: always lowest freq unless it requires full
	   power.

You can simply read the full code (and output examples) at:

	http://www.xtrarom.org/~juan/sysmon_cpufreq/

What do you think about it? do you have any suggestion/comment or fix?

Please speak up and let me improve sysmon_cpufreq(9) and powerctl(8).

(Sorry, no manpages yet... I want to finish the code first).

Thanks.