From 544bc8443de1adfeae136e20c548ed0f91b6181f Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Thu, 5 Jul 2012 15:11:15 -0400 Subject: [PATCH] Detect manually changed affinities of non-excluded interrupts If an administrator manually changes the affinity of an irq, irqbalance doesn't detect that, which can lead to erroneous load calculations when rebalancing. Since the irq that was changed wasn't explicitly excluded, restore the affinity that irqbalance has recorded for it, so we stay in sync. Signed-off-by: Shaohua Li Signed-off-by: Neil Horman Resolves: http://code.google.com/p/irqbalance/issues/detail?id=34 --- activate.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/activate.c b/activate.c index 8734c5c..9e983df 100644 --- a/activate.c +++ b/activate.c @@ -32,34 +32,60 @@ #include "irqbalance.h" +static int check_affinity(struct irq_info *info, cpumask_t applied_mask) +{ + cpumask_t current_mask; + char buf[PATH_MAX]; + char *line = NULL; + size_t size = 0; + FILE *file; + + sprintf(buf, "/proc/irq/%i/smp_affinity", info->irq); + file = fopen(buf, "r"); + if (!file) + return 1; + if (getline(&line, &size, file)==0) { + free(line); + fclose(file); + return 1; + } + cpumask_parse_user(line, strlen(line), current_mask); + fclose(file); + free(line); + + return cpus_equal(applied_mask, current_mask); +} static void activate_mapping(struct irq_info *info, void *data __attribute__((unused))) { char buf[PATH_MAX]; FILE *file; cpumask_t applied_mask; + int valid_mask = 0; + + if ((hint_policy == HINT_POLICY_EXACT) && + (!cpus_empty(info->affinity_hint))) { + applied_mask = info->affinity_hint; + valid_mask = 1; + } else if (info->assigned_obj) { + applied_mask = info->assigned_obj->mask; + valid_mask = 1; + } /* * only activate mappings for irqs that have moved */ - if (!info->moved) + if (!info->moved && (!valid_mask || check_affinity(info, applied_mask))) return; if (!info->assigned_obj) return; - sprintf(buf, "/proc/irq/%i/smp_affinity", info->irq); file = fopen(buf, "w"); if (!file) return; - if ((hint_policy == HINT_POLICY_EXACT) && - (!cpus_empty(info->affinity_hint))) - applied_mask = info->affinity_hint; - else - applied_mask = info->assigned_obj->mask; - cpumask_scnprintf(buf, PATH_MAX, applied_mask); fprintf(file, "%s", buf); fclose(file);