Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp196715rwi; Fri, 14 Oct 2022 00:08:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XD1YQy87BH/90R0/qNtQr9LA2bJqU5p7hVoWSDZyd/aZqVPVEGE8tL5J1rb9YVyXSrUQK X-Received: by 2002:a17:902:d4c6:b0:184:6926:abbd with SMTP id o6-20020a170902d4c600b001846926abbdmr3989997plg.33.1665731316983; Fri, 14 Oct 2022 00:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665731316; cv=none; d=google.com; s=arc-20160816; b=JlTqYzpet6fnoRTbVgiHmx5hSWsotPfBDaGzqLheWYAL1lYxnEHzWOOQEaOTChqACZ TQNTShtzwT7XCu/G2c6ucfrKZXsey5pGpJM5+8v/+GJHyRUaP5RXk1lJLQwQWJMl6Gkj zricLiPEHHFK6ev4PVOY10mHOrIaE6d4PR/mfpo83VMbaImB0Tpk6KUBBFCqFtQu9KNm Z+6pWvmfueS4UaJrro9Poyfk0qqG58VY3XwA1L+WR+LBxT7FB3s5jEkgStlyt5sBdFlL saSA/Y4qYEa8MNY/e1jbYzcwxOsBsMKAWP5GKydujJouuZdtsaE63jx6ExNNuLLTQP1A GzAQ== 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=UCEX8+4DtKvjzpeGjCjNvRZfSVdikj6WeltMAM1MA+6ve1t5t5GOv5X4KstsowcuQR 702KL9T1rnHhEm2xl21FHNTzOdfpnT/M6j5V8S/JbkB5iPCzzNf+IgDti70bsV0ZvA90 Z3Vo/y3dwwqMBO7VaNb4nmDyH8Qa1CX240v3gUnKAphTZ4050NWfSyF98MhpuKKAWpOm kRhf1dhvucOU8/Ru3wLVLDAJX01ns51747veB/ZYO9hT8LTHPcLoGD/e+NLMU9PBLBy5 s6Yidti92QokFpugUJFA4Q4EQP+vTa0T5OvKueQ+Ar1KJD7OpjcI2dlZRasU73XMI/lx 4BFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ecdtNwOW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o28-20020a63731c000000b0042b95537587si1810483pgc.359.2022.10.14.00.08.23; Fri, 14 Oct 2022 00:08:36 -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=ecdtNwOW; 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 S229782AbiJNGQ5 (ORCPT + 99 others); Fri, 14 Oct 2022 02:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbiJNGQG (ORCPT ); Fri, 14 Oct 2022 02:16:06 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 732F61ACA97; Thu, 13 Oct 2022 23:16:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id pq16so4045794pjb.2; Thu, 13 Oct 2022 23:16:03 -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=ecdtNwOW4la+h9gxPqzdVVZAAuOGaARVWg9USJMX5lUxWYwmEVVtZbAgCKLZL/Pa3j 5sfEZ6fdR9yqIQf00lGtAl3niatSqMfy31HSG44jXhwoN2Y5iEMIETJ150FB4xz2JU6+ 6eOxmCZJwx7rhe1ikhKzq1jxd9w/ylkwpPMGf5YDR9gXsZTW7DCxMIR1nFkEj1FaWtKu pxIYbqJO7XVDu8XQ3uvXy0TrGtI95Ss/AeG5UDt3/K/QqWPqQCRAgFGJclZDMsPN/6W1 iSeI+qPz2Qj44oqcrJe26m9uFHTZp1KVBaFHjPH1hhIvEOqQ7rj4C2xx4zpd/10Z7seI NKhA== 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=vRYpZXjmnaf+eqI3GMc76VlhPlxmlYNFgO/QRULmh6aNT/RQDfO8DE+C4LJ2X7y+q7 alvOQeHVZ3Se87jNfidfIv983my/kpuaaPo3l2PVs+ow6RKaEAoB+Vyp24VICQtOT3Lr 5MK2LYkq4cAZc4CUJMGo9JAfmCmIUSm7u7llc7L5cZ+YstJa/EGlSY01yMKzZdCSFZrs M8teHabQg/4gO72VLchGUN5MHGcuHl/Eu3UUItQEpH3KqWeOs0nApZxYkfEh4Ph7luIU d/nmoQIyL/v5pMtJqiddDHd4+fUzrolaoAkBriHdzhoXo18GbvcyQmiuhhgmqPCm9q4B kj2w== X-Gm-Message-State: ACrzQf2JMHPoXPJ0grcwgY8xPx3TcvCMhHabiqUL5nk0duWmg8QPvjcd YPx3b6570DL+AGmxEluUprE= X-Received: by 2002:a17:903:2606:b0:180:8799:3685 with SMTP id jd6-20020a170903260600b0018087993685mr3520101plb.31.1665728162181; Thu, 13 Oct 2022 23:16:02 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:01 -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 Subject: [PATCH 06/19] perf stat: Add 'needs_sort' argument to cpu_aggr_map__new() Date: Thu, 13 Oct 2022 23:15:37 -0700 Message-Id: <20221014061550.463644-7-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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); -- 2.38.0.413.g74048e4d9e-goog