aboutsummaryrefslogtreecommitdiff
path: root/getcore.c
blob: a0f01e405015f2e8225e93cfed82055d15c2e696 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "getcore.h"

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>

static unsigned int cores;

/***********************************************************************
 * Return true/false if specified core num exists
 **********************************************************************/
bool core_exists(unsigned int core)
{
	char path[1024];
	int result;
	snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq", core);
	result = access(path, F_OK);
	return (result != -1);
}


/***********************************************************************
 * Initialise surrounding variables
 **********************************************************************/
void gc_init()
{
	cores = 0;
	while (core_exists(cores))
		cores++;
}


/***********************************************************************
 * Return number of cores
 **********************************************************************/
unsigned int gc_number()
{
	return cores;
}