Browse Source

Add proximity.c

Serj Kalichev 10 years ago
parent
commit
c7982329e1
3 changed files with 107 additions and 2 deletions
  1. 4 2
      Makefile.am
  2. 97 0
      proximity.c
  3. 6 0
      proximity.h

+ 4 - 2
Makefile.am

@@ -21,7 +21,8 @@ noinst_HEADERS = \
 	irq.h \
 	cpu.h \
 	statistics.h \
-	balance.h
+	balance.h \
+	proximity.h
 
 birq_SOURCES = \
 	birq.c \
@@ -29,7 +30,8 @@ birq_SOURCES = \
 	irq_parse.c \
 	cpu_parse.c \
 	statistics.c \
-	balance.c
+	balance.c \
+	proximity.c
 
 birq_LDADD = liblub.a
 birq_DEPENDENCIES = liblub.a

+ 97 - 0
proximity.c

@@ -0,0 +1,97 @@
+/* proximity.c
+ * Parse manual proximity config.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <limits.h>
+#include <ctype.h>
+
+#include "lub/list.h"
+#include "proximity.h"
+
+#define STR(str) ( str ? str : "" )
+
+int parse_pxm_config(const char *fname)
+{
+	FILE *file;
+	char *line = NULL;
+	size_t size = 0;
+	char *saveptr;
+
+	if (!fname)
+		return -1;
+	file = fopen(fname, "r");
+	if (!file)
+		return -1;
+
+	while (!feof(file)) {
+		if (getline(&line, &size, file) == 0)
+			break;
+printf("%s\n", line);
+/*		if (!strstr(line, "cpu"))
+			break;
+		cpunr = strtoul(&line[3], NULL, 10);
+
+		cpu = cpu_list_search(cpus, cpunr);
+		if (!cpu)
+			continue;
+
+		rc = sscanf(line, "%*s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
+			&l_user, &l_nice, &l_system, &l_idle, &l_iowait,
+			&l_irq, &l_softirq, &l_steal, &l_guest, &l_guest_nice);
+		if (rc < 2)
+			break;
+		cpucount++;
+
+		load_all = l_user + l_nice + l_system + l_idle + l_iowait +
+			l_irq + l_softirq + l_steal + l_guest + l_guest_nice;
+		load_irq = l_irq + l_softirq;
+
+		cpu->old_load = cpu->load;
+		if (cpu->old_load_all == 0) {
+			cpu->load = 0;
+		} else {
+			float d_all = (float)(load_all - cpu->old_load_all);
+			float d_irq = (float)(load_irq - cpu->old_load_irq);
+			cpu->load = d_irq * 100 / d_all;
+		}
+
+		cpu->old_load_all = load_all;
+		cpu->old_load_irq = load_irq;
+*/
+	}
+
+	/* Parse "intr" line. Get number of interrupts. */
+#if 0
+	strtok_r(line, " ", &saveptr);
+	strtok_r(NULL, " ", &saveptr); /* Total number of interrupts */
+	for (intr_str = strtok_r(NULL, " ", &saveptr);
+		intr_str; intr_str = strtok_r(NULL, " ", &saveptr)) {
+		unsigned long long intr = 0;
+		char *endptr;
+		irq_t *irq;
+		
+		irq = irq_list_search(irqs, inum);
+		inum++;
+		if (!irq)
+			continue;
+		intr = strtoull(intr_str, &endptr, 10);
+		if (endptr == intr_str)
+			intr = 0;
+		if (irq->old_intr == 0)
+			irq->intr = 0;
+		else
+			irq->intr = intr - irq->old_intr;
+		irq->old_intr = intr;
+	}
+#endif
+
+	fclose(file);
+	free(line);
+
+	return 0;
+}

+ 6 - 0
proximity.h

@@ -0,0 +1,6 @@
+#ifndef _proximity_h
+#define _proximity_h
+
+#include "cpumask.h"
+
+#endif