linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-team@lge.com,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	David Miller <davem@davemloft.net>
Subject: [PATCH v2.1] perf ui/tui: Fix possible UI rendering breakage
Date: Tue, 20 Nov 2018 21:07:11 +0900	[thread overview]
Message-ID: <20181120120711.23955-1-namhyung@kernel.org> (raw)
In-Reply-To: <20181120115120.21300-1-namhyung@kernel.org>

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@kernel.org>
---
* use browser->helpline for display instead of helpline (format)

 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(browser->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


  reply	other threads:[~2018-11-20 12:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19 12:20 [PATCH 00/12] perf top: Rework processing code Jiri Olsa
2018-11-19 12:20 ` [PATCH 01/12] perf tools: Fix build on sparc Jiri Olsa
2018-11-19 12:20 ` [PATCH 02/12] perf tools: Rework show_progress for __ordered_events__flush Jiri Olsa
2018-11-19 12:20 ` [PATCH 03/12] perf tools: Add private data to struct ordered_events Jiri Olsa
2018-11-19 12:20 ` [PATCH 04/12] perf top: Save and display the lost count stats Jiri Olsa
2018-11-19 12:20 ` [PATCH 05/12] perf top: Moving lost events warning to helpline Jiri Olsa
2018-11-20  2:04   ` Namhyung Kim
2018-11-20 11:33     ` Namhyung Kim
2018-11-20 11:51       ` [PATCH v2] perf ui/tui: Fix possible UI rendering breakage Namhyung Kim
2018-11-20 12:07         ` Namhyung Kim [this message]
2018-11-20 11:37     ` [PATCHv2 05/12] perf top: Moving lost events warning to helpline Jiri Olsa
2018-11-20 11:41     ` [PATCH " Jiri Olsa
2018-11-19 12:20 ` [PATCH 06/12] perf top: Add processing thread Jiri Olsa
2018-11-19 12:20 ` [PATCH 07/12] perf top: Use cond variable instead of the lock Jiri Olsa
2018-11-19 12:20 ` [PATCH 08/12] perf top: Set session_done when exiting Jiri Olsa
2018-11-19 12:20 ` [PATCH 09/12] perf top: Drop samples which are behind more than refresh rate Jiri Olsa
2018-11-19 12:20 ` [PATCH 10/12] perf top: Save and display the drop count stats Jiri Olsa
2018-11-19 12:20 ` [PATCH 11/12] perf top: Display slow reader warning for when droping samples Jiri Olsa
2018-11-19 12:20 ` [PATCH 12/12] perf top: Move perf_top__reset_sample_counters after counts display Jiri Olsa
2018-11-20  1:26 ` [PATCH 00/12] perf top: Rework processing code David Miller
2018-11-20  2:29 ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181120120711.23955-1-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).