Fix affinity_hint code.

Theres a problem with the affintiy_hint code.  Specifically it fails to
determine when an affinity_hint file is all f's (affinity_hint == all cpus).  As
such, irqbalance is currently allowing all cpus to handle all irqs, which is the
antithesis of its function.  It also makes use of cpus_full, which is poorly
formed, as it assumes that the affinity_hint mask is always NR_CPUS in length,
and each bit is set (even for those cpus not actually present in the system).
This patch corrects both of those problems, by only checking all the present
cpus in the system in the mask, and detecting when that mask is all f's. 

Signed-off-by: Neil Horman  <nhorman@tuxdriver.com>




git-svn-id: https://irqbalance.googlecode.com/svn/trunk@30 46b42954-3823-0410-bd82-eb80b452c9b5
This commit is contained in:
nhorman 2010-08-10 13:32:58 +00:00
parent a2071483d9
commit 3c7fe6d3cc
4 changed files with 21 additions and 2 deletions

View File

@ -74,6 +74,19 @@ int __bitmap_full(const unsigned long *bitmap, int bits)
return 1;
}
int __bitmap_weight(const unsigned long *bitmap, int bits)
{
int k, w = 0, lim = bits/BITS_PER_LONG;
for (k = 0; k < lim; k++)
w += hweight_long(bitmap[k]);
if (bits % BITS_PER_LONG)
w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
return w;
}
int __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, int bits)
{

View File

@ -47,6 +47,7 @@ int core_count;
/* Users want to be able to keep interrupts away from some cpus; store these in a cpumask_t */
cpumask_t banned_cpus;
cpumask_t cpu_possible_map;
/*
it's convenient to have the complement of banned_cpus available so that
@ -158,6 +159,8 @@ static void do_one_cpu(char *path)
memset(cpu, 0, sizeof(struct cpu_core));
cpu->number = strtoul(&path[27], NULL, 10);
cpu_set(cpu->number, cpu_possible_map);
cpu_set(cpu->number, cpu->mask);

View File

@ -39,6 +39,7 @@ GList *interrupts;
void get_affinity_hint(struct interrupt *irq, int number)
{
char buf[PATH_MAX];
cpumask_t tempmask;
char *line = NULL;
size_t size = 0;
FILE *file;
@ -51,7 +52,9 @@ void get_affinity_hint(struct interrupt *irq, int number)
fclose(file);
return;
}
cpumask_parse_user(line, strlen(line), irq->node_mask);
cpumask_parse_user(line, strlen(line), tempmask);
if (!__cpus_full(&tempmask, num_possible_cpus()))
irq->node_mask = tempmask;
fclose(file);
free(line);
}

View File

@ -272,7 +272,7 @@ static void place_affinity_hint(GList *list)
}
if ((!cpus_empty(irq->node_mask)) &&
(!cpus_equal(irq->mask, irq->node_mask)) &&
(!cpus_full(irq->node_mask))) {
(!__cpus_full(&irq->node_mask, num_possible_cpus()))) {
irq->old_mask = irq->mask;
irq->mask = irq->node_mask;
}