irqbalance/numa.c
nhorman 565db19e3d Enhance irqbalance logic to condier PCI bus topology in IRQ mapping
This patch enhances irqbalance so that, it considers the proximity of devices to
cpus when making irq mapping decisions.  In large numa systems this will cause
irqs to be biased such that they have unique affinity for cpus on the same numa
node as the device triggering them.

Resolves:
http://code.google.com/p/irqbalance/issues/detail?id=17

Thanks to Petr Holasek for authoring the patch




git-svn-id: https://irqbalance.googlecode.com/svn/trunk@34 46b42954-3823-0410-bd82-eb80b452c9b5
2011-08-01 18:25:02 +00:00

113 lines
2.7 KiB
C

/*
* Copyright (C) 2006, Intel Corporation
*
* This file is part of irqbalance
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/*
* This file tries to map numa affinity of pci devices to their interrupts
* In addition the PCI class information is used to refine the classification
* of interrupt sources
*/
#include "config.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include "irqbalance.h"
void pci_numa_scan(void)
{
DIR *dir;
struct dirent *entry;
cpumask_t mask;
char line[PATH_MAX];
FILE *file;
int irq;
int node_num;
unsigned int class;
dir = opendir("/sys/bus/pci/devices");
if (!dir)
return;
do {
int type;
entry = readdir(dir);
if (!entry)
break;
if (strlen(entry->d_name)<3)
continue;
sprintf(line,"/sys/bus/pci/devices/%s/irq", entry->d_name);
file = fopen(line, "r");
if (!file)
continue;
if (fgets(line, PATH_MAX, file)==NULL)
line[0]=0;
fclose(file);
irq = strtoul(line, NULL, 10);
if (!irq)
continue;
sprintf(line,"/sys/bus/pci/devices/%s/class", entry->d_name);
file = fopen(line, "r");
if (!file)
continue;
if (fgets(line, PATH_MAX, file)==NULL)
line[0]=0;
fclose(file);
class = strtoul(line, NULL, 16);
sprintf(line,"/sys/bus/pci/devices/%s/local_cpus", entry->d_name);
file = fopen(line, "r");
if (!file)
continue;
if (fgets(line, PATH_MAX, file)==NULL)
line[0]=0;
fclose(file);
cpumask_parse_user(line, strlen(line), mask);
/* Add numa_node file support */
sprintf(line,"/sys/bus/pci/devices/%s/numa_node", entry->d_name);
file = fopen(line, "r");
if (!file)
continue;
if (fgets(line, PATH_MAX, file)==NULL)
line[0]=0;
node_num = strtol(line, NULL, 10);
type = IRQ_OTHER;
if ((class>>16) == 0x01)
type = IRQ_SCSI;
/*
* Ethernet gets the type via /proc/net/dev; in addition down'd interfaces
* shouldn't boost interrupts
if ((class>>16) == 0x02)
type = IRQ_ETH;
*/
if ((class>>16) >= 0x03 && (class>>16) <= 0x0C)
type = IRQ_LEGACY;
add_interrupt_numa(irq, mask, node_num, type);
} while (entry);
closedir(dir);
}