synchronize patches
This commit is contained in:
parent
4b5fc530d1
commit
b80d2a2702
@ -48,6 +48,18 @@ index 0946603..364ca72 100644
|
||||
close(sock);
|
||||
}
|
||||
|
||||
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
||||
index 5a76ddf..005eea4 100644
|
||||
--- a/ui/irqbalance-ui.c
|
||||
+++ b/ui/irqbalance-ui.c
|
||||
@@ -66,6 +66,7 @@ int init_connection()
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
addr.sun_family = AF_UNIX;
|
||||
if (connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
+ close(socket_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
|
||||
57
Fix-irqbalance-ui-failing-to-connect-to-irqbalance-d.patch
Normal file
57
Fix-irqbalance-ui-failing-to-connect-to-irqbalance-d.patch
Normal file
@ -0,0 +1,57 @@
|
||||
From ce806df0081cf09344197285e32bd2113d86f554 Mon Sep 17 00:00:00 2001
|
||||
From: Kairui Song <kasong@redhat.com>
|
||||
Date: Mon, 3 Sep 2018 00:30:14 +0800
|
||||
Subject: [PATCH 23/58] Fix irqbalance ui failing to connect to irqbalance
|
||||
daemon
|
||||
|
||||
irqbalance ui is faling due to the changes in commit 19c25dd.
|
||||
This patch align irqbalance-ui's socket connecting routine with
|
||||
irqbalance.c
|
||||
---
|
||||
ui/irqbalance-ui.c | 16 +++++++++++-----
|
||||
ui/irqbalance-ui.h | 1 +
|
||||
2 files changed, 12 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
||||
index 47dd5dc..5a76ddf 100644
|
||||
--- a/ui/irqbalance-ui.c
|
||||
+++ b/ui/irqbalance-ui.c
|
||||
@@ -57,12 +57,18 @@ int init_connection()
|
||||
}
|
||||
addr.sun_family = AF_UNIX;
|
||||
char socket_name[64];
|
||||
- snprintf(socket_name, 64, "%s%d.sock", SOCKET_PATH, irqbalance_pid);
|
||||
- strncpy(addr.sun_path, socket_name, strlen(addr.sun_path));
|
||||
|
||||
- if(connect(socket_fd, (struct sockaddr *)&addr,
|
||||
- sizeof(sa_family_t) + strlen(socket_name) + 1) < 0) {
|
||||
- return 0;
|
||||
+ snprintf(socket_name, 64, "%s/%s%d.sock", SOCKET_TMPFS, SOCKET_PATH, irqbalance_pid);
|
||||
+ strncpy(addr.sun_path, socket_name, strlen(socket_name));
|
||||
+
|
||||
+ if(connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
+ /* Try connect to abstract */
|
||||
+ memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
+ addr.sun_family = AF_UNIX;
|
||||
+ if (connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
return socket_fd;
|
||||
diff --git a/ui/irqbalance-ui.h b/ui/irqbalance-ui.h
|
||||
index f97fcb1..b32d58a 100644
|
||||
--- a/ui/irqbalance-ui.h
|
||||
+++ b/ui/irqbalance-ui.h
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <glib-unix.h>
|
||||
|
||||
#define SOCKET_PATH "irqbalance"
|
||||
+#define SOCKET_TMPFS "/var/run"
|
||||
|
||||
#define STATS "stats"
|
||||
#define SET_SLEEP "settings sleep "
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -32,6 +32,23 @@ index 60d8a5e..c1a0e15 100644
|
||||
if (bind(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the file-based socket.\n");
|
||||
|
||||
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
||||
index 005eea4..1119665 100644
|
||||
--- a/ui/irqbalance-ui.c
|
||||
+++ b/ui/irqbalance-ui.c
|
||||
@@ -56,10 +56,9 @@ int init_connection()
|
||||
return 0;
|
||||
}
|
||||
addr.sun_family = AF_UNIX;
|
||||
- char socket_name[64];
|
||||
|
||||
- snprintf(socket_name, 64, "%s/%s%d.sock", SOCKET_TMPFS, SOCKET_PATH, irqbalance_pid);
|
||||
- strncpy(addr.sun_path, socket_name, strlen(socket_name));
|
||||
+ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s%d.sock", SOCKET_TMPFS,
|
||||
+ SOCKET_PATH, irqbalance_pid);
|
||||
|
||||
if(connect(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
/* Try connect to abstract */
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
|
||||
@ -14,20 +14,6 @@ diff --git a/classify.c b/classify.c
|
||||
index 9f72ae8..585f2dc 100644
|
||||
--- a/classify.c
|
||||
+++ b/classify.c
|
||||
@@ -331,6 +331,13 @@ static int is_banned_irq(int irq)
|
||||
return entry ? 1:0;
|
||||
}
|
||||
|
||||
+#ifdef TEST
|
||||
+int stub_is_banned_irq(int irq)
|
||||
+{
|
||||
+ return is_banned_irq(irq);
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
gint substr_find(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
if (strstr(b, a))
|
||||
@@ -853,6 +860,9 @@ static void remove_no_existing_irq(struct irq_info *info, void *data __attribute
|
||||
void clear_no_existing_irqs(void)
|
||||
{
|
||||
|
||||
@ -17,11 +17,11 @@ index 3681c48..54f27f0 100644
|
||||
@@ -38,6 +38,7 @@ static GList *banned_irqs = NULL;
|
||||
GList *cl_banned_irqs = NULL;
|
||||
static GList *cl_banned_modules = NULL;
|
||||
GList *vm_banned_irqs = NULL;
|
||||
static GList *vm_banned_irqs = NULL;
|
||||
+extern int need_add_single;
|
||||
|
||||
pthread_mutex_t cl_banned_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t vm_banned_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define SYSFS_DIR "/sys"
|
||||
#define SYSPCI_DIR "/sys/bus/pci/devices"
|
||||
@@ -646,6 +647,21 @@ static int check_for_irq_ban(char *path __attribute__((unused)), int irq, GList
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ index 18cd7de..467e968 100644
|
||||
+ goto error_close_unlink;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ close(lf);
|
||||
+ return 0;
|
||||
+
|
||||
+error_close_unlink:
|
||||
|
||||
27
bugfix-prevent-version-cmd-need-an-argument.patch
Normal file
27
bugfix-prevent-version-cmd-need-an-argument.patch
Normal file
@ -0,0 +1,27 @@
|
||||
From cea147fc56b018266ac3235b82cdaf7d0ba74628 Mon Sep 17 00:00:00 2001
|
||||
From: hejingxian <hejingxian@huawei.com>
|
||||
Date: Fri, 10 Jan 2020 15:36:57 +0800
|
||||
Subject: [PATCH] prevent version cmd need an argument
|
||||
|
||||
In order to prevent the version cmd need an argument,
|
||||
the option 'V' can't be followed by ':'.
|
||||
---
|
||||
irqbalance.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index 15fb0fe..f182b3c 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -133,7 +133,7 @@ static void parse_command_line(int argc, char **argv)
|
||||
unsigned long val;
|
||||
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
- "odfji:p:s:c:b:l:m:t:V:h:v:r:ne:g:",
|
||||
+ "odfjVni:p:s:c:b:l:m:t:h:v:r:e:g:",
|
||||
lopts, &longind)) != -1) {
|
||||
|
||||
switch(opt) {
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -0,0 +1,121 @@
|
||||
From 84a2df1c9962a87f55e1c0d3bd2118fd754a4b48 Mon Sep 17 00:00:00 2001
|
||||
From: hejingxian <hejingxian@huawei.com>
|
||||
Date: Fri, 3 Jan 2020 16:43:28 +0800
|
||||
Subject: [PATCH] add new irq migrate rule to avoid high cpu irq load
|
||||
|
||||
By the old irq migrate rule, the irqs cannot be moved if the adjustment_load will become smaller then
|
||||
the min_load after moving irq. However, we can accept that the delta load become smaller after moving irq.
|
||||
---
|
||||
irqbalance.c | 14 ++++++++++++--
|
||||
irqbalance.h | 3 ++-
|
||||
irqlist.c | 15 ++++++++++++++-
|
||||
3 files changed, 28 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index 1ca401e..15fb0fe 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -69,6 +69,8 @@ int sleep_interval = SLEEP_INTERVAL;
|
||||
int last_interval;
|
||||
int hint_enabled = 0;
|
||||
int poll_hint_interval = SLEEP_INTERVAL / 5;
|
||||
+unsigned long migrate_val = 0;
|
||||
+unsigned long load_limit = 0;
|
||||
GMainLoop *main_loop;
|
||||
|
||||
char *cpu_ban_string = NULL;
|
||||
@@ -106,6 +108,8 @@ struct option lopts[] = {
|
||||
{"verifyhint", 1, NULL, 'v'},
|
||||
{"rulesconfig", 1, NULL, 'r'},
|
||||
{"notclearhint", 0, NULL, 'n'},
|
||||
+ {"migrateval", 1, NULL, 'e'},
|
||||
+ {"loadlimit", 1, NULL, 'g'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -114,7 +118,7 @@ static void usage(void)
|
||||
log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] [--foreground | -f] [--journal | -j] [--hintpolicy | -h <subset>]\n");
|
||||
log(TO_CONSOLE, LOG_INFO, " [--powerthresh= | -p <off> | <n>] [--banirq= | -i <n>] [--banmod= | -m <module>] [--policyscript= | -l <script>]\n");
|
||||
log(TO_CONSOLE, LOG_INFO, " [--pid= | -s <file>] [--deepestcache= | -c <n>] [--interval= | -t <n>] [--verifyhint= | -v n]\n");
|
||||
- log(TO_CONSOLE, LOG_INFO, " [--rulesconfig= | -r <config>] [--notclearhint | -n]\n");
|
||||
+ log(TO_CONSOLE, LOG_INFO, " [--rulesconfig= | -r <config>] [--notclearhint | -n] [--migrateval= | -e <n>] [--loadlimit= | -g <n>]\n");
|
||||
}
|
||||
|
||||
static void version(void)
|
||||
@@ -129,7 +133,7 @@ static void parse_command_line(int argc, char **argv)
|
||||
unsigned long val;
|
||||
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
- "odfji:p:s:c:b:l:m:t:V:h:v:r:n",
|
||||
+ "odfji:p:s:c:b:l:m:t:V:h:v:r:ne:g:",
|
||||
lopts, &longind)) != -1) {
|
||||
|
||||
switch(opt) {
|
||||
@@ -231,6 +235,12 @@ static void parse_command_line(int argc, char **argv)
|
||||
case 'n':
|
||||
clear_affinity_hint = 0;
|
||||
break;
|
||||
+ case 'e':
|
||||
+ migrate_val = strtoul(optarg, NULL, 10);
|
||||
+ break;
|
||||
+ case 'g':
|
||||
+ load_limit = strtoul(optarg, NULL, 10);
|
||||
+ break;
|
||||
|
||||
}
|
||||
}
|
||||
diff --git a/irqbalance.h b/irqbalance.h
|
||||
index 72e141b..d4f6e7a 100644
|
||||
--- a/irqbalance.h
|
||||
+++ b/irqbalance.h
|
||||
@@ -124,7 +124,8 @@ extern struct irq_info *add_new_irq(int irq, struct irq_info *hint, GList *proc_
|
||||
extern void clear_no_existing_irqs(void);
|
||||
extern int hint_enabled, poll_hint_interval;
|
||||
extern int sleep_interval;
|
||||
-
|
||||
+extern unsigned long migrate_val;
|
||||
+extern unsigned long load_limit;
|
||||
/*
|
||||
* Generic object functions
|
||||
*/
|
||||
diff --git a/irqlist.c b/irqlist.c
|
||||
index 95ccc7a..3c38b18 100644
|
||||
--- a/irqlist.c
|
||||
+++ b/irqlist.c
|
||||
@@ -76,6 +76,7 @@ static void compute_deviations(struct topo_obj *obj, void *data)
|
||||
static void move_candidate_irqs(struct irq_info *info, void *data)
|
||||
{
|
||||
struct load_balance_info *lb_info = data;
|
||||
+ unsigned long delta_load = 0;
|
||||
|
||||
/* Don't rebalance irqs that don't want it */
|
||||
if (info->level == BALANCE_NONE)
|
||||
@@ -91,12 +92,24 @@ static void move_candidate_irqs(struct irq_info *info, void *data)
|
||||
if (info->load <= 1)
|
||||
return;
|
||||
|
||||
+ if (migrate_val > 0) {
|
||||
+ delta_load = (lb_info->adjustment_load - lb_info->min_load) / migrate_val;
|
||||
+ }
|
||||
+
|
||||
/* If we can migrate an irq without swapping the imbalance do it. */
|
||||
if ((lb_info->adjustment_load - info->load) > (lb_info->min_load + info->load)) {
|
||||
lb_info->adjustment_load -= info->load;
|
||||
lb_info->min_load += info->load;
|
||||
- } else
|
||||
+ } else if (delta_load && load_limit && (lb_info->adjustment_load > load_limit) &&
|
||||
+ (lb_info->min_load + info->load) - (lb_info->adjustment_load - info->load) < delta_load) {
|
||||
+ lb_info->adjustment_load -= info->load;
|
||||
+ lb_info->min_load += info->load;
|
||||
+ if (lb_info->min_load > lb_info->adjustment_load) {
|
||||
+ lb_info->min_load = lb_info->adjustment_load;
|
||||
+ }
|
||||
+ } else {
|
||||
return;
|
||||
+ }
|
||||
|
||||
log(TO_CONSOLE, LOG_INFO, "Selecting irq %d for rebalancing\n", info->irq);
|
||||
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -9,14 +9,14 @@ for every irq.
|
||||
---
|
||||
Makefile.am | 2 +-
|
||||
classify.c | 32 +++++++--
|
||||
irqbalance.c | 34 +++++----
|
||||
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, 267 insertions(+), 23 deletions(-)
|
||||
9 files changed, 271 insertions(+), 23 deletions(-)
|
||||
create mode 100644 rules_config.c
|
||||
create mode 100644 rules_config.h
|
||||
|
||||
@ -28,9 +28,9 @@ index 62ac482..9276bfb 100644
|
||||
endif
|
||||
|
||||
irqbalance_SOURCES = activate.c bitmap.c classify.c cputree.c irqbalance.c \
|
||||
- irqlist.c numa.c placement.c procinterrupts.c sockapi.c
|
||||
+ irqlist.c numa.c placement.c procinterrupts.c sockapi.c rules_config.c
|
||||
irqbalance_LDADD = $(LIBCAP_NG_LIBS) $(GLIB2_LIBS) -lpthread
|
||||
- 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
|
||||
@ -153,7 +153,7 @@ index 21d578a..d41753c 100644
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -539,6 +543,21 @@ int main(int argc, char** argv)
|
||||
@@ -539,6 +543,25 @@ int main(int argc, char** argv)
|
||||
log(TO_ALL, LOG_WARNING, "Unable to determin HZ defaulting to 100\n");
|
||||
HZ = 100;
|
||||
}
|
||||
@ -171,6 +171,10 @@ index 21d578a..d41753c 100644
|
||||
+
|
||||
+ if (read_user_policy_config() != 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Read user policy config fail.\n");
|
||||
+ }
|
||||
+ if (rules_config_file) {
|
||||
+ free(rules_config_file);
|
||||
+ rules_config_file = NULL;
|
||||
+ }
|
||||
|
||||
build_object_tree();
|
||||
@ -193,13 +197,13 @@ index 21d578a..d41753c 100644
|
||||
g_unix_signal_add(SIGTERM, handler, NULL);
|
||||
g_unix_signal_add(SIGUSR1, handler, NULL);
|
||||
@@ -589,6 +598,7 @@ int main(int argc, char** argv)
|
||||
ret = EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
+ log(TO_ALL, LOG_INFO, "irqbalance start scan.\n");
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
int *last_interval = &sleep_interval;
|
||||
g_timeout_add_seconds(sleep_interval, scan, last_interval);
|
||||
last_interval = sleep_interval;
|
||||
g_timeout_add_seconds(sleep_interval, scan, NULL);
|
||||
diff --git a/irqbalance.h b/irqbalance.h
|
||||
index 120bc9b..42f95cb 100644
|
||||
--- a/irqbalance.h
|
||||
@ -249,7 +253,7 @@ index 60b2545..18b3ceb 100644
|
||||
#endif
|
||||
}
|
||||
- info->name = strdupa(irq_mod);
|
||||
+
|
||||
+
|
||||
+ info->name = strdup(irq_mod);
|
||||
}
|
||||
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
From 6f90062816b218809dc5d1e06ac7e0f7198368d6 Mon Sep 17 00:00:00 2001
|
||||
From: hejingxian <hejingxian@huawei.com>
|
||||
Date: Sun, 10 Nov 2019 17:24:43 +0800
|
||||
Subject: [PATCH] Add test interfaces for irqbalance core functions
|
||||
|
||||
There exists some core functions which can't be called by llt. Therefore,
|
||||
we add external functions for user calling the core functions.
|
||||
---
|
||||
classify.c | 7 +++++++
|
||||
procinterrupts.c | 34 ++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 41 insertions(+)
|
||||
|
||||
diff --git a/classify.c b/classify.c
|
||||
index 3921710..5aed9e5 100644
|
||||
--- a/classify.c
|
||||
+++ b/classify.c
|
||||
@@ -1068,3 +1068,10 @@ int is_pci_assigned_irq(const char *line)
|
||||
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
+#ifdef TEST
|
||||
+void get_irq_user_policy_test(char *path, int irq, struct user_irq_policy *pol)
|
||||
+{
|
||||
+ get_irq_user_policy(path, irq, pol);
|
||||
+}
|
||||
+#endif
|
||||
diff --git a/procinterrupts.c b/procinterrupts.c
|
||||
index 59df6d7..cd99f35 100644
|
||||
--- a/procinterrupts.c
|
||||
+++ b/procinterrupts.c
|
||||
@@ -148,6 +148,18 @@ static void guess_arm_irq_hints(char *name, struct irq_info *info)
|
||||
|
||||
}
|
||||
|
||||
+#ifdef TEST
|
||||
+void guess_arm_irq_hints_test(char *name, struct irq_info *info)
|
||||
+{
|
||||
+ guess_arm_irq_hints(name, info);
|
||||
+}
|
||||
+
|
||||
+int check_platform_device_test(char *name, struct irq_info *info)
|
||||
+{
|
||||
+ return check_platform_device(name, info);
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
/*
|
||||
* This check is only invoked at service startup, and avoid any impact on the system,
|
||||
* The scheme just only reads the irq's aff, and write it back. According to the result
|
||||
@@ -674,3 +686,25 @@ void parse_proc_stat(void)
|
||||
for_each_object(numa_nodes, compute_irq_branch_load_share, NULL);
|
||||
|
||||
}
|
||||
+
|
||||
+#ifdef TEST
|
||||
+void init_irq_class_and_type_test(char *savedline, struct irq_info *info, int irq)
|
||||
+{
|
||||
+ init_irq_class_and_type(savedline, info, irq);
|
||||
+}
|
||||
+
|
||||
+void set_load_test(struct topo_obj *d, void *data __attribute__((unused)))
|
||||
+{
|
||||
+ set_load(d, data);
|
||||
+}
|
||||
+
|
||||
+void compute_irq_branch_load_share_test(struct topo_obj *d, void *data __attribute__((unused)))
|
||||
+{
|
||||
+ compute_irq_branch_load_share(d, data);
|
||||
+}
|
||||
+
|
||||
+void accumulate_interrupts_test(struct topo_obj *d, void *data __attribute__((unused)))
|
||||
+{
|
||||
+ accumulate_interrupts(d, data);
|
||||
+}
|
||||
+#endif
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -97,7 +97,7 @@ index d41753c..7d8d15c 100644
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
gboolean scan(gpointer data)
|
||||
gboolean scan(gpointer data __attribute__((unused)))
|
||||
{
|
||||
log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n");
|
||||
@@ -305,7 +328,7 @@ gboolean scan(gpointer data)
|
||||
|
||||
43
feature-enable-irqbalance-to-link-with-multiple-clie.patch
Normal file
43
feature-enable-irqbalance-to-link-with-multiple-clie.patch
Normal file
@ -0,0 +1,43 @@
|
||||
From 2fdfbc218be09a6335df8dde15498f75fa12bc0a Mon Sep 17 00:00:00 2001
|
||||
From: liuchao <liuchao173@huawei.com>
|
||||
Date: Thu, 6 Feb 2020 06:44:51 +0000
|
||||
Subject: [PATCH] feature: enable irqbalance to link with multiple clients at
|
||||
the same time
|
||||
|
||||
Type:bugfix/CVE/requirement/cleancode/testcode
|
||||
CVE:
|
||||
DTS/AR:
|
||||
reason:
|
||||
---
|
||||
irqbalance.c | 2 +-
|
||||
irqbalance.h | 2 ++
|
||||
2 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index 1af23c6..dc8307d 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -622,7 +622,7 @@ int init_socket()
|
||||
log(TO_ALL, LOG_WARNING, "Unable to set socket options.\n");
|
||||
return 1;
|
||||
}
|
||||
- listen(socket_fd, 1);
|
||||
+ listen(socket_fd, MAX_CLIENT_NUM);
|
||||
g_unix_fd_add(socket_fd, G_IO_IN, sock_handle, NULL);
|
||||
return 0;
|
||||
}
|
||||
diff --git a/irqbalance.h b/irqbalance.h
|
||||
index 61b39dd..2d59d31 100644
|
||||
--- a/irqbalance.h
|
||||
+++ b/irqbalance.h
|
||||
@@ -177,5 +177,7 @@ extern unsigned int log_mask;
|
||||
#define SOCKET_PATH "irqbalance"
|
||||
#define SOCKET_TMPFS "/var/run"
|
||||
#define SOCKET_RECV_BUF_LEN 4096
|
||||
+#define MAX_CLIENT_NUM 32
|
||||
+
|
||||
#endif /* __INCLUDE_GUARD_IRQBALANCE_H_ */
|
||||
|
||||
--
|
||||
2.19.1
|
||||
|
||||
@ -0,0 +1,678 @@
|
||||
From 5390ed72086f1d9ffce2b4ca367daf2cbda4d358 Mon Sep 17 00:00:00 2001
|
||||
From: hejingxian <hejingxian@huawei.com>
|
||||
Date: Tue, 18 Feb 2020 14:49:31 +0800
|
||||
Subject: [PATCH] encapsulate and compile the functions in irqbalance-ui
|
||||
into a shared library
|
||||
|
||||
users can send settings msg to irqbalance or get information from irqbalance
|
||||
by calling external functions in the shared library.
|
||||
|
||||
Signed-off-by: Liu Chao <liuchao173@huawei.com>
|
||||
Signed-off-by: He Jingxian <hejingxian@huawei.com>
|
||||
---
|
||||
irqbalance.c | 4 +-
|
||||
irqbalance.h | 2 +-
|
||||
ui/Makefile | 30 ++++
|
||||
ui/client.c | 434 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
ui/irqbalance-ui.c | 4 +-
|
||||
ui/irqbalance-ui.h | 1 +
|
||||
ui/irqbalance_client.h | 111 +++++++++++++
|
||||
7 files changed, 581 insertions(+), 5 deletions(-)
|
||||
create mode 100644 ui/Makefile
|
||||
create mode 100644 ui/client.c
|
||||
create mode 100644 ui/irqbalance_client.h
|
||||
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index 1af23c6..7c79087 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -452,12 +452,12 @@ void get_object_stat(struct topo_obj *object, void *data)
|
||||
|
||||
gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attribute__((unused)))
|
||||
{
|
||||
- char buff[500];
|
||||
+ char buff[SOCKET_RECV_BUF_LEN];
|
||||
int sock;
|
||||
int recv_size = 0;
|
||||
int valid_user = 0;
|
||||
|
||||
- struct iovec iov = { buff, 500 };
|
||||
+ struct iovec iov = { buff, SOCKET_RECV_BUF_LEN };
|
||||
struct msghdr msg = { 0 };
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
diff --git a/irqbalance.h b/irqbalance.h
|
||||
index b2e5409..842cead 100644
|
||||
--- a/irqbalance.h
|
||||
+++ b/irqbalance.h
|
||||
@@ -175,6 +175,6 @@ extern unsigned int log_mask;
|
||||
|
||||
#define SOCKET_PATH "irqbalance"
|
||||
#define SOCKET_TMPFS "/var/run"
|
||||
-
|
||||
+#define SOCKET_RECV_BUF_LEN 4096
|
||||
#endif /* __INCLUDE_GUARD_IRQBALANCE_H_ */
|
||||
|
||||
diff --git a/ui/Makefile b/ui/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..27e0fbf
|
||||
--- /dev/null
|
||||
+++ b/ui/Makefile
|
||||
@@ -0,0 +1,30 @@
|
||||
+#!/bin/make
|
||||
+export SHELL = /bin/bash
|
||||
+DIR = $(shell pwd)
|
||||
+TARGET = libirqbalance_client.so
|
||||
+
|
||||
+RM = rm
|
||||
+LINK = ld
|
||||
+CC = gcc
|
||||
+
|
||||
+SRC = $(wildcard $(DIR)/*.c)
|
||||
+OBJ = $(patsubst $(DIR)/%.c,$(DIR)/%.o,$(SRC))
|
||||
+
|
||||
+INC = -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
|
||||
+CFLAG = -g3 -Wall -fPIC -D_GNU_SOURCE
|
||||
+SHARED = -shared
|
||||
+LFLAG = -lglib-2.0 -lncursesw
|
||||
+
|
||||
+CFLAG += $(INC)
|
||||
+
|
||||
+all: $(TARGET)
|
||||
+
|
||||
+$(TARGET): $(OBJ)
|
||||
+ $(LINK) $(SHARED) $(LFLAG) -o $@ $(OBJ)
|
||||
+
|
||||
+$(DIR)/%.o: $(DIR)/%.c
|
||||
+ $(CC) $(CFLAG) -c $< -o $@
|
||||
+
|
||||
+clean:
|
||||
+ -$(RM) $(DIR)/*.o
|
||||
+ -$(RM) $(TARGET)
|
||||
diff --git a/ui/client.c b/ui/client.c
|
||||
new file mode 100644
|
||||
index 0000000..027404b
|
||||
--- /dev/null
|
||||
+++ b/ui/client.c
|
||||
@@ -0,0 +1,434 @@
|
||||
+/*
|
||||
+ * Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
||||
+ *
|
||||
+ * 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.
|
||||
+ */
|
||||
+#include <sys/socket.h>
|
||||
+#include <stdio.h>
|
||||
+#include <string.h>
|
||||
+
|
||||
+#include "irqbalance-ui.h"
|
||||
+#include "irqbalance_client.h"
|
||||
+
|
||||
+extern int irqbalance_pid;
|
||||
+extern GList *tree;
|
||||
+
|
||||
+void irqbalance_set_pid(int pid)
|
||||
+{
|
||||
+ irqbalance_pid = pid;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * string format:
|
||||
+ * <int> <int> <int> <int> ... or NONE
|
||||
+ */
|
||||
+int irqbalance_set_ban_irqs(const char *irqs)
|
||||
+{
|
||||
+ char *data = NULL;
|
||||
+ const char *tmp;
|
||||
+ int ret = IRQBALANCE_SUCCESS;
|
||||
+ int socket_fd = 0;
|
||||
+ int i;
|
||||
+ struct msghdr *msg = NULL;
|
||||
+ struct iovec iov;
|
||||
+
|
||||
+ if (irqs == NULL || strlen(irqs) == 0) {
|
||||
+ ret = IRQBALANCE_INPUT_ILLEGAL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (strncmp(irqs, "NONE", strlen("NONE"))) {
|
||||
+ tmp = irqs;
|
||||
+ for (i = 0; i < strlen(irqs); i++) {
|
||||
+ if (*tmp != ' ' && (*tmp < '0' || *tmp > '9')) {
|
||||
+ ret = IRQBALANCE_INPUT_ILLEGAL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ tmp++;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ socket_fd = init_connection();
|
||||
+ if (!socket_fd) {
|
||||
+ ret = IRQBALANCE_CONNECT_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ data = (char *)malloc(strlen(irqs) + strlen(BAN_IRQS) + 1);
|
||||
+ if (!data) {
|
||||
+ ret = IRQBALANCE_MALLOC_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ msg = create_credentials_msg();
|
||||
+ if (!msg) {
|
||||
+ ret = IRQBALANCE_MALLOC_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ snprintf(data, strlen(irqs) + strlen(BAN_IRQS) + 1,
|
||||
+ "%s%s", BAN_IRQS, irqs);
|
||||
+ iov.iov_base = (void *) data;
|
||||
+ iov.iov_len = strlen(data) + 1;
|
||||
+ msg->msg_iov = &iov;
|
||||
+ if (sendmsg(socket_fd, msg, 0) == -1)
|
||||
+ ret = IRQBALANCE_SEND_FAIL;
|
||||
+
|
||||
+out:
|
||||
+ if (socket_fd > 0)
|
||||
+ close(socket_fd);
|
||||
+ if (msg)
|
||||
+ free(msg->msg_control);
|
||||
+ free(msg);
|
||||
+ free(data);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+unsigned int char_to_hex(char c)
|
||||
+{
|
||||
+ unsigned int hex;
|
||||
+
|
||||
+ if (c >= '0' && c <= '9') {
|
||||
+ hex = c - '0';
|
||||
+ } else {
|
||||
+ hex = c - 'a' + 10;
|
||||
+ }
|
||||
+ return hex;
|
||||
+}
|
||||
+
|
||||
+char *parse_cpus_to_cpulist(const char *cpus)
|
||||
+{
|
||||
+ int i, ret;
|
||||
+ const char *tmp;
|
||||
+ char *cpulist;
|
||||
+ int cpus_len;
|
||||
+ unsigned int hex;
|
||||
+ int index;
|
||||
+
|
||||
+ if (cpus == NULL
|
||||
+ || strlen(cpus) == 0
|
||||
+ || strlen(cpus) > CPU_MASK_MAX_LEN)
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (strncmp(cpus, "NULL", strlen("NULL"))) {
|
||||
+ tmp = cpus;
|
||||
+ cpus_len = strlen(cpus);
|
||||
+ for (i = 0; i < cpus_len; i++) {
|
||||
+ if ((*tmp < '0' || *tmp > '9')
|
||||
+ && (*tmp < 'a' || *tmp > 'f'))
|
||||
+ return NULL;
|
||||
+ tmp++;
|
||||
+ }
|
||||
+ cpulist = (char *)malloc(CPU_LIST_MAX_LEN);
|
||||
+ if (!cpulist)
|
||||
+ return NULL;
|
||||
+ cpulist[0] = 0;
|
||||
+ for (i = 0; i < cpus_len; i++) {
|
||||
+ hex = char_to_hex(cpus[cpus_len - 1 - i]);
|
||||
+ index = 0;
|
||||
+ while (hex) {
|
||||
+ if (hex & 1) {
|
||||
+ ret = snprintf(cpulist + strlen(cpulist),
|
||||
+ CPU_LIST_MAX_LEN - strlen(cpulist), "%d,", (i << 2) + index);
|
||||
+ if (ret < 0)
|
||||
+ break;
|
||||
+ }
|
||||
+ index++;
|
||||
+ hex = (hex >> 1);
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ cpulist = strdup(cpus);
|
||||
+ }
|
||||
+ return cpulist;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * string format:
|
||||
+ * 00000001 or NULL
|
||||
+ */
|
||||
+int irqbalance_set_ban_cpus(const char *cpus)
|
||||
+{
|
||||
+ int socket_fd = 0;
|
||||
+ int ret = IRQBALANCE_SUCCESS;
|
||||
+ char *data = NULL;
|
||||
+ char *cpulist = NULL;
|
||||
+ struct msghdr *msg = NULL;
|
||||
+ struct iovec iov;
|
||||
+
|
||||
+ cpulist = parse_cpus_to_cpulist(cpus);
|
||||
+ if(!cpulist) {
|
||||
+ ret = IRQBALANCE_INPUT_ILLEGAL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ socket_fd = init_connection();
|
||||
+ if(!socket_fd) {
|
||||
+ ret = IRQBALANCE_CONNECT_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ data = (char *)malloc(strlen(cpulist) + strlen(BAN_CPUS) + 1);
|
||||
+ if (!data) {
|
||||
+ ret = IRQBALANCE_MALLOC_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ msg = create_credentials_msg();
|
||||
+ if (!msg) {
|
||||
+ ret = IRQBALANCE_MALLOC_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ snprintf(data, strlen(cpulist) + strlen(BAN_CPUS) + 1,
|
||||
+ "%s%s", BAN_CPUS, cpulist);
|
||||
+ iov.iov_base = (void *) data;
|
||||
+ iov.iov_len = strlen(data) + 1;
|
||||
+ msg->msg_iov = &iov;
|
||||
+ if (sendmsg(socket_fd, msg, 0) == -1)
|
||||
+ ret = IRQBALANCE_SEND_FAIL;
|
||||
+
|
||||
+out:
|
||||
+ if (socket_fd)
|
||||
+ close(socket_fd);
|
||||
+ if (msg)
|
||||
+ free(msg->msg_control);
|
||||
+ free(msg);
|
||||
+ free(data);
|
||||
+ free(cpulist);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+int irqbalance_set_sleep_interval(int sleep)
|
||||
+{
|
||||
+ char data[DATA_BUF_MAX_LEN];
|
||||
+ int ret = IRQBALANCE_SUCCESS;
|
||||
+ int socket_fd = 0;
|
||||
+ struct msghdr *msg = NULL;
|
||||
+ struct iovec iov;
|
||||
+
|
||||
+ if (sleep < 1) {
|
||||
+ ret = IRQBALANCE_INPUT_ILLEGAL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ socket_fd = init_connection();
|
||||
+ if(!socket_fd) {
|
||||
+ ret = IRQBALANCE_CONNECT_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ msg = create_credentials_msg();
|
||||
+ if (!msg) {
|
||||
+ ret = IRQBALANCE_MALLOC_FAIL;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ snprintf(data, DATA_BUF_MAX_LEN, "%s %d", SET_SLEEP, sleep);
|
||||
+ iov.iov_base = (void *) data;
|
||||
+ iov.iov_len = strlen(data) + 1;
|
||||
+ msg->msg_iov = &iov;
|
||||
+ if (sendmsg(socket_fd, msg, 0) == -1)
|
||||
+ ret = IRQBALANCE_SEND_FAIL;
|
||||
+
|
||||
+out:
|
||||
+ if (socket_fd)
|
||||
+ close(socket_fd);
|
||||
+ if (msg)
|
||||
+ free(msg->msg_control);
|
||||
+ free(msg);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+void free_banned_irq_list(irqbalance_banned_irq_list_t *list_head)
|
||||
+{
|
||||
+ irqbalance_banned_irq_list_t *banned_irq = list_head;
|
||||
+ irqbalance_banned_irq_list_t *next_banned_irq;
|
||||
+
|
||||
+ while (banned_irq) {
|
||||
+ next_banned_irq = banned_irq->next;
|
||||
+ free(banned_irq);
|
||||
+ banned_irq = next_banned_irq;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/* get user setup info, including sleep setting, banned irqs and banned cpus info */
|
||||
+irqbalance_setup_t *irqbalance_get_setup_info()
|
||||
+{
|
||||
+ char *token, *ptr, *setup_info;
|
||||
+ char *copy = NULL;
|
||||
+ char *scan;
|
||||
+ int i, sleep, setup_size;
|
||||
+ int ban_irq_num = 0;
|
||||
+ int ban_irq_size = sizeof(irqbalance_banned_irq_t);
|
||||
+ irqbalance_setup_t *setup_data = NULL;
|
||||
+ irqbalance_banned_irq_list_t *banned_irq = NULL;
|
||||
+ irqbalance_banned_irq_list_t *list_head = NULL;
|
||||
+
|
||||
+ setup_info = get_data(SETUP);
|
||||
+ if (setup_info == NULL || strlen(setup_info) == 0)
|
||||
+ return NULL;
|
||||
+ copy = strdup(setup_info);
|
||||
+ if (!copy)
|
||||
+ goto out;
|
||||
+
|
||||
+ token = strtok_r(copy, " ", &ptr);
|
||||
+ if (!token)
|
||||
+ goto out;
|
||||
+ if(strncmp(token, "SLEEP", strlen("SLEEP")))
|
||||
+ goto out;
|
||||
+ scan = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!scan)
|
||||
+ goto out;
|
||||
+ sleep = strtol(scan, NULL, 10);
|
||||
+ token = strtok_r(NULL, " ", &ptr);
|
||||
+ while(token && !strncmp(token, "IRQ", strlen("IRQ"))) {
|
||||
+ banned_irq = (irqbalance_banned_irq_list_t *)malloc(sizeof(irqbalance_banned_irq_list_t));
|
||||
+ if (!banned_irq)
|
||||
+ goto out;
|
||||
+ scan = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!scan)
|
||||
+ goto out;
|
||||
+ banned_irq->irq = strtol(scan, NULL, 10);
|
||||
+ token = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!token || strncmp(token, "LOAD", strlen("LOAD")))
|
||||
+ goto out;
|
||||
+ scan = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!scan)
|
||||
+ goto out;
|
||||
+ banned_irq->load = strtol(scan, NULL, 10);
|
||||
+ token = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!token || strncmp(token, "DIFF", strlen("DIFF")))
|
||||
+ goto out;
|
||||
+ scan = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!scan)
|
||||
+ goto out;
|
||||
+ banned_irq->diff = strtol(scan, NULL, 10);
|
||||
+ token = strtok_r(ptr, " ", &ptr);
|
||||
+ if (!token || strncmp(token, "CLASS", strlen("CLASS")))
|
||||
+ goto out;
|
||||
+ scan = strtok_r(NULL, " ", &ptr);
|
||||
+ if (!scan)
|
||||
+ goto out;
|
||||
+ banned_irq->class = strtol(scan, NULL, 10);
|
||||
+ banned_irq->next = list_head;
|
||||
+ list_head = banned_irq;
|
||||
+ ban_irq_num++;
|
||||
+ token = strtok_r(NULL, " ", &ptr);
|
||||
+ banned_irq = NULL;
|
||||
+ }
|
||||
+ if (ban_irq_num > 1)
|
||||
+ setup_size = sizeof(irqbalance_setup_t) + (ban_irq_num - 1) * ban_irq_size;
|
||||
+ else
|
||||
+ setup_size = sizeof(irqbalance_setup_t);
|
||||
+ setup_data = (irqbalance_setup_t *)malloc(setup_size);
|
||||
+ if (!setup_data)
|
||||
+ goto out;
|
||||
+ memset(setup_data->banned_cpus, 0, NR_CPUS + 1);
|
||||
+ setup_data->sleep = sleep;
|
||||
+ setup_data->ban_irq_num = ban_irq_num;
|
||||
+ banned_irq = list_head;
|
||||
+ for (i = ban_irq_num; i > 0; i--) {
|
||||
+ memcpy(&(setup_data->banned_irqs[i - 1]), banned_irq, ban_irq_size);
|
||||
+ banned_irq = banned_irq->next;
|
||||
+ }
|
||||
+ if(strncmp(token, "BANNED", strlen("BANNED")))
|
||||
+ goto out;
|
||||
+ token = strtok_r(NULL, " ", &ptr);
|
||||
+ if (strlen(token) > NR_CPUS)
|
||||
+ goto out;
|
||||
+ strcpy(setup_data->banned_cpus, token);
|
||||
+out:
|
||||
+ free(setup_info);
|
||||
+ free(copy);
|
||||
+ free_banned_irq_list(list_head);
|
||||
+ return setup_data;
|
||||
+}
|
||||
+
|
||||
+/* the type of the GList pointer data is irqbalance_cpu_node_t*/
|
||||
+GList *irqbalance_get_stats_info()
|
||||
+{
|
||||
+ char *stats_data;
|
||||
+
|
||||
+ stats_data = get_data(STATS);
|
||||
+ if (stats_data == NULL)
|
||||
+ return NULL;
|
||||
+ parse_into_tree(stats_data);
|
||||
+ return tree;
|
||||
+}
|
||||
+
|
||||
+/* get banned cpus mask */
|
||||
+char *irqbalance_get_banned_cpus()
|
||||
+{
|
||||
+ char *setup_info;
|
||||
+ char *copy;
|
||||
+ char *bancpu_str;
|
||||
+
|
||||
+ setup_info = get_data(SETUP);
|
||||
+ if (setup_info == NULL)
|
||||
+ return NULL;
|
||||
+ bancpu_str = strstr(setup_info, "BANNED");
|
||||
+ if (bancpu_str == NULL) {
|
||||
+ free(setup_info);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ copy = strdup(bancpu_str + strlen("BANNED") + 1);
|
||||
+ free(setup_info);
|
||||
+ return copy;
|
||||
+}
|
||||
+
|
||||
+/* get banned irqs string */
|
||||
+char *irqbalance_get_banned_irqs()
|
||||
+{
|
||||
+ char *setup_info;
|
||||
+ char *copy;
|
||||
+ char *start_ptr, *end_ptr;
|
||||
+ char *ret_str, *temp, *last_temp;;
|
||||
+
|
||||
+ setup_info = get_data(SETUP);
|
||||
+ if (setup_info == NULL)
|
||||
+ return NULL;
|
||||
+ start_ptr = strstr(setup_info, "IRQ");
|
||||
+ if (start_ptr == NULL) {
|
||||
+ free(setup_info);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ copy = strdup(start_ptr);
|
||||
+ free(setup_info);
|
||||
+ if (copy == NULL)
|
||||
+ return NULL;
|
||||
+ end_ptr = strstr(copy, "BANNED");
|
||||
+ if (end_ptr)
|
||||
+ *end_ptr = '\0';
|
||||
+
|
||||
+ ret_str = (char*)malloc(strlen(copy) + 1);
|
||||
+ if (ret_str == NULL) {
|
||||
+ free(copy);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ memset(ret_str, 0, strlen(copy) + 1);
|
||||
+ temp = copy + strlen("IRQ") + 1;
|
||||
+ last_temp = temp;
|
||||
+ while (*temp) {
|
||||
+ temp = strstr(last_temp, " ");
|
||||
+ if (temp)
|
||||
+ *temp = '\0';
|
||||
+ else
|
||||
+ break;
|
||||
+ strcat(ret_str, last_temp);
|
||||
+ strcat(ret_str, " ");
|
||||
+ last_temp = strstr(temp + 1, "IRQ");
|
||||
+ if (last_temp == NULL)
|
||||
+ break;
|
||||
+ last_temp = last_temp + strlen("IRQ") + 1;
|
||||
+ temp = last_temp;
|
||||
+ }
|
||||
+ free(copy);
|
||||
+ if (strlen(ret_str) == 0) {
|
||||
+ free(ret_str);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return ret_str;
|
||||
+}
|
||||
+
|
||||
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
||||
index 943f008..f0deaf8 100644
|
||||
--- a/ui/irqbalance-ui.c
|
||||
+++ b/ui/irqbalance-ui.c
|
||||
@@ -120,8 +120,8 @@ char * get_data(char *string)
|
||||
* With a select, ioctl to determine size, and malloc based
|
||||
* on that
|
||||
*/
|
||||
- char *data = malloc(8192);
|
||||
- int len = recv(socket_fd, data, 8192, 0);
|
||||
+ char *data = malloc(RECV_BUF_SIZE);
|
||||
+ int len = recv(socket_fd, data, RECV_BUF_SIZE, 0);
|
||||
close(socket_fd);
|
||||
data[len] = '\0';
|
||||
free(msg->msg_control);
|
||||
diff --git a/ui/irqbalance-ui.h b/ui/irqbalance-ui.h
|
||||
index b32d58a..503c0c5 100644
|
||||
--- a/ui/irqbalance-ui.h
|
||||
+++ b/ui/irqbalance-ui.h
|
||||
@@ -26,6 +26,7 @@
|
||||
#define IRQ_10GBETH 6
|
||||
#define IRQ_VIRT_EVENT 7
|
||||
|
||||
+#define RECV_BUF_SIZE (4096 * 8)
|
||||
|
||||
/* Typedefs */
|
||||
|
||||
diff --git a/ui/irqbalance_client.h b/ui/irqbalance_client.h
|
||||
new file mode 100644
|
||||
index 0000000..8f18b79
|
||||
--- /dev/null
|
||||
+++ b/ui/irqbalance_client.h
|
||||
@@ -0,0 +1,111 @@
|
||||
+/*
|
||||
+ * Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
||||
+ *
|
||||
+ * 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.
|
||||
+ */
|
||||
+#include <glib.h>
|
||||
+#include <glib-unix.h>
|
||||
+
|
||||
+#ifndef IRQBALANCE_CLIENT_H
|
||||
+#define IRQBALANCE_CLIENT_H
|
||||
+
|
||||
+/* ERRORNO */
|
||||
+#define IRQBALANCE_SUCCESS 0
|
||||
+#define IRQBALANCE_INPUT_ILLEGAL 1
|
||||
+#define IRQBALANCE_CONNECT_FAIL 2
|
||||
+#define IRQBALANCE_SEND_FAIL 3
|
||||
+#define IRQBALANCE_MALLOC_FAIL 4
|
||||
+
|
||||
+#define BAN_CPUS "settings cpus "
|
||||
+#define DATA_BUF_MAX_LEN 128
|
||||
+#define NR_CPUS 1024
|
||||
+#define CPU_LIST_MAX_LEN 4096
|
||||
+#define CPU_MASK_MAX_LEN 256
|
||||
+
|
||||
+typedef enum irqbalance_node_type {
|
||||
+ IRQ_OBJ_TYPE_CPU,
|
||||
+ IRQ_OBJ_TYPE_CACHE,
|
||||
+ IRQ_OBJ_TYPE_PACKAGE,
|
||||
+ IRQ_OBJ_TYPE_NODE
|
||||
+} irqbalance_node_type_e;
|
||||
+
|
||||
+typedef struct irqbalance_irq {
|
||||
+ int vector;
|
||||
+ unsigned long load;
|
||||
+ unsigned long diff;
|
||||
+ char is_banned;
|
||||
+ GList *assigned_to;
|
||||
+ int class;
|
||||
+} irqbalance_irq_t;
|
||||
+
|
||||
+typedef struct irqbalance_cpu_node {
|
||||
+ irqbalance_node_type_e type;
|
||||
+ int number;
|
||||
+ unsigned long load;
|
||||
+ int is_powersave;
|
||||
+ struct irqbalance_cpu_node *parent;
|
||||
+ GList *children;
|
||||
+ GList *irqs;
|
||||
+ GList *cpu_list;
|
||||
+ char *cpu_mask;
|
||||
+} irqbalance_cpu_node_t;
|
||||
+
|
||||
+typedef struct irqbalance_banned_irq_list {
|
||||
+ int irq;
|
||||
+ int class;
|
||||
+ unsigned long load;
|
||||
+ unsigned long diff;
|
||||
+ struct irqbalance_banned_irq_list *next;
|
||||
+} irqbalance_banned_irq_list_t;
|
||||
+
|
||||
+typedef struct irqbalance_banned_irq_info {
|
||||
+ int irq;
|
||||
+ int class;
|
||||
+ unsigned long load;
|
||||
+ unsigned long diff;
|
||||
+} irqbalance_banned_irq_t;
|
||||
+
|
||||
+typedef struct irqbalance_setup_data {
|
||||
+ int sleep;
|
||||
+ char banned_cpus[NR_CPUS + 1];
|
||||
+ int ban_irq_num;
|
||||
+ irqbalance_banned_irq_t banned_irqs[1];
|
||||
+} irqbalance_setup_t;
|
||||
+
|
||||
+/*
|
||||
+ * set_ban_irqs string format:
|
||||
+ * <int> <int> <int> <int> ... or NONE
|
||||
+ * */
|
||||
+int irqbalance_set_ban_irqs(const char *irqs);
|
||||
+
|
||||
+/*
|
||||
+ * set_ban_cpus string format:
|
||||
+ * 00000001 or NULL
|
||||
+ * */
|
||||
+int irqbalance_set_ban_cpus(const char *cpus);
|
||||
+
|
||||
+/* set sleep interval of irqbalance main loop */
|
||||
+int irqbalance_set_sleep_interval(int sleep);
|
||||
+
|
||||
+/* get user setup info, including sleep setting, banned irqs and banned cpus info */
|
||||
+irqbalance_setup_t *irqbalance_get_setup_info();
|
||||
+
|
||||
+/* get irqbalance stats tree */
|
||||
+GList *irqbalance_get_stats_info();
|
||||
+
|
||||
+/* get banned cpus mask */
|
||||
+char *irqbalance_get_banned_cpus();
|
||||
+
|
||||
+/* get banned irqs string */
|
||||
+char *irqbalance_get_banned_irqs();
|
||||
+
|
||||
+/* set the pid of irqbalance server */
|
||||
+void irqbalance_set_pid(int pid);
|
||||
+#endif
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -10,13 +10,13 @@ introduce the periodically affinity hint verify.
|
||||
activate.c | 24 +++++------
|
||||
classify.c | 18 ++++++--
|
||||
cpumask.h | 7 +++
|
||||
hint_verify.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
hint_verify.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
hint_verify.h | 21 +++++++++
|
||||
irqbalance.c | 39 +++++++++++------
|
||||
irqbalance.c | 40 +++++++++++------
|
||||
irqbalance.h | 4 ++
|
||||
placement.c | 14 ++++++
|
||||
types.h | 1 +
|
||||
10 files changed, 250 insertions(+), 29 deletions(-)
|
||||
10 files changed, 252 insertions(+), 30 deletions(-)
|
||||
create mode 100644 hint_verify.c
|
||||
create mode 100644 hint_verify.h
|
||||
|
||||
@ -28,9 +28,9 @@ index 9276bfb..5fac265 100644
|
||||
endif
|
||||
|
||||
irqbalance_SOURCES = activate.c bitmap.c classify.c cputree.c irqbalance.c \
|
||||
- irqlist.c numa.c placement.c procinterrupts.c sockapi.c rules_config.c
|
||||
+ irqlist.c numa.c placement.c procinterrupts.c sockapi.c rules_config.c hint_verify.c
|
||||
irqbalance_LDADD = $(LIBCAP_NG_LIBS) $(GLIB2_LIBS) -lpthread
|
||||
- irqlist.c numa.c placement.c procinterrupts.c rules_config.c
|
||||
+ irqlist.c numa.c placement.c procinterrupts.c rules_config.c hint_verify.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/activate.c b/activate.c
|
||||
@ -149,7 +149,7 @@ new file mode 100644
|
||||
index 0000000..7a904b0
|
||||
--- /dev/null
|
||||
+++ b/hint_verify.c
|
||||
@@ -0,0 +1,149 @@
|
||||
@@ -0,0 +1,151 @@
|
||||
+/*
|
||||
+ * Copyright (C) 2019. Huawei Technologies Co., Ltd. All rights reserved.
|
||||
+ *
|
||||
@ -169,6 +169,7 @@ index 0000000..7a904b0
|
||||
+extern int keep_going;
|
||||
+extern GMainLoop *main_loop;
|
||||
+extern gboolean scan();
|
||||
+extern int last_interval;
|
||||
+
|
||||
+int real_sleep_interval;
|
||||
+int sleep_interval_count;
|
||||
@ -238,7 +239,7 @@ index 0000000..7a904b0
|
||||
+ * 1. scan opration for irq balancing;
|
||||
+ * 2. poll irq affinity hint changes for quickly applying them.
|
||||
+ */
|
||||
+gboolean poll_hint_affinity_and_scan(gpointer data)
|
||||
+gboolean poll_hint_affinity_and_scan(gpointer data __attribute__((unused)))
|
||||
+{
|
||||
+ gboolean need_verify_flag = FALSE;
|
||||
+ gboolean need_scan_flag = FALSE;
|
||||
@ -272,9 +273,10 @@ index 0000000..7a904b0
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (data != &real_sleep_interval) {
|
||||
+ data = &real_sleep_interval;
|
||||
+ g_timeout_add_seconds(real_sleep_interval, poll_hint_affinity_and_scan, data);
|
||||
+ update_interval_and_count();
|
||||
+ if (last_interval != real_sleep_interval) {
|
||||
+ last_interval = real_sleep_interval;
|
||||
+ g_timeout_add_seconds(real_sleep_interval, poll_hint_affinity_and_scan, NULL);
|
||||
+ return FALSE;
|
||||
+ }
|
||||
+
|
||||
@ -331,14 +333,14 @@ index faa8e6a..4a7eb39 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -65,6 +65,8 @@ char *banscript = NULL;
|
||||
char *polscript = NULL;
|
||||
long HZ;
|
||||
int sleep_interval = SLEEP_INTERVAL;
|
||||
int last_interval;
|
||||
+int hint_enabled = 0;
|
||||
+int poll_hint_interval = SLEEP_INTERVAL / 5;
|
||||
GMainLoop *main_loop;
|
||||
|
||||
char *banned_cpumask_from_ui = NULL;
|
||||
char *cpu_ban_string = NULL;
|
||||
@@ -99,15 +101,16 @@ struct option lopts[] = {
|
||||
{"banmod", 1 , NULL, 'm'},
|
||||
{"interval", 1 , NULL, 't'},
|
||||
@ -394,18 +396,19 @@ index faa8e6a..4a7eb39 100644
|
||||
return 0;
|
||||
}
|
||||
|
||||
-gboolean scan(gpointer data)
|
||||
-gboolean scan(gpointer data __attribute__((unused)))
|
||||
+gboolean scan()
|
||||
{
|
||||
log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n");
|
||||
clear_work_stats();
|
||||
@@ -338,16 +357,9 @@ gboolean scan(gpointer data)
|
||||
@@ -338,17 +357,9 @@ gboolean scan(gpointer data)
|
||||
keep_going = 0;
|
||||
cycle_count++;
|
||||
|
||||
- if (data != &sleep_interval) {
|
||||
- data = &sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, data);
|
||||
- /* sleep_interval may be changed by socket */
|
||||
- if (last_interval != sleep_interval) {
|
||||
- last_interval = sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, NULL);
|
||||
- return FALSE;
|
||||
- }
|
||||
-
|
||||
@ -417,15 +420,15 @@ index faa8e6a..4a7eb39 100644
|
||||
}
|
||||
}
|
||||
@@ -626,9 +638,10 @@ int main(int argc, char** argv)
|
||||
goto out;
|
||||
}
|
||||
|
||||
log(TO_ALL, LOG_INFO, "irqbalance start scan.\n");
|
||||
+ update_interval_and_count();
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
- int *last_interval = &sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, last_interval);
|
||||
+ int *last_interval = &real_sleep_interval;
|
||||
+ g_timeout_add_seconds(real_sleep_interval, poll_hint_affinity_and_scan, last_interval);
|
||||
- last_interval = sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, NULL);
|
||||
+ last_interval = real_sleep_interval;
|
||||
+ g_timeout_add_seconds(real_sleep_interval, poll_hint_affinity_and_scan, NULL);
|
||||
g_main_loop_run(main_loop);
|
||||
|
||||
g_main_loop_quit(main_loop);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From a7d86761f9c66eb6fb6d13b77e753d6c42b90e12 Mon Sep 17 00:00:00 2001
|
||||
From: Zengruan Ye <yezengruan@huawei.com>
|
||||
Date: Tue, 16 Jul 2019 00:07:36 +0800
|
||||
Subject: [PATCH 6/6] feature: irqbalance: Add ability for socket communication
|
||||
From 8e84d5ba4aad02509165cb1926091baa3630e418 Mon Sep 17 00:00:00 2001
|
||||
From: hejingxian <hejingxian@huawei.com>
|
||||
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
|
||||
@ -18,20 +18,21 @@ Data to send to socket:
|
||||
values are forgotten, not added to)
|
||||
|
||||
Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
|
||||
Signed-off-by: He Jingxian <hejingxian@huawei.com>
|
||||
---
|
||||
Makefile.am | 6 +-
|
||||
classify.c | 20 ++-
|
||||
cputree.c | 5 +-
|
||||
irqbalance.c | 185 +++--------------------------------------------------------
|
||||
irqbalance.h | 2 +
|
||||
sockapi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
sockapi.h | 18 +++
|
||||
7 files changed, 462 insertions(+), 179 deletions(-)
|
||||
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 abf1e8d..62ac482 100644
|
||||
index 46e7173..c7be22d 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -30,7 +30,7 @@ UI_DIR = ui
|
||||
@ -39,135 +40,75 @@ index abf1e8d..62ac482 100644
|
||||
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
|
||||
+ types.h sockapi.h $(UI_DIR)/helpers.h $(UI_DIR)/irqbalance-ui.h $(UI_DIR)/ui.h
|
||||
sbin_PROGRAMS = irqbalance
|
||||
|
||||
if IRQBALANCEUI
|
||||
@@ -38,8 +38,8 @@ sbin_PROGRAMS += irqbalance-ui
|
||||
@@ -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
|
||||
-irqbalance_LDADD = $(LIBCAP_NG_LIBS) $(GLIB2_LIBS)
|
||||
+ irqlist.c numa.c placement.c procinterrupts.c sockapi.c
|
||||
+irqbalance_LDADD = $(LIBCAP_NG_LIBS) $(GLIB2_LIBS) -lpthread
|
||||
- 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 \
|
||||
$(UI_DIR)/ui.c
|
||||
diff --git a/classify.c b/classify.c
|
||||
index 52fd74a..1e277c4 100644
|
||||
index 91ff022..b0bb3b4 100644
|
||||
--- a/classify.c
|
||||
+++ b/classify.c
|
||||
@@ -37,7 +37,10 @@ static GList *interrupts_db = NULL;
|
||||
@@ -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;
|
||||
+
|
||||
+pthread_mutex_t cl_banned_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
+pthread_mutex_t vm_banned_list_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
extern int need_add_single;
|
||||
|
||||
#define SYSFS_DIR "/sys"
|
||||
#define SYSPCI_DIR "/sys/bus/pci/devices"
|
||||
@@ -299,12 +302,16 @@ void add_banned_list_irq(int irq)
|
||||
|
||||
void add_cl_banned_irq(int irq)
|
||||
{
|
||||
+ irqbalance_mutex_lock(&cl_banned_list_mutex);
|
||||
add_banned_irq(irq, &cl_banned_irqs, 0);
|
||||
+ irqbalance_mutex_unlock(&cl_banned_list_mutex);
|
||||
}
|
||||
|
||||
void add_vm_banned_irq(int irq)
|
||||
{
|
||||
+ irqbalance_mutex_lock(&vm_banned_list_mutex);
|
||||
add_banned_irq(irq, &vm_banned_irqs, IRQ_FLAG_VM_BANNED);
|
||||
+ irqbalance_mutex_unlock(&vm_banned_list_mutex);
|
||||
}
|
||||
|
||||
static int is_banned_irq(int irq)
|
||||
@@ -314,7 +321,9 @@ static int is_banned_irq(int irq)
|
||||
|
||||
find.irq = irq;
|
||||
|
||||
+ irqbalance_mutex_lock(&vm_banned_list_mutex);
|
||||
entry = g_list_find_custom(vm_banned_irqs, &find, compare_ints);
|
||||
+ irqbalance_mutex_unlock(&vm_banned_list_mutex);
|
||||
if (!entry)
|
||||
entry = g_list_find_custom(banned_irqs, &find, compare_ints);
|
||||
|
||||
@@ -586,7 +595,9 @@ static int check_for_irq_ban(char *path __attribute__((unused)), int irq, GList
|
||||
* Check to see if we banned this irq on the command line
|
||||
*/
|
||||
find.irq = irq;
|
||||
+ irqbalance_mutex_lock(&cl_banned_list_mutex);
|
||||
entry = g_list_find_custom(cl_banned_irqs, &find, compare_ints);
|
||||
+ irqbalance_mutex_unlock(&cl_banned_list_mutex);
|
||||
if (entry)
|
||||
return 1;
|
||||
|
||||
@@ -821,9 +832,11 @@ void free_irq_db(void)
|
||||
banned_irqs = NULL;
|
||||
g_list_free(rebalance_irq_list);
|
||||
rebalance_irq_list = NULL;
|
||||
+ irqbalance_mutex_lock(&vm_banned_list_mutex);
|
||||
for_each_irq(vm_banned_irqs, free_irq, NULL);
|
||||
g_list_free(vm_banned_irqs);
|
||||
vm_banned_irqs = NULL;
|
||||
+ irqbalance_mutex_unlock(&vm_banned_list_mutex);
|
||||
}
|
||||
|
||||
void free_cl_opts(void)
|
||||
@@ -918,8 +931,11 @@ struct irq_info *get_irq_info(int irq)
|
||||
find.irq = irq;
|
||||
entry = g_list_find_custom(interrupts_db, &find, compare_ints);
|
||||
|
||||
- if (!entry)
|
||||
+ if (!entry) {
|
||||
+ irqbalance_mutex_lock(&vm_banned_list_mutex);
|
||||
entry = g_list_find_custom(vm_banned_irqs, &find, compare_ints);
|
||||
+ irqbalance_mutex_unlock(&vm_banned_list_mutex);
|
||||
+ }
|
||||
|
||||
if (!entry)
|
||||
entry = g_list_find_custom(banned_irqs, &find, compare_ints);
|
||||
diff --git a/cputree.c b/cputree.c
|
||||
index 5551784..0dbb5c8 100644
|
||||
index 741c7c8..5a96e30 100644
|
||||
--- a/cputree.c
|
||||
+++ b/cputree.c
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "irqbalance.h"
|
||||
@@ -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;
|
||||
@@ -77,8 +78,8 @@ static void setup_banned_cpus(void)
|
||||
@@ -78,12 +80,18 @@ static void setup_banned_cpus(void)
|
||||
cpus_clear(nohz_full);
|
||||
|
||||
/* A manually specified cpumask overrides auto-detection. */
|
||||
- if (banned_cpumask_from_ui != NULL) {
|
||||
- if (cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) {
|
||||
- cpulist_parse(banned_cpumask_from_ui,
|
||||
+ if (is_set_banned_cpumask_from_ui) {
|
||||
+ cpumask_parse_user(banned_cpumask_from_ui,
|
||||
strlen(banned_cpumask_from_ui), banned_cpus);
|
||||
- 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 27cf2eb..6e9de88 100644
|
||||
index dc8307d..1774eda 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <fcntl.h>
|
||||
+#include <pthread.h>
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
@@ -42,6 +43,7 @@
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <cap-ng.h>
|
||||
#endif
|
||||
#include "irqbalance.h"
|
||||
@ -175,231 +116,115 @@ index 27cf2eb..6e9de88 100644
|
||||
|
||||
volatile int keep_going = 1;
|
||||
volatile int ban_pci_assigned_irq = 1;
|
||||
@@ -388,178 +390,6 @@ void get_object_stat(struct topo_obj *object, void *data)
|
||||
}
|
||||
@@ -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 <subset>]\n");
|
||||
log(TO_CONSOLE, LOG_INFO, " [--powerthresh= | -p <off> | <n>] [--banirq= | -i <n>] [--banmod= | -m <module>] [--policyscript= | -l <script>]\n");
|
||||
- log(TO_CONSOLE, LOG_INFO, " [--pid= | -s <file>] [--deepestcache= | -c <n>] [--interval= | -t <n>] [--verifyhint= | -v n]\n");
|
||||
- log(TO_CONSOLE, LOG_INFO, " [--rulesconfig= | -r <config>] [--notclearhint | -n] [--migrateval= | -e <n>] [--loadlimit= | -g <n>]\n");
|
||||
+ log(TO_CONSOLE, LOG_INFO, " [--pid= | -s <file>] [--deepestcache= | -c <n>] [--interval= | -t <n>] [--verifyhint= | -v n] [--blocksocket | -k]\n");
|
||||
+ log(TO_CONSOLE, LOG_INFO, " [--rulesconfig= | -r <config>] [--notclearhint | -n] [--migrateval= | -e <n>] [--loadlimit= | -g <n>]\n");
|
||||
}
|
||||
|
||||
-gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attribute__((unused)))
|
||||
-{
|
||||
- char buff[500];
|
||||
- int sock;
|
||||
- int recv_size = 0;
|
||||
- int valid_user = 0;
|
||||
static void version(void)
|
||||
@@ -132,7 +135,7 @@ static void parse_command_line(int argc, char **argv)
|
||||
unsigned long val;
|
||||
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
- "odfjVni:p:s:c:b:l:m:t:h:v:r:e:g:",
|
||||
+ "odfjVni:p:s:c:b:l:m:t:h:v:r:e:g:k",
|
||||
lopts, &longind)) != -1) {
|
||||
|
||||
switch(opt) {
|
||||
@@ -240,7 +243,9 @@ static void parse_command_line(int argc, char **argv)
|
||||
case 'g':
|
||||
load_limit = strtoul(optarg, NULL, 10);
|
||||
break;
|
||||
-
|
||||
- struct iovec iov = { buff, 500 };
|
||||
- struct msghdr msg = { 0 };
|
||||
- msg.msg_iov = &iov;
|
||||
- msg.msg_iovlen = 1;
|
||||
- msg.msg_control = malloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
- msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
-
|
||||
- struct cmsghdr *cmsg;
|
||||
-
|
||||
- if (condition == G_IO_IN) {
|
||||
- sock = accept(fd, NULL, NULL);
|
||||
- if (sock < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n");
|
||||
- goto out;
|
||||
- }
|
||||
- if ((recv_size = recvmsg(sock, &msg, 0)) < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Error while receiving data.\n");
|
||||
- goto out_close;
|
||||
- }
|
||||
- cmsg = CMSG_FIRSTHDR(&msg);
|
||||
- if (!cmsg) {
|
||||
- log(TO_ALL, LOG_WARNING, "Connection no memory.\n");
|
||||
- goto out_close;
|
||||
- }
|
||||
- if ((cmsg->cmsg_level == SOL_SOCKET) &&
|
||||
- (cmsg->cmsg_type == SCM_CREDENTIALS)) {
|
||||
- struct ucred *credentials = (struct ucred *) CMSG_DATA(cmsg);
|
||||
- if (!credentials->uid) {
|
||||
- valid_user = 1;
|
||||
- }
|
||||
- }
|
||||
- if (!valid_user) {
|
||||
- log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
|
||||
- goto out_close;
|
||||
- }
|
||||
-
|
||||
- if (!strncmp(buff, "stats", strlen("stats"))) {
|
||||
- char *stats = NULL;
|
||||
- for_each_object(numa_nodes, get_object_stat, &stats);
|
||||
- send(sock, stats, strlen(stats), 0);
|
||||
- free(stats);
|
||||
- }
|
||||
- if (!strncmp(buff, "settings ", strlen("settings "))) {
|
||||
- if (!(strncmp(buff + strlen("settings "), "sleep ",
|
||||
- strlen("sleep ")))) {
|
||||
- char *sleep_string = malloc(
|
||||
- sizeof(char) * (recv_size - strlen("settings sleep ")));
|
||||
- if (!sleep_string)
|
||||
- goto out_close;
|
||||
- strncpy(sleep_string, buff + strlen("settings sleep "),
|
||||
- recv_size - strlen("settings sleep "));
|
||||
- int new_iterval = strtoul(sleep_string, NULL, 10);
|
||||
- if (new_iterval >= 1) {
|
||||
- sleep_interval = new_iterval;
|
||||
- }
|
||||
- free(sleep_string);
|
||||
- } else if (!(strncmp(buff + strlen("settings "), "ban irqs ",
|
||||
- strlen("ban irqs ")))) {
|
||||
- char *end;
|
||||
- char *irq_string = malloc(
|
||||
- sizeof(char) * (recv_size - strlen("settings ban irqs ")));
|
||||
- if (!irq_string)
|
||||
- goto out_close;
|
||||
- strncpy(irq_string, buff + strlen("settings ban irqs "),
|
||||
- recv_size - strlen("settings ban irqs "));
|
||||
- g_list_free_full(cl_banned_irqs, free);
|
||||
- cl_banned_irqs = NULL;
|
||||
- need_rescan = 1;
|
||||
- if (!strncmp(irq_string, "NONE", strlen("NONE"))) {
|
||||
- free(irq_string);
|
||||
- goto out_close;
|
||||
- }
|
||||
- int irq = strtoul(irq_string, &end, 10);
|
||||
- do {
|
||||
- add_cl_banned_irq(irq);
|
||||
- } while((irq = strtoul(end, &end, 10)));
|
||||
- free(irq_string);
|
||||
- } else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||
- strlen("cpus")))) {
|
||||
- char *cpu_ban_string = malloc(
|
||||
- sizeof(char) * (recv_size - strlen("settings cpus ")));
|
||||
- if (!cpu_ban_string)
|
||||
- goto out_close;
|
||||
- strncpy(cpu_ban_string, buff + strlen("settings cpus "),
|
||||
- recv_size - strlen("settings cpus "));
|
||||
- banned_cpumask_from_ui = strtok(cpu_ban_string, " ");
|
||||
- if (!strncmp(banned_cpumask_from_ui, "NULL", strlen("NULL"))) {
|
||||
- banned_cpumask_from_ui = NULL;
|
||||
- }
|
||||
- need_rescan = 1;
|
||||
- free(cpu_ban_string);
|
||||
- }
|
||||
- }
|
||||
- if (!strncmp(buff, "setup", strlen("setup"))) {
|
||||
- char banned[512];
|
||||
- char *setup = calloc(strlen("SLEEP ") + 11 + 1, 1);
|
||||
- char *newptr = NULL;
|
||||
- if (!setup)
|
||||
- goto out_close;
|
||||
- snprintf(setup, strlen("SLEEP ") + 11 + 1, "SLEEP %d ", sleep_interval);
|
||||
+ case 'k':
|
||||
+ use_unblock_socket = 0;
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,9 +567,12 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||
if (!setup)
|
||||
goto out_close;
|
||||
snprintf(setup, strlen("SLEEP ") + 11 + 1, "SLEEP %d ", sleep_interval);
|
||||
- if(g_list_length(cl_banned_irqs) > 0) {
|
||||
- for_each_irq(cl_banned_irqs, get_irq_data, &setup);
|
||||
- }
|
||||
- cpumask_scnprintf(banned, 512, banned_cpus);
|
||||
- newptr = realloc(setup, strlen(setup) + strlen(banned) + 7 + 1);
|
||||
- if (!newptr)
|
||||
- goto out_free_setup;
|
||||
-
|
||||
- setup = newptr;
|
||||
- snprintf(setup + strlen(setup), strlen(banned) + 7 + 1,
|
||||
- "BANNED %s", banned);
|
||||
- send(sock, setup, strlen(setup), 0);
|
||||
-out_free_setup:
|
||||
- free(setup);
|
||||
- }
|
||||
-
|
||||
-out_close:
|
||||
- close(sock);
|
||||
- }
|
||||
-
|
||||
-out:
|
||||
- free(msg.msg_control);
|
||||
- return TRUE;
|
||||
-}
|
||||
-
|
||||
-int init_socket()
|
||||
-{
|
||||
- struct sockaddr_un addr;
|
||||
- memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
-
|
||||
- socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
- if (socket_fd < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Socket couldn't be created.\n");
|
||||
- return 1;
|
||||
- }
|
||||
-
|
||||
- /*
|
||||
- * First try to create a file-based socket in tmpfs. If that doesn't
|
||||
- * succeed, fall back to an abstract socket (non file-based).
|
||||
- */
|
||||
- addr.sun_family = AF_UNIX;
|
||||
- snprintf(socket_name, 64, "%s/%s%d.sock", SOCKET_TMPFS, SOCKET_PATH, getpid());
|
||||
- strncpy(addr.sun_path, socket_name, sizeof(addr.sun_path));
|
||||
- if (bind(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the file-based socket.\n");
|
||||
-
|
||||
- /* Try binding to abstract */
|
||||
- memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
- addr.sun_family = AF_UNIX;
|
||||
- if (bind(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the abstract socket, bailing out.\n");
|
||||
- return 1;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- int optval = 1;
|
||||
- if (setsockopt(socket_fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) < 0) {
|
||||
- log(TO_ALL, LOG_WARNING, "Unable to set socket options.\n");
|
||||
- return 1;
|
||||
- }
|
||||
- listen(socket_fd, 1);
|
||||
- g_unix_fd_add(socket_fd, G_IO_IN, sock_handle, NULL);
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
static int create_lock_pidfile(const char *lockfile)
|
||||
{
|
||||
struct flock lock = { 0 };
|
||||
@@ -633,6 +463,8 @@ error_close:
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
+ int err;
|
||||
+ pthread_t socket_tid;
|
||||
sigset_t sigset, old_sigset;
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
@@ -750,10 +582,13 @@ int main(int argc, char** argv)
|
||||
+ if (g_list_length(cl_banned_irqs) > 0) {
|
||||
for_each_irq(cl_banned_irqs, get_irq_data, &setup);
|
||||
}
|
||||
+ if (g_list_length(vm_banned_irqs) > 0) {
|
||||
+ for_each_irq(vm_banned_irqs, get_irq_data, &setup);
|
||||
+ }
|
||||
cpumask_scnprintf(banned, 512, banned_cpus);
|
||||
newptr = realloc(setup, strlen(setup) + strlen(banned) + 7 + 1);
|
||||
if (!newptr)
|
||||
@@ -827,10 +835,18 @@ int main(int argc, char** argv)
|
||||
parse_proc_interrupts();
|
||||
parse_proc_stat();
|
||||
|
||||
- if (init_socket()) {
|
||||
- ret = EXIT_FAILURE;
|
||||
- goto out;
|
||||
+ err = pthread_create(&socket_tid, NULL, &handle_socket_api_event, NULL);
|
||||
+ if (0 != err) {
|
||||
+ log(TO_CONSOLE, LOG_WARNING, "WARNING: Failed to create irqbalance socket thread, return %d.\n", err);
|
||||
+ ret = EXIT_FAILURE;
|
||||
+ goto out;
|
||||
+ if (use_unblock_socket) {
|
||||
+ if (init_unblock_socket()) {
|
||||
+ ret = EXIT_FAILURE;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (init_socket()) {
|
||||
+ ret = EXIT_FAILURE;
|
||||
+ goto out;
|
||||
+ }
|
||||
}
|
||||
+
|
||||
log(TO_ALL, LOG_INFO, "irqbalance start scan.\n");
|
||||
update_interval_and_count();
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
int *last_interval = &sleep_interval;
|
||||
g_timeout_add_seconds(sleep_interval, scan, last_interval);
|
||||
@@ -852,6 +868,7 @@ out:
|
||||
close(socket_fd);
|
||||
if (socket_name[0])
|
||||
unlink(socket_name);
|
||||
+ free(banned_cpumask_from_ui);
|
||||
|
||||
return ret;
|
||||
}
|
||||
diff --git a/irqbalance.h b/irqbalance.h
|
||||
index 339e2a3..f9b554e 100644
|
||||
index fc42a9b..7473ee7 100644
|
||||
--- a/irqbalance.h
|
||||
+++ b/irqbalance.h
|
||||
@@ -44,6 +44,8 @@ extern void set_msi_interrupt_numa(int number);
|
||||
@@ -65,6 +65,7 @@ extern GList *cache_domains;
|
||||
extern GList *cpus;
|
||||
extern int numa_avail;
|
||||
extern GList *cl_banned_irqs;
|
||||
+extern GList *vm_banned_irqs;
|
||||
|
||||
extern GList *rebalance_irq_list;
|
||||
|
||||
+void irqbalance_mutex_lock(pthread_mutex_t *lock);
|
||||
+void irqbalance_mutex_unlock(pthread_mutex_t *lock);
|
||||
void update_migration_status(void);
|
||||
void dump_workloads(void);
|
||||
void sort_irq_list(GList **list);
|
||||
extern int debug_mode;
|
||||
extern int journal_logging;
|
||||
diff --git a/sockapi.c b/sockapi.c
|
||||
new file mode 100644
|
||||
index 0000000..4a0e683
|
||||
index 0000000..9891978
|
||||
--- /dev/null
|
||||
+++ b/sockapi.c
|
||||
@@ -0,0 +1,404 @@
|
||||
@@ -0,0 +1,297 @@
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <unistd.h>
|
||||
@ -423,34 +248,11 @@ index 0000000..4a0e683
|
||||
+extern int socket_fd;
|
||||
+extern char socket_name[64];
|
||||
+extern int sleep_interval;
|
||||
+extern pthread_mutex_t cl_banned_list_mutex;
|
||||
+extern GList *cl_banned_irqs;
|
||||
+extern pthread_mutex_t vm_banned_list_mutex;
|
||||
+extern GList *vm_banned_irqs;
|
||||
+extern cpumask_t banned_cpus;
|
||||
+extern int keep_going;
|
||||
+
|
||||
+void irqbalance_mutex_lock(pthread_mutex_t *lock)
|
||||
+{
|
||||
+ int err = 0;
|
||||
+
|
||||
+ err = pthread_mutex_lock(lock);
|
||||
+ if (err) {
|
||||
+ log(TO_ALL, LOG_ERR, "irqbalance: err(%d) irqbalance_mutex_lock failed", err);
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void irqbalance_mutex_unlock(pthread_mutex_t *lock)
|
||||
+{
|
||||
+ int err = 0;
|
||||
+
|
||||
+ err = pthread_mutex_unlock(lock);
|
||||
+ if (err) {
|
||||
+ log(TO_ALL, LOG_ERR, "irqbalance: err(%d) irqbalance_mutex_unlock failed", err);
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+}
|
||||
+int cur_fd_count = 0;
|
||||
+
|
||||
+static void fill_banned_cpus(char *cpustr, int length)
|
||||
+{
|
||||
@ -465,8 +267,6 @@ index 0000000..4a0e683
|
||||
+ struct irq_info *info = NULL;
|
||||
+
|
||||
+ (void)snprintf(irqstr, length, "IRQ:");
|
||||
+
|
||||
+ irqbalance_mutex_lock(&cl_banned_list_mutex);
|
||||
+ entry = g_list_first(cl_banned_irqs);
|
||||
+ if (!entry)
|
||||
+ (void)snprintf(irqstr + strlen(irqstr), length - strlen(irqstr), "None ");
|
||||
@ -477,11 +277,9 @@ index 0000000..4a0e683
|
||||
+ "%d,", info->irq);
|
||||
+ entry = next;
|
||||
+ }
|
||||
+ irqbalance_mutex_unlock(&cl_banned_list_mutex);
|
||||
+
|
||||
+ (void)snprintf(irqstr + strlen(irqstr) - 1, length - strlen(irqstr), " PCI:");
|
||||
+
|
||||
+ irqbalance_mutex_lock(&vm_banned_list_mutex);
|
||||
+ entry = g_list_first(vm_banned_irqs);
|
||||
+ if (!entry)
|
||||
+ (void)snprintf(irqstr + strlen(irqstr), length - strlen(irqstr), "None");
|
||||
@ -492,7 +290,6 @@ index 0000000..4a0e683
|
||||
+ "%d,", info->irq);
|
||||
+ entry = next;
|
||||
+ }
|
||||
+ irqbalance_mutex_unlock(&vm_banned_list_mutex);
|
||||
+}
|
||||
+
|
||||
+static int send_msg(int fd, char* buf, int len)
|
||||
@ -508,7 +305,8 @@ index 0000000..4a0e683
|
||||
+
|
||||
+static int setnonblocking(int fd)
|
||||
+{
|
||||
+ if (fcntl(fd, F_SETFL, fcntl(socket_fd, F_GETFD, 0)|O_NONBLOCK) < 0) {
|
||||
+ if (fcntl(fd, F_SETFL,
|
||||
+ (int)((unsigned int)fcntl(socket_fd, F_GETFL, 0) | O_NONBLOCK)) < 0) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return 0;
|
||||
@ -520,10 +318,8 @@ index 0000000..4a0e683
|
||||
+ char *last = irq_string;
|
||||
+ int irq;
|
||||
+
|
||||
+ irqbalance_mutex_lock(&cl_banned_list_mutex);
|
||||
+ g_list_free_full(cl_banned_irqs, free);
|
||||
+ cl_banned_irqs = NULL;
|
||||
+ irqbalance_mutex_unlock(&cl_banned_list_mutex);
|
||||
+
|
||||
+ log(TO_ALL, LOG_INFO, "Ban irqs(%s) online.\n", irq_string);
|
||||
+ if (!strncmp(irq_string, "NONE", strlen("NONE"))) {
|
||||
@ -553,92 +349,116 @@ index 0000000..4a0e683
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * recived cmdline format:
|
||||
+ * 1: settings sleep <int>
|
||||
+ * 2: settings ban irqs "<int> <int> <int> <int> ..." or settings ban irqs "NONE"
|
||||
+ * 3: settings ban cpus <cpumask> <cpumask> or settings ban cpus NONE
|
||||
+ * */
|
||||
+int sock_handle(int client_fd)
|
||||
+gboolean recv_msg_handle(gint client_fd,
|
||||
+ GIOCondition condition,
|
||||
+ gpointer user_data __attribute__((unused)))
|
||||
+{
|
||||
+ char buff[FILE_LINE_MAX_NUM] = { 0 };
|
||||
+ int ret = -1;
|
||||
+ char buff[FILE_LINE_MAX_NUM];
|
||||
+ struct cmsghdr *cmsg;
|
||||
+ int recv_size = 0;
|
||||
+ int valid_user = 0;
|
||||
+ struct iovec iov = { buff, FILE_LINE_MAX_NUM - 1 };
|
||||
+ struct msghdr msg = { 0 };
|
||||
+ int new_iterval = 0;
|
||||
+
|
||||
+ struct cmsghdr *cmsg = NULL;
|
||||
+ struct ucred *credentials = NULL;
|
||||
+ struct iovec iov = { buff, FILE_LINE_MAX_NUM - 1 };
|
||||
+ struct msghdr msg = { NULL, 0, &iov, 1, NULL, 0, 0 };
|
||||
+
|
||||
+ msg.msg_control = malloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
+ msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
+
|
||||
+ if ((recv_size = recvmsg(client_fd, &msg, 0)) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Error while receiving data.\n");
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+
|
||||
+ cmsg = CMSG_FIRSTHDR(&msg);
|
||||
+ if (cmsg == NULL) {
|
||||
+ log(TO_ALL, LOG_INFO, "There isn't enough space for a cmsghdr in the buffer.\n");
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+
|
||||
+ if ((cmsg->cmsg_level == SOL_SOCKET) &&
|
||||
+ (cmsg->cmsg_type == SCM_CREDENTIALS)) {
|
||||
+ credentials = (struct ucred *) CMSG_DATA(cmsg);
|
||||
+ if (!credentials->uid) {
|
||||
+ valid_user = 1;
|
||||
+ if (condition == G_IO_IN) {
|
||||
+ msg.msg_iov = &iov;
|
||||
+ msg.msg_iovlen = 1;
|
||||
+ msg.msg_control = malloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
+ if (!msg.msg_control) {
|
||||
+ goto out_close;
|
||||
+ }
|
||||
+ }
|
||||
+ if (!valid_user) {
|
||||
+ log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+
|
||||
+ if (!strncmp(buff, "settings ", strlen("settings "))) {
|
||||
+ if (!(strncmp(buff + strlen("settings "), "sleep ",
|
||||
+ strlen("sleep ")))) {
|
||||
+ new_iterval = strtoul(buff + strlen("settings sleep "), NULL, 10);
|
||||
+ if (new_iterval >= 1) {
|
||||
+ sleep_interval = new_iterval;
|
||||
+ msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
+ if ((recv_size = recvmsg(client_fd, &msg, 0)) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Error while receiving data:%d %s\n", recv_size, strerror(errno));
|
||||
+ goto out_close;
|
||||
+ }
|
||||
+ cmsg = CMSG_FIRSTHDR(&msg);
|
||||
+ if ((cmsg->cmsg_level == SOL_SOCKET) &&
|
||||
+ (cmsg->cmsg_type == SCM_CREDENTIALS)) {
|
||||
+ struct ucred *credentials = (struct ucred *) CMSG_DATA(cmsg);
|
||||
+ if (!credentials->uid) {
|
||||
+ valid_user = 1;
|
||||
+ }
|
||||
+ } else if (!(strncmp(buff + strlen("settings "), "ban irqs \"",
|
||||
+ strlen("ban irqs \"")))
|
||||
+ && buff[recv_size - 1] == '\"') {
|
||||
+ buff[recv_size - 1] = '\0';
|
||||
+ prase_banned_irq_string(buff + strlen("settings ban irqs \""));
|
||||
+ need_rescan = 1;
|
||||
+ } else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||
+ strlen("cpus")))) {
|
||||
+ if (recv_size > (int)(NR_CPUS + strlen("settings cpus "))) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Recived error setting cpus string %s, ONLY %d cpus support.\n", buff, NR_CPUS);
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+ if (!valid_user) {
|
||||
+ log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
|
||||
+ goto out_close;
|
||||
+ }
|
||||
+ if (!strncmp(buff, "settings ", strlen("settings "))) {
|
||||
+ if (!(strncmp(buff + strlen("settings "), "sleep ",
|
||||
+ strlen("sleep ")))) {
|
||||
+ new_iterval = strtoul(buff + strlen("settings sleep "), NULL, 10);
|
||||
+ if (new_iterval >= 1) {
|
||||
+ sleep_interval = new_iterval;
|
||||
+ }
|
||||
+ } else if (!(strncmp(buff + strlen("settings "), "ban irqs \"",
|
||||
+ strlen("ban irqs \"")))
|
||||
+ && buff[recv_size - 1] == '\"') {
|
||||
+ buff[recv_size - 1] = '\0';
|
||||
+ prase_banned_irq_string(buff + strlen("settings ban irqs \""));
|
||||
+ need_rescan = 1;
|
||||
+ } else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||
+ strlen("cpus")))) {
|
||||
+ if (recv_size > (int)(NR_CPUS + strlen("settings cpus "))) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Setting cpus more than limit: %d.\n",
|
||||
+ NR_CPUS);
|
||||
+ goto out_close;
|
||||
+ }
|
||||
+ buff[recv_size] = '\0';
|
||||
+ prase_banned_cpu_string(buff + strlen("settings cpus "));
|
||||
+ need_rescan = 1;
|
||||
+ }
|
||||
+ } else if (!strncmp(buff, "stats ", strlen("stats "))) {
|
||||
+ if (!(strncmp(buff + strlen("stats "), "cpu", strlen("cpu")))) {
|
||||
+ fill_banned_cpus(buff, FILE_LINE_MAX_NUM - 1);
|
||||
+ send_msg(client_fd, buff, strlen(buff));
|
||||
+ } else if (!(strncmp(buff + strlen("stats "), "irq", strlen("irq")))) {
|
||||
+ fill_banned_irqs(buff, FILE_LINE_MAX_NUM - 1);
|
||||
+ send_msg(client_fd, buff, strlen(buff));
|
||||
+ }
|
||||
+ buff[recv_size] = '\0';
|
||||
+ prase_banned_cpu_string(buff + strlen("settings cpus "));
|
||||
+ need_rescan = 1;
|
||||
+ }
|
||||
+ } else if (!strncmp(buff, "stats ", strlen("stats "))) {
|
||||
+ if (!(strncmp(buff + strlen("stats "), "cpu", strlen("cpu")))) {
|
||||
+ fill_banned_cpus(buff, FILE_LINE_MAX_NUM - 1);
|
||||
+ send_msg(client_fd, buff, strlen(buff));
|
||||
+ } else if (!(strncmp(buff + strlen("stats "), "irq", strlen("irq")))) {
|
||||
+ fill_banned_irqs(buff, FILE_LINE_MAX_NUM - 1);
|
||||
+ send_msg(client_fd, buff, strlen(buff));
|
||||
+ }
|
||||
+out_close:
|
||||
+ close(client_fd);
|
||||
+ free(msg.msg_control);
|
||||
+ cur_fd_count--;
|
||||
+ }
|
||||
+
|
||||
+ ret = 0;
|
||||
+
|
||||
+cleanup:
|
||||
+ free(msg.msg_control);
|
||||
+ return ret;
|
||||
+ return FALSE;
|
||||
+}
|
||||
+
|
||||
+int init_socket()
|
||||
+gboolean accept_handle(gint fd,
|
||||
+ GIOCondition condition,
|
||||
+ gpointer user_data __attribute__((unused)))
|
||||
+{
|
||||
+ int client_fd;
|
||||
+
|
||||
+ if (condition != G_IO_IN) {
|
||||
+ return TRUE;
|
||||
+ }
|
||||
+ client_fd = accept(fd, NULL, NULL);
|
||||
+ if (client_fd < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n");
|
||||
+ return TRUE;
|
||||
+ }
|
||||
+ if (cur_fd_count >= MAX_EVENTS) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon support no more than %d connection\n",
|
||||
+ MAX_EVENTS);
|
||||
+ close(client_fd);
|
||||
+ return TRUE;
|
||||
+ }
|
||||
+ if (setnonblocking(client_fd) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon set connection nonblocking failed: %s.\n",
|
||||
+ strerror(errno));
|
||||
+ close(client_fd);
|
||||
+ return TRUE;
|
||||
+ }
|
||||
+ cur_fd_count++;
|
||||
+ g_unix_fd_add(client_fd, G_IO_IN, recv_msg_handle, NULL);
|
||||
+ return TRUE;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+int init_unblock_socket()
|
||||
+{
|
||||
+ struct sockaddr_un addr;
|
||||
+ int optval = 1;
|
||||
@ -648,13 +468,7 @@ index 0000000..4a0e683
|
||||
+ socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
+ if (socket_fd < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Socket couldn't be created.\n");
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+
|
||||
+ if (access(SOCKET_TMPFS, F_OK) != 0) {
|
||||
+ if (mkdir(SOCKET_TMPFS, 0644) == -1) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't create directory %s.\n", SOCKET_TMPFS);
|
||||
+ }
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
@ -663,6 +477,7 @@ index 0000000..4a0e683
|
||||
+ */
|
||||
+ memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
+ addr.sun_family = AF_UNIX;
|
||||
+ snprintf(socket_name, 64, "%s/%s%d.sock", SOCKET_TMPFS, SOCKET_PATH, getpid());
|
||||
+ strncpy(addr.sun_path, socket_name, sizeof(addr.sun_path));
|
||||
+ if (bind(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the file-based socket.\n");
|
||||
@ -670,146 +485,49 @@ index 0000000..4a0e683
|
||||
+ memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
+ addr.sun_family = AF_UNIX;
|
||||
+ if (bind(socket_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the abstract socket, bailing out.\n");
|
||||
+ goto cleanup;
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't be bound to the abstract socket.\n");
|
||||
+ return 1;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (chmod(socket_name, SOCK_RWX_MODE) != 0) {
|
||||
+ /* when use abstract socket, chmod may fail. No need return here. */
|
||||
+ log(TO_ALL, LOG_WARNING, "socket name : %s, chmod failed\n", socket_name);
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+
|
||||
+ if (setsockopt(socket_fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Unable to set socket options: %s.\n", strerror(errno));
|
||||
+ goto cleanup;
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ if (listen(socket_fd, MAX_CLIENT) != 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't be listening to the socket: %s.\n", strerror(errno));
|
||||
+ goto cleanup;
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon couldn't be listening to the socket: %s.\n",
|
||||
+ strerror(errno));
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ if (setnonblocking(socket_fd) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon set connection(listen) nonblocking failed: %s.\n", strerror(errno));
|
||||
+ goto cleanup;
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon set connection(listen) nonblocking failed: %s.\n",
|
||||
+ strerror(errno));
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ return socket_fd;
|
||||
+
|
||||
+cleanup:
|
||||
+ if (socket_fd >= 0)
|
||||
+ close(socket_fd);
|
||||
+
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
+void *handle_socket_api_event(void *args __attribute__((unused)))
|
||||
+{
|
||||
+ int epoll_fd = -1;
|
||||
+ int conn_fd = -1;
|
||||
+ int nfds = -1;
|
||||
+ int i = 0;
|
||||
+ int cur_fd_count = 1;
|
||||
+
|
||||
+ struct epoll_event ev;
|
||||
+ struct epoll_event *events = NULL;
|
||||
+
|
||||
+ snprintf(socket_name, 64, "%s/%s%d.sock", SOCKET_TMPFS, SOCKET_PATH, getpid());
|
||||
+
|
||||
+ memset((void*)&ev, 0, sizeof(ev));
|
||||
+ socket_fd = init_socket();
|
||||
+ if (socket_fd < 0)
|
||||
+ exit(-1);
|
||||
+
|
||||
+ epoll_fd = epoll_create(MAX_EVENTS);
|
||||
+ if (epoll_fd < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Unable to create epoll: %s.\n", strerror(errno));
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+ ev.events = EPOLLIN | EPOLLRDHUP;
|
||||
+ ev.data.fd = socket_fd;
|
||||
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, socket_fd, &ev) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon epoll set insertion error: %s.\n", strerror(errno));
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+
|
||||
+ events = (struct epoll_event *)malloc(sizeof(struct epoll_event) * MAX_EVENTS);
|
||||
+ if (NULL == events) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon faild to malloc epoll event space.\n");
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+ memset((void*)events, 0, sizeof(struct epoll_event) * MAX_EVENTS);
|
||||
+
|
||||
+ banned_cpumask_from_ui = (char*)malloc(NR_CPUS + 1);
|
||||
+ if (!banned_cpumask_from_ui) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon faild to malloc banned_cpumask_from_ui space.\n");
|
||||
+ exit(-1);
|
||||
+ return 1;
|
||||
+ }
|
||||
+ memset((void*)banned_cpumask_from_ui, 0, NR_CPUS + 1);
|
||||
+
|
||||
+ while (keep_going) {
|
||||
+ nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
|
||||
+ if ( 0 == nfds) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon epoll wait failed: %s.\n", strerror(errno));
|
||||
+ (void)usleep(SLEEP_TIME);
|
||||
+ continue;
|
||||
+ }
|
||||
+ for (i = 0; i < nfds; i++) {
|
||||
+ if (events[i].data.fd == socket_fd) {
|
||||
+ conn_fd = accept(socket_fd, NULL, NULL);
|
||||
+ if (conn_fd < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon accept failed: %s\n", strerror(errno));
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (cur_fd_count >= MAX_EVENTS) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon support no more than %d connection\n", MAX_EVENTS);
|
||||
+ close(conn_fd);
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (setnonblocking(conn_fd) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemon set connection nonblocking failed: %s.\n", strerror(errno));
|
||||
+ close(conn_fd);
|
||||
+ continue;
|
||||
+ }
|
||||
+ memset((void*)&ev, 0, sizeof(ev));
|
||||
+ ev.events = EPOLLIN | EPOLLRDHUP;
|
||||
+ ev.data.fd = conn_fd;
|
||||
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, conn_fd, &ev) < 0) {
|
||||
+ log(TO_ALL, LOG_WARNING, "Daemonadd socket '%d' to poll failed: %s\n", conn_fd, strerror(errno));
|
||||
+ continue;
|
||||
+ }
|
||||
+ cur_fd_count++;
|
||||
+ continue;
|
||||
+ } else if (events[i].events&EPOLLERR || events[i].events&EPOLLHUP ) {
|
||||
+ log(TO_ALL, LOG_WARNING, "epoll is error: %u\n", events[i].events);
|
||||
+ } else {
|
||||
+ /* one socket connection only support send&recv data once */
|
||||
+ sock_handle(events[i].data.fd);
|
||||
+ }
|
||||
+ epoll_ctl(epoll_fd, EPOLL_CTL_DEL, events[i].data.fd, &ev);
|
||||
+ close(events[i].data.fd);
|
||||
+ events[i].data.fd = -1;
|
||||
+ cur_fd_count--;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ free(events);
|
||||
+ free(banned_cpumask_from_ui);
|
||||
+ banned_cpumask_from_ui = NULL;
|
||||
+ if (socket_fd >= 0)
|
||||
+ close(socket_fd);
|
||||
+ if (socket_name[0])
|
||||
+ unlink(socket_name);
|
||||
+ g_unix_fd_add(socket_fd, G_IO_IN, accept_handle, NULL);
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/sockapi.h b/sockapi.h
|
||||
new file mode 100644
|
||||
index 0000000..254dd3f
|
||||
index 0000000..3875234
|
||||
--- /dev/null
|
||||
+++ b/sockapi.h
|
||||
@@ -0,0 +1,18 @@
|
||||
@@ -0,0 +1,19 @@
|
||||
+#ifndef UVP_IRQBALANCE_SOCKAPI_H_
|
||||
+#define UVP_IRQBALANCE_SOCKAPI_H_
|
||||
+
|
||||
@ -821,11 +539,12 @@ index 0000000..254dd3f
|
||||
+#define SLEEP_TIME (100 * 1000) /* 100ms */
|
||||
+
|
||||
+#define MAX_CLIENT 512
|
||||
+
|
||||
+#define MAX_EVENTS 1024
|
||||
+
|
||||
+#define FILE_LINE_MAX_NUM (4096*6)
|
||||
+
|
||||
+void *handle_socket_api_event(void *args);
|
||||
+int init_unblock_socket();
|
||||
+
|
||||
+#endif
|
||||
--
|
||||
|
||||
96
fix-invalid-pointer-dereference-banned_cpumask_from_.patch
Normal file
96
fix-invalid-pointer-dereference-banned_cpumask_from_.patch
Normal file
@ -0,0 +1,96 @@
|
||||
From 6c350eb9af2e36c40f4c1f2122e4b5b270c011b2 Mon Sep 17 00:00:00 2001
|
||||
From: Weiping Zhang <zhangweiping@didiglobal.com>
|
||||
Date: Fri, 8 Nov 2019 23:43:55 +0800
|
||||
Subject: [PATCH 5/5] fix invalid pointer dereference banned_cpumask_from_ui
|
||||
|
||||
The memory of cpu_ban_string was release in sock_handle function,
|
||||
so the banned_cpumask_from_ui will dereference an invalid memory.
|
||||
|
||||
Fix this issue by delay release memory.
|
||||
|
||||
Reproduce:
|
||||
echo "settings cpus 0-3" | nc -U `find /var/run/irqbalance/ -name *sock`
|
||||
|
||||
Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com>
|
||||
---
|
||||
cputree.c | 7 ++++++-
|
||||
irqbalance.c | 21 ++++++++++++++++++---
|
||||
2 files changed, 24 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/cputree.c b/cputree.c
|
||||
index 305f617..4c5fdf5 100644
|
||||
--- a/cputree.c
|
||||
+++ b/cputree.c
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "irqbalance.h"
|
||||
|
||||
extern char *banned_cpumask_from_ui;
|
||||
+extern char *cpu_ban_string;
|
||||
|
||||
GList *cpus;
|
||||
GList *cache_domains;
|
||||
@@ -104,9 +105,13 @@ static void setup_banned_cpus(void)
|
||||
cpus_clear(nohz_full);
|
||||
|
||||
/* A manually specified cpumask overrides auto-detection. */
|
||||
- if (banned_cpumask_from_ui != NULL) {
|
||||
+ if (cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) {
|
||||
cpulist_parse(banned_cpumask_from_ui,
|
||||
strlen(banned_cpumask_from_ui), banned_cpus);
|
||||
+ /* release it safety, it was allocated in sock_handle */
|
||||
+ free(cpu_ban_string);
|
||||
+ cpu_ban_string = NULL;
|
||||
+ banned_cpumask_from_ui = NULL;
|
||||
goto out;
|
||||
}
|
||||
if (getenv("IRQBALANCE_BANNED_CPUS")) {
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index c9379ad..7630e38 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -65,6 +65,7 @@ int sleep_interval = SLEEP_INTERVAL;
|
||||
int last_interval;
|
||||
GMainLoop *main_loop;
|
||||
|
||||
+char *cpu_ban_string = NULL;
|
||||
char *banned_cpumask_from_ui = NULL;
|
||||
|
||||
static void sleep_approx(int seconds)
|
||||
@@ -469,7 +470,14 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||
free(irq_string);
|
||||
} else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||
strlen("cpus")))) {
|
||||
- char *cpu_ban_string = malloc(
|
||||
+ /*
|
||||
+ * if cpu_ban_string has not been consumed,
|
||||
+ * just ignore this request.
|
||||
+ */
|
||||
+ if (cpu_ban_string != NULL)
|
||||
+ goto out_close;
|
||||
+
|
||||
+ cpu_ban_string = malloc(
|
||||
sizeof(char) * (recv_size - strlen("settings cpus ")));
|
||||
if (!cpu_ban_string)
|
||||
goto out_close;
|
||||
@@ -479,9 +487,16 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||
banned_cpumask_from_ui = strtok(cpu_ban_string, " ");
|
||||
if (!strncmp(banned_cpumask_from_ui, "NULL", strlen("NULL"))) {
|
||||
banned_cpumask_from_ui = NULL;
|
||||
+ free(cpu_ban_string);
|
||||
+ cpu_ban_string = NULL;;
|
||||
+ } else {
|
||||
+ /*
|
||||
+ * don't free cpu_ban_string at here, it will be
|
||||
+ * released after we have store it to @banned_cpus
|
||||
+ * in setup_banned_cpus function.
|
||||
+ */
|
||||
+ need_rescan = 1;
|
||||
}
|
||||
- need_rescan = 1;
|
||||
- free(cpu_ban_string);
|
||||
}
|
||||
}
|
||||
if (!strncmp(buff, "setup", strlen("setup"))) {
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -43,7 +43,7 @@ index cace4d8..5e5ef9b 100644
|
||||
+ goto out;
|
||||
}
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
int *last_interval = &sleep_interval;
|
||||
last_interval = sleep_interval;
|
||||
@@ -682,6 +684,7 @@ int main(int argc, char** argv)
|
||||
|
||||
g_main_loop_quit(main_loop);
|
||||
|
||||
62
fix-sleep-interval-when-sleep_interval-is-changed-by.patch
Normal file
62
fix-sleep-interval-when-sleep_interval-is-changed-by.patch
Normal file
@ -0,0 +1,62 @@
|
||||
From 97730f051e042e67da5728a3b59528c9d0fb72d2 Mon Sep 17 00:00:00 2001
|
||||
From: Pyxisha <xiashuang1@huawei.com>
|
||||
Date: Mon, 15 Jul 2019 20:47:07 +0800
|
||||
Subject: [PATCH 45/50] fix sleep interval when sleep_interval is changed by
|
||||
socket
|
||||
|
||||
currently, in scan, irqbalance compare sleep_interval's address to decide if sleep_interval is changed, accutually this judgement is always false now.
|
||||
|
||||
sign_off_by: Shuang Xia <xiashuang1@huawei.com>
|
||||
---
|
||||
irqbalance.c | 14 ++++++++------
|
||||
1 file changed, 8 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index c1a0e15..d424326 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -61,6 +61,7 @@ char *pidfile = NULL;
|
||||
char *polscript = NULL;
|
||||
long HZ;
|
||||
int sleep_interval = SLEEP_INTERVAL;
|
||||
+int last_interval;
|
||||
GMainLoop *main_loop;
|
||||
|
||||
char *banned_cpumask_from_ui = NULL;
|
||||
@@ -251,7 +252,7 @@ gboolean force_rescan(gpointer data __attribute__((unused)))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
-gboolean scan(gpointer data)
|
||||
+gboolean scan(gpointer data __attribute__((unused)))
|
||||
{
|
||||
log(TO_CONSOLE, LOG_INFO, "\n\n\n-----------------------------------------------------------------------------\n");
|
||||
clear_work_stats();
|
||||
@@ -289,9 +290,10 @@ gboolean scan(gpointer data)
|
||||
keep_going = 0;
|
||||
cycle_count++;
|
||||
|
||||
- if (data != &sleep_interval) {
|
||||
- data = &sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, data);
|
||||
+ /* sleep_interval may be changed by socket */
|
||||
+ if (last_interval != sleep_interval) {
|
||||
+ last_interval = sleep_interval;
|
||||
+ g_timeout_add_seconds(sleep_interval, scan, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -623,8 +625,8 @@ int main(int argc, char** argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
- int *last_interval = &sleep_interval;
|
||||
- g_timeout_add_seconds(sleep_interval, scan, last_interval);
|
||||
+ last_interval = sleep_interval;
|
||||
+ g_timeout_add_seconds(sleep_interval, scan, NULL);
|
||||
g_main_loop_run(main_loop);
|
||||
|
||||
g_main_loop_quit(main_loop);
|
||||
--
|
||||
2.19.1
|
||||
|
||||
66
free-cpu_ban_string-when-the-next-request-come.patch
Normal file
66
free-cpu_ban_string-when-the-next-request-come.patch
Normal file
@ -0,0 +1,66 @@
|
||||
From 0fab11043aef5b835ed5564dc15476cdbfb54d5b Mon Sep 17 00:00:00 2001
|
||||
From: SuperSix173 <liuchao173@huawei.com>
|
||||
Date: Thu, 6 Feb 2020 11:43:48 +0800
|
||||
Subject: [PATCH] free cpu_ban_string when the next request come
|
||||
|
||||
---
|
||||
cputree.c | 4 ----
|
||||
irqbalance.c | 19 +++++--------------
|
||||
2 files changed, 5 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/cputree.c b/cputree.c
|
||||
index 9aa4794..bef1f40 100644
|
||||
--- a/cputree.c
|
||||
+++ b/cputree.c
|
||||
@@ -118,10 +118,6 @@ static void setup_banned_cpus(void)
|
||||
if (cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) {
|
||||
cpulist_parse(banned_cpumask_from_ui,
|
||||
strlen(banned_cpumask_from_ui), banned_cpus);
|
||||
- /* release it safety, it was allocated in sock_handle */
|
||||
- free(cpu_ban_string);
|
||||
- cpu_ban_string = NULL;
|
||||
- banned_cpumask_from_ui = NULL;
|
||||
goto out;
|
||||
}
|
||||
if (getenv("IRQBALANCE_BANNED_CPUS")) {
|
||||
diff --git a/irqbalance.c b/irqbalance.c
|
||||
index e76d27b..9f65c88 100644
|
||||
--- a/irqbalance.c
|
||||
+++ b/irqbalance.c
|
||||
@@ -471,12 +471,9 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||
free(irq_string);
|
||||
} else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||
strlen("cpus")))) {
|
||||
- /*
|
||||
- * if cpu_ban_string has not been consumed,
|
||||
- * just ignore this request.
|
||||
- */
|
||||
- if (cpu_ban_string != NULL)
|
||||
- goto out_close;
|
||||
+ banned_cpumask_from_ui = NULL;
|
||||
+ free(cpu_ban_string);
|
||||
+ cpu_ban_string = NULL;
|
||||
|
||||
cpu_ban_string = malloc(
|
||||
sizeof(char) * (recv_size - strlen("settings cpus ")));
|
||||
@@ -489,15 +486,9 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||
if (!strncmp(banned_cpumask_from_ui, "NULL", strlen("NULL"))) {
|
||||
banned_cpumask_from_ui = NULL;
|
||||
free(cpu_ban_string);
|
||||
- cpu_ban_string = NULL;;
|
||||
- } else {
|
||||
- /*
|
||||
- * don't free cpu_ban_string at here, it will be
|
||||
- * released after we have store it to @banned_cpus
|
||||
- * in setup_banned_cpus function.
|
||||
- */
|
||||
- need_rescan = 1;
|
||||
+ cpu_ban_string = NULL;
|
||||
}
|
||||
+ need_rescan = 1;
|
||||
}
|
||||
}
|
||||
if (!strncmp(buff, "setup", strlen("setup"))) {
|
||||
--
|
||||
2.21.0.windows.1
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
Summary: A dynamic adaptive IRQ balancing daemon
|
||||
Name: irqbalance
|
||||
Version: 1.4.0
|
||||
Release: 15
|
||||
Release: 16
|
||||
Epoch: 3
|
||||
|
||||
License: GPLv2
|
||||
@ -32,11 +32,12 @@ Patch5: Fix-some-string-copy-limitations.patch
|
||||
Patch6: irqbalance-Add-support-for-file-based-socket-for-IPC.patch
|
||||
Patch7: Fix-several-memleak-problems-found-by-covscan.patch
|
||||
Patch8: Fix-an-possible-overflow-error.patch
|
||||
Patch9: procinterrupts-check-xen-dyn-event-more-flexible.patch
|
||||
Patch10:Fix-ambiguous-parsing-of-node-entries-in-sys.patch
|
||||
Patch11:Don-t-leak-socket-fd-on-connection-error.patch
|
||||
Patch12:Fix-string-truncation-issues-detected-by-GCC-8.patch
|
||||
Patch13:fix-balancing-when-numa-information-isn-t-available.patch
|
||||
Patch9: Fix-irqbalance-ui-failing-to-connect-to-irqbalance-d.patch
|
||||
Patch10:procinterrupts-check-xen-dyn-event-more-flexible.patch
|
||||
Patch11:Fix-ambiguous-parsing-of-node-entries-in-sys.patch
|
||||
Patch12:Don-t-leak-socket-fd-on-connection-error.patch
|
||||
Patch13:Fix-string-truncation-issues-detected-by-GCC-8.patch
|
||||
Patch14:fix-balancing-when-numa-information-isn-t-available.patch
|
||||
|
||||
Patch6000: Checking-return-value-of-strdup-in-collect_full_irq_.patch
|
||||
Patch6001: getline-clean-up-freeing-of-lines-from-getline.patch
|
||||
@ -45,7 +46,10 @@ Patch6003: prevent-NULL-pointer-dereference-when-memory-allocat.patch
|
||||
Patch6004: fix-resource-leak-for-not-invoking-closedir-after-op.patch
|
||||
Patch6005: correct-to-use-realloc-function.patch
|
||||
Patch6006: fix-the-problem-of-banmod-that-memory-is-freed-befor.patch
|
||||
Patch6007: fix-resource-leak-on-the-error-paths-in-main.patch
|
||||
Patch6007: fix-sleep-interval-when-sleep_interval-is-changed-by.patch
|
||||
Patch6008: fix-resource-leak-on-the-error-paths-in-main.patch
|
||||
Patch6009: fix-invalid-pointer-dereference-banned_cpumask_from_.patch
|
||||
Patch6010: free-cpu_ban_string-when-the-next-request-come.patch
|
||||
|
||||
Patch9000: irqbalance-1.0.4-env-file-path.patch
|
||||
Patch9001: bugfix-fix-a-hole-that-flees-hotplug-event.patch
|
||||
@ -56,23 +60,25 @@ Patch9005: feature-irqbalance-arm64-Add-irq-aff-change-check.patch
|
||||
Patch9006: feature-irqbalance-auto-banned-pci-assigned-irq.patch
|
||||
Patch9007: bugfix-irqbalance-fix-wrong-pid-value-in-pid-file.patch
|
||||
Patch9008: feature-supplement-irqbalance-service-config.patch
|
||||
Patch9009: feature-irqbalance-Add-ability-for-socket-communicat.patch
|
||||
Patch9010: bugfix-fgets-will-get-a-redundant-new-line.patch
|
||||
Patch9011: bugfix-Prevent-inserting-a-duplicate-entry-to-avoid-list-ch.patch
|
||||
Patch9012: bugfix-guess_arm_irq_hints.patch
|
||||
Patch9013: feature-add-new-user-irq-policy-config-rule.patch
|
||||
Patch9014: bugfix-make-the-return-value-of-getline-handled-correct.patch
|
||||
Patch9015: bugfix-change-irq-ban-check-path-to-devpath.patch
|
||||
Patch9016: bugfix-fix-new-irqs-in-hotplug-keep-stay-on-one-numa.patch
|
||||
Patch9017: feature-add-the-switch-of-printing-log.patch
|
||||
Patch9018: bugfix-fix-new-msi-irq-hasnot-been-added-to-rebalance-list.patch
|
||||
Patch9019: bugfix-delete-no-existing-banned-irq.patch
|
||||
Patch9020: feature-add-test-interfaces-for-irqbalance-core-functions.patch
|
||||
Patch9021: bugfix-fix-strcat-may-cause-buffer-overrun.patch
|
||||
Patch9022: feature-introduce-verifyhint-to-detect-hint-variation.patch
|
||||
Patch9023: bugfix-fix-memory-leak-of-strdup-in-collect_full_irq_list.patch
|
||||
Patch9024: bugfix-fix-sleep-interval-when-sleep_interval-is-changed-by.patch
|
||||
Patch9025: feature-add-switch-to-clear-affinity-hint.patch
|
||||
Patch9009: bugfix-fgets-will-get-a-redundant-new-line.patch
|
||||
Patch9010: bugfix-Prevent-inserting-a-duplicate-entry-to-avoid-list-ch.patch
|
||||
Patch9011: bugfix-guess_arm_irq_hints.patch
|
||||
Patch9012: feature-add-new-user-irq-policy-config-rule.patch
|
||||
Patch9013: bugfix-make-the-return-value-of-getline-handled-correct.patch
|
||||
Patch9014: bugfix-change-irq-ban-check-path-to-devpath.patch
|
||||
Patch9015: bugfix-fix-new-irqs-in-hotplug-keep-stay-on-one-numa.patch
|
||||
Patch9016: feature-add-the-switch-of-printing-log.patch
|
||||
Patch9017: bugfix-fix-new-msi-irq-hasnot-been-added-to-rebalance-list.patch
|
||||
Patch9018: bugfix-delete-no-existing-banned-irq.patch
|
||||
Patch9019: bugfix-fix-strcat-may-cause-buffer-overrun.patch
|
||||
Patch9020: feature-introduce-verifyhint-to-detect-hint-variation.patch
|
||||
Patch9021: bugfix-fix-memory-leak-of-strdup-in-collect_full_irq_list.patch
|
||||
Patch9022: feature-add-switch-to-clear-affinity-hint.patch
|
||||
Patch9023: feature-add-new-irq-migrate-rule-to-avoid-high-cpu-irq-load.patch
|
||||
Patch9024: bugfix-prevent-version-cmd-need-an-argument.patch
|
||||
Patch9025: feature-encapsulate-and-compile-the-functions-in-irqbalance-ui.patch
|
||||
Patch9026: feature-enable-irqbalance-to-link-with-multiple-clie.patch
|
||||
Patch9027: feature-irqbalance-Add-ability-for-socket-communicat.patch
|
||||
|
||||
%description
|
||||
Irqbalance is a daemon to help balance the cpu load generated by
|
||||
@ -82,6 +88,20 @@ single unique cpu, so that load is spread as much as possible over
|
||||
an entire processor set, while minimizing cache miss rates for irq
|
||||
handlers.
|
||||
|
||||
%package devel
|
||||
Summary: The development files of irqbalance client
|
||||
Requires: glib2-devel ncurses-devel irqbalance-libs
|
||||
|
||||
%description devel
|
||||
Development files for irqbalance client.
|
||||
|
||||
%package libs
|
||||
Summary: The shared librariy of irqbalance client
|
||||
Requires: glib2 ncurses-libs
|
||||
|
||||
%description libs
|
||||
Shared librariy for irqbalanace client
|
||||
|
||||
%package_help
|
||||
|
||||
%prep
|
||||
@ -91,6 +111,9 @@ handlers.
|
||||
./autogen.sh
|
||||
%configure
|
||||
CFLAGS="%{optflags}" %make_build CFLAGS+='-fstack-protector-strong '
|
||||
cd ui
|
||||
make
|
||||
cd -
|
||||
|
||||
%install
|
||||
install -D -p -m 0755 %{name} %{buildroot}%{_sbindir}/%{name}
|
||||
@ -99,6 +122,9 @@ install -D -p -m 0644 %{SOURCE1} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
|
||||
install -D -p -m 0755 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}.rules
|
||||
install -D -p -m 0755 %{SOURCE3} %{buildroot}%{_sbindir}/irq_balancer
|
||||
|
||||
install -D -p -m 0755 ui/irqbalance_client.h %{buildroot}%{_includedir}/irqbalance_client.h
|
||||
install -D -p -m 0755 ui/libirqbalance_client.so %{buildroot}%{_libdir}/libirqbalance_client.so
|
||||
|
||||
install -d %{buildroot}%{_mandir}/man1/
|
||||
install -p -m 0644 ./%{name}.1 %{buildroot}%{_mandir}/man1/
|
||||
|
||||
@ -113,10 +139,15 @@ make check
|
||||
%{_sysconfdir}/sysconfig/%{name}.rules
|
||||
%{_sbindir}/irq_balancer
|
||||
|
||||
%files devel
|
||||
%{_includedir}/irqbalance_client.h
|
||||
|
||||
%files libs
|
||||
%{_libdir}/libirqbalance_client.so
|
||||
|
||||
%files help
|
||||
%{_mandir}/man1/*
|
||||
|
||||
|
||||
%post
|
||||
%systemd_post %{name}.service
|
||||
|
||||
@ -133,6 +164,12 @@ fi
|
||||
/sbin/chkconfig --del %{name} >/dev/null 2>&1 || :
|
||||
|
||||
%changelog
|
||||
* Wed Mar 11 2020 liuchao<liuchao173@huawei.com> - 3:1.4.0-16
|
||||
- Type:enhanced
|
||||
- ID:NA
|
||||
- SUG:restart
|
||||
- DESC:synchronize patches
|
||||
|
||||
* Mon Dec 30 2019 yuxiangyang<yuxiangyang4@huawei.com> - 3:1.4.0-15
|
||||
- Type:enhanced
|
||||
- ID:NA
|
||||
@ -155,7 +192,7 @@ fi
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
- SUG:restart
|
||||
- DESC:synchronize patches from R8
|
||||
- DESC:synchronize patches
|
||||
|
||||
* Wed Nov 13 2019 liuchao<liuchao173@huawei.com> - 3:1.4.0-11
|
||||
- Type:other
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user