Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4085329rdh; Tue, 28 Nov 2023 11:21:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMYkR5w0rDK6edaWpMUMKi6gOTydsw/cOrs1tVIpwst53EGfNWnxHxC5fmOvy+c1zgKX23 X-Received: by 2002:a05:6808:19aa:b0:3b8:339a:9fa3 with SMTP id bj42-20020a05680819aa00b003b8339a9fa3mr22499838oib.10.1701199290480; Tue, 28 Nov 2023 11:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701199290; cv=none; d=google.com; s=arc-20160816; b=T9i1xrCHnigT3S1BkfNlNEqgraHvq+vIrHZPWCvZJAKyqn0xIe+3RAkOUHBWNcJS1h npLqzAbF8fcAf0Pm5fc4kCRmP+AXzHkTpmLZritqIe6v6lh9jMw2qaZPd7yFMPt1gidS 5n3pOUmyeQA8Eib2roBoFBhCVb7pNzUeqoppob1dfriycd8hYpHPB1jZ2Aw9spvWQ2WO 92duE1My4+ZZTl6SvoIWN6xw8UY8Rp52C6+QaRCh1MVV5OaLutFD59W7kYeUIttklcFG B+rxjY2vB7LicJqpZAD7KcMiq437yFQfK5sYW2GLIWDJCA2eWBYgplECG/NqmEwkFBvI 68hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=C2kX/2e3hW2xYuQeL6N8B1cfHiFYGSQRCDO5Myxr9Ek=; fh=Pbu1BQwhCOAA2d/C0IOLVYR5czI2/+Avx4u+s0uioL8=; b=OmFVLxmiHnidAz35b9GYRToLwZkIUIWZhriOsNuBHEbw5v4O7Z1GMfN+2inFSQQsoX xlsS24FrPAvexte0ragiQGAEDrqEZz0XFdMGMFEM0dFbzY4KExjulj1KnlW3wPbHYLJ4 hFnr8TCxSf/W80Kwij6JvBRFucrwCSaJOSHyxJXEIHX7bYiLhfPXljfU6pMmVC+r+Ddh stUUOZTRhtU2RqW8DmhV+enwttFwnqq+5F1V4Su8xRkEjfci+fw0S59kVDIrsdKIb/UF HAWWa54lQLsXEnmE6zrv+8Y3nPoEI0NA16bj/ZpXpaUpNlxMtokpcLz/JF5d2M6DAcZF 2oRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q+yjBtnf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 23-20020a630017000000b00578eafd0826si12100148pga.398.2023.11.28.11.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 11:21:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Q+yjBtnf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 57D1480A7912; Tue, 28 Nov 2023 11:21:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346190AbjK1TVK (ORCPT + 99 others); Tue, 28 Nov 2023 14:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344921AbjK1TVI (ORCPT ); Tue, 28 Nov 2023 14:21:08 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927121998 for ; Tue, 28 Nov 2023 11:21:13 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40b35199f94so12175e9.0 for ; Tue, 28 Nov 2023 11:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701199272; x=1701804072; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=C2kX/2e3hW2xYuQeL6N8B1cfHiFYGSQRCDO5Myxr9Ek=; b=Q+yjBtnfYkpbLTeio0fdiG/FnCqPVL1DIezBqIQYe93Yg6vhAmN7a17yWqyUZONXO9 T9ZuqkrtSDaUOhu872WfQpxPd1vXb9AHs9Wglx/umiaYGoI/riEekoHSYL2jAwLhUuv2 Oi4HcwulemIOLIrKPYhlDIIdvBMI9JT3KA2gn3iZ1wEeocus8qxeMyGb59dKf5i83Y4A H/u2e+3wyWbThIyNCHf0oG+tQLCNydt6UlnBzcvIEMKPY2neRS6cDNhdMNQ+17dz13qs au9Bu4N+0D4unmP/oo/vyys8fsV8rjwkpdZNQTdN2Y5Wri/iSGEdC77y17uoa0EytJ0s QrGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701199272; x=1701804072; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C2kX/2e3hW2xYuQeL6N8B1cfHiFYGSQRCDO5Myxr9Ek=; b=t7fESfgb92y8w4kcSA4V7AkK26ZDGNuOsZMDwmdEwn+TbJqcgvE0k3K4WesSbkbU+a GjYrXHFqCOURNm2LFVEhif5ZZCBI9mS3D4YigNxswBMQsw+bGeacRHZqB/eVfCJag14U u7OEH8DtdGJgso8NMqmPHJHCdcAd3VEg8sVX/X1wOH+tdKUKj1HbJbtEfqPHAne/Ztmm Q0LAXp1d4TmFsTzAMOBiKNPe5VmkP2E4fVR95+fKVThzJyvRV8bFWHZH+RGZvBtsosTp AdKeEyCwQZ6gYtIsEFV/VXsLIR3G1lbfl2NvLjqywGt8QCfFHPSmIrUsI2xiYPr14nqL 2Wxg== X-Gm-Message-State: AOJu0Yx3Cb8zRLxr1UN51USIJVPytgUy2+bTpBRvRpNAh1NA1fOcXxJk bOebmpDL+9j/yLhIipxj1nNVQZszgH73ocKt1vFXOA== X-Received: by 2002:a05:600c:5112:b0:40b:2979:9cc2 with SMTP id o18-20020a05600c511200b0040b29799cc2mr820326wms.1.1701199271844; Tue, 28 Nov 2023 11:21:11 -0800 (PST) MIME-Version: 1.0 References: <20231128175441.721579-1-namhyung@kernel.org> <20231128175441.721579-7-namhyung@kernel.org> In-Reply-To: <20231128175441.721579-7-namhyung@kernel.org> From: Ian Rogers Date: Tue, 28 Nov 2023 11:20:59 -0800 Message-ID: Subject: Re: [PATCH 6/8] perf annotate: Ensure init/exit for global options To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 28 Nov 2023 11:21:27 -0800 (PST) On Tue, Nov 28, 2023 at 9:54=E2=80=AFAM Namhyung Kim = wrote: > > Now it only cares about the global options so it can just handle it > without the argument. If annotate_opts were accessed by a function then you could pthread_once the initialization on the first call to get annotate_opts. Removing annotation_options__init/exit would remove some potential for error. Thanks, Ian > Signed-off-by: Namhyung Kim > --- > tools/perf/builtin-annotate.c | 8 ++++---- > tools/perf/builtin-report.c | 8 ++++---- > tools/perf/builtin-top.c | 8 ++++---- > tools/perf/util/annotate.c | 19 +++++++++++-------- > tools/perf/util/annotate.h | 8 ++++---- > 5 files changed, 27 insertions(+), 24 deletions(-) > > diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.= c > index 87af95634879..9b3dd456a1ee 100644 > --- a/tools/perf/builtin-annotate.c > +++ b/tools/perf/builtin-annotate.c > @@ -616,13 +616,13 @@ int cmd_annotate(int argc, const char **argv) > set_option_flag(options, 0, "show-total-period", PARSE_OPT_EXCLUS= IVE); > set_option_flag(options, 0, "show-nr-samples", PARSE_OPT_EXCLUSIV= E); > > - annotation_options__init(&annotate_opts); > + annotation_options__init(); > > ret =3D hists__init(); > if (ret < 0) > return ret; > > - annotation_config__init(&annotate_opts); > + annotation_config__init(); > > argc =3D parse_options(argc, argv, options, annotate_usage, 0); > if (argc) { > @@ -652,7 +652,7 @@ int cmd_annotate(int argc, const char **argv) > return -ENOMEM; > } > > - if (annotate_check_args(&annotate_opts) < 0) > + if (annotate_check_args() < 0) > return -EINVAL; > > #ifdef HAVE_GTK2_SUPPORT > @@ -733,7 +733,7 @@ int cmd_annotate(int argc, const char **argv) > #ifndef NDEBUG > perf_session__delete(annotate.session); > #endif > - annotation_options__exit(&annotate_opts); > + annotation_options__exit(); > > return ret; > } > diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c > index bc0d986c1e0c..17fb171e898b 100644 > --- a/tools/perf/builtin-report.c > +++ b/tools/perf/builtin-report.c > @@ -1430,7 +1430,7 @@ int cmd_report(int argc, const char **argv) > */ > symbol_conf.keep_exited_threads =3D true; > > - annotation_options__init(&annotate_opts); > + annotation_options__init(); > > ret =3D perf_config(report__config, &report); > if (ret) > @@ -1464,7 +1464,7 @@ int cmd_report(int argc, const char **argv) > return -ENOMEM; > } > > - if (annotate_check_args(&annotate_opts) < 0) { > + if (annotate_check_args() < 0) { > ret =3D -EINVAL; > goto exit; > } > @@ -1696,7 +1696,7 @@ int cmd_report(int argc, const char **argv) > */ > symbol_conf.priv_size +=3D sizeof(u32); > } > - annotation_config__init(&annotate_opts); > + annotation_config__init(); > } > > if (symbol__init(&session->header.env) < 0) > @@ -1750,7 +1750,7 @@ int cmd_report(int argc, const char **argv) > zstd_fini(&(session->zstd_data)); > perf_session__delete(session); > exit: > - annotation_options__exit(&annotate_opts); > + annotation_options__exit(); > free(sort_order_help); > free(field_order_help); > return ret; > diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c > index 60399e4233ee..0de963ca3196 100644 > --- a/tools/perf/builtin-top.c > +++ b/tools/perf/builtin-top.c > @@ -1608,7 +1608,7 @@ int cmd_top(int argc, const char **argv) > if (status < 0) > return status; > > - annotation_options__init(&annotate_opts); > + annotation_options__init(); > > annotate_opts.min_pcnt =3D 5; > annotate_opts.context =3D 4; > @@ -1660,7 +1660,7 @@ int cmd_top(int argc, const char **argv) > if (status) > goto out_delete_evlist; > > - if (annotate_check_args(&annotate_opts) < 0) > + if (annotate_check_args() < 0) > goto out_delete_evlist; > > if (!top.evlist->core.nr_entries) { > @@ -1786,7 +1786,7 @@ int cmd_top(int argc, const char **argv) > if (status < 0) > goto out_delete_evlist; > > - annotation_config__init(&annotate_opts); > + annotation_config__init(); > > symbol_conf.try_vmlinux_path =3D (symbol_conf.vmlinux_name =3D=3D= NULL); > status =3D symbol__init(NULL); > @@ -1839,7 +1839,7 @@ int cmd_top(int argc, const char **argv) > out_delete_evlist: > evlist__delete(top.evlist); > perf_session__delete(top.session); > - annotation_options__exit(&annotate_opts); > + annotation_options__exit(); > > return status; > } > diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c > index daff9af552f4..626ff3baeb85 100644 > --- a/tools/perf/util/annotate.c > +++ b/tools/perf/util/annotate.c > @@ -3416,8 +3416,10 @@ static int annotation__config(const char *var, con= st char *value, void *data) > return 0; > } > > -void annotation_options__init(struct annotation_options *opt) > +void annotation_options__init(void) > { > + struct annotation_options *opt =3D &annotate_opts; > + > memset(opt, 0, sizeof(*opt)); > > /* Default values. */ > @@ -3428,16 +3430,15 @@ void annotation_options__init(struct annotation_o= ptions *opt) > opt->percent_type =3D PERCENT_PERIOD_LOCAL; > } > > - > -void annotation_options__exit(struct annotation_options *opt) > +void annotation_options__exit(void) > { > - zfree(&opt->disassembler_style); > - zfree(&opt->objdump_path); > + zfree(&annotate_opts.disassembler_style); > + zfree(&annotate_opts.objdump_path); > } > > -void annotation_config__init(struct annotation_options *opt) > +void annotation_config__init(void) > { > - perf_config(annotation__config, opt); > + perf_config(annotation__config, &annotate_opts); > } > > static unsigned int parse_percent_type(char *str1, char *str2) > @@ -3491,8 +3492,10 @@ int annotate_parse_percent_type(const struct optio= n *opt __maybe_unused, const c > return err; > } > > -int annotate_check_args(struct annotation_options *args) > +int annotate_check_args(void) > { > + struct annotation_options *args =3D &annotate_opts; > + > if (args->prefix_strip && !args->prefix) { > pr_err("--prefix-strip requires --prefix\n"); > return -1; > diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h > index 857c5fa0e6b1..4283eb4522b2 100644 > --- a/tools/perf/util/annotate.h > +++ b/tools/perf/util/annotate.h > @@ -428,14 +428,14 @@ static inline int symbol__tui_annotate(struct map_s= ymbol *ms __maybe_unused, > } > #endif > > -void annotation_options__init(struct annotation_options *opt); > -void annotation_options__exit(struct annotation_options *opt); > +void annotation_options__init(void); > +void annotation_options__exit(void); > > -void annotation_config__init(struct annotation_options *opt); > +void annotation_config__init(void); > > int annotate_parse_percent_type(const struct option *opt, const char *_s= tr, > int unset); > > -int annotate_check_args(struct annotation_options *args); > +int annotate_check_args(void); > > #endif /* __PERF_ANNOTATE_H */ > -- > 2.43.0.rc1.413.gea7ed67945-goog >