From patchwork Thu Nov 2 22:26:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 161134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp679392vqu; Thu, 2 Nov 2023 15:27:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdegys1TM1xk1OqHDaqG+OJK68/F75N16EPraqfMqaSpD5n+Xx3DNKbpEFPiA5hzuHlCZL X-Received: by 2002:a17:90a:134c:b0:280:35ce:5e0f with SMTP id y12-20020a17090a134c00b0028035ce5e0fmr12251533pjf.11.1698964060419; Thu, 02 Nov 2023 15:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698964060; cv=none; d=google.com; s=arc-20160816; b=CXPMzcdKAKCGCwNLEVKIaWt3//B7B7hZPtqZw6/1G++TP02q3qdm1QfGqo9ipOBV0M sOfTp2nKCK34aS9G6VQythMxUGx1ewvgbJmNXnfpD5AnpcXMbiXAwD1yFXHZCYbsEf1+ ySlnMMBdTeth7ivLwxQQx/7s9nnSYnl4/kjJQVg5sZhddyxhL1Mc8/lqglk6vvLvdHlt TM8y97kX8IZC/Rzv+Q/UCIu/uno39/INXfmTFbfh1x9O5rZuRPZX8vjzsua992qeEhtq 9oNhyNhCSR9N89cspk3p+EAOmwkpMNHt3dPJ6AMSDs2Aq+mFCZ0s9N4hWwJcxec/JiQf AVxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=nmFivyb8v0w5waZiQyZwSre0AC5T9ucB7JHzxYcIEWg=; fh=/TViaxNXj9Ubl1KVZseJCqJutBKG0dvzf3DPkf/1G64=; b=UyYkYvR+igKCGOg/kISfgoA8TkJUTKa1cruUHH0J4lcMF1Z6lvlJQw1++Lshzz1OZp Q0aIkznYON5ypin04AvISXJdKGrQcl5FR03kmKgBjV+KbU1M5IynhMIJRLFNsEyRtvHc n7VGatxQIHMmxfscdJ4R+V1n5vY8P5VY5rgSB+4NgjTd5JuIWH2g3ZawnUCRn++v5+6R mfm3kn1VQwzaSpymlkNdaZwCMgul/39mjuC7yZF7qdofR+FYyE8bfP+dpdx/ruihmZP7 zxyOuEkd007ycEkNPmD2SJG/n0EDQq8RxEUzCjpan2vMhd5FSvxBAKjBli2iEorcX9KB BD0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=azwsDFng; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o17-20020a17090aac1100b00280cc652dd6si482042pjq.173.2023.11.02.15.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:27:40 -0700 (PDT) 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=@gmail.com header.s=20230601 header.b=azwsDFng; 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=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 1B3C2811C147; Thu, 2 Nov 2023 15:27:24 -0700 (PDT) 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 S1377499AbjKBW1B (ORCPT + 37 others); Thu, 2 Nov 2023 18:27:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377489AbjKBW07 (ORCPT ); Thu, 2 Nov 2023 18:26:59 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E0ABDC; Thu, 2 Nov 2023 15:26:57 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1cc0d0a0355so11859375ad.3; Thu, 02 Nov 2023 15:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698964017; x=1699568817; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=nmFivyb8v0w5waZiQyZwSre0AC5T9ucB7JHzxYcIEWg=; b=azwsDFngSANJyaj4U7crq06wNWfZVlzabcGbjfkGUF569h8j9r5OXLqL4lxgwbwTQW kVjHD281oY2JgCL4GxaaFRQGBXRQl9cuyjq+F8k4DfH9xH8+rYJgzCs22pY2LMAqUjHA NIV5MI4CrLZrGXiUVxSC2lofVdsw7L9wnNpVfSxHA6f4u9ri/DR3wQvTstPZ2LEDe5+d Veb2TQqAxTFcK5NzchoDLUccSbXmobMe7sTzvMuIghQUljid1tRN/uM0PLYzoAYOcqIG 1WUSck9ZBBJPY7LH/FBkgq2xN7iesQ0HsY300ozfwV6ji8FCgmHBS1blEnKSgH1O71E/ 0HnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698964017; x=1699568817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nmFivyb8v0w5waZiQyZwSre0AC5T9ucB7JHzxYcIEWg=; b=Z7YW2QR16nTs5WXEXyC0/HdTdDmW/N2xD+soyZrt5n+Si1vAKnQzjlWWSPApTOL+3y MZTSErLL5gr2RkvZqlDio4xG8fZdzZy/D5afVQ+Gx6gQ2IUWliXSiWGzDj0ByH1aaNXJ FG0XrRw5UV/P1lVWWKWORZpFs/GfOipz7wRzTbTZ3YzM3t8ac1cXTco5km9oIqgNx6J9 AKfIZrdCNDA6ran7cnsmMCeRIWJjlYWAKEI5ZVXPjWY0/wMzmCqvwIdd1G+YQMgof/nh vtTPKi7Dy12I45Fn023i31NiA6yNlzeQNgYeFv1tVEqB8ek/kjZA+ncalEFhESpsj3Xc ol7A== X-Gm-Message-State: AOJu0YwP3CR5JIhIv3X1Etl29phglNmR8h9XqnEIJGKKGRbaSHBEm0Ff edlImx3Sp2/TTcACI4nU1Zg= X-Received: by 2002:a17:90b:1a8d:b0:27d:3968:8366 with SMTP id ng13-20020a17090b1a8d00b0027d39688366mr17281010pjb.8.1698964016618; Thu, 02 Nov 2023 15:26:56 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id cn18-20020a17090af09200b0027d015c365csm309894pjb.31.2023.11.02.15.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:26:56 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/5] perf annotate: Split struct cycles_info Date: Thu, 2 Nov 2023 15:26:49 -0700 Message-ID: <20231102222653.4165959-2-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231102222653.4165959-1-namhyung@kernel.org> References: <20231102222653.4165959-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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]); Thu, 02 Nov 2023 15:27:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781492938404840471 X-GMAIL-MSGID: 1781492938404840471 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) + continue; + } if (ch->have_start) annotation__count_and_fill(notes, ch->start, offset, ch); - al = notes->offsets[offset]; if (al && ch->num_aggr) { - al->cycles = ch->cycles_aggr / ch->num_aggr; - al->cycles_max = ch->cycles_max; - al->cycles_min = ch->cycles_min; + al->cycles->avg = ch->cycles_aggr / ch->num_aggr; + al->cycles->max = ch->cycles_max; + al->cycles->min = ch->cycles_min; } notes->have_cycles = true; } @@ -1225,6 +1230,7 @@ static void annotation_line__exit(struct annotation_line *al) { zfree_srcline(&al->path); zfree(&al->line); + zfree(&al->cycles); } static size_t disasm_line_size(int nr) @@ -3083,8 +3089,8 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati int printed; if (first_line && (al->offset == -1 || percent_max == 0.0)) { - if (notes->have_cycles) { - if (al->ipc == 0.0 && al->cycles == 0) + if (notes->have_cycles && al->cycles) { + if (al->cycles->ipc == 0.0 && al->cycles->avg == 0) show_title = true; } else show_title = true; @@ -3121,17 +3127,17 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati } if (notes->have_cycles) { - if (al->ipc) - obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->ipc); + if (al->cycles && al->cycles->ipc) + obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->cycles->ipc); else if (!show_title) obj__printf(obj, "%*s", ANNOTATION__IPC_WIDTH, " "); else obj__printf(obj, "%*s ", ANNOTATION__IPC_WIDTH - 1, "IPC"); if (!notes->options->show_minmax_cycle) { - if (al->cycles) + if (al->cycles && al->cycles->avg) obj__printf(obj, "%*" PRIu64 " ", - ANNOTATION__CYCLES_WIDTH - 1, al->cycles); + ANNOTATION__CYCLES_WIDTH - 1, al->cycles->avg); else if (!show_title) obj__printf(obj, "%*s", ANNOTATION__CYCLES_WIDTH, " "); @@ -3145,8 +3151,8 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati scnprintf(str, sizeof(str), "%" PRIu64 "(%" PRIu64 "/%" PRIu64 ")", - al->cycles, al->cycles_min, - al->cycles_max); + al->cycles->avg, al->cycles->min, + al->cycles->max); obj__printf(obj, "%*s ", ANNOTATION__MINMAX_CYCLES_WIDTH - 1, diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 962780559176..16d27952fd5c 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -130,6 +130,13 @@ struct annotation_data { struct sym_hist_entry he; }; +struct cycles_info { + float ipc; + u64 avg; + u64 max; + u64 min; +}; + struct annotation_line { struct list_head node; struct rb_node rb_node; @@ -137,12 +144,9 @@ struct annotation_line { char *line; int line_nr; char *fileloc; - int jump_sources; - float ipc; - u64 cycles; - u64 cycles_max; - u64 cycles_min; char *path; + struct cycles_info *cycles; + int jump_sources; u32 idx; int idx_asm; int data_nr; From patchwork Thu Nov 2 22:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 161135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp679501vqu; Thu, 2 Nov 2023 15:27:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIkH7X47iCHHlXkKw9THknX4EjY86lCsi19LAfMoJtSCe41NFVnz80xBIAvqF1uDiasgDL X-Received: by 2002:a17:902:f10a:b0:1cc:3932:4a87 with SMTP id e10-20020a170902f10a00b001cc39324a87mr10350517plb.56.1698964077804; Thu, 02 Nov 2023 15:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698964077; cv=none; d=google.com; s=arc-20160816; b=V286SMiCbG+tlGe2HZgzpK8tTsttMOC6SPl0gXbZk/XrfEQ8Fqc1o6XGk+CHZOmC/A RPCeBzWGXjxbGa+Uehiq4VuoEjQe+tLFURjwnZRZWq8SPLibt2A8sW3NlTy83FtVfe0Z DVrhhtWjoLnzwN2/Ru1ZWy0QCPAaffXUNGbnem/VvmJvVurrMjst5GqgdcTuNI4sP1WX 2rXz/fMsUnBWic9viXldfvud515wwMcTuJf7TdtSNGuUdcVIBNVydnT7x0cehOsdpG8d t0zXk0rJEnAmgjwq4o8yWl5dQ4RNsVJXP4WZL/RThrF3I6ebg6yDi1YHVI+6Bvd8beb3 pDBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=HhC5Yt36t3sxJcc1M7cNnf45Xz8JZXT4W0GtB3DI7Is=; fh=/TViaxNXj9Ubl1KVZseJCqJutBKG0dvzf3DPkf/1G64=; b=zqPU1vkcnOfp4vpbtLB6VE2zNUgzDCMrrMS3qGYiqO2RlJIAtc8Ap0lOF1Lv+OIAwu tYDQXnyCva2pz6GRLOnE9/hTHzv9+jp7L1Nbxauhu+H8M2z5v2Bkx0LvpK408v9V9Fms YSDco182j8Pl2L0EL3Aud8DQn3UrXHQRJ6fQOP0DpTiFV09bsPq9B0aWqRNoPfJCCUbi jV0SsjUu992CvOdVndXSYOwrvHFyS2HoG6EY1x85b4MzqVTmwtzVucs5KZ75L1m2Wo6R nChrF0pkTTkCHtSQHCiE8thUn5HCu6PLfsl1107Famew0Cwh+2U5krnrIOh7+HlBWnX6 JTfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mnE0F07F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s9-20020a170902c64900b001c9e680c178si339761pls.394.2023.11.02.15.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mnE0F07F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 9D94B83A9F8F; Thu, 2 Nov 2023 15:27:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377508AbjKBW1E (ORCPT + 37 others); Thu, 2 Nov 2023 18:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377501AbjKBW1B (ORCPT ); Thu, 2 Nov 2023 18:27:01 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59AA2191; Thu, 2 Nov 2023 15:26:58 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6c34e87b571so473335b3a.3; Thu, 02 Nov 2023 15:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698964018; x=1699568818; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=HhC5Yt36t3sxJcc1M7cNnf45Xz8JZXT4W0GtB3DI7Is=; b=mnE0F07FY0Za8yTyGgdOi52OJu1pZxiEPX1zPn533Aa76cKVayaqWD27vMo07zLYp7 PBRpaS6VWyy/HsBhfc3sKKNoKF1ChNwwsxTBmO0N9YSlD65jiKcBoW3asKT+N1U5OyNQ QfrCMPnNWV5x7t9wlsUYfSLsUFaTUksnimhFyoxhADToGOiyD6wvPBnCJGWyLXhgAq7m zL++YmAVYWFbZwaRwvnSxiHtqzBztxO4l4qpi/BWEiSGCoVwWzsFzF4C+tk8UuLenSXC Q4JFmkO+CwzSDsHHedWfWZU9p61KsmX8qwHPBW/lHBknmbE6jk+TFaeHdYl6JkVju2Ge fWUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698964018; x=1699568818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HhC5Yt36t3sxJcc1M7cNnf45Xz8JZXT4W0GtB3DI7Is=; b=mfk08OINe6Bs6XeYaJuaYO7Hk0ELLoc95Um0XEfGOZ7LRHCZGDTmKoMxaCI4JNjF9s S96gxKGMSr3hBRVLAbC9xET/mix6kwReHH4J9C/vR6bdCNWUqG5qVZogkjEwzCouf/AO LRL4ny6U01m4d/pTiujK2ywvd/WGF5fA1WY523FWQkQnLAnmaXV0qOopVeLYX2GjRm4H k2roTRcr67OSVUm3C1UBCTD653djmaePsqrH5AIKUhXwVwUR/qZDUyElp7mGkCs2q2tP weCTRi1EGDgnwWVnJj1wcmNkVROGWDKCS/GNBZ0jeCopWPA7RxLbZkJ8fCXLmTddLbcN qbQQ== X-Gm-Message-State: AOJu0YxroJy54PpJedZ8qsetQidBnkh8UPNmXooaNj7xWAhoQrhtpfnQ 7zUMwSgdkH3iOJWJ7ytKeQg= X-Received: by 2002:a05:6a21:9994:b0:15e:dc75:66a7 with SMTP id ve20-20020a056a21999400b0015edc7566a7mr20765379pzb.24.1698964017700; Thu, 02 Nov 2023 15:26:57 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id cn18-20020a17090af09200b0027d015c365csm309894pjb.31.2023.11.02.15.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:26:57 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 2/5] perf annotate: Split struct annotated_branch Date: Thu, 2 Nov 2023 15:26:50 -0700 Message-ID: <20231102222653.4165959-3-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231102222653.4165959-1-namhyung@kernel.org> References: <20231102222653.4165959-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 15:27:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781492956688054676 X-GMAIL-MSGID: 1781492956688054676 The cycles info is only meaninful when sample has branch stacks. To save the memory for normal cases, move those fields to annotated_branch and dynamically allocate it when needed. Also move cycles_hist from annotated_source as it's related here. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 97 ++++++++++++++++++++---------------- tools/perf/util/annotate.h | 17 ++++--- tools/perf/util/block-info.c | 4 +- tools/perf/util/sort.c | 14 +++--- 4 files changed, 72 insertions(+), 60 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3e7f75827270..2fa1ce3a0858 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -810,7 +810,6 @@ static __maybe_unused void annotated_source__delete(struct annotated_source *src if (src == NULL) return; zfree(&src->histograms); - zfree(&src->cycles_hist); free(src); } @@ -845,18 +844,6 @@ static int annotated_source__alloc_histograms(struct annotated_source *src, return src->histograms ? 0 : -1; } -/* The cycles histogram is lazily allocated. */ -static int symbol__alloc_hist_cycles(struct symbol *sym) -{ - struct annotation *notes = symbol__annotation(sym); - const size_t size = symbol__size(sym); - - notes->src->cycles_hist = calloc(size, sizeof(struct cyc_hist)); - if (notes->src->cycles_hist == NULL) - return -1; - return 0; -} - void symbol__annotate_zero_histograms(struct symbol *sym) { struct annotation *notes = symbol__annotation(sym); @@ -865,9 +852,10 @@ void symbol__annotate_zero_histograms(struct symbol *sym) if (notes->src != NULL) { memset(notes->src->histograms, 0, notes->src->nr_histograms * notes->src->sizeof_sym_hist); - if (notes->src->cycles_hist) - memset(notes->src->cycles_hist, 0, - symbol__size(sym) * sizeof(struct cyc_hist)); + } + if (notes->branch && notes->branch->cycles_hist) { + memset(notes->branch->cycles_hist, 0, + symbol__size(sym) * sizeof(struct cyc_hist)); } annotation__unlock(notes); } @@ -958,23 +946,33 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms, return 0; } +static struct annotated_branch *annotation__get_branch(struct annotation *notes) +{ + if (notes == NULL) + return NULL; + + if (notes->branch == NULL) + notes->branch = zalloc(sizeof(*notes->branch)); + + return notes->branch; +} + static struct cyc_hist *symbol__cycles_hist(struct symbol *sym) { struct annotation *notes = symbol__annotation(sym); + struct annotated_branch *branch; - if (notes->src == NULL) { - notes->src = annotated_source__new(); - if (notes->src == NULL) - return NULL; - goto alloc_cycles_hist; - } + branch = annotation__get_branch(notes); + if (branch == NULL) + return NULL; + + if (branch->cycles_hist == NULL) { + const size_t size = symbol__size(sym); - if (!notes->src->cycles_hist) { -alloc_cycles_hist: - symbol__alloc_hist_cycles(sym); + branch->cycles_hist = calloc(size, sizeof(struct cyc_hist)); } - return notes->src->cycles_hist; + return branch->cycles_hist; } struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists) @@ -1083,6 +1081,14 @@ static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64 return n_insn; } +static void annotated_branch__delete(struct annotated_branch *branch) +{ + if (branch) { + free(branch->cycles_hist); + free(branch); + } +} + static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 end, struct cyc_hist *ch) { unsigned n_insn; @@ -1091,6 +1097,7 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 n_insn = annotation__count_insn(notes, start, end); if (n_insn && ch->num && ch->cycles) { + struct annotated_branch *branch; float ipc = n_insn / ((double)ch->cycles / (double)ch->num); /* Hide data when there are too many overlaps. */ @@ -1106,10 +1113,11 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 } } - if (cover_insn) { - notes->hit_cycles += ch->cycles; - notes->hit_insn += n_insn * ch->num; - notes->cover_insn += cover_insn; + branch = annotation__get_branch(notes); + if (cover_insn && branch) { + branch->hit_cycles += ch->cycles; + branch->hit_insn += n_insn * ch->num; + branch->cover_insn += cover_insn; } } } @@ -1118,19 +1126,19 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) { s64 offset; - if (!notes->src || !notes->src->cycles_hist) + if (!notes->branch || !notes->branch->cycles_hist) return; - notes->total_insn = annotation__count_insn(notes, 0, size - 1); - notes->hit_cycles = 0; - notes->hit_insn = 0; - notes->cover_insn = 0; + notes->branch->total_insn = annotation__count_insn(notes, 0, size - 1); + notes->branch->hit_cycles = 0; + notes->branch->hit_insn = 0; + notes->branch->cover_insn = 0; annotation__lock(notes); for (offset = size - 1; offset >= 0; --offset) { struct cyc_hist *ch; - ch = ¬es->src->cycles_hist[offset]; + ch = ¬es->branch->cycles_hist[offset]; if (ch && ch->cycles) { struct annotation_line *al; @@ -1147,7 +1155,6 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) al->cycles->max = ch->cycles_max; al->cycles->min = ch->cycles_min; } - notes->have_cycles = true; } } annotation__unlock(notes); @@ -1305,6 +1312,7 @@ int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool r void annotation__exit(struct annotation *notes) { annotated_source__delete(notes->src); + annotated_branch__delete(notes->branch); } static struct sharded_mutex *sharded_mutex; @@ -3058,13 +3066,14 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes, static void ipc_coverage_string(char *bf, int size, struct annotation *notes) { double ipc = 0.0, coverage = 0.0; + struct annotated_branch *branch = annotation__get_branch(notes); - if (notes->hit_cycles) - ipc = notes->hit_insn / ((double)notes->hit_cycles); + if (branch && branch->hit_cycles) + ipc = branch->hit_insn / ((double)branch->hit_cycles); - if (notes->total_insn) { - coverage = notes->cover_insn * 100.0 / - ((double)notes->total_insn); + if (branch && branch->total_insn) { + coverage = branch->cover_insn * 100.0 / + ((double)branch->total_insn); } scnprintf(bf, size, "(Average IPC: %.2f, IPC Coverage: %.1f%%)", @@ -3089,7 +3098,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati int printed; if (first_line && (al->offset == -1 || percent_max == 0.0)) { - if (notes->have_cycles && al->cycles) { + if (notes->branch && al->cycles) { if (al->cycles->ipc == 0.0 && al->cycles->avg == 0) show_title = true; } else @@ -3126,7 +3135,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati } } - if (notes->have_cycles) { + if (notes->branch) { if (al->cycles && al->cycles->ipc) obj__printf(obj, "%*.2f ", ANNOTATION__IPC_WIDTH - 1, al->cycles->ipc); else if (!show_title) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 16d27952fd5c..9c199629305d 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -271,17 +271,20 @@ struct annotated_source { struct list_head source; int nr_histograms; size_t sizeof_sym_hist; - struct cyc_hist *cycles_hist; struct sym_hist *histograms; }; -struct LOCKABLE annotation { - u64 max_coverage; - u64 start; +struct annotated_branch { u64 hit_cycles; u64 hit_insn; unsigned int total_insn; unsigned int cover_insn; + struct cyc_hist *cycles_hist; +}; + +struct LOCKABLE annotation { + u64 max_coverage; + u64 start; struct annotation_options *options; struct annotation_line **offsets; int nr_events; @@ -297,8 +300,8 @@ struct LOCKABLE annotation { u8 max_addr; u8 max_ins_name; } widths; - bool have_cycles; struct annotated_source *src; + struct annotated_branch *branch; }; static inline void annotation__init(struct annotation *notes __maybe_unused) @@ -312,10 +315,10 @@ bool annotation__trylock(struct annotation *notes) EXCLUSIVE_TRYLOCK_FUNCTION(tr static inline int annotation__cycles_width(struct annotation *notes) { - if (notes->have_cycles && notes->options->show_minmax_cycle) + if (notes->branch && notes->options->show_minmax_cycle) return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH; - return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0; + return notes->branch ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0; } static inline int annotation__pcnt_width(struct annotation *notes) diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c index 591fc1edd385..08f82c1f166c 100644 --- a/tools/perf/util/block-info.c +++ b/tools/perf/util/block-info.c @@ -129,9 +129,9 @@ int block_info__process_sym(struct hist_entry *he, struct block_hist *bh, al.sym = he->ms.sym; notes = symbol__annotation(he->ms.sym); - if (!notes || !notes->src || !notes->src->cycles_hist) + if (!notes || !notes->branch || !notes->branch->cycles_hist) return 0; - ch = notes->src->cycles_hist; + ch = notes->branch->cycles_hist; for (unsigned int i = 0; i < symbol__size(he->ms.sym); i++) { if (ch[i].num_aggr) { struct block_info *bi; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 80e4f6132740..27b123ccd2d1 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -583,21 +583,21 @@ static int hist_entry__sym_ipc_snprintf(struct hist_entry *he, char *bf, { struct symbol *sym = he->ms.sym; - struct annotation *notes; + struct annotated_branch *branch; double ipc = 0.0, coverage = 0.0; char tmp[64]; if (!sym) return repsep_snprintf(bf, size, "%-*s", width, "-"); - notes = symbol__annotation(sym); + branch = symbol__annotation(sym)->branch; - if (notes->hit_cycles) - ipc = notes->hit_insn / ((double)notes->hit_cycles); + if (branch && branch->hit_cycles) + ipc = branch->hit_insn / ((double)branch->hit_cycles); - if (notes->total_insn) { - coverage = notes->cover_insn * 100.0 / - ((double)notes->total_insn); + if (branch && branch->total_insn) { + coverage = branch->cover_insn * 100.0 / + ((double)branch->total_insn); } snprintf(tmp, sizeof(tmp), "%-5.2f [%5.1f%%]", ipc, coverage); From patchwork Thu Nov 2 22:26:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 161137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp679699vqu; Thu, 2 Nov 2023 15:28:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3u8D/dZEk8xv+tJz5QdccX9HIGedIjivP+RcQem6jqmkb4hp14OuuwOwOkBJNeHS7Ncyy X-Received: by 2002:a05:6a21:4842:b0:181:9778:1326 with SMTP id au2-20020a056a21484200b0018197781326mr3528054pzc.19.1698964110868; Thu, 02 Nov 2023 15:28:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698964110; cv=none; d=google.com; s=arc-20160816; b=LsVOzb4GUkC4RXIFTwuAvdTXcjmiTVVk5fysKboeFs29SrZhjMsFaoqxbPqS8V8YJq SjAQfE5pDaAzkW2u4oN0LjiOLRBb8YSGHzxtfyucEm9xh3iMiZahxc+SeNnjK7OCxibT GeHeEdZqljJhXWPXSBoQ7IAfS52HEI0/d0aKBsxg8/TVwMsMAk7Y+cpQOMT1QJoiS8r4 Wg+MjnbW9pleFyI0qQ2LXtKcaxkoaPGAHds1VOYiFln4VveE/hLck9BFrgKsNGNHyRiU nO4761I2gaX/e42mGb6a6IsxIFVNbA3RI2693aDnCC2L0g6osZr0/DriPqbpLkOcHbGc 6O5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=L8tqb2qz0r5dpxN3b4ngTYkFDyTuwNwqrYBhWYtfaoc=; fh=/TViaxNXj9Ubl1KVZseJCqJutBKG0dvzf3DPkf/1G64=; b=Au/510S01xH7z6r5ZwUX+vac3yGHoT1URL4XQXLB+ix3BJg1QIBAATGujvBdrFo18U tAY3Ba571E8H2o1/KXPceoXgWt2ZM2FpNes9y01BqsYMvhBCBeFSALFHUmtbcjN5r7eA GguVHFFc6tkk0CDbIS4cajNVZbkW25gztm3+f8DlAJwmaBJQuz3BgbNC72vovrOyvFDO t2g3BO6KEN0SAvaygzJVXorZQr10ZfQCJv2/zqcyHLbTUxchfXjWrPtV9jiaoY4dvOyb LxzzFwsHud41EnqrWAWY0mdSjtqXPnO+p6QFqA8oiXWiFsjEWw/A6/RK8R/aVPRag/W8 qWOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BwQ3bVxo; 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q1-20020a056a00150100b0068fa57cc15bsi374661pfu.124.2023.11.02.15.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:28:30 -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; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BwQ3bVxo; 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 0C79480755E1; Thu, 2 Nov 2023 15:27:20 -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 S1377512AbjKBW1G (ORCPT + 37 others); Thu, 2 Nov 2023 18:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377489AbjKBW1C (ORCPT ); Thu, 2 Nov 2023 18:27:02 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E9BB7; Thu, 2 Nov 2023 15:26:59 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-27ff83feb29so1431022a91.3; Thu, 02 Nov 2023 15:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698964019; x=1699568819; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=L8tqb2qz0r5dpxN3b4ngTYkFDyTuwNwqrYBhWYtfaoc=; b=BwQ3bVxoVagv+itzBp79J2JBIuGlW/q6dPVEp19oqr/HgZL70hXI+zDWdrIH3PgQGv otzOXCfesJc4S99G1cpWyEhrvXqVXtFMi+f/cfLD9leG/tFYA8njhBObvy3krBck/LpM wH+tAIWGdpJb6ANdBDI/mjPkuHZq4lJ/zRaL9mKtS8EfDX1opX2XC6WjOQfGL8cG3VDS dkgAd+wU2+KWJrThfxsakrFE7Xuj6fNmD6MmkXg4gnalOusYYcMOBALFb8S2axP91D5G ui3vQZeAHZk7yae9wQdh4rCAa5imNdzfYtCaVOpqSiz0LSB/rTd7U7vbPSSj+K2/yi1y a1bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698964019; x=1699568819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=L8tqb2qz0r5dpxN3b4ngTYkFDyTuwNwqrYBhWYtfaoc=; b=CtwjEqy/bslV7+kDwqrYCJlLQ1ZoxTchOBgDk5dw1kBWxZ2Bv+pZiBRZ7b/fTBTNZh vZxSt1R948slOaqy7hpOlv+raB/3exlyaG3O2vLa2RjY/SjtJ8Dt9C/TzPZlQdWgMt1K Io0LQW1iwuyEhsRK/dqnQLZffr2F6W39el/FVmwE7vDs7C8ubXPrxB4BPd/K8T5EAnl1 tj5EVPZaV4+tuXU218XSJodNh1t0HjFu1QsrvtnZ4iGUrzSifc7RqXFi0UnQkV36lqrj EUe8CLVCGcUP74pY+uromhZt/iFadSK3Q4QGsmoR3Qt7rK+RFo3Rn5IDFMMz5ybGbVB2 adHA== X-Gm-Message-State: AOJu0YzvLhE9srO+/gncTQGKX+n7IyLjqDtIlnXgKdvYik87Yxg8N+4o lzDsOZAusUYBFUDZ+rdwevw= X-Received: by 2002:a17:90a:c698:b0:280:3772:5c2e with SMTP id n24-20020a17090ac69800b0028037725c2emr14529374pjt.25.1698964018759; Thu, 02 Nov 2023 15:26:58 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id cn18-20020a17090af09200b0027d015c365csm309894pjb.31.2023.11.02.15.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:26:58 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/5] perf annotate: Move max_coverage to annotated_branch Date: Thu, 2 Nov 2023 15:26:51 -0700 Message-ID: <20231102222653.4165959-4-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231102222653.4165959-1-namhyung@kernel.org> References: <20231102222653.4165959-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,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]); Thu, 02 Nov 2023 15:27:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781492991020333389 X-GMAIL-MSGID: 1781492991020333389 The max_coverage is only used when branch stack info is available so it'd be natural to move to the annotated_branch. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/builtin-annotate.c | 7 +++++-- tools/perf/util/annotate.c | 2 +- tools/perf/util/annotate.h | 4 +++- tools/perf/util/block-range.c | 7 ++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index aeeb801f1ed7..a9129b51d511 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -94,6 +94,7 @@ static void process_basic_block(struct addr_map_symbol *start, struct annotation *notes = sym ? symbol__annotation(sym) : NULL; struct block_range_iter iter; struct block_range *entry; + struct annotated_branch *branch; /* * Sanity; NULL isn't executable and the CPU cannot execute backwards @@ -105,6 +106,8 @@ static void process_basic_block(struct addr_map_symbol *start, if (!block_range_iter__valid(&iter)) return; + branch = annotation__get_branch(notes); + /* * First block in range is a branch target. */ @@ -118,8 +121,8 @@ static void process_basic_block(struct addr_map_symbol *start, entry->coverage++; entry->sym = sym; - if (notes) - notes->max_coverage = max(notes->max_coverage, entry->coverage); + if (branch) + branch->max_coverage = max(branch->max_coverage, entry->coverage); } while (block_range_iter__next(&iter)); diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2fa1ce3a0858..92a9adf9d5eb 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -946,7 +946,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms, return 0; } -static struct annotated_branch *annotation__get_branch(struct annotation *notes) +struct annotated_branch *annotation__get_branch(struct annotation *notes) { if (notes == NULL) return NULL; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 9c199629305d..d8a221591926 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -280,10 +280,10 @@ struct annotated_branch { unsigned int total_insn; unsigned int cover_insn; struct cyc_hist *cycles_hist; + u64 max_coverage; }; struct LOCKABLE annotation { - u64 max_coverage; u64 start; struct annotation_options *options; struct annotation_line **offsets; @@ -356,6 +356,8 @@ static inline struct annotation *symbol__annotation(struct symbol *sym) int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, struct evsel *evsel); +struct annotated_branch *annotation__get_branch(struct annotation *notes); + int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, struct addr_map_symbol *start, unsigned cycles); diff --git a/tools/perf/util/block-range.c b/tools/perf/util/block-range.c index 680e92774d0c..15c42196c24c 100644 --- a/tools/perf/util/block-range.c +++ b/tools/perf/util/block-range.c @@ -311,6 +311,7 @@ struct block_range_iter block_range__create(u64 start, u64 end) double block_range__coverage(struct block_range *br) { struct symbol *sym; + struct annotated_branch *branch; if (!br) { if (block_ranges.blocks) @@ -323,5 +324,9 @@ double block_range__coverage(struct block_range *br) if (!sym) return -1; - return (double)br->coverage / symbol__annotation(sym)->max_coverage; + branch = symbol__annotation(sym)->branch; + if (!branch) + return -1; + + return (double)br->coverage / branch->max_coverage; } From patchwork Thu Nov 2 22:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 161138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp679708vqu; Thu, 2 Nov 2023 15:28:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHskp1oIsvUBxtgrx+U7BbwR28R1fSVn2ncUFwfPHGmc/CvYHaz+YnlsmGSJZ8aVc1NTL/b X-Received: by 2002:a05:6a21:4841:b0:181:8e2:ba3c with SMTP id au1-20020a056a21484100b0018108e2ba3cmr9628231pzc.19.1698964112082; Thu, 02 Nov 2023 15:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698964112; cv=none; d=google.com; s=arc-20160816; b=NwSKmO6yvYnKqZFUxDvDu+v1tqvttb/p2NAiUZ2mPBu81JWb0iYT/57vj733R8YsvX i3OgvxCSQG2J4MGtbmwlSTaDZVKAQzC/yytzCVeNH4sPzQwj0cyyfrIbqz5fBj7ognD1 4X4Hn0HGvxXOamfCidTE6nXTeVncibqcavcnc1LxUMSszE9JokrvYIpZS8turbIVM9go v6nCtyH3gCT7d5k80YS05z74Tnz1bdmqGXaGlKNJqaHlggV1o1i0el3QHxhK78nXBNCy qBdHPfXDLNnJ5J/1cFPnUeO7aojZfBi1hNKAVTG+oi/hgOfcg8piv60qc0UNkEpXdprv Q+pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=UfeDJJAakAHGSmerBO7TwpTzcsIOcntyODz+PgBSHd0=; fh=/TViaxNXj9Ubl1KVZseJCqJutBKG0dvzf3DPkf/1G64=; b=U5K5RHWYzNd1SPKepLzXLccPAQpBlsX8R2OxYu1NVvVUU+XHoN+hV/2z60QHnTqnnZ KmnrgV7ld7CDJD0wi55fMnAjyliVc5bHZQqWWmUMmmO39HVeyBjIMRnFDcwxDi7R8wZo 54waXlYIo+m5CKTmq02uHgWf+/FQ4TAKElqDzGyQq8iObrbGSEJvqbp6h8q0mKr6VjK3 Wln4n32+KPsHCyCDC62wXtUriTFitLDdC0EzD7TEYBggcXjJMHMKlnCwLt733kKDfHHm DPOrpspYCMgRCi8e+Dda4nM4BFpA0IjgOqaHzr8jGNL++PmIILQSRu+16uA+xHh5bomm csSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bY7wOe5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id na9-20020a17090b4c0900b002802d12083fsi429811pjb.54.2023.11.02.15.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:28:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bY7wOe5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 0166D8065007; Thu, 2 Nov 2023 15:27:27 -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 S1377518AbjKBW1J (ORCPT + 37 others); Thu, 2 Nov 2023 18:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377503AbjKBW1D (ORCPT ); Thu, 2 Nov 2023 18:27:03 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91BDDDC; Thu, 2 Nov 2023 15:27:00 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5b9a7357553so1177946a12.0; Thu, 02 Nov 2023 15:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698964020; x=1699568820; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=UfeDJJAakAHGSmerBO7TwpTzcsIOcntyODz+PgBSHd0=; b=bY7wOe5yL0wwM16bJryT8fNXF/IGkTKfYUhpNQTfjwlwR9KwyheRZ3A06Up2/OTzou XDb4Q6FpXVeMFe0TP30JX9DLPXvunqqT0gz3vsJoBlfi29Heg31EdMM1+4EWHy0yRBwt EkataOAPqWPyEXZxyE3dboCzxk4RnZBU7EQD5XLZZeON7mK2cdQZd0yRsaPZwTzVR4o2 Pm0cBtb/hcpr80JsG0u3MH692jS6pjwGPyfMpcXsRoECzALy89nN3kx+Ij4+QjrFPx0+ 9DdrQkrOFcgZTdniYUIbuQ5b4KDFrbqy37adK7BPBkshpETJwMYxx/iahiBe1z+B4Cll tbEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698964020; x=1699568820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UfeDJJAakAHGSmerBO7TwpTzcsIOcntyODz+PgBSHd0=; b=ldR3m3dPwn5cPP3rWhF/yiTOftU4qaSkfNW4t3XaS37vO4lASxvFlaTYWprc5FRaoP 0HjLqirDzvG5EyzPLuxXJgHNvWirDxz42YQivPybVBYQaon0wmcZkbwzzGnAuW5aJWOd GEFrXD8EmW5GgojmCZrWL/bTB3unJx4FJKniA0emtQgLTXnck5weRbTeLg8vhwaeOSFp 9h2HAIRhR8DY6D64r7BTidwrOi7hWGfFhDRusvXU2krY6ko4SEhf3lEPt7pbExpeCg5N HDAAj0raAH5h7y/8TvJLnpAEptshAQT3oStTPQB2NaQknQ6kdMeKegwh0WYtTpHZHCjn qDaQ== X-Gm-Message-State: AOJu0Yw6dqBoBc6FD3rBnBnIgi48s4+6Jg/cyQb6o8YR6Ju0CC3j4dKb KCPQlhao3dg2UFW9gsI5LV4= X-Received: by 2002:a17:90a:3c86:b0:27c:fb84:101a with SMTP id g6-20020a17090a3c8600b0027cfb84101amr18099517pjc.29.1698964019924; Thu, 02 Nov 2023 15:26:59 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id cn18-20020a17090af09200b0027d015c365csm309894pjb.31.2023.11.02.15.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:26:59 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 4/5] perf annotate: Move some fields to annotated_source Date: Thu, 2 Nov 2023 15:26:52 -0700 Message-ID: <20231102222653.4165959-5-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231102222653.4165959-1-namhyung@kernel.org> References: <20231102222653.4165959-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,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]); Thu, 02 Nov 2023 15:27:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781492992981063286 X-GMAIL-MSGID: 1781492992981063286 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 Reviewed-by: Ian Rogers --- 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; + size_t sizeof_sym_hist; + struct sym_hist *histograms; + int nr_entries; + int nr_asm_entries; + u16 max_line_len; }; struct annotated_branch { @@ -289,9 +292,6 @@ struct LOCKABLE annotation { struct annotation_line **offsets; int nr_events; int max_jump_sources; - int nr_entries; - int nr_asm_entries; - u16 max_line_len; struct { u8 addr; u8 jumps; From patchwork Thu Nov 2 22:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 161136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp679608vqu; Thu, 2 Nov 2023 15:28:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOsQpv+atje0E+3F+q/SHfcxHanL56evVXrG2cvO8mEGvqPyEhGvPkEfRuoNwSHolhTrYH X-Received: by 2002:a05:6a20:42a6:b0:159:c07d:66f0 with SMTP id o38-20020a056a2042a600b00159c07d66f0mr1394855pzj.6.1698964095462; Thu, 02 Nov 2023 15:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698964095; cv=none; d=google.com; s=arc-20160816; b=WjZuPlpMYIn4Ltp3f3DFFhBp0rj3o2fIzjC6hxaVjElj6QQPBfDMOEMdg4mpZCdlCJ OOy147PoSfbOSho1wGC1q0bf1/LTFdeb7d491X09JIEhAHRJouM7E0HxbL6d1CC0FqlO Hq0Q3NpwPTmy0leC2Oy7GEHhTodGMMK6lozrF89jVmddlDvu+mYppwflDCBEeNKohgi8 p+RMGqZwv90GCQkVO/44Jnz+Srl0waQmUEEwWz0ahSMUjZMsdI2M0LrQ0jRDsh28Lo1r +WDBZPNdxKzaCJA0DVzxCSc66E52WH8Xc2lxABd0Ip0QvGUVHLK9aER7w4MjlZOJp1v9 iggA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=2lcxJn56vYeVd7h+U3NtVdyMbKNFOVxA21AaKaNaS0g=; fh=/TViaxNXj9Ubl1KVZseJCqJutBKG0dvzf3DPkf/1G64=; b=zQTvBy6GQsIkv+P0GDJS2cnkJKllbFF86k9fvUizs7L9wiM2fVmo2+2Wac43JamzNp 0m6gWR+ZSLXvWOjt0ZM+2oPV4GVwQ8uQKHiKzkhEhItLAugMr2iAjtNnKa9OE7B+cR3R /zAc6yW0tIU5kNKX34ldvLEEgtCc9i/xTPWhiOR9JCQrLFMh5vdBM/p+YYcVwvhqh/kh u16ZW0z3ltGW0eLcrwFIAt50zOD/+ewaPRjZ7//Smp7BwB3fjo+1wxiUhYkujlJx71O8 q+3VKAGq8lJzn2He1W2PpYMaYaH/jkovleo4SduGyXu9uEkmlS7rLHDVbGjnTnyYWTxb yLIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fxI/K0eU"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b12-20020a056a000ccc00b006c339c0cc08si367490pfv.196.2023.11.02.15.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:28:15 -0700 (PDT) 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=@gmail.com header.s=20230601 header.b="fxI/K0eU"; 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=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 C42B0811ADD5; Thu, 2 Nov 2023 15:28:12 -0700 (PDT) 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 S1377544AbjKBW1M (ORCPT + 37 others); Thu, 2 Nov 2023 18:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377509AbjKBW1E (ORCPT ); Thu, 2 Nov 2023 18:27:04 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B26FD138; Thu, 2 Nov 2023 15:27:01 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5b9390d6bd3so2093584a12.0; Thu, 02 Nov 2023 15:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698964021; x=1699568821; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=2lcxJn56vYeVd7h+U3NtVdyMbKNFOVxA21AaKaNaS0g=; b=fxI/K0eUfCjc8wkzZYneCznDqOtstoteIipECHHVnZKUulTGI82oAyKneWl6x48gr3 040F5jLfihojj35uYC1aezntDg/b25+CF7P+Uj9paXqVnFz45twwO8f9Q4cm36e8O2iP V/8S1tbwDEShFIzMxSfNyTxiZf14wWX9W59VGuG0WXYcRpoIGyvthzAl08fMN3aCGyz0 xUuCW/uT0ZLateq5RNjw//blDAm7532HSlSz1GWWjhGG3n2gHX2ZpT9/X4MxnGXz8V/9 3lhLanMGU3RIWUVaybrDXeeC6fR2a1IAh1ilg0QcFoqghmQpu8RMj2t8OH/kwGNPGzN4 QjbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698964021; x=1699568821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2lcxJn56vYeVd7h+U3NtVdyMbKNFOVxA21AaKaNaS0g=; b=wLGkI1tLYtylVHHgiEP6f+Ys7kT41eNLQsGgNkHB9C2ll8V+dXjYmdJx9taA3PTIoX uM9E8DtnM/YqyMq8rYE+iM/K4A1JUnpG7gb9eGk5CFDN9BVKPXszxL7Qp2S6769YCd7h VhopUX6NnsoI/ActtAcUmaCIM6Pb9/tZXeG0EVrdoAaTqpUGfgV/GTj8oIJy1lsMihPC ar16Wi/5KaU+pFhKZguh+0HwixD/yqZJiycRqLMvgR67fCj3MsxYFL7FZPUAzjurCrQM 4DQUcCIvZDitje9ff/Vbk8bFGehSNFEjhd0xY/YMI7TgNeFxiC8DZIRGapWNrwExgTJt K71w== X-Gm-Message-State: AOJu0Yxl8uMaDcRfa1P1lRM7PoTDo8Kdltrc14osYUlL5Cm+rFtk7+dg tciGEsrQoPoIdRB0b095iMA= X-Received: by 2002:a17:90b:3e88:b0:27c:df02:88b3 with SMTP id rj8-20020a17090b3e8800b0027cdf0288b3mr1310728pjb.8.1698964021032; Thu, 02 Nov 2023 15:27:01 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id cn18-20020a17090af09200b0027d015c365csm309894pjb.31.2023.11.02.15.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 15:27:00 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 5/5] perf annotate: Move offsets to annotated_source Date: Thu, 2 Nov 2023 15:26:53 -0700 Message-ID: <20231102222653.4165959-6-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231102222653.4165959-1-namhyung@kernel.org> References: <20231102222653.4165959-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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]); Thu, 02 Nov 2023 15:28:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781492975313563323 X-GMAIL-MSGID: 1781492975313563323 The offsets array keeps pointers to struct annotation_line which is available in the annotated_source. Let's move it to there. Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/ui/browsers/annotate.c | 4 ++-- tools/perf/util/annotate.c | 18 +++++++++--------- tools/perf/util/annotate.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 1b42db70c998..163f916fff68 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -188,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) * name right after the '<' token and probably treating this like a * 'call' instruction. */ - target = notes->offsets[cursor->ops.target.offset]; + target = notes->src->offsets[cursor->ops.target.offset]; if (target == NULL) { ui_helpline__printf("WARN: jump target inconsistency, press 'o', notes->offsets[%#x] = NULL\n", cursor->ops.target.offset); @@ -1006,6 +1006,6 @@ int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel, out_free_offsets: if(not_annotated) - zfree(¬es->offsets); + zfree(¬es->src->offsets); return ret; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index ee7b8e1848a8..8ab2e1cf63ea 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1075,7 +1075,7 @@ static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64 u64 offset; for (offset = start; offset <= end; offset++) { - if (notes->offsets[offset]) + if (notes->src->offsets[offset]) n_insn++; } return n_insn; @@ -1105,7 +1105,7 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64 return; for (offset = start; offset <= end; offset++) { - struct annotation_line *al = notes->offsets[offset]; + struct annotation_line *al = notes->src->offsets[offset]; if (al && al->cycles && al->cycles->ipc == 0.0) { al->cycles->ipc = ipc; @@ -1142,7 +1142,7 @@ void annotation__compute_ipc(struct annotation *notes, size_t size) if (ch && ch->cycles) { struct annotation_line *al; - al = notes->offsets[offset]; + al = notes->src->offsets[offset]; if (al && al->cycles == NULL) { al->cycles = zalloc(sizeof(*al->cycles)); if (al->cycles == NULL) @@ -2783,7 +2783,7 @@ void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym) return; for (offset = 0; offset < size; ++offset) { - struct annotation_line *al = notes->offsets[offset]; + struct annotation_line *al = notes->src->offsets[offset]; struct disasm_line *dl; dl = disasm_line(al); @@ -2791,7 +2791,7 @@ void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym) if (!disasm_line__is_valid_local_jump(dl, sym)) continue; - al = notes->offsets[dl->ops.target.offset]; + al = notes->src->offsets[dl->ops.target.offset]; /* * FIXME: Oops, no jump target? Buggy disassembler? Or do we @@ -2830,7 +2830,7 @@ void annotation__set_offsets(struct annotation *notes, s64 size) * E.g. copy_user_generic_unrolled */ if (al->offset < size) - notes->offsets[al->offset] = al; + notes->src->offsets[al->offset] = al; } else al->idx_asm = -1; } @@ -3263,8 +3263,8 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, size_t size = symbol__size(sym); int nr_pcnt = 1, err; - notes->offsets = zalloc(size * sizeof(struct annotation_line *)); - if (notes->offsets == NULL) + notes->src->offsets = zalloc(size * sizeof(struct annotation_line *)); + if (notes->src->offsets == NULL) return ENOMEM; if (evsel__is_group_event(evsel)) @@ -3290,7 +3290,7 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, return 0; out_free_offsets: - zfree(¬es->offsets); + zfree(¬es->src->offsets); return err; } diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index c51ceb857bd6..44af7e71a204 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -272,6 +272,7 @@ struct annotated_source { int nr_histograms; size_t sizeof_sym_hist; struct sym_hist *histograms; + struct annotation_line **offsets; int nr_entries; int nr_asm_entries; u16 max_line_len; @@ -289,7 +290,6 @@ struct annotated_branch { struct LOCKABLE annotation { u64 start; struct annotation_options *options; - struct annotation_line **offsets; int nr_events; int max_jump_sources; struct {