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

perf ui: Update use of pthread mutex

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

Signed-off-by: Ian 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: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
82aff6cc 0bd14ac2

+35 -35
+10 -10
tools/perf/ui/browser.c
··· 268 268 269 269 void ui_browser__show_title(struct ui_browser *browser, const char *title) 270 270 { 271 - pthread_mutex_lock(&ui__lock); 271 + mutex_lock(&ui__lock); 272 272 __ui_browser__show_title(browser, title); 273 - pthread_mutex_unlock(&ui__lock); 273 + mutex_unlock(&ui__lock); 274 274 } 275 275 276 276 int ui_browser__show(struct ui_browser *browser, const char *title, ··· 284 284 285 285 browser->refresh_dimensions(browser); 286 286 287 - pthread_mutex_lock(&ui__lock); 287 + mutex_lock(&ui__lock); 288 288 __ui_browser__show_title(browser, title); 289 289 290 290 browser->title = title; ··· 295 295 va_end(ap); 296 296 if (err > 0) 297 297 ui_helpline__push(browser->helpline); 298 - pthread_mutex_unlock(&ui__lock); 298 + mutex_unlock(&ui__lock); 299 299 return err ? 0 : -1; 300 300 } 301 301 302 302 void ui_browser__hide(struct ui_browser *browser) 303 303 { 304 - pthread_mutex_lock(&ui__lock); 304 + mutex_lock(&ui__lock); 305 305 ui_helpline__pop(); 306 306 zfree(&browser->helpline); 307 - pthread_mutex_unlock(&ui__lock); 307 + mutex_unlock(&ui__lock); 308 308 } 309 309 310 310 static void ui_browser__scrollbar_set(struct ui_browser *browser) ··· 352 352 353 353 int ui_browser__refresh(struct ui_browser *browser) 354 354 { 355 - pthread_mutex_lock(&ui__lock); 355 + mutex_lock(&ui__lock); 356 356 __ui_browser__refresh(browser); 357 - pthread_mutex_unlock(&ui__lock); 357 + mutex_unlock(&ui__lock); 358 358 359 359 return 0; 360 360 } ··· 390 390 while (1) { 391 391 off_t offset; 392 392 393 - pthread_mutex_lock(&ui__lock); 393 + mutex_lock(&ui__lock); 394 394 err = __ui_browser__refresh(browser); 395 395 SLsmg_refresh(); 396 - pthread_mutex_unlock(&ui__lock); 396 + mutex_unlock(&ui__lock); 397 397 if (err < 0) 398 398 break; 399 399
+1 -1
tools/perf/ui/browsers/annotate.c
··· 8 8 #include "../../util/hist.h" 9 9 #include "../../util/sort.h" 10 10 #include "../../util/map.h" 11 + #include "../../util/mutex.h" 11 12 #include "../../util/symbol.h" 12 13 #include "../../util/evsel.h" 13 14 #include "../../util/evlist.h" 14 15 #include <inttypes.h> 15 - #include <pthread.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/string.h> 18 18 #include <linux/zalloc.h>
+3 -2
tools/perf/ui/setup.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include <pthread.h> 3 2 #include <dlfcn.h> 4 3 #include <unistd.h> 5 4 ··· 7 8 #include "../util/hist.h" 8 9 #include "ui.h" 9 10 10 - pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; 11 + struct mutex ui__lock; 11 12 void *perf_gtk_handle; 12 13 int use_browser = -1; 13 14 ··· 75 76 76 77 void setup_browser(bool fallback_to_pager) 77 78 { 79 + mutex_init(&ui__lock); 78 80 if (use_browser < 2 && (!isatty(1) || dump_trace)) 79 81 use_browser = 0; 80 82 ··· 118 118 default: 119 119 break; 120 120 } 121 + mutex_destroy(&ui__lock); 121 122 }
+2 -3
tools/perf/ui/tui/helpline.c
··· 2 2 #include <stdio.h> 3 3 #include <stdlib.h> 4 4 #include <string.h> 5 - #include <pthread.h> 6 5 #include <linux/kernel.h> 7 6 #include <linux/string.h> 8 7 ··· 32 33 int ret; 33 34 static int backlog; 34 35 35 - pthread_mutex_lock(&ui__lock); 36 + mutex_lock(&ui__lock); 36 37 ret = vscnprintf(ui_helpline__last_msg + backlog, 37 38 sizeof(ui_helpline__last_msg) - backlog, format, ap); 38 39 backlog += ret; ··· 44 45 SLsmg_refresh(); 45 46 backlog = 0; 46 47 } 47 - pthread_mutex_unlock(&ui__lock); 48 + mutex_unlock(&ui__lock); 48 49 49 50 return ret; 50 51 }
+4 -4
tools/perf/ui/tui/progress.c
··· 45 45 } 46 46 47 47 ui__refresh_dimensions(false); 48 - pthread_mutex_lock(&ui__lock); 48 + mutex_lock(&ui__lock); 49 49 y = SLtt_Screen_Rows / 2 - 2; 50 50 SLsmg_set_color(0); 51 51 SLsmg_draw_box(y, 0, 3, SLtt_Screen_Cols); ··· 56 56 bar = ((SLtt_Screen_Cols - 2) * p->curr) / p->total; 57 57 SLsmg_fill_region(y, 1, 1, bar, ' '); 58 58 SLsmg_refresh(); 59 - pthread_mutex_unlock(&ui__lock); 59 + mutex_unlock(&ui__lock); 60 60 } 61 61 62 62 static void tui_progress__finish(void) ··· 67 67 return; 68 68 69 69 ui__refresh_dimensions(false); 70 - pthread_mutex_lock(&ui__lock); 70 + mutex_lock(&ui__lock); 71 71 y = SLtt_Screen_Rows / 2 - 2; 72 72 SLsmg_set_color(0); 73 73 SLsmg_fill_region(y, 0, 3, SLtt_Screen_Cols, ' '); 74 74 SLsmg_refresh(); 75 - pthread_mutex_unlock(&ui__lock); 75 + mutex_unlock(&ui__lock); 76 76 } 77 77 78 78 static struct ui_progress_ops tui_progress__ops = {
+4 -4
tools/perf/ui/tui/setup.c
··· 29 29 { 30 30 if (force || ui__need_resize) { 31 31 ui__need_resize = 0; 32 - pthread_mutex_lock(&ui__lock); 32 + mutex_lock(&ui__lock); 33 33 SLtt_get_screen_size(); 34 34 SLsmg_reinit_smg(); 35 - pthread_mutex_unlock(&ui__lock); 35 + mutex_unlock(&ui__lock); 36 36 } 37 37 } 38 38 ··· 170 170 "Press any key...", 0); 171 171 172 172 SLtt_set_cursor_visibility(1); 173 - if (!pthread_mutex_trylock(&ui__lock)) { 173 + if (mutex_trylock(&ui__lock)) { 174 174 SLsmg_refresh(); 175 175 SLsmg_reset_smg(); 176 - pthread_mutex_unlock(&ui__lock); 176 + mutex_unlock(&ui__lock); 177 177 } 178 178 SLang_reset_tty(); 179 179 perf_error__unregister(&perf_tui_eops);
+9 -9
tools/perf/ui/tui/util.c
··· 95 95 t = sep + 1; 96 96 } 97 97 98 - pthread_mutex_lock(&ui__lock); 98 + mutex_lock(&ui__lock); 99 99 100 100 max_len += 2; 101 101 nr_lines += 8; ··· 125 125 SLsmg_write_nstring((char *)exit_msg, max_len); 126 126 SLsmg_refresh(); 127 127 128 - pthread_mutex_unlock(&ui__lock); 128 + mutex_unlock(&ui__lock); 129 129 130 130 x += 2; 131 131 len = 0; 132 132 key = ui__getch(delay_secs); 133 133 while (key != K_TIMER && key != K_ENTER && key != K_ESC) { 134 - pthread_mutex_lock(&ui__lock); 134 + mutex_lock(&ui__lock); 135 135 136 136 if (key == K_BKSPC) { 137 137 if (len == 0) { 138 - pthread_mutex_unlock(&ui__lock); 138 + mutex_unlock(&ui__lock); 139 139 goto next_key; 140 140 } 141 141 SLsmg_gotorc(y, x + --len); ··· 147 147 } 148 148 SLsmg_refresh(); 149 149 150 - pthread_mutex_unlock(&ui__lock); 150 + mutex_unlock(&ui__lock); 151 151 152 152 /* XXX more graceful overflow handling needed */ 153 153 if (len == sizeof(buf) - 1) { ··· 215 215 216 216 void ui__info_window(const char *title, const char *text) 217 217 { 218 - pthread_mutex_lock(&ui__lock); 218 + mutex_lock(&ui__lock); 219 219 __ui__info_window(title, text, NULL); 220 220 SLsmg_refresh(); 221 - pthread_mutex_unlock(&ui__lock); 221 + mutex_unlock(&ui__lock); 222 222 } 223 223 224 224 int ui__question_window(const char *title, const char *text, 225 225 const char *exit_msg, int delay_secs) 226 226 { 227 - pthread_mutex_lock(&ui__lock); 227 + mutex_lock(&ui__lock); 228 228 __ui__info_window(title, text, exit_msg); 229 229 SLsmg_refresh(); 230 - pthread_mutex_unlock(&ui__lock); 230 + mutex_unlock(&ui__lock); 231 231 return ui__getch(delay_secs); 232 232 } 233 233
+2 -2
tools/perf/ui/ui.h
··· 2 2 #ifndef _PERF_UI_H_ 3 3 #define _PERF_UI_H_ 1 4 4 5 - #include <pthread.h> 5 + #include "../util/mutex.h" 6 6 #include <stdbool.h> 7 7 #include <linux/compiler.h> 8 8 9 - extern pthread_mutex_t ui__lock; 9 + extern struct mutex ui__lock; 10 10 extern void *perf_gtk_handle; 11 11 12 12 extern int use_browser;