summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-05-17 15:55:50 +0100
committerAlastair Poole <netstar@gmail.com>2021-05-17 15:55:50 +0100
commit67561639fd2286b01548d432704c13fc50f84aab (patch)
tree2eaaada71d0c228a479b2457fe3f49bc6fe1ce06
parent981b377523f8463b48c6c5aa75ab3e42c7ce0395 (diff)
cores: cores morez lawz.
-rw-r--r--src/bin/evisum_watcher.c8
-rw-r--r--src/bin/next/machine.h34
-rw-r--r--src/bin/next/machine/cpu.x73
3 files changed, 61 insertions, 54 deletions
diff --git a/src/bin/evisum_watcher.c b/src/bin/evisum_watcher.c
index 81f6536..621f3ce 100644
--- a/src/bin/evisum_watcher.c
+++ b/src/bin/evisum_watcher.c
@@ -17,15 +17,19 @@ main(int argc, char **argv)
17 17
18 puts("CORES:"); 18 puts("CORES:");
19 19
20 printf("total: %i online %i\n", cores_count(), cores_online_count());
21
20 cores = cores_find(); 22 cores = cores_find();
23 cores_topology(cores);
21 for (int i = 0; i < 10; i++) 24 for (int i = 0; i < 10; i++)
22 { 25 {
23 cores_check(cores); 26 cores_check(cores);
24 EINA_LIST_FOREACH(cores, l, core) 27 EINA_LIST_FOREACH(cores, l, core)
25 { 28 {
26 printf("core %i = %1.2f%%\n", core->id, core->percent); 29 printf("core %i = %1.2f%%\t%1.2fMHz %iC\n", core->id, core->percent,
30 (double) core_id_frequency(core->id) / 1000, core_id_temperature(core->id));
27 } 31 }
28 usleep(1000000); 32 usleep(1000000);
29 } 33 }
30 EINA_LIST_FREE(cores, core) 34 EINA_LIST_FREE(cores, core)
31 free(core); 35 free(core);
diff --git a/src/bin/next/machine.h b/src/bin/next/machine.h
index d0674d2..d3871a0 100644
--- a/src/bin/next/machine.h
+++ b/src/bin/next/machine.h
@@ -13,6 +13,7 @@ typedef struct
13 unsigned long idle; 13 unsigned long idle;
14 float percent; 14 float percent;
15 int id; 15 int id;
16 int top_id;
16} Cpu_Core; 17} Cpu_Core;
17 18
18#define MEM_VIDEO_CARD_MAX 8 19#define MEM_VIDEO_CARD_MAX 8
@@ -108,12 +109,6 @@ void
108memory_info(Meminfo *memory); 109memory_info(Meminfo *memory);
109 110
110void 111void
111cores_check(Eina_List *cores);
112
113Eina_List *
114cores_find(void);
115
116void
117sensor_free(Sensor *sensor); 112sensor_free(Sensor *sensor);
118 113
119Eina_Bool 114Eina_Bool
@@ -122,24 +117,35 @@ sensor_check(Sensor *sensor);
122Eina_List * 117Eina_List *
123network_interfaces_find(void); 118network_interfaces_find(void);
124 119
120Eina_List *
121cores_find(void);
122
123void
124cores_check(Eina_List *cores);
125 125
126// XXX
127int 126int
128system_cpu_frequency_get(void); 127cores_count(void);
129 128
130int 129int
131system_cpu_n_frequency_get(int n); 130cores_online_count(void);
131
132void
133cores_topology(Eina_List *cores);
132 134
133int 135int
134system_cpu_n_temperature_get(int n); 136cores_frequency(void);
135 137
136int 138int
137system_cpu_temperature_min_max_get(int *min, int *max); 139core_id_frequency(int d);
138 140
139int 141int
140system_cpu_frequency_min_max_get(int *min, int *max); 142core_id_temperature(int id);
143
144int
145cores_temperature_min_max(int *min, int *max);
146
147int
148cores_frequency_min_max(int *min, int *max);
141 149
142void
143system_cpu_topology_get(int *ids, int ncpus);
144 150
145#endif 151#endif
diff --git a/src/bin/next/machine/cpu.x b/src/bin/next/machine/cpu.x
index 66c7253..9d2d712 100644
--- a/src/bin/next/machine/cpu.x
+++ b/src/bin/next/machine/cpu.x
@@ -4,8 +4,8 @@
4# define CPU_STATES 5 4# define CPU_STATES 5
5#endif 5#endif
6 6
7static int 7int
8cpu_count(void) 8cores_count(void)
9{ 9{
10 static int cores = 0; 10 static int cores = 0;
11 11
@@ -45,13 +45,7 @@ cpu_count(void)
45} 45}
46 46
47int 47int
48system_cpu_count_get(void) 48cores_online_count(void)
49{
50 return cpu_count();
51}
52
53int
54system_cpu_online_count_get(void)
55{ 49{
56#if defined(__OpenBSD__) 50#if defined(__OpenBSD__)
57 static int cores = 0; 51 static int cores = 0;
@@ -63,11 +57,11 @@ system_cpu_online_count_get(void)
63 57
64 len = sizeof(cores); 58 len = sizeof(cores);
65 if (sysctl(mib, 2, &cores, &len, NULL, 0) < 0) 59 if (sysctl(mib, 2, &cores, &len, NULL, 0) < 0)
66 return cpu_count(); 60 return cores_count();
67 61
68 return cores; 62 return cores;
69#else 63#else
70 return cpu_count(); 64 return cores_count();
71#endif 65#endif
72} 66}
73 67
@@ -201,14 +195,14 @@ cores_check(Eina_List *cores)
201 mach_msg_type_number_t count; 195 mach_msg_type_number_t count;
202 processor_cpu_load_info_t load; 196 processor_cpu_load_info_t load;
203 mach_port_t mach_port; 197 mach_port_t mach_port;
204 unsigned int cpu_count; 198 unsigned int cores_count;
205 int i; 199 int i;
206 200
207 cpu_count = eina_list_count(cores); 201 cores_count = eina_list_count(cores);
208 202
209 count = HOST_CPU_LOAD_INFO_COUNT; 203 count = HOST_CPU_LOAD_INFO_COUNT;
210 mach_port = mach_host_self(); 204 mach_port = mach_host_self();
211 if (host_processor_info(mach_port, PROCESSOR_CPU_LOAD_INFO, &cpu_count, 205 if (host_processor_info(mach_port, PROCESSOR_CPU_LOAD_INFO, &cores_count,
212 (processor_info_array_t *)&load, &count) != KERN_SUCCESS) 206 (processor_info_array_t *)&load, &count) != KERN_SUCCESS)
213 exit(-1); 207 exit(-1);
214 208
@@ -247,7 +241,7 @@ cores_find(void)
247 Cpu_Core *core; 241 Cpu_Core *core;
248 int i, ncpu; 242 int i, ncpu;
249 243
250 ncpu = cpu_count(); 244 ncpu = cores_count();
251 for (i = 0; i < ncpu; i++) 245 for (i = 0; i < ncpu; i++)
252 { 246 {
253 core = calloc(1, sizeof(Cpu_Core)); 247 core = calloc(1, sizeof(Cpu_Core));
@@ -263,7 +257,7 @@ static char _core_temps[256][512];
263static char _hwmon_path[256]; 257static char _hwmon_path[256];
264 258
265int 259int
266_cpu_n_temperature_read(int n) 260_core_n_temperature_read(int n)
267{ 261{
268 int temp = -1; 262 int temp = -1;
269#if defined(__linux__) 263#if defined(__linux__)
@@ -304,9 +298,9 @@ static void
304_coretemp_init(void) 298_coretemp_init(void)
305{ 299{
306 char buf[4096]; 300 char buf[4096];
307 int cpu_count = system_cpu_count_get(); 301 int count = cores_count();
308 302
309 for (int j = 0; j < cpu_count; j++) 303 for (int j = 0; j < count; j++)
310 { 304 {
311 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", j); 305 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", j);
312 char *b = file_contents(buf); 306 char *b = file_contents(buf);
@@ -322,16 +316,16 @@ _coretemp_init(void)
322static void 316static void
323_generic_init(void) 317_generic_init(void)
324{ 318{
325 int i, cpu_count = system_cpu_count_get(); 319 int i, count = cores_count();
326 320
327 for (i = 0; i < cpu_count; i++) 321 for (i = 0; i < count; i++)
328 snprintf(_core_temps[i], sizeof(_core_temps[i]), "%s/temp1_input", _hwmon_path); 322 snprintf(_core_temps[i], sizeof(_core_temps[i]), "%s/temp1_input", _hwmon_path);
329} 323}
330 324
331#endif 325#endif
332 326
333int 327int
334system_cpu_n_temperature_get(int n) 328core_id_temperature(int id)
335{ 329{
336#if defined(__linux__) 330#if defined(__linux__)
337 static int init = 0; 331 static int init = 0;
@@ -396,7 +390,7 @@ system_cpu_n_temperature_get(int n)
396 390
397 if (!_hwmon_path[0]) return -1; 391 if (!_hwmon_path[0]) return -1;
398 392
399 return _cpu_n_temperature_read(n); 393 return _core_n_temperature_read(id);
400#elif defined(__FreeBSD__) || defined(__DragonFly__) 394#elif defined(__FreeBSD__) || defined(__DragonFly__)
401 static int init = 0; 395 static int init = 0;
402 396
@@ -406,13 +400,13 @@ system_cpu_n_temperature_get(int n)
406 init = 1; 400 init = 1;
407 } 401 }
408 402
409 return _cpu_n_temperature_read(n); 403 return _core_n_temperature_read(n);
410#endif 404#endif
411 return -1; 405 return -1;
412} 406}
413 407
414int 408int
415system_cpu_temperature_min_max_get(int *min, int *max) 409cores_temperature_min_max(int *min, int *max)
416{ 410{
417 411
418 *min = _cpu_temp_min; 412 *min = _cpu_temp_min;
@@ -422,7 +416,7 @@ system_cpu_temperature_min_max_get(int *min, int *max)
422} 416}
423 417
424int 418int
425system_cpu_n_frequency_get(int n) 419core_id_frequency(int id)
426{ 420{
427#if defined(__linux__) 421#if defined(__linux__)
428 int freq = -1; 422 int freq = -1;
@@ -430,7 +424,7 @@ system_cpu_n_frequency_get(int n)
430 char buf[4096]; 424 char buf[4096];
431 int tmp; 425 int tmp;
432 426
433 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", n); 427 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", id);
434 f = fopen(buf, "r"); 428 f = fopen(buf, "r");
435 if (f) 429 if (f)
436 { 430 {
@@ -446,14 +440,14 @@ system_cpu_n_frequency_get(int n)
446 440
447 return freq; 441 return freq;
448#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 442#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
449 return system_cpu_frequency_get(); 443 return core_frequency();
450#endif 444#endif
451 445
452 return -1; 446 return -1;
453} 447}
454 448
455int 449int
456system_cpu_frequency_min_max_get(int *min, int *max) 450cores_frequency_min_max(int *min, int *max)
457{ 451{
458 int freq_min = 0x7fffffff, freq_max = 0; 452 int freq_min = 0x7fffffff, freq_max = 0;
459#if defined(__linux__) 453#if defined(__linux__)
@@ -537,7 +531,7 @@ system_cpu_frequency_min_max_get(int *min, int *max)
537} 531}
538 532
539int 533int
540system_cpu_frequency_get(void) 534cores_frequency(void)
541{ 535{
542 int freq = -1; 536 int freq = -1;
543 537
@@ -592,7 +586,8 @@ system_cpu_frequency_get(void)
592 586
593#if defined(__linux__) 587#if defined(__linux__)
594 588
595typedef struct { 589typedef struct
590{
596 short id; 591 short id;
597 short core_id; 592 short core_id;
598} core_top_t; 593} core_top_t;
@@ -611,31 +606,33 @@ _cmp(const void *a, const void *b)
611#endif 606#endif
612 607
613void 608void
614system_cpu_topology_get(int *ids, int ncpu) 609cores_topology(Eina_List *cores)
615{ 610{
616#if defined(__linux__) 611#if defined(__linux__)
617 char buf[4096]; 612 char buf[4096];
618 core_top_t *cores = malloc(ncpu * sizeof(core_top_t)); 613 int ncpu = eina_list_count(cores);
614 core_top_t *cores_top = malloc(ncpu * sizeof(core_top_t));
619 615
620 for (int i = 0; i < ncpu; i++) 616 for (int i = 0; i < ncpu; i++)
621 { 617 {
622 cores[i].id = i; 618 cores_top[i].id = i;
623 cores[i].core_id = i; 619 cores_top[i].core_id = i;
624 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", i); 620 snprintf(buf, sizeof(buf), "/sys/devices/system/cpu/cpu%i/topology/core_id", i);
625 char *b = file_contents(buf); 621 char *b = file_contents(buf);
626 if (b) 622 if (b)
627 { 623 {
628 cores[i].core_id = atoi(b); 624 cores_top[i].core_id = atoi(b);
629 free(b); 625 free(b);
630 } 626 }
631 } 627 }
632 628
633 qsort(cores, ncpu, sizeof(core_top_t), _cmp); 629 qsort(cores_top, ncpu, sizeof(core_top_t), _cmp);
634 630
635 for (int i = 0; i < ncpu; i++) 631 for (int i = 0; i < ncpu; i++)
636 { 632 {
637 ids[i] = cores[i].id; 633 Cpu_Core *core = eina_list_nth(cores, i);
634 core->top_id = cores_top[i].id;
638 } 635 }
639 free(cores); 636 free(cores_top);
640#endif 637#endif
641} 638}