5 -- Use the key "cpufreq_[KMG]" to get the current CPU frequency in
6 -- K/M/GHz, according to /sys/devices/system/cpu/cpuX/cpufreq/. (This
7 -- has the advantage of being a much "rounder" number than the one in
8 -- /proc/cpuinfo, as provided by statusd_cpuspeed.lua.)
10 -- The "cpu" option to the statusd settings for cpufreq modifies which
13 local defaults
={ update_interval
=2*1000, cpu
=0 }
14 local settings
=table.join(statusd
.get_config("cpufreq"), defaults
)
16 function get_cpufreq()
17 local f
=io
.open('/sys/devices/system/cpu/cpu'.. settings
.cpu
..'/cpufreq/scaling_cur_freq')
18 local cpufreq_K
= f
:read('*a')
21 local cpufreq_M
= cpufreq_K
/ 1000
22 local cpufreq_G
= cpufreq_M
/ 1000
24 return tostring(cpufreq_K
), tostring(cpufreq_M
), tostring(cpufreq_G
)
27 function update_cpufreq()
28 local cpufreq_K
, cpufreq_M
, cpufreq_G
= get_cpufreq()
29 statusd
.inform("cpufreq_K", cpufreq_K
)
30 statusd
.inform("cpufreq_M", cpufreq_M
)
31 statusd
.inform("cpufreq_G", cpufreq_G
)
32 cpufreq_timer
:set(settings
.update_interval
, update_cpufreq
)
35 cpufreq_timer
= statusd
.create_timer()