From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A27EECAAA3 for ; Fri, 26 Aug 2022 19:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238612AbiHZTUu (ORCPT ); Fri, 26 Aug 2022 15:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbiHZTUr (ORCPT ); Fri, 26 Aug 2022 15:20:47 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756346CD32; Fri, 26 Aug 2022 12:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661541646; x=1693077646; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=+Ad09Os/PUvK/J76FchENgrJ52K2/K/VEG9kiQ+ar/Q=; b=n9is3YBMJkvP0neh/9fwPpzcliUTZb1yENjweqwxbDJNA672BiOklqhC SFbeelea1gRq9pMFixEZU8bXlq+g8TsWlQEyypN7LL8WRwhazzgGjdFd1 jxEu2XPGknTI0/3nFRgzRFejLNauhoyENVZd5/Hmn9Un9wn6E9EQheAle c64UHOLJa5XLFhjwiMj0SgdTi3/5y4GqzixCaC8yCP5hcdOReTPRHc2NB JqJedaaCCVpCADcoPq/jseJEosAipNV1fyvWA6IK3PRTNIZQupKYoYLIB 0ZdtetuN3HbR6lZAM078WnvkQ9bI4+05H3JnXtVkQsGsgHVbFzwqXMEkv g==; X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="293320759" X-IronPort-AV: E=Sophos;i="5.93,266,1654585200"; d="scan'208";a="293320759" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 12:20:46 -0700 X-IronPort-AV: E=Sophos;i="5.93,266,1654585200"; d="scan'208";a="671588431" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.50.209]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 12:20:34 -0700 Message-ID: Date: Fri, 26 Aug 2022 22:20:28 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v3 09/18] perf ui: Update use of pthread mutex Content-Language: en-US To: Namhyung Kim Cc: Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Thomas Gleixner , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=c3=a9_Almeida?= , Nathan Chancellor , Nick Desaulniers , Tom Rix , Weiguo Li , Athira Rajeev , Thomas Richter , Ravi Bangoria , Dario Petrillo , Hewenliang , yaowenbin , Wenyu Liu , Song Liu , Andrii Nakryiko , Dave Marchevsky , Leo Yan , Kim Phillips , Pavithra Gurushankar , Alexandre Truong , Quentin Monnet , William Cohen , Andres Freund , =?UTF-8?Q?Martin_Li=c5=a1ka?= , Colin Ian King , James Clark , Fangrui Song , Stephane Eranian , Kajol Jain , Alexey Bayduraev , Riccardo Mancini , Andi Kleen , Masami Hiramatsu , Zechuan Chen , Jason Wang , Christophe JAILLET , Remi Bernon , linux-kernel , linux-perf-users , bpf , llvm@lists.linux.dev References: <20220824153901.488576-1-irogers@google.com> <20220824153901.488576-10-irogers@google.com> <2cf6edac-6e41-b43c-2bc1-f49cb739201a@intel.com> <43540a3d-e64e-ec08-e12e-aebb236a2efe@intel.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/08/22 22:00, Namhyung Kim wrote: > On Fri, Aug 26, 2022 at 11:53 AM Adrian Hunter wrote: >> Below seems adequate for now, at least logically, but maybe it >> would confuse clang thread-safety analysis? > > I think it's not just about locks, the exit_browser should bail out early > if the setup code was not called. In those cases, use_browser is 0 or -1 unless someone has inserted an invalid perf config like "tui.script=on" or "gtk.script=on". So currently, in cases where exit_browser() is called without setup_browser(), it does nothing. Which means it is only the unconditional mutex_destroy() that needs to be conditional. > > Thanks, > Namhyung > > >> >> diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c >> index 25ded88801a3..6d81be6a349e 100644 >> --- a/tools/perf/ui/setup.c >> +++ b/tools/perf/ui/setup.c >> @@ -73,9 +73,17 @@ int stdio__config_color(const struct option *opt __maybe_unused, >> return 0; >> } >> >> +/* >> + * exit_browser() can get called without setup_browser() having been called >> + * first, so it is necessary to keep track of whether ui__lock has been >> + * initialized. >> + */ >> +static bool ui__lock_initialized; >> + >> void setup_browser(bool fallback_to_pager) >> { >> mutex_init(&ui__lock); >> + ui__lock_initialized = true; >> if (use_browser < 2 && (!isatty(1) || dump_trace)) >> use_browser = 0; >> >> @@ -118,5 +126,6 @@ void exit_browser(bool wait_for_ok) >> default: >> break; >> } >> - mutex_destroy(&ui__lock); >> + if (ui__lock_initialized) >> + mutex_destroy(&ui__lock); >> } >>