From 8e84d5ba4aad02509165cb1926091baa3630e418 Mon Sep 17 00:00:00 2001 From: hejingxian Date: Fri, 14 Feb 2020 16:42:01 +0800 Subject: [PATCH] feature: add ability for unblock socket communication This will be used with user interface and also can be used as API for users to create their own scripts on top of. The socket communication can be used for receiving data about IRQs-to-CPUs assignments and setup, as well as setting some options during runtime. Socket address: /var/run/uvp_irqbalance.socket Data to send to socket: settings sleep : set new sleep interval value settings cpus ... : ban listed CPUs from IRQ handling (old values are forgotten, not added to) settings ban irqs ... : ban listed IRQs from balancing (old values are forgotten, not added to) Signed-off-by: Xu Yandong Signed-off-by: He Jingxian --- Makefile.am | 4 +- classify.c | 2 +- cputree.c | 20 ++-- irqbalance.c | 33 +++++-- irqbalance.h | 1 + sockapi.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sockapi.h | 19 ++++ 7 files changed, 359 insertions(+), 17 deletions(-) create mode 100644 sockapi.c create mode 100644 sockapi.h diff --git a/Makefile.am b/Makefile.am index 46e7173..c7be22d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,7 @@ UI_DIR = ui AM_CFLAGS = $(LIBCAP_NG_CFLAGS) $(GLIB2_CFLAGS) AM_CPPFLAGS = -I${top_srcdir} -W -Wall -Wshadow -Wformat -Wundef -D_GNU_SOURCE noinst_HEADERS = bitmap.h constants.h cpumask.h irqbalance.h non-atomic.h \ - types.h $(UI_DIR)/helpers.h $(UI_DIR)/irqbalance-ui.h $(UI_DIR)/ui.h + types.h sockapi.h $(UI_DIR)/helpers.h $(UI_DIR)/irqbalance-ui.h $(UI_DIR)/ui.h sbin_PROGRAMS = irqbalance if IRQBALANCEUI @@ -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 rules_config.c hint_verify.c + irqlist.c numa.c placement.c procinterrupts.c rules_config.c hint_verify.c sockapi.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 91ff022..b0bb3b4 100644 --- a/classify.c +++ b/classify.c @@ -37,7 +37,7 @@ static GList *interrupts_db = NULL; static GList *banned_irqs = NULL; GList *cl_banned_irqs = NULL; static GList *cl_banned_modules = NULL; -static GList *vm_banned_irqs = NULL; +GList *vm_banned_irqs = NULL; extern int need_add_single; #define SYSFS_DIR "/sys" diff --git a/cputree.c b/cputree.c index 741c7c8..5a96e30 100644 --- a/cputree.c +++ b/cputree.c @@ -40,6 +40,8 @@ extern char *banned_cpumask_from_ui; extern char *cpu_ban_string; +extern int use_unblock_socket; +extern int is_set_banned_cpumask_from_ui; GList *cpus; GList *cache_domains; @@ -78,12 +80,18 @@ static void setup_banned_cpus(void) cpus_clear(nohz_full); /* A manually specified cpumask overrides auto-detection. */ - if (cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) { - cpulist_parse(banned_cpumask_from_ui, - strlen(banned_cpumask_from_ui), banned_cpus); - goto out; - } - if (getenv("IRQBALANCE_BANNED_CPUS")) { + if (!use_unblock_socket && cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) { + cpulist_parse(banned_cpumask_from_ui, + strlen(banned_cpumask_from_ui), banned_cpus); + goto out; + } + if (use_unblock_socket && is_set_banned_cpumask_from_ui) { + cpumask_parse_user(banned_cpumask_from_ui, + strlen(banned_cpumask_from_ui), banned_cpus); + goto out; + } + + if (getenv("IRQBALANCE_BANNED_CPUS")) { cpumask_parse_user(getenv("IRQBALANCE_BANNED_CPUS"), strlen(getenv("IRQBALANCE_BANNED_CPUS")), banned_cpus); goto out; } diff --git a/irqbalance.c b/irqbalance.c index dc8307d..1774eda 100644 --- a/irqbalance.c +++ b/irqbalance.c @@ -42,6 +42,7 @@ #include #endif #include "irqbalance.h" +#include "sockapi.h" volatile int keep_going = 1; volatile int ban_pci_assigned_irq = 1; @@ -73,6 +74,7 @@ GMainLoop *main_loop; char *cpu_ban_string = NULL; char *banned_cpumask_from_ui = NULL; +int use_unblock_socket = 1; static void sleep_approx(int seconds) { @@ -109,6 +111,7 @@ struct option lopts[] = { {"notclearhint", 0, NULL, 'n'}, {"migrateval", 1, NULL, 'e'}, {"loadlimit", 1, NULL, 'g'}, + {"blocksocket", 0, NULL, 'k'}, {0, 0, 0, 0} }; @@ -116,8 +119,8 @@ 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