[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181120115120.21300-1-namhyung@kernel.org>
Date: Tue, 20 Nov 2018 20:51:20 +0900
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
LKML <linux-kernel@...r.kernel.org>, kernel-team@....com,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
David Miller <davem@...emloft.net>
Subject: [PATCH v2] perf ui/tui: Fix possible UI rendering breakage
The tui_helpline__push() should acquire/release the ui__lock when it
deals with screen setting. Otherwise it could race with display thread
and screen rendering would not be handled properly.
Also move helpline__push/pop out of ui__lock to prevent deadlock.
Fixes: e6e904687949 ("perf ui: Introduce struct ui_helpline")
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
tools/perf/ui/browser.c | 7 ++++---
tools/perf/ui/tui/helpline.c | 17 ++++++++++++-----
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 4f75561424ed..2a99a0fbbcf6 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -294,16 +294,17 @@ int ui_browser__show(struct ui_browser *browser, const char *title,
va_start(ap, helpline);
err = vasprintf(&browser->helpline, helpline, ap);
va_end(ap);
- if (err > 0)
- ui_helpline__push(browser->helpline);
pthread_mutex_unlock(&ui__lock);
+
+ if (err > 0)
+ ui_helpline__push(helpline);
return err ? 0 : -1;
}
void ui_browser__hide(struct ui_browser *browser)
{
- pthread_mutex_lock(&ui__lock);
ui_helpline__pop();
+ pthread_mutex_lock(&ui__lock);
zfree(&browser->helpline);
pthread_mutex_unlock(&ui__lock);
}
diff --git a/tools/perf/ui/tui/helpline.c b/tools/perf/ui/tui/helpline.c
index 4ca799aadb4e..83b6eebb451a 100644
--- a/tools/perf/ui/tui/helpline.c
+++ b/tools/perf/ui/tui/helpline.c
@@ -12,6 +12,14 @@
char ui_helpline__last_msg[1024];
bool tui_helpline__set;
+static void tui_helpline__puts(const char *msg)
+{
+ SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
+ SLsmg_set_color(0);
+ SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
+ SLsmg_refresh();
+}
+
static void tui_helpline__pop(void)
{
}
@@ -20,11 +28,10 @@ static void tui_helpline__push(const char *msg)
{
const size_t sz = sizeof(ui_helpline__current);
- SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
- SLsmg_set_color(0);
- SLsmg_write_nstring((char *)msg, SLtt_Screen_Cols);
- SLsmg_refresh();
+ pthread_mutex_lock(&ui__lock);
strncpy(ui_helpline__current, msg, sz)[sz - 1] = '\0';
+ tui_helpline__puts(msg);
+ pthread_mutex_unlock(&ui__lock);
}
static int tui_helpline__show(const char *format, va_list ap)
@@ -40,7 +47,7 @@ static int tui_helpline__show(const char *format, va_list ap)
tui_helpline__set = true;
if (ui_helpline__last_msg[backlog - 1] == '\n') {
- ui_helpline__puts(ui_helpline__last_msg);
+ tui_helpline__puts(ui_helpline__last_msg);
SLsmg_refresh();
backlog = 0;
}
--
2.19.0
Powered by blists - more mailing lists