| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef _GNU_SOURCE |
| 22 |
# define _GNU_SOURCE |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#include "common.h" |
| 30 |
#include "cputopology.h" |
| 31 |
#include "logging.h" |
| 32 |
#include "system.h" |
| 33 |
#include "xalloc.h" |
| 34 |
|
| 35 |
#define PROC_ROOT "/proc" |
| 36 |
#define PROC_INTR PROC_ROOT "/interrupts" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
unsigned long * |
| 43 |
proc_interrupts_get_nintr_per_cpu (unsigned int *ncpus) |
| 44 |
{ |
| 45 |
FILE *fp; |
| 46 |
char *p, *end, *line = NULL; |
| 47 |
size_t len = 0; |
| 48 |
ssize_t chread; |
| 49 |
bool header = true; |
| 50 |
unsigned int cpu; |
| 51 |
|
| 52 |
if ((fp = fopen (PROC_INTR, "r")) == NULL) |
| 53 |
return NULL; |
| 54 |
|
| 55 |
*ncpus = get_processor_number_online (); |
| 56 |
unsigned long value, |
| 57 |
*vintr = xnmalloc (*ncpus, sizeof (unsigned long)); |
| 58 |
|
| 59 |
while ((chread = getline (&line, &len, fp)) != -1) |
| 60 |
{ |
| 61 |
|
| 62 |
if (header) |
| 63 |
{ |
| 64 |
header = false; |
| 65 |
continue; |
| 66 |
} |
| 67 |
|
| 68 |
p = strchr(line, ':'); |
| 69 |
if (NULL == p) |
| 70 |
continue; |
| 71 |
|
| 72 |
dbg ("%s", line); |
| 73 |
for (cpu = 0; cpu < *ncpus; cpu++) |
| 74 |
{ |
| 75 |
if (*p == '\0' || *p == '\n') |
| 76 |
continue; |
| 77 |
value = strtoul (p + 1, &end, 10); |
| 78 |
dbg (" --> cpu%u = %lu\n", cpu, value); |
| 79 |
vintr[cpu] += value; |
| 80 |
p = end + 1; |
| 81 |
} |
| 82 |
dbg ("\n"); |
| 83 |
} |
| 84 |
|
| 85 |
free (line); |
| 86 |
|
| 87 |
return vintr; |
| 88 |
} |