Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2364968rdf; Mon, 6 Nov 2023 11:54:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbrEzM+OL7QuHLQKh9g0Inh0nJfXBXrypV5fyhqzD5dl1RrNEuHrhL1DXQnglvcayGjeNX X-Received: by 2002:a17:902:f093:b0:1cc:2f9d:6e9b with SMTP id p19-20020a170902f09300b001cc2f9d6e9bmr19328470pla.20.1699300440447; Mon, 06 Nov 2023 11:54:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699300440; cv=none; d=google.com; s=arc-20160816; b=CPqw66o+bWkAKMG/7Zz5j4bb/VJVdhVnjfnHwxSIBZrNHxElVDK3fOG4wDKToIC5NN sglDQ1RFNEidMMd6gG6D7LwM3Ex23jMdC5ypKXfrlpUKgjUAgnqf3qHslJUlQh+EGGbg /LPLfAl6Jrh3CvkaOvtI66JG425qofLsdtvVDzu95CwQYTzGBvzOj2+QdXmWjTfAiy77 ZaNFOlxsguWjV3KcY4Tonk8YP3tau+pPBeFvD1cgn0GIVYawQ6XAxS5iJE+lVbxdmBJR X3d3noZyRNah82eSh9PU1F+H2ZeVVHXXn4CPYghhrGNAqlWUfKQ0BMpd9Q3kjPP+OdBC rX4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RohsL7eRarW2bN8TYdLG4ng1ciIKC5a8HTR9MvnYwUQ=; fh=za47ybhYKmv7OM64+7HbktyZdnqmv+uiFc1S6ky7FuY=; b=HyQRwyZqUgczjBWPNC0GcxZvIy+Um6aheB/JXgJy+DRVOiYznJefQDVUpk7gPantdy 3unYnii7Cicj0X9gQx1JRrUAIO4r/hOXx/z5r5quDrt+MfPkDw/ATWudZC//v6gwvhNP Il0nWO/GFi47cpXdfsbX16u9Ob0DYRaYDEu+qJgdFD1Z4x9q9NCDLEhx8T9IvRH6fb3N JCkMGKVVrIxnuqouQfTvkrSHPOeunLPfieRHc+FwHeVL3Ehu7EWb1Q7lxDel+iMFS5BR AvZMRJT10uisXFJp9B3jkwvXL8NihdeJkK9FdfkS2auLSLii3ZmmTEPSxqF32Gt0igZn q3Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VWMuyGbh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h5-20020a170902b94500b001c736266dedsi8256144pls.189.2023.11.06.11.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:54:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VWMuyGbh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5E1D1804EE6A; Mon, 6 Nov 2023 11:53:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232618AbjKFTxm (ORCPT + 99 others); Mon, 6 Nov 2023 14:53:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231555AbjKFTxl (ORCPT ); Mon, 6 Nov 2023 14:53:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FA15DB for ; Mon, 6 Nov 2023 11:53:38 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9640AC433C8; Mon, 6 Nov 2023 19:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699300418; bh=zRnp3/+P5SOqdbJs98+fKP7mcvAOuH+BcWqDVT5w1I0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VWMuyGbhWb+99XI6CaXOnN+In4t9/oJivSghk3iyYk1O8OggZtdP60+/JWbepNzRs ERCCM4JWIL85/4U/Cvn9oCd6M0FlwwwN99HJDNMQOBRVVdf4sNmoSnyqADugQ1lBYm FF29ulVbZmiRYweStkCekKaDhMNI9sU1VA0trarFphCHgbaDXt07ihr3iFMwabsiLm dRc5Sc1kCBRVXWhjVa+X6U511HGDopFQNDynO7ezCMtejycRRgAC6+YsOjs2MtHrzJ 3K9P5ZyUkGe6QoOLffbHyYkNcPQz7v+t0zzxzhnRNr1195isktbLgTqeW0h0kNm5RX 9GE24ob/uqc6g== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 175F34035D; Mon, 6 Nov 2023 16:53:35 -0300 (-03) Date: Mon, 6 Nov 2023 16:53:35 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Christophe JAILLET Subject: Re: [PATCH 1/5] perf annotate: Split struct cycles_info Message-ID: References: <20231103191907.54531-1-namhyung@kernel.org> <20231103191907.54531-2-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Mon, 06 Nov 2023 11:53:57 -0800 (PST) Em Mon, Nov 06, 2023 at 04:34:51PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Fri, Nov 03, 2023 at 12:19:03PM -0700, Namhyung Kim escreveu: > > The cycles info is used only when branch stack is provided. Split them > > into a separate struct and lazy allocate them to save some memory. > > > > Signed-off-by: Namhyung Kim > > --- > > tools/perf/ui/browsers/annotate.c | 2 +- > > tools/perf/util/annotate.c | 34 ++++++++++++++++++------------- > > tools/perf/util/annotate.h | 14 ++++++++----- > > 3 files changed, 30 insertions(+), 20 deletions(-) > > > > diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c > > index ccdb2cd11fbf..d2470f87344d 100644 > > --- a/tools/perf/ui/browsers/annotate.c > > +++ b/tools/perf/ui/browsers/annotate.c > > @@ -337,7 +337,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, > > max_percent = percent; > > } > > > > - if (max_percent < 0.01 && pos->al.ipc == 0) { > > + if (max_percent < 0.01 && (!pos->al.cycles || pos->al.cycles->ipc == 0)) { > > RB_CLEAR_NODE(&pos->al.rb_node); > > continue; > > } > > diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c > > index 82956adf9963..3e7f75827270 100644 > > --- a/tools/perf/util/annotate.c > > +++ b/tools/perf/util/annotate.c > > @@ -1100,8 +1100,8 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 > > for (offset = start; offset <= end; offset++) { > > struct annotation_line *al = notes->offsets[offset]; > > > > - if (al && al->ipc == 0.0) { > > - al->ipc = ipc; > > + if (al && al->cycles && al->cycles->ipc == 0.0) { > > + al->cycles->ipc = ipc; > > cover_insn++; > > } > > } > > @@ -1134,13 +1134,18 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) > > if (ch && ch->cycles) { > > struct annotation_line *al; > > > > + al = notes->offsets[offset]; > > + if (al && al->cycles == NULL) { > > + al->cycles = zalloc(sizeof(*al->cycles)); > > + if (al->cycles == NULL) > > Shouldn't we stop here and tell the user that his system is really tight > on memory instead of just ignoring it? > > if (al->cycles == NULL) { > ui__error("Not enough memory for allocating branch stack cycles info!\n"); > return ... its a void function :-\ > } > > Since its a void function, can't we detect that we need al->cycles > allocated at the tool start and allocate it there, then propagate back > the error? > > Its per line, so doing it lazily is indeed easier, so make that function > return an error and bail out when not being able to calculate the ipc > for the remaining lines? I.e. with this folded into this patch, all but one of the callers of symbol__annotate2() already call a ui error messagem for instance: err = symbol__annotate2(ms, evsel, opts, &browser.arch); if (err) { char msg[BUFSIZ]; dso->annotate_warned = true; symbol__strerror_disassemble(ms, err, msg, sizeof(msg)); ui__error("Couldn't annotate %s:\n%s", sym->name, msg); - Arnaldo diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3e7f758272703554..99ff3bb9cad8daa6 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1114,12 +1114,13 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 } } -void annotation__compute_ipc(struct annotation *notes, size_t size) +static int annotation__compute_ipc(struct annotation *notes, size_t size) { + int err = 0; s64 offset; if (!notes->src || !notes->src->cycles_hist) - return; + return 0; notes->total_insn = annotation__count_insn(notes, 0, size - 1); notes->hit_cycles = 0; @@ -1137,8 +1138,10 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) al = notes->offsets[offset]; if (al && al->cycles == NULL) { al->cycles = zalloc(sizeof(*al->cycles)); - if (al->cycles == NULL) - continue; + if (al->cycles == NULL) { + err = ENOMEM; + break; + } } if (ch->have_start) annotation__count_and_fill(notes, ch->start, offset, ch); @@ -1150,7 +1153,21 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) notes->have_cycles = true; } } + + if (err) { + while (++offset < (s64)size) { + struct cyc_hist *ch = ¬es->src->cycles_hist[offset]; + + if (ch && ch->cycles) { + struct annotation_line *al = notes->offsets[offset]; + if (al) + zfree(&al->cycles); + } + } + } + annotation__unlock(notes); + return 0; } int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, @@ -3270,7 +3287,11 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, annotation__set_offsets(notes, size); annotation__mark_jump_targets(notes, sym); - annotation__compute_ipc(notes, size); + + err = annotation__compute_ipc(notes, size); + if (err) + goto out_free_offsets; + annotation__init_column_widths(notes, sym); notes->nr_events = nr_pcnt; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 16d27952fd5c1b47..19bc2f03917575a8 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -329,7 +329,6 @@ static inline bool annotation_line__filter(struct annotation_line *al, struct an } void annotation__set_offsets(struct annotation *notes, s64 size); -void annotation__compute_ipc(struct annotation *notes, size_t size); void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym); void annotation__update_column_widths(struct annotation *notes); void annotation__init_column_widths(struct annotation *notes, struct symbol *sym);