From e44eed4faef6ee1bd1ae41dd27a8513d37681f7f Mon Sep 17 00:00:00 2001 From: liuchao Date: Tue, 17 Dec 2019 02:54:57 +0000 Subject: [PATCH] add switch to clear affinity hint All irqs' affinity hints are cleared in update_affinity_hint and forced to rebalance. In some scenarios, it will affect performance. --- hint_verify.c | 26 +++++++++++++++++++++++++- irqbalance.c | 10 ++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hint_verify.c b/hint_verify.c index 0718078..11ef868 100644 --- a/hint_verify.c +++ b/hint_verify.c @@ -16,6 +16,7 @@ extern int keep_going; extern GMainLoop *main_loop; extern gboolean scan(); extern int last_interval; +extern int clear_affinity_hint; int real_sleep_interval; int sleep_interval_count; @@ -57,7 +58,8 @@ void update_affinity_hint(struct irq_info *info, void *data __attribute__((unuse if (!hint_enabled) return; - cpus_clear(info->affinity_hint); + if (clear_affinity_hint) + cpus_clear(info->affinity_hint); sprintf(path, "/proc/irq/%d/affinity_hint", info->irq); file = fopen(path, "r"); if (!file) @@ -80,6 +82,27 @@ void update_affinity_hint(struct irq_info *info, void *data __attribute__((unuse free(line); } +static void check_clear() +{ + char *line = NULL; + size_t size = 0; + FILE *file; + + file = fopen("/etc/sysconfig/irqbalance_clear", "r"); + if (!file) + return; + if (getline(&line, &size, file) <= 0) + goto out; + if (line != NULL && strstr(line, "0") != NULL) + clear_affinity_hint = 0; + else + clear_affinity_hint = 1; + +out: + fclose(file); + free(line); +} + /* * This function is the main loop of irqbalance, which include: * 1. scan opration for irq balancing; @@ -104,6 +127,7 @@ gboolean poll_hint_affinity_and_scan(gpointer data __attribute__((unused))) sleep_count++; if (need_verify_flag && hint_changed()) { + check_clear(); for_each_irq(NULL, update_affinity_hint, NULL); if (hint_has_changed) { hint_has_changed = FALSE; diff --git a/irqbalance.c b/irqbalance.c index 05eaa29..77076fa 100644 --- a/irqbalance.c +++ b/irqbalance.c @@ -55,6 +55,7 @@ int foreground_mode; int numa_avail; int journal_logging = 0; int need_rescan; +int clear_affinity_hint = 1; unsigned int log_mask = TO_ALL; const char *log_indent; unsigned long power_thresh = ULONG_MAX; @@ -104,15 +105,16 @@ struct option lopts[] = { {"loadlimit", 1, NULL, 'g'}, {"rulesconfig", 1, NULL, 'r'}, {"verifyhint", 1, NULL, 'v'}, + {"notclearhint", 0, NULL, 'n'}, {0, 0, 0, 0} }; static void usage(void) { log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] [--foreground | -f] [--journal | -j] [--hintpolicy | -h ]\n"); log(TO_CONSOLE, LOG_INFO, " [--powerthresh= | -p | ] [--banirq= | -i ] [--banmod= | -m ] [--policyscript= | -l