Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

C bindings to CPUFreq in Linux sysfs

License

NotificationsYou must be signed in to change notification settings

powercap/cpufreq-bindings

Repository files navigation

The projects provides thecpufreq-bindings C library.

For Linux kernel documentation on cpufreq, see:https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt

If using this project for other scientific works or publications, please reference:

  • Connor Imes, Huazhe Zhang, Kevin Zhao, Henry Hoffmann. "CoPPer: Soft Real-time Application Performance Using Hardware Power Capping". In: IEEE International Conference on Autonomic Computing (ICAC). 2019. DOI:https://doi.org/10.1109/ICAC.2019.00015

Building

This project uses CMake.

To build, run:

mkdir _buildcd _buildcmake ..make

Installing

To install, run with proper privileges:

make install

On Linux, installation typically places libraries in/usr/local/lib and header files in/usr/local/include.

Uninstalling

Install must be run before uninstalling in order to have a manifest.To uninstall, run with proper privileges:

make uninstall

Linking

Get linker information withpkg-config:

pkg-config --libs cpufreq-bindings

Or in your Makefile, add to your linker flags with:

$(shell pkg-config --libs cpufreq-bindings)

Depending on your install location, you may also need to augment your compiler flags with:

pkg-config --cflags cpufreq-bindings

Usage

See theinc/cpufreq-bindings.h header file for function descriptions.

A simple example of setting DVFS frequencies (error checking is ignored):

// In real scenarios, core count and IDs could be discovered dynamically using other meansuint32_tNCORES=4;uint32_tCORE_IDS[]= {0,1,2,3 };uint32_tavailable_freqs[32];intsetspeed_fds[NCORES];uint32_ti,j,nfreqs,freq;// populate "available_freqs" arraynfreqs=cpufreq_bindings_get_scaling_available_frequencies(-1,CORE_IDS[0],available_freqs,32);for (i=0;i<NCORES;i++) {// set "userspace" governor on all corescpufreq_bindings_set_scaling_governor(-1,CORE_IDS[i],"userspace",sizeof("userspace"));// cache file descriptors for setting frequencies with "userspace" governor// a "performance" governor would instead use CPUFREQ_BINDINGS_FILE_SCALING_MAX_FREQsetspeed_fds[i]=cpufreq_bindings_file_open(CORE_IDS[i],CPUFREQ_BINDINGS_FILE_SCALING_SETSPEED,-1);  }// do application work, breaking from loop when finished...while (do_work()) {// pick new frequency from "available_freqs" for 0 <= j < nfreqsfreq=available_freqs[j];for (i=0;i<NCORES;i++) {// set new frequencies using cached file descriptorscpufreq_bindings_set_scaling_setspeed(setspeed_fds[i],CORE_IDS[i],freq);    }  }for (i=0;i<NCORES;i++) {// close cached file descriptorscpufreq_bindings_file_close(setspeed_fds[i]);// perhaps set scaling governor back to "ondemand", or whatever the system default iscpufreq_bindings_set_scaling_governor(-1,CORE_IDS[i],"ondemand",sizeof("ondemand"));  }

Project Source

Find this and related project sources at thepowercap organization on GitHub.
This project originates at:https://github.com/powercap/cpufreq-bindings

Bug reports and pull requests are welcome.


[8]ページ先頭

©2009-2025 Movatter.jp