Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf TUI: Don't ignore job control

In its infinite wisdom, by default, SLang sets susp undef, and this can
only be un-done by calling SLtty_set_suspend_state(true). After every
SLang_init_tty().

Additionally, no provisions are made for maintaining the teletype
attributes across suspend/continue (outside of curses emulation
mode(?!), which provides full support, naturally), so we need to save
and restore the flags ourselves, as well as reset the text colours when
going under. We need to also re-draw the screen, and raising SIGWINCH,
shockingly, Just Works.

The correct solution would be to Not Use SLang, but as a stop-gap,
this makes TUI 'perf report' usable.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: yaowenbin <yaowenbin1@huawei.com>
Link: https://lore.kernel.org/r/0354dcae23a8713f75f4fed609e0caec3c6e3cd5.1672174189.git.nabijaczleweli@nabijaczleweli.xyz
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ahelenia Ziemiańska and committed by
Arnaldo Carvalho de Melo
6af6d224 360b045f

+26
+1
tools/perf/ui/browsers/annotate.c
··· 938 938 /* reset abort key so that it can get Ctrl-C as a key */ 939 939 SLang_reset_tty(); 940 940 SLang_init_tty(0, 0, 0); 941 + SLtty_set_suspend_state(true); 941 942 942 943 return map_symbol__tui_annotate(&he->ms, evsel, hbt); 943 944 }
+2
tools/perf/ui/browsers/hists.c
··· 3000 3000 /* reset abort key so that it can get Ctrl-C as a key */ 3001 3001 SLang_reset_tty(); 3002 3002 SLang_init_tty(0, 0, 0); 3003 + SLtty_set_suspend_state(true); 3003 3004 3004 3005 if (min_pcnt) 3005 3006 browser->min_pcnt = min_pcnt; ··· 3668 3667 /* reset abort key so that it can get Ctrl-C as a key */ 3669 3668 SLang_reset_tty(); 3670 3669 SLang_init_tty(0, 0, 0); 3670 + SLtty_set_suspend_state(true); 3671 3671 3672 3672 memset(&action, 0, sizeof(action)); 3673 3673
+1
tools/perf/ui/browsers/scripts.c
··· 166 166 printf("\033[c\033[H\033[J"); 167 167 fflush(stdout); 168 168 SLang_init_tty(0, 0, 0); 169 + SLtty_set_suspend_state(true); 169 170 SLsmg_refresh(); 170 171 } 171 172
+22
tools/perf/ui/tui/setup.c
··· 2 2 #include <signal.h> 3 3 #include <stdbool.h> 4 4 #include <stdlib.h> 5 + #include <termios.h> 5 6 #include <unistd.h> 6 7 #include <linux/kernel.h> 7 8 #ifdef HAVE_BACKTRACE_SUPPORT 8 9 #include <execinfo.h> 9 10 #endif 10 11 12 + #include "../../util/color.h" 11 13 #include "../../util/debug.h" 12 14 #include "../browser.h" 13 15 #include "../helpline.h" ··· 123 121 exit(0); 124 122 } 125 123 124 + static void ui__sigcont(int sig) 125 + { 126 + static struct termios tty; 127 + 128 + if (sig == SIGTSTP) { 129 + while (tcgetattr(SLang_TT_Read_FD, &tty) == -1 && errno == EINTR) 130 + ; 131 + while (write(SLang_TT_Read_FD, PERF_COLOR_RESET, sizeof(PERF_COLOR_RESET) - 1) == -1 && errno == EINTR) 132 + ; 133 + raise(SIGSTOP); 134 + } else { 135 + while (tcsetattr(SLang_TT_Read_FD, TCSADRAIN, &tty) == -1 && errno == EINTR) 136 + ; 137 + raise(SIGWINCH); 138 + } 139 + } 140 + 126 141 int ui__init(void) 127 142 { 128 143 int err; ··· 154 135 err = SLang_init_tty(-1, 0, 0); 155 136 if (err < 0) 156 137 goto out; 138 + SLtty_set_suspend_state(true); 157 139 158 140 err = SLkp_init(); 159 141 if (err < 0) { ··· 169 149 signal(SIGINT, ui__signal); 170 150 signal(SIGQUIT, ui__signal); 171 151 signal(SIGTERM, ui__signal); 152 + signal(SIGTSTP, ui__sigcont); 153 + signal(SIGCONT, ui__sigcont); 172 154 173 155 perf_error__register(&perf_tui_eops); 174 156