Browse Source

Some comments and renaming

Serj Kalichev 10 years ago
parent
commit
dd2460d449
6 changed files with 39 additions and 26 deletions
  1. 10 6
      birq.c
  2. 10 3
      birq.h
  3. 6 6
      cpu.h
  4. 4 2
      cpu_parse.c
  5. 6 6
      irq.h
  6. 3 3
      irq_parse.c

+ 10 - 6
birq.c

@@ -78,9 +78,9 @@ int main(int argc, char **argv)
 	/* NetLink vars */
 	nl_fds_t *nl_fds = NULL; /* NetLink socket */
 
-	/* IRQ list. It contain all found irqs. */
+	/* IRQ list. It contain all found IRQs. */
 	lub_list_t *irqs;
-	/* IRQs to balance */
+	/* IRQs need to be balanced */
 	lub_list_t *balance_irqs;
 	/* CPU list. It contain all found CPUs. */
 	lub_list_t *cpus;
@@ -161,7 +161,7 @@ int main(int argc, char **argv)
 			if (opts->debug)
 				fprintf(stdout, "Scanning hardware...\n");
 			rescan = 0;
-			irq_list_populate(irqs, balance_irqs);
+			scan_irqs(irqs, balance_irqs);
 			if (opts->debug)
 				irq_list_show(irqs);
 		}
@@ -181,21 +181,25 @@ int main(int argc, char **argv)
 			}
 		}
 
+		/* Gather statistics on CPU load and number of interrupts. */
 		gather_statistics(cpus, irqs);
 		show_statistics(cpus);
 		/* Choose IRQ to move to another CPU.
-		   Don't choose IRQ if we have new IRQs to balance */
+		   Don't choose IRQ if we already have new IRQs to balance */
 		if (lub_list_len(balance_irqs) == 0) {
 			choose_irqs_to_move(cpus, balance_irqs,
 				opts->threshold);
 		}
-		/* Nothing to balance */
+		/* If nothing to balance */
 		if (lub_list_len(balance_irqs) == 0) {
 			interval = BIRQ_LONG_INTERVAL;
 			continue;
 		}
+		/* Set short interval to make balancing faster. */
 		interval = BIRQ_SHORT_INTERVAL;
+		/* Choose new CPU for IRQs need to be balanced. */
 		balance(cpus, balance_irqs, opts->threshold);
+		/* Write new values to /proc/irq/<IRQ>/smp_affinity */
 		apply_affinity(balance_irqs);
 		/* Free list of balanced IRQs */
 		while ((node = lub_list__get_tail(balance_irqs))) {
@@ -225,7 +229,6 @@ err:
 
 	/* Free command line options */
 	opts_free(opts);
-
 	syslog(LOG_ERR, "Stop daemon.\n");
 
 	return retval;
@@ -378,5 +381,6 @@ static void help(int status, const char *argv0)
 		printf("\t-d, --debug\tDebug mode. Don't daemonize.\n");
 		printf("\t-p <path>, --pid=<path>\tFile to save daemon's PID to.\n");
 		printf("\t-O, --facility\tSyslog facility. Default is DAEMON.\n");
+		printf("\t-t <float>, --threshold=<float>\tThreshold to consider CPU is overloaded, in percents.\n");
 	}
 }

+ 10 - 3
birq.h

@@ -2,8 +2,15 @@
 #define _birq_h
 
 #define BIRQ_PIDFILE "/var/run/birq.pid"
-#define BIRQ_LONG_INTERVAL 5 /* in seconds */
-#define BIRQ_SHORT_INTERVAL 2 /* in seconds */
-#define BIRQ_DEFAULT_THRESHOLD 95.00
+
+/* Interval beetween balance iterations, in seconds.
+   The long interval is used when there are no overloaded CPUs.
+   Else the short interval is used. */
+#define BIRQ_LONG_INTERVAL 5
+#define BIRQ_SHORT_INTERVAL 2
+
+/* Threshold to consider CPU as overloaded.
+   In percents, float value. Can't be greater than 100.0 */
+#define BIRQ_DEFAULT_THRESHOLD 95.0
 
 #endif

+ 6 - 6
cpu.h

@@ -8,14 +8,15 @@ struct cpu_s {
 	unsigned int id; /* Logical processor ID */
 	unsigned int package_id;
 	unsigned int core_id;
-	cpumask_t cpumask;
-	unsigned long long old_load_all;
-	unsigned long long old_load_irq;
-	float load;
-	lub_list_t *irqs;
+	cpumask_t cpumask; /* Mask with one bit set - current CPU. */
+	unsigned long long old_load_all; /* Previous whole load from /proc/stat */
+	unsigned long long old_load_irq; /* Previous IRQ, softIRQ load */
+	float load; /* Current CPU load in percents. */
+	lub_list_t *irqs; /* List of IRQs belong to this CPU. */
 };
 typedef struct cpu_s cpu_t;
 
+/* System CPU info */
 #define SYSFS_CPU_PATH "/sys/devices/system/cpu"
 
 /* CPU IDs compare function */
@@ -23,7 +24,6 @@ int cpu_list_compare(const void *first, const void *second);
 int cpu_list_compare_len(const void *first, const void *second);
 
 /* CPU list functions */
-int cpu_list_populate(lub_list_t *cpus);
 int cpu_list_free(lub_list_t *cpus);
 int scan_cpus(lub_list_t *cpus);
 int show_cpus(lub_list_t *cpus);

+ 4 - 2
cpu_parse.c

@@ -16,8 +16,6 @@
 #include "cpu.h"
 #include "irq.h"
 
-#define STR(str) ( str ? str : "" )
-
 int cpu_list_compare(const void *first, const void *second)
 {
 	const cpu_t *f = (const cpu_t *)first;
@@ -61,6 +59,9 @@ static void cpu_free(cpu_t *cpu)
 	free(cpu);
 }
 
+/* Search for CPU with specified package and core IDs.
+   The second CPU with the same IDs is a thread of Hyper Threading.
+   We don't want to use HT for IRQ balancing. */
 static cpu_t * cpu_list_search_ht(lub_list_t *cpus,
 	unsigned int package_id,
 	unsigned int core_id)
@@ -139,6 +140,7 @@ int show_cpus(lub_list_t *cpus)
 	return 0;
 }
 
+/* Search for CPUs */
 int scan_cpus(lub_list_t *cpus)
 {
 	FILE *fd;

+ 6 - 6
irq.h

@@ -5,14 +5,14 @@
 #include "cpu.h"
 
 struct irq_s {
-	unsigned int irq;
+	unsigned int irq; /* IRQ's ID */
 	char *type; /* IRQ type from /proc/interrupts like PCI-MSI-edge */
 	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;
-	cpu_t *cpu;
+	cpumask_t local_cpus; /* Local CPUs for this IRQs */
+	unsigned long long intr; /* Current number of interrupts */
+	unsigned long long old_intr; /* Previous total number of interrupts. */
+	cpu_t *cpu; /* Current IRQ affinity. Reference to correspondent CPU */
 };
 typedef struct irq_s irq_t;
 
@@ -24,7 +24,7 @@ typedef struct irq_s irq_t;
 int irq_list_compare(const void *first, const void *second);
 
 /* IRQ list functions */
-int irq_list_populate(lub_list_t *irqs, lub_list_t *balance_irqs);
+int scan_irqs(lub_list_t *irqs, lub_list_t *balance_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);

+ 3 - 3
irq_parse.c

@@ -140,7 +140,7 @@ static int parse_local_cpus(lub_list_t *irqs, const char *sysfs_path,
 	return 0;
 }
 
-static int scan_sysfs(lub_list_t *irqs)
+static int parse_sysfs(lub_list_t *irqs)
 {
 	DIR *dir;
 	DIR *msi;
@@ -195,7 +195,7 @@ static int scan_sysfs(lub_list_t *irqs)
 }
 
 /* Parse /proc/interrupts to get actual IRQ list */
-int irq_list_populate(lub_list_t *irqs, lub_list_t *balance_irqs)
+int scan_irqs(lub_list_t *irqs, lub_list_t *balance_irqs)
 {
 	FILE *fd;
 	unsigned int num;
@@ -269,7 +269,7 @@ int irq_list_populate(lub_list_t *irqs, lub_list_t *balance_irqs)
 	}
 
 	/* Add IRQ info from sysfs */
-	scan_sysfs(irqs);
+	parse_sysfs(irqs);
 
 	return 0;
 }