Browse Source

Possibility to use non-local cpus for balancing. Option non_local_cpus. The HT is on by default.

Serj Kalichev 4 years ago
parent
commit
74bea5cb0c
3 changed files with 47 additions and 13 deletions
  1. 11 8
      balance.c
  2. 1 1
      balance.h
  3. 35 4
      birq.c

+ 11 - 8
balance.c

@@ -153,7 +153,7 @@ static int irq_set_affinity(irq_t *irq, cpumask_t *cpumask)
 
 /* Find best CPUs for IRQs need to be balanced. */
 int balance(lub_list_t *cpus, lub_list_t *balance_irqs,
-	float load_limit, cpumask_t *exclude_cpus)
+	float load_limit, cpumask_t *exclude_cpus, int non_local_cpus)
 {
 	lub_list_node_t *iter;
 
@@ -180,14 +180,17 @@ int balance(lub_list_t *cpus, lub_list_t *balance_irqs,
 		/* Non-local CPUs were disabled. It seems there is
 		   no advantages to use them. The all interactions will
 		   be held by QPI-like interfaces through local CPUs. */
-/*		if (!cpu) {
-			cpumask_t complement;
-			cpus_init(complement);
-			cpus_complement(complement, irq->local_cpus);
-			cpu = choose_cpu(cpus, &complement, load_limit);
-			cpus_free(complement);
+		/* May be the previous note is wrong. Using of non local
+		   cpus depends on config option "non_local_cpus" now. */
+		if (!cpu && non_local_cpus) {
+			cpus_init(possible_cpus);
+			cpus_copy(possible_cpus, *exclude_cpus);
+			cpus_or(possible_cpus, possible_cpus, irq->local_cpus);
+			cpus_complement(possible_cpus, possible_cpus);
+			cpu = choose_cpu(cpus, &possible_cpus, load_limit);
+			cpus_free(possible_cpus);
 		}
-*/
+
 		if (cpu) {
 			if (irq->cpu)
 				printf("Move IRQ %u from CPU%u to CPU%u\n",

+ 1 - 1
balance.h

@@ -14,7 +14,7 @@ typedef enum {
 int remove_irq_from_cpu(irq_t *irq, cpu_t *cpu);
 int move_irq_to_cpu(irq_t *irq, cpu_t *cpu);
 int balance(lub_list_t *cpus, lub_list_t *balance_irqs,
-	float load_limit, cpumask_t *exclude_cpus);
+	float load_limit, cpumask_t *exclude_cpus, int non_local_cpus);
 int apply_affinity(lub_list_t *balance_irqs);
 int choose_irqs_to_move(lub_list_t *cpus, lub_list_t *balance_irqs,
 	float threshold, birq_choose_strategy_e strategy,

+ 35 - 4
birq.c

@@ -64,6 +64,7 @@ struct options {
 	float load_limit;
 	int verbose;
 	int ht;
+	int non_local_cpus;
 	unsigned int long_interval;
 	unsigned int short_interval;
 	birq_choose_strategy_e strategy;
@@ -236,7 +237,7 @@ int main(int argc, char **argv)
 			interval = opts->short_interval;
 			/* Choose new CPU for IRQs need to be balanced. */
 			balance(cpus, balance_irqs, opts->load_limit,
-				&opts->exclude_cpus);
+				&opts->exclude_cpus, opts->non_local_cpus);
 			/* Write new values to /proc/irq/<IRQ>/smp_affinity */
 			apply_affinity(balance_irqs);
 			/* Free list of balanced IRQs */
@@ -310,7 +311,8 @@ static struct options *opts_init(void)
 	opts->threshold = BIRQ_DEFAULT_THRESHOLD;
 	opts->load_limit = BIRQ_DEFAULT_LOAD_LIMIT;
 	opts->verbose = 0;
-	opts->ht = 0;
+	opts->ht = 1; /* It's 1 since 1.5.0 */
+	opts->non_local_cpus = 0;
 	opts->long_interval = BIRQ_LONG_INTERVAL;
 	opts->short_interval = BIRQ_SHORT_INTERVAL;
 	opts->strategy = BIRQ_CHOOSE_RND;
@@ -334,6 +336,27 @@ static void opts_free(struct options *opts)
 	free(opts);
 }
 
+/* Parse y/n options */
+static int opt_parse_y_n(const char *optarg, int *flag)
+{
+	assert(optarg);
+	assert(flag);
+
+	if (!strcmp(optarg, "y"))
+		*flag = 1;
+	else if (!strcmp(optarg, "yes"))
+		*flag = 1;
+	else if (!strcmp(optarg, "n"))
+		*flag = 0;
+	else if (!strcmp(optarg, "no"))
+		*flag = 0;
+	else {
+		fprintf(stderr, "Error: Illegal flag value %s.\n", optarg);
+		return -1;
+	}
+	return 0;
+}
+
 /* Parse 'strategy' option */
 static int opt_parse_strategy(const char *optarg, birq_choose_strategy_e *strategy)
 {
@@ -450,7 +473,7 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 			opts->verbose = 1;
 			break;
 		case 'r':
-			opts->ht = 1;
+			fprintf(stderr, "Warning: The -r option is obsoleted. The HT is enabled by default.\n");
 			break;
 		case 'O':
 			if (lub_log_facility(optarg, &(opts->log_facility))) {
@@ -520,7 +543,7 @@ static void help(int status, const char *argv0)
 		printf("\t-h, --help Print this help.\n");
 		printf("\t-d, --debug Debug mode. Don't daemonize.\n");
 		printf("\t-v, --verbose Be verbose.\n");
-		printf("\t-r, --ht Enable Hyper Threading.\n");
+		printf("\t-r, --ht This option is obsoleted. The Hyper Threading is enabled by default.\n");
 		printf("\t-p <path>, --pid=<path> File to save daemon's PID to (" BIRQ_PIDFILE ").\n");
 		printf("\t-c <path>, --conf=<path> Config file (" BIRQ_CFGFILE ").\n");
 		printf("\t-x <path>, --pxm=<path> Proximity config file.\n");
@@ -575,6 +598,14 @@ static int parse_config(const char *fname, struct options *opts)
 			goto err;
 		}
 
+	if ((tmp = lub_ini_find(ini, "ht")))
+		if (opt_parse_y_n(tmp, &opts->ht))
+			goto err;
+
+	if ((tmp = lub_ini_find(ini, "non-local-cpus")))
+		if (opt_parse_y_n(tmp, &opts->non_local_cpus))
+			goto err;
+
 	ret = 0;
 err:
 	lub_ini_free(ini);