Recently I was looking through the kernel at kobjects and sysfs.
I know/understand the following..
kobjects
should be no exception to this rulekobjects
(maybe includes ksets
and other k* stuff..not sure)Given this information, I'm not sure I understand exactly what happens when I run echo ondemand >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
I can see that the cpufreq module has a function called store_scaling_governor
which handles writes to this 'file'..but how does usermode transcend into kernelmode with this simple echo?
When you execute command echo ondemand >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
, your shell calls write
system call, then kernel dispatch it for corresponding handler.
The cpufreq setups struct kobj_type ktype_cpufreq
with sysfs_ops
. Then cpufreq register it in cpufreq_add_dev_interface()
. After that, kernel can get corresponding handler to execute on write
syscall.