cores: cores morez lawz.
This commit is contained in:
parent
981b377523
commit
67561639fd
|
@ -17,15 +17,19 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
puts("CORES:");
|
puts("CORES:");
|
||||||
|
|
||||||
|
printf("total: %i online %i\n", cores_count(), cores_online_count());
|
||||||
|
|
||||||
cores = cores_find();
|
cores = cores_find();
|
||||||
|
cores_topology(cores);
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
cores_check(cores);
|
cores_check(cores);
|
||||||
EINA_LIST_FOREACH(cores, l, core)
|
EINA_LIST_FOREACH(cores, l, core)
|
||||||
{
|
{
|
||||||
printf("core %i = %1.2f%%\n", core->id, core->percent);
|
printf("core %i = %1.2f%%\t%1.2fMHz %iC\n", core->id, core->percent,
|
||||||
|
(double) core_id_frequency(core->id) / 1000, core_id_temperature(core->id));
|
||||||
}
|
}
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
}
|
}
|
||||||
EINA_LIST_FREE(cores, core)
|
EINA_LIST_FREE(cores, core)
|
||||||
free(core);
|
free(core);
|
||||||
|
|
|
@ -13,6 +13,7 @@ typedef struct
|
||||||
unsigned long idle;
|
unsigned long idle;
|
||||||
float percent;
|
float percent;
|
||||||
int id;
|
int id;
|
||||||
|
int top_id;
|
||||||
} Cpu_Core;
|
} Cpu_Core;
|
||||||
|
|
||||||
#define MEM_VIDEO_CARD_MAX 8
|
#define MEM_VIDEO_CARD_MAX 8
|
||||||
|
@ -107,12 +108,6 @@ sensors_find(void);
|
||||||
void
|
void
|
||||||
memory_info(Meminfo *memory);
|
memory_info(Meminfo *memory);
|
||||||
|
|
||||||
void
|
|
||||||
cores_check(Eina_List *cores);
|
|
||||||
|
|
||||||
Eina_List *
|
|
||||||
cores_find(void);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sensor_free(Sensor *sensor);
|
sensor_free(Sensor *sensor);
|
||||||
|
|
||||||
|
@ -122,24 +117,35 @@ sensor_check(Sensor *sensor);
|
||||||
Eina_List *
|
Eina_List *
|
||||||
network_interfaces_find(void);
|
network_interfaces_find(void);
|
||||||
|
|
||||||
|
Eina_List *
|
||||||
// XXX
|
cores_find(void);
|
||||||
int
|
|
||||||
system_cpu_frequency_get(void);
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_n_frequency_get(int n);
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_n_temperature_get(int n);
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_temperature_min_max_get(int *min, int *max);
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_frequency_min_max_get(int *min, int *max);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
system_cpu_topology_get(int *ids, int ncpus);
|
cores_check(Eina_List *cores);
|
||||||
|
|
||||||
|
int
|
||||||
|
cores_count(void);
|
||||||
|
|
||||||
|
int
|
||||||
|
cores_online_count(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
cores_topology(Eina_List *cores);
|
||||||
|
|
||||||
|
int
|
||||||
|
cores_frequency(void);
|
||||||
|
|
||||||
|
int
|
||||||
|
core_id_frequency(int d);
|
||||||
|
|
||||||
|
int
|
||||||
|
core_id_temperature(int id);
|
||||||
|
|
||||||
|
int
|
||||||
|
cores_temperature_min_max(int *min, int *max);
|
||||||
|
|
||||||
|
int
|
||||||
|
cores_frequency_min_max(int *min, int *max);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
# define CPU_STATES 5
|
# define CPU_STATES 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
int
|
||||||
cpu_count(void)
|
cores_count(void)
|
||||||
{
|
{
|
||||||
static int cores = 0;
|
static int cores = 0;
|
||||||
|
|
||||||
|
@ -45,13 +45,7 @@ cpu_count(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_count_get(void)
|
cores_online_count(void)
|
||||||
{
|
|
||||||
return cpu_count();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
system_cpu_online_count_get(void)
|
|
||||||
{
|
{
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
static int cores = 0;
|
static int cores = 0;
|
||||||
|
@ -63,11 +57,11 @@ system_cpu_online_count_get(void)
|
||||||
|
|
||||||
len = sizeof(cores);
|
len = sizeof(cores);
|
||||||
if (sysctl(mib, 2, &cores, &len, NULL, 0) < 0)
|
if (sysctl(mib, 2, &cores, &len, NULL, 0) < 0)
|
||||||
return cpu_count();
|
return cores_count();
|
||||||
|
|
||||||
return cores;
|
return cores;
|
||||||
#else
|
#else
|
||||||
return cpu_count();
|
return cores_count();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,14 +195,14 @@ cores_check(Eina_List *cores)
|
||||||
mach_msg_type_number_t count;
|
mach_msg_type_number_t count;
|
||||||
processor_cpu_load_info_t load;
|
processor_cpu_load_info_t load;
|
||||||
mach_port_t mach_port;
|
mach_port_t mach_port;
|
||||||
unsigned int cpu_count;
|
unsigned int cores_count;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cpu_count = eina_list_count(cores);
|
cores_count = eina_list_count(cores);
|
||||||
|
|
||||||
count = HOST_CPU_LOAD_INFO_COUNT;
|
count = HOST_CPU_LOAD_INFO_COUNT;
|
||||||
mach_port = mach_host_self();
|
mach_port = mach_host_self();
|
||||||
if (host_processor_info(mach_port, PROCESSOR_CPU_LOAD_INFO, &cpu_count,
|
if (host_processor_info(mach_port, PROCESSOR_CPU_LOAD_INFO, &cores_count,
|
||||||
(processor_info_array_t *)&load, &count) != KERN_SUCCESS)
|
(processor_info_array_t *)&load, &count) != KERN_SUCCESS)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
|
@ -247,7 +241,7 @@ cores_find(void)
|
||||||
Cpu_Core *core;
|
Cpu_Core *core;
|
||||||
int i, ncpu;
|
int i, ncpu;
|
||||||
|
|
||||||
ncpu = cpu_count();
|
ncpu = cores_count();
|
||||||
for (i = 0; i < ncpu; i++)
|
for (i = 0; i < ncpu; i++)
|
||||||
{
|
{
|
||||||
core = calloc(1, sizeof(Cpu_Core));
|
core = calloc(1, sizeof(Cpu_Core));
|
||||||
|
@ -263,7 +257,7 @@ static char _core_temps[256][512];
|
||||||
static char _hwmon_path[256];
|
static char _hwmon_path[256];
|
||||||
|
|
||||||
int
|
int
|
||||||
_cpu_n_temperature_read(int n)
|
_core_n_temperature_read(int n)
|
||||||
{
|
{
|
||||||
int temp = -1;
|
int temp = -1;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
@ -304,9 +298,9 @@ static void
|
||||||
_coretemp_init(void)
|
_coretemp_init(void)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int cpu_count = system_cpu_count_get();
|
int count = cores_count();
|
||||||
|
|
||||||
for (int j = 0; j < cpu_count; j++)
|
for (int j = 0; j < count; j++)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", j);
|
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", j);
|
||||||
char *b = file_contents(buf);
|
char *b = file_contents(buf);
|
||||||
|
@ -322,16 +316,16 @@ _coretemp_init(void)
|
||||||
static void
|
static void
|
||||||
_generic_init(void)
|
_generic_init(void)
|
||||||
{
|
{
|
||||||
int i, cpu_count = system_cpu_count_get();
|
int i, count = cores_count();
|
||||||
|
|
||||||
for (i = 0; i < cpu_count; i++)
|
for (i = 0; i < count; i++)
|
||||||
snprintf(_core_temps[i], sizeof(_core_temps[i]), "%s/temp1_input", _hwmon_path);
|
snprintf(_core_temps[i], sizeof(_core_temps[i]), "%s/temp1_input", _hwmon_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_n_temperature_get(int n)
|
core_id_temperature(int id)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
|
@ -396,7 +390,7 @@ system_cpu_n_temperature_get(int n)
|
||||||
|
|
||||||
if (!_hwmon_path[0]) return -1;
|
if (!_hwmon_path[0]) return -1;
|
||||||
|
|
||||||
return _cpu_n_temperature_read(n);
|
return _core_n_temperature_read(id);
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
|
|
||||||
|
@ -406,13 +400,13 @@ system_cpu_n_temperature_get(int n)
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cpu_n_temperature_read(n);
|
return _core_n_temperature_read(n);
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_temperature_min_max_get(int *min, int *max)
|
cores_temperature_min_max(int *min, int *max)
|
||||||
{
|
{
|
||||||
|
|
||||||
*min = _cpu_temp_min;
|
*min = _cpu_temp_min;
|
||||||
|
@ -422,7 +416,7 @@ system_cpu_temperature_min_max_get(int *min, int *max)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_n_frequency_get(int n)
|
core_id_frequency(int id)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
int freq = -1;
|
int freq = -1;
|
||||||
|
@ -430,7 +424,7 @@ system_cpu_n_frequency_get(int n)
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", n);
|
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", id);
|
||||||
f = fopen(buf, "r");
|
f = fopen(buf, "r");
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
|
@ -446,14 +440,14 @@ system_cpu_n_frequency_get(int n)
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
||||||
return system_cpu_frequency_get();
|
return core_frequency();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_frequency_min_max_get(int *min, int *max)
|
cores_frequency_min_max(int *min, int *max)
|
||||||
{
|
{
|
||||||
int freq_min = 0x7fffffff, freq_max = 0;
|
int freq_min = 0x7fffffff, freq_max = 0;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
@ -537,7 +531,7 @@ system_cpu_frequency_min_max_get(int *min, int *max)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
system_cpu_frequency_get(void)
|
cores_frequency(void)
|
||||||
{
|
{
|
||||||
int freq = -1;
|
int freq = -1;
|
||||||
|
|
||||||
|
@ -592,7 +586,8 @@ system_cpu_frequency_get(void)
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
short id;
|
short id;
|
||||||
short core_id;
|
short core_id;
|
||||||
} core_top_t;
|
} core_top_t;
|
||||||
|
@ -611,31 +606,33 @@ _cmp(const void *a, const void *b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
system_cpu_topology_get(int *ids, int ncpu)
|
cores_topology(Eina_List *cores)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
core_top_t *cores = malloc(ncpu * sizeof(core_top_t));
|
int ncpu = eina_list_count(cores);
|
||||||
|
core_top_t *cores_top = malloc(ncpu * sizeof(core_top_t));
|
||||||
|
|
||||||
for (int i = 0; i < ncpu; i++)
|
for (int i = 0; i < ncpu; i++)
|
||||||
{
|
{
|
||||||
cores[i].id = i;
|
cores_top[i].id = i;
|
||||||
cores[i].core_id = i;
|
cores_top[i].core_id = i;
|
||||||
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", i);
|
snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", i);
|
||||||
char *b = file_contents(buf);
|
char *b = file_contents(buf);
|
||||||
if (b)
|
if (b)
|
||||||
{
|
{
|
||||||
cores[i].core_id = atoi(b);
|
cores_top[i].core_id = atoi(b);
|
||||||
free(b);
|
free(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(cores, ncpu, sizeof(core_top_t), _cmp);
|
qsort(cores_top, ncpu, sizeof(core_top_t), _cmp);
|
||||||
|
|
||||||
for (int i = 0; i < ncpu; i++)
|
for (int i = 0; i < ncpu; i++)
|
||||||
{
|
{
|
||||||
ids[i] = cores[i].id;
|
Cpu_Core *core = eina_list_nth(cores, i);
|
||||||
|
core->top_id = cores_top[i].id;
|
||||||
}
|
}
|
||||||
free(cores);
|
free(cores_top);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue