Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp697263rdf; Fri, 3 Nov 2023 12:08:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7qGNvr+mOpd2wGCDbw7VaQb+bAw8uMnJ324rWu2ooXWLoEImYmQ9gp+TndocUYHPNHrET X-Received: by 2002:a17:90a:31c5:b0:27d:549b:3e65 with SMTP id j5-20020a17090a31c500b0027d549b3e65mr19097676pjf.49.1699038525895; Fri, 03 Nov 2023 12:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699038525; cv=none; d=google.com; s=arc-20160816; b=VnKAY+4jcdHsEIvTrE/tcLAwaemnPaTzWyYgvLaY0ccpn4KFOUGhT7p2++pNBRyPpy TGJsm7TH8zlmrdJZZ8Ztlo6JsImoSOtt9HtMN1xqRHpuD+p7ixlb/ojh2/f+xsLMWlM1 +I0gtOW9Hs/bBPn5x1zxrRjiCwKeAFJn8Jq+m1zW5lE3hB2ew8OvfirqdXcNxH3du6YP mAbzscdOUYjXIpHA2s+Is2y0KaDZ44yt2UEYS7Wa9SLVZAsElb9hU7nOyUkm2VIcIDk3 vncoyPtHLXuWjd994SU9NwXjE5ZpCE/ADNSnh6H1bBnnem8BAfLLcmpjP65BPfYgFh9o Tlpg== 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; bh=G+Gw+3yI5d4czMQGUnnJvIN9gUJ2CUH3q6S+gSt8GnI=; fh=DBc9WMJMdwBhTy5KJY4Q8c33Y9ltrkwIobRTl722qyY=; b=H/EYQGDkAZNQWSR/gdVCp3XQzcP8XRN4dqLeulyrl8nIAyBLOXyasXPJcfaEEsPHyJ ZTiqajtlg5tcwr/7etRT29nMn1a3CcTr3s313YvoyhOn6uRBnlZEZhL7UMPfNTcG7Ahy PVG4GeYHS+g8211MmqgHCwS3K5j9Xu5Alzy3bGA4lDfRrsXUgH7hEQkNvPNE4IUrrd+7 QFwiqD8/oAxq3R4JqkZzR16QWK9/FKmEMF0sEaVmQPJbCvkY3ueF8Cs1QmWfa0c/KbSL 6KJVIHFT+45lQdtZcAmee6/KzJ48nS9Bh1+xtLs8RWq5Rg4PCxoCFYWQYrxquo3DONBb VOoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t6-20020a17090abc4600b00280c97a5663si2194800pjv.132.2023.11.03.12.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:08:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 68DD482D766F; Fri, 3 Nov 2023 12:08:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234477AbjKCS7S convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Nov 2023 14:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbjKCS7Q (ORCPT ); Fri, 3 Nov 2023 14:59:16 -0400 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E96DDD5C; Fri, 3 Nov 2023 11:58:42 -0700 (PDT) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6be1bc5aa1cso2538699b3a.3; Fri, 03 Nov 2023 11:58:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699037922; x=1699642722; 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=HsepAUpXpJFKU4XV8IuMmYlOnjqVxBUaHisnVnUUj9g=; b=Vg7fTiTH6pj+M9scIlGx2Ycu1fWXzEPt5c3crtJZI2MlCQV0tUNea770FDlVxCkngS V7Dq+JRFxJ4nITF0BKl0DnWFxYO5Tx9sQZs1RZHjCD5VJLyrSNkj9NgcRH5hZ7QiePkf fw5WPUKiK9TrJN48RsSMwNzHWHdGj3lokLak969F6Ck6RmpRKcfKZSVfAjt64kLgWpH0 7v9p+6JKIbOl0HiZSupnw3R4M7Mb/ZloN62t0C8hJVy/2yfeXvJVisi2miG+TY85/a11 MDXq/tqPxZK/HkvBqWHUY+2CTgtzbp+B57VuCwzYb8D+nFy+oECMcklSu0Fwr2y/IJIt tnAA== X-Gm-Message-State: AOJu0YyJX7QzSrHshixcDtzfCKMeBHXfVdyL58GaLtwdZSdOJ6Nym/uT wCbnZsg61xbfWTbSOFRtv7z8M9rqvwxD1V+BhloKmmg5 X-Received: by 2002:a05:6a00:1356:b0:6c0:4006:4195 with SMTP id k22-20020a056a00135600b006c040064195mr25950354pfu.0.1699037922172; Fri, 03 Nov 2023 11:58:42 -0700 (PDT) MIME-Version: 1.0 References: <20231102222653.4165959-1-namhyung@kernel.org> <20231102222653.4165959-5-namhyung@kernel.org> <133a66fe-a7e7-42e2-822b-1f3caea7862a@wanadoo.fr> In-Reply-To: <133a66fe-a7e7-42e2-822b-1f3caea7862a@wanadoo.fr> From: Namhyung Kim Date: Fri, 3 Nov 2023 11:58:31 -0700 Message-ID: Subject: Re: [PATCH 4/5] perf annotate: Move some fields to annotated_source To: Christophe JAILLET Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 12:08:44 -0700 (PDT) Hello, On Thu, Nov 2, 2023 at 10:41 PM Christophe JAILLET wrote: > > Le 02/11/2023 à 23:26, Namhyung Kim a écrit : > > Some fields in the struct annotation are only used with annotated_source > > so better to be moved there in order to reduce memory consumption for > > other symbols. > > > > Signed-off-by: Namhyung Kim > > --- > > tools/perf/ui/browsers/annotate.c | 12 ++++++------ > > tools/perf/util/annotate.c | 17 +++++++++-------- > > tools/perf/util/annotate.h | 14 +++++++------- > > 3 files changed, 22 insertions(+), 21 deletions(-) > > > > diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c > > index d2470f87344d..1b42db70c998 100644 > > --- a/tools/perf/ui/browsers/annotate.c > > +++ b/tools/perf/ui/browsers/annotate.c > > @@ -384,7 +384,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) > > if (al->idx_asm < offset) > > offset = al->idx; > > > > - browser->b.nr_entries = notes->nr_entries; > > + browser->b.nr_entries = notes->src->nr_entries; > > notes->options->hide_src_code = false; > > browser->b.seek(&browser->b, -offset, SEEK_CUR); > > browser->b.top_idx = al->idx - offset; > > @@ -402,7 +402,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser) > > if (al->idx_asm < offset) > > offset = al->idx_asm; > > > > - browser->b.nr_entries = notes->nr_asm_entries; > > + browser->b.nr_entries = notes->src->nr_asm_entries; > > notes->options->hide_src_code = true; > > browser->b.seek(&browser->b, -offset, SEEK_CUR); > > browser->b.top_idx = al->idx_asm - offset; > > @@ -435,7 +435,7 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser) > > { > > struct annotation *notes = browser__annotation(browser); > > ui_browser__reset_index(browser); > > - browser->nr_entries = notes->nr_asm_entries; > > + browser->nr_entries = notes->src->nr_asm_entries; > > } > > > > static int sym_title(struct symbol *sym, struct map *map, char *title, > > @@ -860,7 +860,7 @@ static int annotate_browser__run(struct annotate_browser *browser, > > browser->b.height, > > browser->b.index, > > browser->b.top_idx, > > - notes->nr_asm_entries); > > + notes->src->nr_asm_entries); > > } > > continue; > > case K_ENTER: > > @@ -991,8 +991,8 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel, > > > > ui_helpline__push("Press ESC to exit"); > > > > - browser.b.width = notes->max_line_len; > > - browser.b.nr_entries = notes->nr_entries; > > + browser.b.width = notes->src->max_line_len; > > + browser.b.nr_entries = notes->src->nr_entries; > > browser.b.entries = ¬es->src->source, > > browser.b.width += 18; /* Percentage */ > > > > diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c > > index 92a9adf9d5eb..ee7b8e1848a8 100644 > > --- a/tools/perf/util/annotate.c > > +++ b/tools/perf/util/annotate.c > > @@ -2808,19 +2808,20 @@ void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym) > > void annotation__set_offsets(struct annotation *notes, s64 size) > > { > > struct annotation_line *al; > > + struct annotated_source *src = notes->src; > > > > - notes->max_line_len = 0; > > - notes->nr_entries = 0; > > - notes->nr_asm_entries = 0; > > + src->max_line_len = 0; > > + src->nr_entries = 0; > > + src->nr_asm_entries = 0; > > > > - list_for_each_entry(al, ¬es->src->source, node) { > > + list_for_each_entry(al, &src->source, node) { > > size_t line_len = strlen(al->line); > > > > - if (notes->max_line_len < line_len) > > - notes->max_line_len = line_len; > > - al->idx = notes->nr_entries++; > > + if (src->max_line_len < line_len) > > + src->max_line_len = line_len; > > + al->idx = src->nr_entries++; > > if (al->offset != -1) { > > - al->idx_asm = notes->nr_asm_entries++; > > + al->idx_asm = src->nr_asm_entries++; > > /* > > * FIXME: short term bandaid to cope with assembly > > * routines that comes with labels in the same column > > diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h > > index d8a221591926..c51ceb857bd6 100644 > > --- a/tools/perf/util/annotate.h > > +++ b/tools/perf/util/annotate.h > > @@ -268,10 +268,13 @@ struct cyc_hist { > > * returns. > > */ > > struct annotated_source { > > - struct list_head source; > > - int nr_histograms; > > - size_t sizeof_sym_hist; > > - struct sym_hist *histograms; > > + struct list_head source; > > + int nr_histograms; > > If this int... > > > + size_t sizeof_sym_hist; > > + struct sym_hist *histograms; > > + int nr_entries; > > + int nr_asm_entries; > > + u16 max_line_len; > > ... and these int and u16 were grouped, you would also save a hole in > the struct and reduce padding. > > > On x86_64, after patch 4/5: > struct annotated_source { > struct list_head source; /* 0 16 */ > int nr_histograms; /* 16 4 */ > > /* XXX 4 bytes hole, try to pack */ <==== > > size_t sizeof_sym_hist; /* 24 8 */ > struct sym_hist * histograms; /* 32 8 */ > int nr_entries; /* 40 4 */ > int nr_asm_entries; /* 44 4 */ > u16 max_line_len; /* 48 2 */ > > /* size: 56, cachelines: 1, members: 7 */ > /* sum members: 46, holes: 1, sum holes: 4 */ > /* padding: 6 */ <==== > /* last cacheline: 56 bytes */ > }; > > After patch 5/5, the struct would be just 64 bytes. If fields are > re-ordered, it would be 56 bytes. > > Because of rounding in memory allocations, 56 or 64 shouldn't change > anything. But it would be more future proof, should something else be > added here in the future. Thanks for looking at this. I agree with your analysis and I will reorder the struct. Actually I plan to make more changes here so it's better to make it smaller. Thanks, Namhyung