|
|
120141 |
From b65faa2b658e3cf4edf6d39e4bb1e103a47ac0de Mon Sep 17 00:00:00 2001
|
|
|
120141 |
From: Liu Chao <liuchao173@huawei.com>
|
|
|
120141 |
Date: Thu, 30 Jun 2022 10:19:00 +0800
|
|
|
120141 |
Subject: [PATCH 10/14] irqbalance-ui: can't change window when in editing
|
|
|
120141 |
state
|
|
|
120141 |
|
|
|
120141 |
when invoking setup_irqs in settings or invoking settings in setup_irqs, it
|
|
|
120141 |
doesn't break but enters another while loop.
|
|
|
120141 |
For example:
|
|
|
120141 |
# gdb program `pidof irqbalance-ui`
|
|
|
120141 |
(gdb) bt
|
|
|
120141 |
#0 0x0000ffffb0dcc7b0 in poll () from /usr/lib64/libc.so.6
|
|
|
120141 |
#1 0x0000ffffb0e9097c in _nc_timed_wait () from /usr/lib64/libtinfo.so.6
|
|
|
120141 |
#2 0x0000ffffb0ecc154 in _nc_wgetch () from /usr/lib64/libncursesw.so.6
|
|
|
120141 |
#3 0x0000ffffb0eccb18 in wgetch () from /usr/lib64/libncursesw.so.6
|
|
|
120141 |
#4 0x00000000004045d4 in setup_irqs () at ui/ui.c:637
|
|
|
120141 |
#5 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#6 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#7 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#8 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#9 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#10 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#11 0x0000000000404084 in settings () at ui/ui.c:614
|
|
|
120141 |
#12 0x0000000000401fac in key_loop (data=<optimized out>) at ui/irqbalance-ui.c:387
|
|
|
120141 |
#13 0x0000ffffb105371c in ?? () from /usr/lib64/libglib-2.0.so.0
|
|
|
120141 |
#14 0x0000ffffb1052a84 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
|
|
|
120141 |
#15 0x0000ffffb1052e38 in ?? () from /usr/lib64/libglib-2.0.so.0
|
|
|
120141 |
#16 0x0000ffffb1053188 in g_main_loop_run () from /usr/lib64/libglib-2.0.so.0
|
|
|
120141 |
#17 0x000000000040196c in main (argc=<optimized out>, argv=<optimized out>) at ui/irqbalance-ui.c:445
|
|
|
120141 |
|
|
|
120141 |
Signed-off-by: Liu Chao <liuchao173@huawei.com>
|
|
|
120141 |
---
|
|
|
120141 |
ui/irqbalance-ui.c | 39 ++++++++++---
|
|
|
120141 |
ui/ui.c | 137 ++++++++++++---------------------------------
|
|
|
120141 |
ui/ui.h | 2 +-
|
|
|
120141 |
3 files changed, 69 insertions(+), 109 deletions(-)
|
|
|
120141 |
|
|
|
120141 |
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
|
|
120141 |
index 3ad3553..89ed94a 100644
|
|
|
120141 |
--- a/ui/irqbalance-ui.c
|
|
|
120141 |
+++ b/ui/irqbalance-ui.c
|
|
|
120141 |
@@ -16,11 +16,16 @@
|
|
|
120141 |
#include "helpers.h"
|
|
|
120141 |
|
|
|
120141 |
|
|
|
120141 |
+enum states {
|
|
|
120141 |
+ STATE_TREE,
|
|
|
120141 |
+ STATE_SETTINGS,
|
|
|
120141 |
+ STATE_SETUP_IRQS
|
|
|
120141 |
+};
|
|
|
120141 |
+int state;
|
|
|
120141 |
int irqbalance_pid = -1;
|
|
|
120141 |
GList *tree = NULL;
|
|
|
120141 |
setup_t setup;
|
|
|
120141 |
GMainLoop *main_loop;
|
|
|
120141 |
-int is_tree = 1;
|
|
|
120141 |
static int default_bufsz = 8192;
|
|
|
120141 |
|
|
|
120141 |
struct msghdr * create_credentials_msg()
|
|
|
120141 |
@@ -359,7 +364,7 @@ gboolean rescan_tree(gpointer data __attribute__((unused)))
|
|
|
120141 |
parse_setup(setup_data);
|
|
|
120141 |
char *irqbalance_data = get_data(STATS);
|
|
|
120141 |
parse_into_tree(irqbalance_data);
|
|
|
120141 |
- if(is_tree) {
|
|
|
120141 |
+ if(state == STATE_TREE) {
|
|
|
120141 |
display_tree();
|
|
|
120141 |
}
|
|
|
120141 |
free(setup_data);
|
|
|
120141 |
@@ -375,16 +380,35 @@ gboolean key_loop(gpointer data __attribute__((unused)))
|
|
|
120141 |
close_window(0);
|
|
|
120141 |
break;
|
|
|
120141 |
case KEY_F(3):
|
|
|
120141 |
- is_tree = 1;
|
|
|
120141 |
- display_tree();
|
|
|
120141 |
+ if (state == STATE_SETTINGS || state == STATE_SETUP_IRQS) {
|
|
|
120141 |
+ state = STATE_TREE;
|
|
|
120141 |
+ display_tree();
|
|
|
120141 |
+ }
|
|
|
120141 |
break;
|
|
|
120141 |
case KEY_F(4):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
+ if (state == STATE_TREE || state == STATE_SETUP_IRQS) {
|
|
|
120141 |
+ state = STATE_SETTINGS;
|
|
|
120141 |
+ settings();
|
|
|
120141 |
+ }
|
|
|
120141 |
settings();
|
|
|
120141 |
break;
|
|
|
120141 |
case KEY_F(5):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
- setup_irqs();
|
|
|
120141 |
+ if (state == STATE_TREE || state == STATE_SETTINGS) {
|
|
|
120141 |
+ state = STATE_SETUP_IRQS;
|
|
|
120141 |
+ setup_irqs();
|
|
|
120141 |
+ }
|
|
|
120141 |
+ break;
|
|
|
120141 |
+ case 'c':
|
|
|
120141 |
+ if (state == STATE_SETTINGS)
|
|
|
120141 |
+ handle_cpu_banning();
|
|
|
120141 |
+ break;
|
|
|
120141 |
+ case 'i':
|
|
|
120141 |
+ if (state == STATE_SETUP_IRQS)
|
|
|
120141 |
+ handle_irq_banning();
|
|
|
120141 |
+ break;
|
|
|
120141 |
+ case 's':
|
|
|
120141 |
+ if (state == STATE_SETTINGS)
|
|
|
120141 |
+ handle_sleep_setting();
|
|
|
120141 |
break;
|
|
|
120141 |
default:
|
|
|
120141 |
break;
|
|
|
120141 |
@@ -437,6 +461,7 @@ int main(int argc, char **argv)
|
|
|
120141 |
}
|
|
|
120141 |
}
|
|
|
120141 |
|
|
|
120141 |
+ state = STATE_TREE;
|
|
|
120141 |
init();
|
|
|
120141 |
|
|
|
120141 |
main_loop = g_main_loop_new(NULL, FALSE);
|
|
|
120141 |
diff --git a/ui/ui.c b/ui/ui.c
|
|
|
120141 |
index beafe3a..1e211de 100644
|
|
|
120141 |
--- a/ui/ui.c
|
|
|
120141 |
+++ b/ui/ui.c
|
|
|
120141 |
@@ -273,7 +273,8 @@ void handle_cpu_banning()
|
|
|
120141 |
attrset(COLOR_PAIR(5));
|
|
|
120141 |
mvprintw(LINES - 2, 1,
|
|
|
120141 |
"Press <S> for changing sleep setup, <C> for CPU ban setup. ");
|
|
|
120141 |
- move(LINES - 1, COLS - 1);
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
refresh();
|
|
|
120141 |
break;
|
|
|
120141 |
case 's':
|
|
|
120141 |
@@ -287,8 +288,8 @@ void handle_cpu_banning()
|
|
|
120141 |
attrset(COLOR_PAIR(5));
|
|
|
120141 |
mvprintw(LINES - 2, 1,
|
|
|
120141 |
"Press <S> for changing sleep setup, <C> for CPU ban setup. ");
|
|
|
120141 |
- attrset(COLOR_PAIR(3));
|
|
|
120141 |
- move(LINES - 1, COLS - 1);
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
refresh();
|
|
|
120141 |
char settings_string[1024] = "settings cpus \0";
|
|
|
120141 |
for_each_cpu(all_cpus, get_new_cpu_ban_values, settings_string);
|
|
|
120141 |
@@ -302,16 +303,6 @@ void handle_cpu_banning()
|
|
|
120141 |
processing = 0;
|
|
|
120141 |
close_window(0);
|
|
|
120141 |
break;
|
|
|
120141 |
- case KEY_F(3):
|
|
|
120141 |
- is_tree = 1;
|
|
|
120141 |
- processing = 0;
|
|
|
120141 |
- display_tree();
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(5):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
- processing = 0;
|
|
|
120141 |
- setup_irqs();
|
|
|
120141 |
- break;
|
|
|
120141 |
default:
|
|
|
120141 |
break;
|
|
|
120141 |
}
|
|
|
120141 |
@@ -475,7 +466,8 @@ void handle_irq_banning()
|
|
|
120141 |
attrset(COLOR_PAIR(5));
|
|
|
120141 |
mvprintw(LINES - 2, 1, "Press for setting up IRQ banning.\
|
|
|
120141 |
");
|
|
|
120141 |
- move(LINES - 1, COLS - 1);
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
refresh();
|
|
|
120141 |
break;
|
|
|
120141 |
case 's':
|
|
|
120141 |
@@ -490,7 +482,8 @@ void handle_irq_banning()
|
|
|
120141 |
mvprintw(LINES - 2, 1, "Press for setting up IRQ banning.\
|
|
|
120141 |
");
|
|
|
120141 |
attrset(COLOR_PAIR(3));
|
|
|
120141 |
- move(LINES - 1, COLS - 1);
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
refresh();
|
|
|
120141 |
char settings_string[1024] = BAN_IRQS;
|
|
|
120141 |
for_each_irq(all_irqs, get_new_irq_ban_values, settings_string);
|
|
|
120141 |
@@ -504,22 +497,35 @@ void handle_irq_banning()
|
|
|
120141 |
processing = 0;
|
|
|
120141 |
close_window(0);
|
|
|
120141 |
break;
|
|
|
120141 |
- case KEY_F(3):
|
|
|
120141 |
- is_tree = 1;
|
|
|
120141 |
- processing = 0;
|
|
|
120141 |
- display_tree();
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(4):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
- processing = 0;
|
|
|
120141 |
- settings();
|
|
|
120141 |
- break;
|
|
|
120141 |
default:
|
|
|
120141 |
break;
|
|
|
120141 |
}
|
|
|
120141 |
}
|
|
|
120141 |
}
|
|
|
120141 |
|
|
|
120141 |
+void handle_sleep_setting()
|
|
|
120141 |
+{
|
|
|
120141 |
+ char info[128] = "Current sleep interval between rebalancing: \0";
|
|
|
120141 |
+ uint8_t sleep_input_offset = strlen(info) + 3;
|
|
|
120141 |
+ mvprintw(LINES - 1, 1, "Press ESC for discarding your input.\
|
|
|
120141 |
+ ");
|
|
|
120141 |
+ attrset(COLOR_PAIR(0));
|
|
|
120141 |
+ mvprintw(LINES - 2, 1, " \
|
|
|
120141 |
+ ");
|
|
|
120141 |
+ uint64_t new_sleep = get_valid_sleep_input(sleep_input_offset);
|
|
|
120141 |
+ if(new_sleep != setup.sleep) {
|
|
|
120141 |
+ setup.sleep = new_sleep;
|
|
|
120141 |
+ char settings_data[128];
|
|
|
120141 |
+ snprintf(settings_data, 128, "%s %" PRIu64, SET_SLEEP, new_sleep);
|
|
|
120141 |
+ send_settings(settings_data);
|
|
|
120141 |
+ }
|
|
|
120141 |
+ attrset(COLOR_PAIR(5));
|
|
|
120141 |
+ mvprintw(LINES - 2, 1, "Press <S> for changing sleep setup, <C> for CPU ban setup. ");
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
+ refresh();
|
|
|
120141 |
+}
|
|
|
120141 |
+
|
|
|
120141 |
void init()
|
|
|
120141 |
{
|
|
|
120141 |
signal(SIGINT, close_window);
|
|
|
120141 |
@@ -563,60 +569,15 @@ void settings()
|
|
|
120141 |
parse_setup(setup_data);
|
|
|
120141 |
|
|
|
120141 |
char info[128] = "Current sleep interval between rebalancing: \0";
|
|
|
120141 |
- uint8_t sleep_input_offset = strlen(info) + 3;
|
|
|
120141 |
snprintf(info + strlen(info), 128 - strlen(info), "%" PRIu64 "\n", setup.sleep);
|
|
|
120141 |
attrset(COLOR_PAIR(1));
|
|
|
120141 |
mvprintw(2, 3, "%s", info);
|
|
|
120141 |
print_all_cpus();
|
|
|
120141 |
-
|
|
|
120141 |
- int user_input = 1;
|
|
|
120141 |
- while(user_input) {
|
|
|
120141 |
- attrset(COLOR_PAIR(5));
|
|
|
120141 |
- mvprintw(LINES - 2, 1,
|
|
|
120141 |
- "Press <S> for changing sleep setup, <C> for CPU ban setup. ");
|
|
|
120141 |
- show_frame();
|
|
|
120141 |
- show_footer();
|
|
|
120141 |
- refresh();
|
|
|
120141 |
- int c = getch();
|
|
|
120141 |
- switch(c) {
|
|
|
120141 |
- case 's': {
|
|
|
120141 |
- mvprintw(LINES - 1, 1, "Press ESC for discarding your input.\
|
|
|
120141 |
- ");
|
|
|
120141 |
- attrset(COLOR_PAIR(0));
|
|
|
120141 |
- mvprintw(LINES - 2, 1, " \
|
|
|
120141 |
- ");
|
|
|
120141 |
- uint64_t new_sleep = get_valid_sleep_input(sleep_input_offset);
|
|
|
120141 |
- if(new_sleep != setup.sleep) {
|
|
|
120141 |
- setup.sleep = new_sleep;
|
|
|
120141 |
- char settings_data[128];
|
|
|
120141 |
- snprintf(settings_data, 128, "%s %" PRIu64, SET_SLEEP, new_sleep);
|
|
|
120141 |
- send_settings(settings_data);
|
|
|
120141 |
- }
|
|
|
120141 |
- break;
|
|
|
120141 |
- }
|
|
|
120141 |
- case 'c':
|
|
|
120141 |
- handle_cpu_banning();
|
|
|
120141 |
- break;
|
|
|
120141 |
- /* We need to include window changing options as well because the
|
|
|
120141 |
- * related char was eaten up by getch() already */
|
|
|
120141 |
- case 'q':
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- close_window(0);
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(3):
|
|
|
120141 |
- is_tree = 1;
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- display_tree();
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(5):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- setup_irqs();
|
|
|
120141 |
- break;
|
|
|
120141 |
- default:
|
|
|
120141 |
- break;
|
|
|
120141 |
- }
|
|
|
120141 |
- }
|
|
|
120141 |
+ attrset(COLOR_PAIR(5));
|
|
|
120141 |
+ mvprintw(LINES - 2, 1, "Press <S> for changing sleep setup, <C> for CPU ban setup. ");
|
|
|
120141 |
+ show_frame();
|
|
|
120141 |
+ show_footer();
|
|
|
120141 |
+ refresh();
|
|
|
120141 |
free(setup_data);
|
|
|
120141 |
}
|
|
|
120141 |
|
|
|
120141 |
@@ -631,32 +592,6 @@ void setup_irqs()
|
|
|
120141 |
show_frame();
|
|
|
120141 |
show_footer();
|
|
|
120141 |
refresh();
|
|
|
120141 |
-
|
|
|
120141 |
- int user_input = 1;
|
|
|
120141 |
- while(user_input) {
|
|
|
120141 |
- int c = getch();
|
|
|
120141 |
- switch(c) {
|
|
|
120141 |
- case 'i':
|
|
|
120141 |
- handle_irq_banning();
|
|
|
120141 |
- break;
|
|
|
120141 |
- case 'q':
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- close_window(0);
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(3):
|
|
|
120141 |
- is_tree = 1;
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- display_tree();
|
|
|
120141 |
- break;
|
|
|
120141 |
- case KEY_F(4):
|
|
|
120141 |
- is_tree = 0;
|
|
|
120141 |
- user_input = 0;
|
|
|
120141 |
- settings();
|
|
|
120141 |
- break;
|
|
|
120141 |
- default:
|
|
|
120141 |
- break;
|
|
|
120141 |
- }
|
|
|
120141 |
- }
|
|
|
120141 |
}
|
|
|
120141 |
|
|
|
120141 |
void display_tree_node_irqs(irq_t *irq, void *data)
|
|
|
120141 |
diff --git a/ui/ui.h b/ui/ui.h
|
|
|
120141 |
index 0aa8280..ca2a3a6 100644
|
|
|
120141 |
--- a/ui/ui.h
|
|
|
120141 |
+++ b/ui/ui.h
|
|
|
120141 |
@@ -13,7 +13,6 @@
|
|
|
120141 |
|
|
|
120141 |
extern GList *tree;
|
|
|
120141 |
extern setup_t setup;
|
|
|
120141 |
-extern int is_tree;
|
|
|
120141 |
|
|
|
120141 |
void show_frame();
|
|
|
120141 |
void show_footer();
|
|
|
120141 |
@@ -29,6 +28,7 @@ void display_banned_cpus();
|
|
|
120141 |
int toggle_cpu(GList *cpu_list, int cpu_number);
|
|
|
120141 |
void get_new_cpu_ban_values(cpu_ban_t *cpu, void *data);
|
|
|
120141 |
void get_cpu();
|
|
|
120141 |
+void handle_sleep_setting();
|
|
|
120141 |
void handle_cpu_banning();
|
|
|
120141 |
|
|
|
120141 |
void copy_assigned_obj(int *number, void *data);
|
|
|
120141 |
--
|
|
|
120141 |
2.33.1
|
|
|
120141 |
|