From patchwork Tue Oct 18 02:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734547wrs; Mon, 17 Oct 2022 19:04:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4oP+0h9CvUTr9W/Lu6Oh4T7mVGB0yo/erJra9Vty6Mt7UbPEup26nZmwErr4eo3EEbrgkA X-Received: by 2002:a17:90b:224c:b0:20d:8828:3056 with SMTP id hk12-20020a17090b224c00b0020d88283056mr36545429pjb.136.1666058674056; Mon, 17 Oct 2022 19:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058674; cv=none; d=google.com; s=arc-20160816; b=0D0oON+J4qaUUWzN6FjEQOA16k4XYgqIYfGJLYRrwe5R26Gpx8sfM5UxJ5K6s5qb2k DyEUt/pXs3NkhkiOwSzQFzah6OfXA8Q9bBOg73J9tNepSREjoT8xnHb7aRZNE69+IBOG fx+J835GcvjgqcWzAp06j3B6mV2OSpm0WpVyu4f4eZQWS4VdmH07kyK3V+siAgtAIg1n JsR9Zy80pxZ5XodZdZI+AqGQ4HENG7/nxYULLlz2JwySO9i/Q3pjG5nuqOTQMpqVNqXo dOMt+78M+Z/wQ13jOidAI3//MPPziqTwk/FpRmkw+uIrqcCc9efFPWPPDMkln0FtI3f+ SnfA== 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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=SySdSMobN1x1mxqQYdDI7vyrJtn6yzQUeGGWxYeRzK69YmZIdw4VoHFrMChdT2XmNS 2lITRAwlg9pZUElR9yEuF32XgQYN73URUNlQXoR95jLqg0dUgurxXEYSgYfeSe7SbNLp tBSvPVYb6yqcpzaXJ0wShSFtZclFpTTngogWcPPjRpwOHn7+Y5EZhBvE4s88gj7MACeX wWujjZwaG52PP1/0QnNNvtkaAge3B71CjN3CqkHg1WdJvnSIRFXssAXelfbdanZLkfEr xEOLYPQr74EngF6AMTzI8HUObglmW9/sFT1in5zLQ3beCKRVtdz1E2PF3t3KAqSxAl8+ 9N1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Vzx+mg4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b00455be728dbasi15845640pgi.820.2022.10.17.19.04.20; Mon, 17 Oct 2022 19:04:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Vzx+mg4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230480AbiJRCDF (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230407AbiJRCCv (ORCPT ); Mon, 17 Oct 2022 22:02:51 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 802CC8BB84; Mon, 17 Oct 2022 19:02:42 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id c24so12491440plo.3; Mon, 17 Oct 2022 19:02:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=Vzx+mg4UQoni7cM+BNOEIcGwkEUUNjBpyZzYPEfdNLVugf6uVCUusMi0F/IRZPUeWl 8PmNIYX8iWNKWIL6aZ+gSSwcN0l8MF4GFnnke9MKeWfJJz1Tr7XDMJS0Mi9rtjalUhK1 3wfkXPeEVBmfJePLA/Eu2wKVcFHnmW5s6mr7rInLyu3KWz5prRFA82SwISAAEFfYjknE xV3UihvchvdxWNQOV/v05zz+16thxm98keeSr0exLyneX+6xem48M5hkNQoRVXiq7gw+ raadCH4Na93GBtYk7HMkpQNMpzZrGIZNCSwV8GiLI9cVhiny7aaOreA9fUlp5CXp2PEa ZH+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=D5CrG2Qn7/sdGMA9qw8v3f1wqR62+gBzxB8W+0YBYW8=; b=pV/xwiuE30cDoL/gWJ2Yf7khVykSMVWLZuZ3SyNGI7+mTNKCx91aJyppPBYdGqt9cO nGDfJ6c8AGZLvMXr9rmR7o2b7RmIt9/XJ2gggH241VhtPnDF0hcHu6MztVm8UdUPqPcE 11j+o09UJaT/AAZ7ji8m4QrsYnx+4evt/Xgo2+99bSDCkrUrPOsArGogf0oCwTXZtC3j X1SsWrarcNRieE2zi93BsjpTVt+EkEqYbtxErg1FExHyQwnrX9C4w5tNNt/MssWCG/kB B1b83dkscLYarCoYVf2wwh+J4Akf/WdbEp6Ch5UCcdK8wPGnzzEKO++hb/GsIvd+db37 C+zA== X-Gm-Message-State: ACrzQf00jq/YKjByjJCZWtkdfTIRaRNBdabLsbUYM5poV5fYaGx10BbH uh6sRZcT9T86Zv+W6Sbv9Qg= X-Received: by 2002:a17:90b:268b:b0:20c:e5fa:db70 with SMTP id pl11-20020a17090b268b00b0020ce5fadb70mr869950pjb.23.1666058561317; Mon, 17 Oct 2022 19:02:41 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1f90:85c4:58f0:7a81:6bb5]) by smtp.gmail.com with ESMTPSA id t4-20020a655544000000b00464858cf6b0sm6851564pgr.54.2022.10.17.19.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:40 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan , Andi Kleen , Athira Rajeev , James Clark , Xing Zhengjun , Michael Petlan Subject: [PATCH 06/20] perf stat: Add 'needs_sort' argument to cpu_aggr_map__new() Date: Mon, 17 Oct 2022 19:02:13 -0700 Message-Id: <20221018020227.85905-7-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018020227.85905-1-namhyung@kernel.org> References: <20221018020227.85905-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_NONE,SPF_HELO_NONE, SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746989139977323075?= X-GMAIL-MSGID: =?utf-8?q?1746989139977323075?= In case of no aggregation, it needs to keep the original (cpu) ordering in the aggr_map so that it can be in sync with the cpu map. This will make the code easier to handle AGGR_NONE similar to others. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 7 +++++-- tools/perf/util/cpumap.c | 6 ++++-- tools/perf/util/cpumap.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b03b530fe9a6..9053fd4d15a7 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1458,8 +1458,9 @@ static int perf_stat_init_aggr_mode(void) aggr_cpu_id_get_t get_id = aggr_mode__get_aggr(stat_config.aggr_mode); if (get_id) { + bool needs_sort = stat_config.aggr_mode != AGGR_NONE; stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, - get_id, /*data=*/NULL); + get_id, /*data=*/NULL, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); return -1; @@ -1674,11 +1675,13 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) { struct perf_env *env = &st->session->header.env; aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); + bool needs_sort = stat_config.aggr_mode != AGGR_NONE; if (!get_id) return 0; - stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, get_id, env); + stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, + get_id, env, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); return -1; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 60209fe87456..6e3fcf523de9 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -234,7 +234,7 @@ static int aggr_cpu_id__cmp(const void *a_pointer, const void *b_pointer) struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, aggr_cpu_id_get_t get_id, - void *data) + void *data, bool needs_sort) { int idx; struct perf_cpu cpu; @@ -270,8 +270,10 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, if (trimmed_c) c = trimmed_c; } + /* ensure we process id in increasing order */ - qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); + if (needs_sort) + qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); return c; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index b2ff648bc417..da28b3146ef9 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -97,7 +97,7 @@ typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data) */ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, aggr_cpu_id_get_t get_id, - void *data); + void *data, bool needs_sort); bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b); bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a);