Commit 82aff6cc authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf ui: Update use of pthread mutex



Switch to the use of mutex wrappers that provide better error checking.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Truong <alexandre.truong@arm.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: André Almeida <andrealmeid@igalia.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Colin Ian King <colin.king@intel.com>
Cc: Dario Petrillo <dario.pk1@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Dave Marchevsky <davemarchevsky@fb.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Fangrui Song <maskray@google.com>
Cc: Hewenliang <hewenliang4@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jason Wang <wangborong@cdjrlc.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin Liška <mliska@suse.cz>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Pavithra Gurushankar <gpavithrasha@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Remi Bernon <rbernon@codeweavers.com>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tom Rix <trix@redhat.com>
Cc: Weiguo Li <liwg06@foxmail.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Zechuan Chen <chenzechuan1@huawei.com>
Cc: bpf@vger.kernel.org
Cc: llvm@lists.linux.dev
Cc: yaowenbin <yaowenbin1@huawei.com>
Link: https://lore.kernel.org/r/20220826164242.43412-10-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0bd14ac2
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -268,9 +268,9 @@ void __ui_browser__show_title(struct ui_browser *browser, const char *title)

void ui_browser__show_title(struct ui_browser *browser, const char *title)
{
	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	__ui_browser__show_title(browser, title);
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);
}

int ui_browser__show(struct ui_browser *browser, const char *title,
@@ -284,7 +284,7 @@ int ui_browser__show(struct ui_browser *browser, const char *title,

	browser->refresh_dimensions(browser);

	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	__ui_browser__show_title(browser, title);

	browser->title = title;
@@ -295,16 +295,16 @@ int ui_browser__show(struct ui_browser *browser, const char *title,
	va_end(ap);
	if (err > 0)
		ui_helpline__push(browser->helpline);
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);
	return err ? 0 : -1;
}

void ui_browser__hide(struct ui_browser *browser)
{
	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	ui_helpline__pop();
	zfree(&browser->helpline);
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);
}

static void ui_browser__scrollbar_set(struct ui_browser *browser)
@@ -352,9 +352,9 @@ static int __ui_browser__refresh(struct ui_browser *browser)

int ui_browser__refresh(struct ui_browser *browser)
{
	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	__ui_browser__refresh(browser);
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);

	return 0;
}
@@ -390,10 +390,10 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs)
	while (1) {
		off_t offset;

		pthread_mutex_lock(&ui__lock);
		mutex_lock(&ui__lock);
		err = __ui_browser__refresh(browser);
		SLsmg_refresh();
		pthread_mutex_unlock(&ui__lock);
		mutex_unlock(&ui__lock);
		if (err < 0)
			break;

+1 −1
Original line number Diff line number Diff line
@@ -8,11 +8,11 @@
#include "../../util/hist.h"
#include "../../util/sort.h"
#include "../../util/map.h"
#include "../../util/mutex.h"
#include "../../util/symbol.h"
#include "../../util/evsel.h"
#include "../../util/evlist.h"
#include <inttypes.h>
#include <pthread.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/zalloc.h>
+3 −2
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
#include <pthread.h>
#include <dlfcn.h>
#include <unistd.h>

@@ -8,7 +7,7 @@
#include "../util/hist.h"
#include "ui.h"

pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
struct mutex ui__lock;
void *perf_gtk_handle;
int use_browser = -1;

@@ -76,6 +75,7 @@ int stdio__config_color(const struct option *opt __maybe_unused,

void setup_browser(bool fallback_to_pager)
{
	mutex_init(&ui__lock);
	if (use_browser < 2 && (!isatty(1) || dump_trace))
		use_browser = 0;

@@ -118,4 +118,5 @@ void exit_browser(bool wait_for_ok)
	default:
		break;
	}
	mutex_destroy(&ui__lock);
}
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <linux/kernel.h>
#include <linux/string.h>

@@ -33,7 +32,7 @@ static int tui_helpline__show(const char *format, va_list ap)
	int ret;
	static int backlog;

	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	ret = vscnprintf(ui_helpline__last_msg + backlog,
			sizeof(ui_helpline__last_msg) - backlog, format, ap);
	backlog += ret;
@@ -45,7 +44,7 @@ static int tui_helpline__show(const char *format, va_list ap)
		SLsmg_refresh();
		backlog = 0;
	}
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);

	return ret;
}
+4 −4
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ static void tui_progress__update(struct ui_progress *p)
	}

	ui__refresh_dimensions(false);
	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	y = SLtt_Screen_Rows / 2 - 2;
	SLsmg_set_color(0);
	SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols);
@@ -56,7 +56,7 @@ static void tui_progress__update(struct ui_progress *p)
	bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total;
	SLsmg_fill_region(y, 1, 1, bar, ' ');
	SLsmg_refresh();
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);
}

static void tui_progress__finish(void)
@@ -67,12 +67,12 @@ static void tui_progress__finish(void)
		return;

	ui__refresh_dimensions(false);
	pthread_mutex_lock(&ui__lock);
	mutex_lock(&ui__lock);
	y = SLtt_Screen_Rows / 2 - 2;
	SLsmg_set_color(0);
	SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' ');
	SLsmg_refresh();
	pthread_mutex_unlock(&ui__lock);
	mutex_unlock(&ui__lock);
}

static struct ui_progress_ops tui_progress__ops = {
Loading