Add banscript option

Its been requested in several different ways, that irqbalance have a more robust
mechanism for setting balancing policy at run time.  While I don't feel its
apropriate to have irqbalance be able to implement arbitrary balance policy
(having a flexible mechanism to define which irqs should be placed where can
become exceedingly complex), I do think we need some mechanism that easily
allows users to dynamically exclude irqs from the irqbalance policy at run time.
The banscript option does exactly this.  It allows the user to point irqbalance
toward an exacutable file that is run one for each irq deiscovered passing the
sysfs path of the device and an irq vector as arguments.  A zero exit code tells
irqbalance to manage the irq as it normally would, while a non-zero exit tells
irqbalance to ignore the interrupt entirely.  This provides adminstrators a code
point with which to exclude irqs dynamically based on any programatic
informatino available, and to manage those irqs independently, etither via
another irqbalance like program, or via static affinity setting.

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

Reesolves: http://code.google.com/p/irqbalance/issues/detail?id=33
This commit is contained in:
Neil Horman 2012-07-05 14:54:35 -04:00
parent 1523a7830c
commit 65169e022c
4 changed files with 64 additions and 0 deletions

View file

@ -207,6 +207,43 @@ out:
return new;
}
static int check_for_irq_ban(char *path, int irq)
{
char *cmd;
int rc;
if (!banscript)
return 0;
cmd = alloca(strlen(path)+strlen(banscript)+32);
if (!cmd)
return 0;
sprintf(cmd, "%s %s %d",banscript, path, irq);
rc = system(cmd);
/*
* The system command itself failed
*/
if (rc == -1) {
if (debug_mode)
printf("%s failed, please check the --banscript option\n", cmd);
else
syslog(LOG_INFO, "%s failed, please check the --banscript option\n", cmd);
return 0;
}
if (WEXITSTATUS(rc)) {
if (debug_mode)
printf("irq %d is baned by %s\n", irq, banscript);
else
syslog(LOG_INFO, "irq %d is baned by %s\n", irq, banscript);
return 1;
}
return 0;
}
/*
* Figures out which interrupt(s) relate to the device we're looking at in dirname
*/
@ -231,6 +268,10 @@ static void build_one_dev_entry(const char *dirname)
irqnum = strtol(entry->d_name, NULL, 10);
if (irqnum) {
sprintf(path, "%s/%s", SYSDEV_DIR, dirname);
if (check_for_irq_ban(path, irqnum)) {
add_banned_irq(irqnum);
continue;
}
new = add_one_irq_to_db(path, irqnum);
if (!new)
continue;
@ -253,6 +294,11 @@ static void build_one_dev_entry(const char *dirname)
*/
if (irqnum) {
sprintf(path, "%s/%s", SYSDEV_DIR, dirname);
if (check_for_irq_ban(path, irqnum)) {
add_banned_irq(irqnum);
goto done;
}
new = add_one_irq_to_db(path, irqnum);
if (!new)
goto done;

View file

@ -73,6 +73,17 @@ Add the specified irq list to the set of banned irqs. irqbalance will not affect
the affinity of any irqs on the banned list, allowing them to be specified
manually. This option is addative and can be specified multiple times
.TP
.B --banscript=<script>
Execute the specified script for each irq that is discovered, passing the sysfs
path to the associated device as the first argument, and the irq vector as the
second. An exit value of 0 tells irqbalance that this interrupt should balanced
and managed as a normal irq, while a non-zero exit code indicates this irq
should be ignored by irqbalance completely (see --banirq above). Use of this
script provides users the ability to dynamically select which irqs get exluded
from balancing, and provides an opportunity for manual affinity setting in one
single code point.
.TP
.B --pid=<file>
Have irqbalance write its process id to the specified file. By default no

View file

@ -52,6 +52,7 @@ enum hp_e hint_policy = HINT_POLICY_SUBSET;
unsigned long power_thresh = ULONG_MAX;
unsigned long long cycle_count = 0;
char *pidfile = NULL;
char *banscript = NULL;
void sleep_approx(int seconds)
{
@ -75,6 +76,7 @@ struct option lopts[] = {
{"hintpolicy", 1, NULL, 'h'},
{"powerthresh", 1, NULL, 'p'},
{"banirq", 1 , NULL, 'i'},
{"banscript", 1, NULL, 'b'},
{"pid", 1, NULL, 's'},
{0, 0, 0, 0}
};
@ -99,6 +101,10 @@ static void parse_command_line(int argc, char **argv)
case '?':
usage();
exit(1);
break;
case 'b':
banscript = strdup(optarg);
break;
case 'd':
debug_mode=1;
foreground_mode=1;

View file

@ -68,6 +68,7 @@ extern int need_rescan;
extern enum hp_e hint_policy;
extern unsigned long long cycle_count;
extern unsigned long power_thresh;
extern char *banscript;
/*
* Numa node access routines