4

I want to change cpu(ARM) frequency in my program on linux(Ubuntu).

Is there any cpu frequency scaling and turning off core API in C?

If any, the API can handle each core in multicore cpu?

enc
  • 3,345
  • 4
  • 21
  • 22

2 Answers2

5

There are several ways you can control the frequency in Linux. You can set power state of an supported Intel processor, using the IA32_PERF_CTL register. However, you may use the cpufreq interface exported through the sysfs file system, which have support for not only Intel CPUs.

You can look at the parameters that you may change in /sys/devices/system/cpu/cpuX/*. Here is a couple of tips:

Turning off the frequency scaling is done through a governor, which handles the strategy of which the processors is put in different states. For example, to get full preformance you do:

echo performance > /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor

There are multiple governors, which you can see here:

cat /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors

As it is cumbersome to access this through the file system interface. You may use libudev for accessing the cpufreqs members. See udev documentation and here for tutorial.

One limitation regarding handling each core separately. It depends on the support of the CPU. Sometimes two or more cores must run at the same frequency, as a simple limitation of the hardware. See this post for answers.

Community
  • 1
  • 1
  • 1
    I don't see why it's troublesome to change the frequency through sysfs. And what benefits you gain from using libudev library here. – Kevin Q Apr 27 '13 at 15:07
0

You probably have to use the /sys and /proc/ filesystems, and write into some file under them like e.g. perhaps under /sys/devices/system/cpu/

I'll look into what the cpufreq-set is doing about dynamic frequency scaling

BTW, you could fork with system(3) a cpufreq-set command.

(I don't know the peculiarities of ARM processors on these aspects)

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547