From 0406d202af914881af1a6caf5247e7ac40564366 Mon Sep 17 00:00:00 2001 From: hejingxian Date: Tue, 17 Sep 2019 23:32:54 +0800 Subject: [PATCH] add new user irq policy config rule When there is many irqs, the old user irq policy script will cost too much time. Therefore, we introduce a new user irq policy config rule which avoid policy script running for every irq. --- Makefile.am | 2 +- classify.c | 32 +++++++-- irqbalance.c | 38 +++++---- irqbalance.h | 2 +- misc/irqbalance.service | 2 +- placement.c | 3 +- procinterrupts.c | 3 +- rules_config.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ rules_config.h | 40 +++++++++++ 9 files changed, 271 insertions(+), 23 deletions(-) create mode 100644 rules_config.c create mode 100644 rules_config.h diff --git a/Makefile.am b/Makefile.am index 62ac482..9276bfb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,7 @@ sbin_PROGRAMS += irqbalance-ui endif irqbalance_SOURCES = activate.c bitmap.c classify.c cputree.c irqbalance.c \ - irqlist.c numa.c placement.c procinterrupts.c + irqlist.c numa.c placement.c procinterrupts.c rules_config.c irqbalance_LDADD = $(LIBCAP_NG_LIBS) $(GLIB2_LIBS) if IRQBALANCEUI irqbalance_ui_SOURCES = $(UI_DIR)/helpers.c $(UI_DIR)/irqbalance-ui.c \ diff --git a/classify.c b/classify.c index 65aeae2..7c97d47 100644 --- a/classify.c +++ b/classify.c @@ -663,7 +663,7 @@ struct irq_info *build_one_dev_entry(const char *dirname, GList *tmp_list) sprintf(path, "%s/%s/msi_irqs", SYSPCI_DIR, dirname); sprintf(devpath, "%s/%s", SYSPCI_DIR, dirname); - + memset(&pol, -1, sizeof(struct user_irq_policy)); /* Needs to be further classified */ hint.class = IRQ_OTHER; @@ -679,7 +679,9 @@ struct irq_info *build_one_dev_entry(const char *dirname, GList *tmp_list) new = get_irq_info(irqnum); if (new) continue; - get_irq_user_policy(devpath, irqnum, &pol); + if (user_policy_list == NULL) { + get_irq_user_policy(devpath, irqnum, &pol); + } if ((pol.ban == 1) || (check_for_irq_ban(devpath, irqnum, tmp_list))) { add_banned_irq(irqnum, &banned_irqs, 0); continue; @@ -714,7 +716,9 @@ struct irq_info *build_one_dev_entry(const char *dirname, GList *tmp_list) new = get_irq_info(irqnum); if (new) goto done; - get_irq_user_policy(devpath, irqnum, &pol); + if (user_policy_list == NULL) { + get_irq_user_policy(devpath, irqnum, &pol); + } if ((pol.ban == 1) || (check_for_irq_ban(path, irqnum, tmp_list))) { add_banned_irq(irqnum, &banned_irqs, 0); goto done; @@ -855,18 +859,24 @@ struct irq_info *add_new_irq(int irq, struct irq_info *hint, GList *proc_interru struct irq_info *new = NULL; struct user_irq_policy pol; + memset(&pol, -1, sizeof(struct user_irq_policy)); new = get_irq_info(irq); if (new) return new; /* Set NULL devpath for the irq has no sysfs entries */ - get_irq_user_policy(NULL, irq, &pol); + if (user_policy_list == NULL) { + get_irq_user_policy(NULL, irq, &pol); + } if ((pol.ban == 1) || check_for_irq_ban(NULL, irq, proc_interrupts)) { /*FIXME*/ add_banned_irq(irq, &banned_irqs, 0); new = get_irq_info(irq); - } else + } else { new = add_one_irq_to_db(NULL, hint, &pol); - + if ((new != NULL) && (user_policy_list != NULL)) { + set_usr_irq_policy(hint->name, new); + } + } if (!new) log(TO_CONSOLE, LOG_WARNING, "add_new_irq: Failed to add irq %d\n", irq); @@ -880,6 +890,16 @@ static void add_missing_irq(struct irq_info *info, void *attr) if (!lookup) add_new_irq(info->irq, info, proc_interrupts); + else { + if (user_policy_list != NULL) { + set_usr_irq_policy(info->name, lookup); + } + } + if (info->name) { + free(info->name); + info->name = NULL; + } + } static void free_tmp_irqs(gpointer data) diff --git a/irqbalance.c b/irqbalance.c index 21d578a..d41753c 100644 --- a/irqbalance.c +++ b/irqbalance.c @@ -99,6 +99,7 @@ struct option lopts[] = { {"banmod", 1 , NULL, 'm'}, {"interval", 1 , NULL, 't'}, {"version", 0, NULL, 'V'}, + {"rulesconfig", 1, NULL, 'r'}, {0, 0, 0, 0} }; @@ -106,7 +107,7 @@ static void usage(void) { log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] [--foreground | -f] [--journal | -j] [--hintpolicy= | -h [exact|subset|ignore]]\n"); log(TO_CONSOLE, LOG_INFO, " [--powerthresh= | -p | ] [--banirq= | -i ] [--banmod= | -m ] [--policyscript= | -l