Browse Source

Parse /proc/stat for intr

Serj Kalichev 10 years ago
parent
commit
b09318f76d
5 changed files with 38 additions and 40 deletions
  1. 1 1
      birq.c
  2. 3 0
      irq.h
  3. 3 1
      irq_parse.c
  4. 30 37
      statistics.c
  5. 1 1
      statistics.h

+ 1 - 1
birq.c

@@ -182,7 +182,7 @@ int main(int argc, char **argv)
 
 		if (opts->debug)
 			printf("Some balancing...\n");
-		parse_proc_stat(cpus);
+		parse_proc_stat(cpus, irqs);
 	}
 
 end:

+ 3 - 0
irq.h

@@ -9,6 +9,8 @@ struct irq_s {
 	char *desc; /* IRQ text description - device list */
 	int refresh; /* Refresh flag. It !=0 if irq was found while populate */
 	cpumask_t local_cpus;
+	unsigned long long intr;
+	unsigned long long old_intr;
 };
 typedef struct irq_s irq_t;
 
@@ -23,5 +25,6 @@ int irq_list_compare(const void *first, const void *second);
 int irq_list_populate(lub_list_t *irqs);
 int irq_list_free(lub_list_t *irqs);
 int irq_list_show(lub_list_t *irqs);
+irq_t * irq_list_search(lub_list_t *irqs, unsigned int num);
 
 #endif

+ 3 - 1
irq_parse.c

@@ -32,6 +32,8 @@ static irq_t * irq_new(int num)
 	new->type = NULL;
 	new->desc = NULL;
 	new->refresh = 1;
+	new->old_intr = 0;
+	new->intr = 0;
 	return new;
 }
 
@@ -42,7 +44,7 @@ static void irq_free(irq_t *irq)
 	free(irq);
 }
 
-static irq_t * irq_list_search(lub_list_t *irqs, unsigned int num)
+irq_t * irq_list_search(lub_list_t *irqs, unsigned int num)
 {
 	lub_list_node_t *node;
 	irq_t search;

+ 30 - 37
statistics.c

@@ -12,10 +12,11 @@
 
 #include "statistics.h"
 #include "cpu.h"
+#include "irq.h"
 
 #define STR(str) ( str ? str : "" )
 
-void parse_proc_stat(lub_list_t *cpus)
+void parse_proc_stat(lub_list_t *cpus, lub_list_t *irqs)
 {
 	FILE *file;
 	char *line = NULL;
@@ -32,6 +33,9 @@ void parse_proc_stat(lub_list_t *cpus)
 	unsigned long long l_guest;
 	unsigned long long l_guest_nice;
 	unsigned long long load_irq, load_all;
+	char *intr_str;
+	char *saveptr;
+	unsigned int inum = 0;
 
 	file = fopen("/proc/stat", "r");
 	if (!file) {
@@ -72,6 +76,7 @@ void parse_proc_stat(lub_list_t *cpus)
 		load_irq = l_irq + l_softirq;
 
 		if (cpu->old_load_all == 0) {
+			/* When old_load_all = 0 - it's first iteration */
 			cpu->load = 0;
 		} else {
 			float d_all = (float)(load_all - cpu->old_load_all);
@@ -82,45 +87,33 @@ void parse_proc_stat(lub_list_t *cpus)
 		cpu->old_load_all = load_all;
 		cpu->old_load_irq = load_irq;
 
-printf("CPU %u %.2f\%\n", cpunr, cpu->load);
-
+		printf("CPU %u %.2f%%\n", cpunr, cpu->load);
+	}
 
-		/*
- 		 * For each cpu add the irq and softirq load and propagate that
- 		 * all the way up the device tree
- 		 */
-//		if (cycle_count) {
-//			cpu->load = (irq_load + softirq_load) - (cpu->last_load);
-			/*
-			 * the [soft]irq_load values are in jiffies, with
-			 * HZ jiffies per second.  Convert the load to nanoseconds
-			 * to get a better integer resolution of nanoseconds per
-			 * interrupt.
-			 */
-//			cpu->load *= NSEC_PER_SEC/HZ;
-//		}
-//		cpu->last_load = (irq_load + softirq_load);
+	/* Parse "intr" line. Get number of interrupts. */
+	intr_str = strtok_r(line, " ", &saveptr); /* String "intr" */
+	intr_str = 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;
+		printf("IRQ %u %llu %s\n", irq->irq, irq->intr, irq->desc);
 	}
 
 	fclose(file);
 	free(line);
-//	if (cpucount != get_cpu_count()) {
-//		fprintf(stderr, "Warning: Can't collect load info for all cpus, balancing is broken\n");
-//		return;
-//	}
-
-	/*
- 	 * Reset the load values for all objects above cpus
- 	 */
-//	for_each_object(cache_domains, reset_load, NULL);
-
-	/*
- 	 * Now that we have load for each cpu attribute a fair share of the load
- 	 * to each irq on that cpu
- 	 */
-//	for_each_object(cpus, compute_irq_branch_load_share, NULL);
-//	for_each_object(cache_domains, compute_irq_branch_load_share, NULL);
-//	for_each_object(packages, compute_irq_branch_load_share, NULL);
-//	for_each_object(numa_nodes, compute_irq_branch_load_share, NULL);
-
 }

+ 1 - 1
statistics.h

@@ -3,6 +3,6 @@
 
 #include "lub/list.h"
 
-void parse_proc_stat(lub_list_t *cpus);
+void parse_proc_stat(lub_list_t *cpus, lub_list_t *irqs);
 
 #endif