libdvfs  2.0
A light library to set CPU governor and freqency
dvfs_core.h
Go to the documentation of this file.
1 /*
2  * libdvfs - A light library to set CPU governor and frequency
3  * Copyright (C) 2013-2014 Universite de Versailles
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <fcntl.h>
22 #include <semaphore.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 
36 typedef struct {
37  unsigned int id;
38  unsigned int nb_freqs;
39  unsigned int *freqs;
40 
41  FILE *fd_setf;
42  FILE *fd_getf;
43 
44  char init_gov[128];
45  unsigned int init_freq;
46 
47  sem_t *sem;
48 } dvfs_core;
49 
68 int dvfs_core_open(dvfs_core** ppCore, unsigned int id, bool seq);
69 
79 int dvfs_core_close(dvfs_core *core);
80 
93 int dvfs_core_get_gov(const dvfs_core *core, char *buf, size_t buf_len);
94 
106 int dvfs_core_set_gov(const dvfs_core *core, const char *gov);
107 
120 int dvfs_core_set_freq(const dvfs_core *core, unsigned int freq);
121 
137 int dvfs_core_get_current_freq(const dvfs_core *core, unsigned int* pFreq);
138 
150 int dvfs_core_get_freq(const dvfs_core *core, unsigned int* pFreq, unsigned int freq_id);
151 
161 int dvfs_core_get_nb_freqs (const dvfs_core *core, unsigned int* pNbFreq);
162 
172 int dvfs_core_get_id(const dvfs_core* core, unsigned int* pID);
int dvfs_core_get_freq(const dvfs_core *core, unsigned int *pFreq, unsigned int freq_id)
Gets the frequency currently set for the core.
Definition: dvfs_core.c:460
unsigned int nb_freqs
Number of frequencies available for this core.
Definition: dvfs_core.h:38
int dvfs_core_get_current_freq(const dvfs_core *core, unsigned int *pFreq)
Gets the frequency currently set for the core.
Definition: dvfs_core.c:442
unsigned int init_freq
Freqency used when core get initialised.
Definition: dvfs_core.h:45
int dvfs_core_set_gov(const dvfs_core *core, const char *gov)
Changes the governor on the given core.
Definition: dvfs_core.c:352
unsigned int * freqs
Available frequencies for this core, sorted by increasing order.
Definition: dvfs_core.h:39
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.
Definition: dvfs_core.c:317
unsigned int id
Core id as declared by Linux.
Definition: dvfs_core.h:37
int dvfs_core_open(dvfs_core **ppCore, unsigned int id, bool seq)
Opens the Core context for the given core ID.
Definition: dvfs_core.c:201
int dvfs_core_get_id(const dvfs_core *core, unsigned int *pID)
Gets the ID of the DVFS core.
Definition: dvfs_core.c:489
int dvfs_core_set_freq(const dvfs_core *core, unsigned int freq)
Sets the frequency for the given core.
Definition: dvfs_core.c:395
FILE * fd_getf
Descriptor toward the cur_freq file.
Definition: dvfs_core.h:42
sem_t * sem
Semaphore for sequentialization.
Definition: dvfs_core.h:47
Represents on core.
Definition: dvfs_core.h:36
int dvfs_core_get_nb_freqs(const dvfs_core *core, unsigned int *pNbFreq)
Gets the number of frequencies available for the core.
Definition: dvfs_core.c:477
FILE * fd_setf
File descriptor toward the set_speed file.
Definition: dvfs_core.h:41
int dvfs_core_close(dvfs_core *core)
Closes properly an opened Core context.
Definition: dvfs_core.c:279