libdvfs  2.0
A light library to set CPU governor and freqency
Data Structures | Functions
dvfs_core.h File Reference

Structures and functions to change frequency at the scale of a CPU core. More...

Go to the source code of this file.

Data Structures

struct  dvfs_core
 Represents on core. More...
 

Functions

int dvfs_core_open (dvfs_core **ppCore, unsigned int id, bool seq)
 Opens the Core context for the given core ID. More...
 
int dvfs_core_close (dvfs_core *core)
 Closes properly an opened Core context. More...
 
int dvfs_core_get_gov (const dvfs_core *core, char *buf, size_t buf_len)
 Sets the current DVFS governor on the given core to the given buffer. More...
 
int dvfs_core_set_gov (const dvfs_core *core, const char *gov)
 Changes the governor on the given core. More...
 
int dvfs_core_set_freq (const dvfs_core *core, unsigned int freq)
 Sets the frequency for the given core. More...
 
int dvfs_core_get_current_freq (const dvfs_core *core, unsigned int *pFreq)
 Gets the frequency currently set for the core. More...
 
int dvfs_core_get_freq (const dvfs_core *core, unsigned int *pFreq, unsigned int freq_id)
 Gets the frequency currently set for the core. More...
 
int dvfs_core_get_nb_freqs (const dvfs_core *core, unsigned int *pNbFreq)
 Gets the number of frequencies available for the core. More...
 
int dvfs_core_get_id (const dvfs_core *core, unsigned int *pID)
 Gets the ID of the DVFS core. More...
 

Detailed Description

Structures and functions to change frequency at the scale of a CPU core.

Function Documentation

int dvfs_core_close ( dvfs_core core)

Closes properly an opened Core context.

Sets back the governor that was in place when opening the context.

Parameters
coreThe core to close.
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core is NULL.
int dvfs_core_get_current_freq ( const dvfs_core core,
unsigned int *  pFreq 
)

Gets the frequency currently set for the core.

Warning, this is not necessarily the frequency currently active for the core as other cores in the same unit may have requested a different frequency. In order to determine the frequency actually set for the core, use instead dvfs_unit_get_freq().

Parameters
coreThe CPU core.
pFreqThe frequency currently set.
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or buf are NULL.
DVFS_ERROR_FILE_ERRORoperation on file failed (you can check errno for more details).
See also
dvfs_unit_get_freq()
int dvfs_core_get_freq ( const dvfs_core core,
unsigned int *  pFreq,
unsigned int  freq_id 
)

Gets the frequency currently set for the core.

Parameters
coreThe CPU core.
pFreqThe frequency currentlu set
freq_idThe id of the frequency with respect to the order in the freqs internal array
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or pFreq are NULL.
DVFS_ERROR_INVALID_FREQ_IDthe id passed is not valid
int dvfs_core_get_gov ( const dvfs_core core,
char *  buf,
size_t  buf_len 
)

Sets the current DVFS governor on the given core to the given buffer.

Parameters
coreThe core on which the governor has to be set.
bufThe pointer to the buffer which will be set to the governor string value
buf_lenThe size of the buffer
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or buf are NULL.
DVFS_ERROR_BUFFER_TOO_SHORTif the buffer for the path to the governor file is too short
DVFS_ERROR_FILE_ERRORoperation on file failed (you can check errno for more details).
int dvfs_core_get_id ( const dvfs_core core,
unsigned int *  pID 
)

Gets the ID of the DVFS core.

Parameters
coreThe CPU core.
pIDWill be filled with the ID
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or pNbFreq are NULL.
int dvfs_core_get_nb_freqs ( const dvfs_core core,
unsigned int *  pNbFreq 
)

Gets the number of frequencies available for the core.

Parameters
coreThe CPU core.
pNbFreqThe number of frequencies available for the core
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or pNbFreq are NULL.
int dvfs_core_open ( dvfs_core **  ppCore,
unsigned int  id,
bool  seq 
)

Opens the Core context for the given core ID.

The dvfs_core is valid even if the semaphore failed. The frequency transitions will not be seqeuntialized.

Parameters
ppCorethe instanciated Core context for this core. May return NULL in case of error. The error cases are often related to file opening (such as permission denied). In such cases errno is set appropriately.
idThe id of the core to control.
seqTrue when the frequency transitions must be sequentialized.
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif ppUnit or cores are NULL.
DVFS_ERROR_MEM_ALLOC_FAILEDif memory allocation failed.
See also
dvfs_core_close()
int dvfs_core_set_freq ( const dvfs_core core,
unsigned int  freq 
)

Sets the frequency for the given core.

Assumes that the "userspace" governor has been set, result is unknown otherwise.

Parameters
coreThe related core.
freqThe frequency to set.
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or buf are NULL.
DVFS_ERROR_SET_FREQ_FILEfrequency file not operational.
DVFS_ERROR_FILE_ERRORoperation on file failed (you can check errno for more details).
int dvfs_core_set_gov ( const dvfs_core core,
const char *  gov 
)

Changes the governor on the given core.

Parameters
coreThe core on which the governor has to be set.
govThe governor to set.
Returns
Return values
DVFS_SUCCESSif everything goes right.
DVFS_ERROR_INVALID_ARGif core or buf are NULL.
DVFS_ERROR_BUFFER_TOO_SHORTif the buffer for the path to the governor file is too short.
DVFS_ERROR_FILE_ERRORoperation on file failed (you can check errno for more details).