From patchwork Tue Oct 18 02:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734285wrs; Mon, 17 Oct 2022 19:03:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6b5kzZ0/W/cIsp7b4WRcyKizmCRXH87BvKFI/LvzcsaHKVZZRvfqmaMErGnWcbVHtMACs1 X-Received: by 2002:a17:906:cc0f:b0:78e:1208:8796 with SMTP id ml15-20020a170906cc0f00b0078e12088796mr465968ejb.601.1666058634863; Mon, 17 Oct 2022 19:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058634; cv=none; d=google.com; s=arc-20160816; b=Ir8aqjwT8fkvx2UkZO4kMZ2rP5FXjL2WqPU0Sa31Idq88jgyg1VBCjbbE6Cx4ODeDF mqd/sqxHb6//sX2VKwHBoGFEZbXFWQiCUVzykkIAK0C1DGJms14fz1ZVIgMDSxa2yatv UCEHrDnClqHorOAiuxBduV38hux1iTUF7/D7idnkDnng+p494nxh5XkZLSW4XqC7Eu1Q ZWb2P2c5ceRlGsTiouXjgdwhYrsirmP8oyMnO4CgmZBsc9OR2dQ4DysLsZMq37g5U2DT DfmXui7O5LE2aVGxU8xhOFGWgolzrd9KfR6BqY/toRVoEM/gIUHYX03+XDG4Xd1Vkx5b P0uw== 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=3BRWQ1hkRGo/t2t1Y4zQ7FNnMWXMwqdSp5KgGUNdwvk=; b=scFoOkl1OjYhnwKo0UAOlMDB491JzdRa0mtmYDs4jm0AA70+9eNlG9d9qWCck9PAN1 Nu7fR1RXjJptNTYK7MqdEZzZxnVIorYfFeg/DYMvDm9iqXw8AkOia4d6omFaQseeWk7O /PRZHE/m8LsNnA47mTgVdlqA0Llq2R0dMlrUH9KnyU+f7VZOVLE82dJLCiGqWUFJLPnP t7uj1O1PlzSLxerAD73VHEgK+vJVk1jvJG8NNIieXjFlRMHlnbCZkfi05B9PAsMnX2xc EmEcJkANvzUyU5C9T12FaNl5KmGRU5Bga/dIqhBHcm9yTCae12ZAtESgJOCL824Z7ucZ Nqqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lqIrEEJF; 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 w17-20020a056402269100b0045cc36d6d8fsi11222019edd.336.2022.10.17.19.03.30; Mon, 17 Oct 2022 19:03:54 -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=lqIrEEJF; 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 S230328AbiJRCCk (ORCPT + 99 others); Mon, 17 Oct 2022 22:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbiJRCCd (ORCPT ); Mon, 17 Oct 2022 22:02:33 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E40F844CE; Mon, 17 Oct 2022 19:02:32 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id 67so12738212pfz.12; Mon, 17 Oct 2022 19:02:32 -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=3BRWQ1hkRGo/t2t1Y4zQ7FNnMWXMwqdSp5KgGUNdwvk=; b=lqIrEEJFH+6fv8601BrcwUP0h3xLWOxO77cvpPmE0CacznT2LcC8Ugxa+hS+t7k8XA WpcgdxhteQ6s7zSA8s7i4q0dPnmx8bTiqjSAYcs0Temm/WL53P1LHWuA4eLKGFbV+Qk1 1qrxTy7o+EtDsEsODFrwMHZxG0IjeeuJbgcEDC5bOaDH6xodcH8PTf48Dq2yatHHWQq9 PoSC56BKMPb78adL9cBmBugUTQ25LA0iGyABa7/mKxmdAXv+SLpv4MbI/DDCOs7+5uf/ qdXUyju1IHB81wWVniRANDFaD0tmT/aR/gAAnTwkyaUxUwhTHdcwSsM24zWQG3rgK53c BbCQ== 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=3BRWQ1hkRGo/t2t1Y4zQ7FNnMWXMwqdSp5KgGUNdwvk=; b=CjFiBc16WI3jYqAYKDwpLvBQRek1e4lqRZ+xIDdMO7kzObz72UxZyvVJtiu4BVNN27 zxjU7dxlAAymUqKcCAmvkwCWpuLHozsmWnLS08V2NZFgxDGdNK5BV6VC5fITZHJpbMe/ YdiR2pa3DW5GaumBJWvOFseK6SoWh6t4QQK9WMfKYiGS8way48/WUJ9U01W+yy677oMA r7bLMx6BypfInG3iHjc1EyyGENGbei5MTxFwjldkkHLN+16jYz3rULWBmxBHgO6PCpo7 vv2b1SiBspgFh9Hk6Ux2r7fB7hd11KekkBjVyaPLdVBzDxBB6JdA296BHavCgDVrr9mO DnSw== X-Gm-Message-State: ACrzQf1kueDQbgk/FSJeeGQ+DoDncTz+NSDV2gpw7ck40aEyHAIjt29W gMizBjbFkilt1HvBPyQ28kg= X-Received: by 2002:a63:5a50:0:b0:429:8580:fc61 with SMTP id k16-20020a635a50000000b004298580fc61mr647238pgm.215.1666058552099; Mon, 17 Oct 2022 19:02:32 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:31 -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 01/20] perf tools: Save evsel->pmu in parse_events() Date: Mon, 17 Oct 2022 19:02:08 -0700 Message-Id: <20221018020227.85905-2-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?1746989099214971669?= X-GMAIL-MSGID: =?utf-8?q?1746989099214971669?= Now evsel has a pmu pointer, let's save the info and use it like in evsel__find_pmu(). The missing feature check needs to be changed as the pmu pointer can be set from the beginning. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 20 ++++++++++---------- tools/perf/util/parse-events.c | 1 + tools/perf/util/pmu.c | 4 ++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 76605fde3507..b7140beca970 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -467,6 +467,7 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->collect_stat = orig->collect_stat; evsel->weak_group = orig->weak_group; evsel->use_config_name = orig->use_config_name; + evsel->pmu = orig->pmu; if (evsel__copy_config_terms(evsel, orig) < 0) goto out_err; @@ -1966,17 +1967,16 @@ bool evsel__detect_missing_features(struct evsel *evsel) perf_missing_features.mmap2 = true; pr_debug2_peo("switching off mmap2\n"); return true; - } else if ((evsel->core.attr.exclude_guest || evsel->core.attr.exclude_host) && - (evsel->pmu == NULL || evsel->pmu->missing_features.exclude_guest)) { - if (evsel->pmu == NULL) { + } else if (evsel->core.attr.exclude_guest || evsel->core.attr.exclude_host) { + if (evsel->pmu == NULL) evsel->pmu = evsel__find_pmu(evsel); - if (evsel->pmu) - evsel->pmu->missing_features.exclude_guest = true; - else { - /* we cannot find PMU, disable attrs now */ - evsel->core.attr.exclude_host = false; - evsel->core.attr.exclude_guest = false; - } + + if (evsel->pmu) + evsel->pmu->missing_features.exclude_guest = true; + else { + /* we cannot find PMU, disable attrs now */ + evsel->core.attr.exclude_host = false; + evsel->core.attr.exclude_guest = false; } if (evsel->exclude_GH) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5973f46c2375..6502cd679f57 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -266,6 +266,7 @@ __add_event(struct list_head *list, int *idx, evsel->core.own_cpus = perf_cpu_map__get(cpus); evsel->core.requires_cpu = pmu ? pmu->is_uncore : false; evsel->auto_merge_stats = auto_merge_stats; + evsel->pmu = pmu; if (name) evsel->name = strdup(name); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 03284059175f..6a86e6af0903 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1065,11 +1065,15 @@ struct perf_pmu *evsel__find_pmu(struct evsel *evsel) { struct perf_pmu *pmu = NULL; + if (evsel->pmu) + return evsel->pmu; + while ((pmu = perf_pmu__scan(pmu)) != NULL) { if (pmu->type == evsel->core.attr.type) break; } + evsel->pmu = pmu; return pmu; } From patchwork Tue Oct 18 02:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734336wrs; Mon, 17 Oct 2022 19:04:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5szWV88q5lPN5ZkTqFudWJcy1ysL6cu2qOPq6Zj0R5mHYq5+kD44gjJDMNilEGYeDkv/h+ X-Received: by 2002:a17:907:72c1:b0:783:34ce:87b9 with SMTP id du1-20020a17090772c100b0078334ce87b9mr490728ejc.115.1666058641013; Mon, 17 Oct 2022 19:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058641; cv=none; d=google.com; s=arc-20160816; b=wx2lXcJXug7vSHytXxbUpFwv+NgQrCKejpBKvx7+qBo7BtgclYFnlERfHupSmdDsPP HtB0k7TFwo1WG7Meokczm/4pnF5tx84msLrs8Xucp7trmlqU8SOKYsX0UNJnmAO643cK vRJuYPQuxnNZtBE39eKDPxYsR41elYvBU+LV8Ks3Jv60H1pIJrIadNHaOhDr4bOcRjK8 D6tEcwGNEyvR2z1HoBeWcM4Y9EHfIKjSND1xRKfZKI3qF3HtcxT+pb5FpNqRTIIEXWW2 /f1Lom3hHhCcfVceqMohPdohS8ssKwMjxa8ubWZA/H1SdUUrY03xPCUtLL3HJ3BK1RT5 EnFw== 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=mcP4GbdpRTg6spV/HxyzwMSNL9MGijUUA6+sUlnFP30=; b=sC8OvyGm4F4c3leQSidu+vNbTMc2zgv8f7e6jZV47/AUHhUN5Cad5Kqx8ehNBaXy3G xkL+1/G2iEtwV4HCQeHd8Kqhx5eqBXEMyXLeNypMxauCEvZMmjQX5+RjSL7mqaSobDxD 9JDSQbq4Go/DFckN5TMK5692oapLrnsR1NU9M4PqRCPd48/k0Qm56cbdOxytverBsl6F 3/C0RdGEcKNoP9qo1zmb95zEnEGbphyJEaV0Tm8gRXxzMPXfyPN6LI7ZsIz3rxLTgtG0 gJNwg3E4kv2STTA6Qon/s7oDrvMdh/AMkAEuw916ci/qyhBcr966JR7cimg8GYFr2/Be brjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CY2n7t9K; 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 f14-20020a056402354e00b00457dcfa56cbsi12112536edd.343.2022.10.17.19.03.35; Mon, 17 Oct 2022 19:04:01 -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=CY2n7t9K; 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 S230310AbiJRCCq (ORCPT + 99 others); Mon, 17 Oct 2022 22:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbiJRCCf (ORCPT ); Mon, 17 Oct 2022 22:02:35 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A062844CE; Mon, 17 Oct 2022 19:02:34 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id e129so12044819pgc.9; Mon, 17 Oct 2022 19:02:34 -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=mcP4GbdpRTg6spV/HxyzwMSNL9MGijUUA6+sUlnFP30=; b=CY2n7t9KmgGwYwl5tgxWrVZcJdY2PTnNC0T7rRdSFzweDWqb/OfgiAQT+k4dJxc2Ly sXZnR5NuEDL5dKzc9j0lnphgZRYyjTuYJOVk0Lolt/TDGjGpXLgBkMikfA02+KR1AcmB 879/iHDqNhznOND8LUpWWFAIcrBv5Dbq8LADiq8AVk1Q6TLeKL85mGRkPWQaJ4Laeg6g orpTnJGYGeJunVHDmEpZnHg9skRzwVX5JRvXVNBodOdAYqfwQW34kH28oR1yCNiWkkOC 4Z6nH88d3U0gKzSeVcncm6TAafwqf59yS0DlJDxyRXJWDlkK6mMhelt4JX4/Ranu6gHN MRTw== 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=mcP4GbdpRTg6spV/HxyzwMSNL9MGijUUA6+sUlnFP30=; b=j8lQxA09yFOwORI7A/6xNKOx0cOLk+lCqGA1nKOWzMpuEfxfpDz5ObVwCyGOxe+TzK 5r5Y5nWihqKKvD0KGPnmEScJEOJMhfzFEWyBZV28QxqGSUGdZj3qar4JEd6pwQSkXrGx PmyuI9Zkt6Dt3mRKwNm36jnv63U+y8iFyOBH5DRAm9GcpgFb99Aw13f1pt7qlUZGAasf LfUxzcouUk85XcXGg7mDsw6g1zmbdz5+JapcSQl5mwvJ679QIlBwXoLQfttCDjGmwhEW ixNVqjOjKUFFaS6rEprV4jhUIesbpNIaYOU1QHauSsjGXp8yRjT8UBbf/oD1JrooIOEP GuAQ== X-Gm-Message-State: ACrzQf2l0046Ek7HbVx/0ga+6HIIxRtQVJLrAceNZtfdTN5T7T9YTHIc BKXyd0G0qJ8c6C/AcOAl8p0= X-Received: by 2002:a63:8643:0:b0:462:9b02:a0c1 with SMTP id x64-20020a638643000000b004629b02a0c1mr665747pgd.536.1666058553748; Mon, 17 Oct 2022 19:02:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:33 -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 02/20] perf tools: Use pmu info in evsel__is_hybrid() Date: Mon, 17 Oct 2022 19:02:09 -0700 Message-Id: <20221018020227.85905-3-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?1746989105624478871?= X-GMAIL-MSGID: =?utf-8?q?1746989105624478871?= If evsel has pmu, it can use pmu->is_hybrid directly. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b7140beca970..c9fef26d0702 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3131,6 +3131,9 @@ void evsel__zero_per_pkg(struct evsel *evsel) bool evsel__is_hybrid(struct evsel *evsel) { + if (evsel->pmu) + return evsel->pmu->is_hybrid; + return evsel->pmu_name && perf_pmu__is_hybrid(evsel->pmu_name); } From patchwork Tue Oct 18 02:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734458wrs; Mon, 17 Oct 2022 19:04:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6UR1EToVlUZZi558dSF3oQBdA84oTNlBtVq9hVNoLZQijuL2XQl8hSTwSqACnFmI3Pv8T0 X-Received: by 2002:a17:906:dc93:b0:791:95dd:aaf6 with SMTP id cs19-20020a170906dc9300b0079195ddaaf6mr502587ejc.456.1666058659132; Mon, 17 Oct 2022 19:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058659; cv=none; d=google.com; s=arc-20160816; b=HdoK3aARmB7RocLSLSmze0jnILIFDomjpFZQLChTZNBxBHtXEt0mOceD8jOM7j769/ kfKYKOjhTTCZwJ0ciG25EMB/TJEJDoWR4JkTTx0+YBOwMtAlWPHEMlOfKdixKBbiEpiu NZqvkGkNwHkAjZbL0k9IK1PEHFNizrZ4dzKoNKxQ22DQC+Hw4q/Qt9vCfyrgYoAgltAi K/Cxfr7CunR10APkyqclIX1Qzbmcd94rc5laG1VPmgP3ITcqcBmLI422dosG9tg4o0BJ 6kDpgqa7A8D3guSTR+O8PsCjAYYynj6JNAEjxTHfvZ5E+l0oA1pdZOATP9FypvpU9Tev dIBA== 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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=CR+1Prmsx9srcgSiRWzu7aUZD7lMLR5Z4PORXJErBRG4RshMjkK9rNQvqxZMiUTu+m W4pO++nn2Md3I/X8GPQF2mXhpe10+6seLyR0+7DiU5W7HIwe4YwBW487NyDFNytM2T/E XU3uQRQjiTG+gaSm5HAQWkGlstrFo4qA1MGPTqi/So2RD1vfoKrtK2dCmPdoBQILJGBO 1/bvDmNDyZk8le387QJvFoh5JpBTYEPl3mE3v8R/d74H7v9n6K6S+3hOa4pYCXurBVnh Sdf9/nV2Er5wsI4AV8rGHwerK1jS0uMTJXkGtp1GuwiuTNFWV9Vysi7glORR9yyr0r31 giNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iCrejwQo; 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 hq13-20020a1709073f0d00b0073317d6b047si4423595ejc.569.2022.10.17.19.03.53; Mon, 17 Oct 2022 19:04:19 -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=iCrejwQo; 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 S230406AbiJRCCv (ORCPT + 99 others); Mon, 17 Oct 2022 22:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbiJRCCi (ORCPT ); Mon, 17 Oct 2022 22:02:38 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42CE389960; Mon, 17 Oct 2022 19:02:36 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id x31-20020a17090a38a200b0020d2afec803so12647378pjb.2; Mon, 17 Oct 2022 19:02:36 -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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=iCrejwQoNjPnaOJtP4D9FKmuMPZRa9yViKCjpstrhaXtvkYlKkEx/LHbxPZiJPSkzz 1Pi/VnauJtLS0AEfWLHeyFUWW1khgUtngaEBXeJlTwlY8ORfYZ6JaDV42oFZutwNihI3 /QB7Ts119MyVtyKvlysiN6c4q7kteiz/J6yAQd+PuzFvQUye88tShs5rfergZaMh05lo DPF0Nhc90ol7+XxKojrxN7IX74gPqG3Mu7+KNoHsKYyL8STWnqxDg08MjKUZnR7nFejk CdxStYCGmhscmVfCovE/VDLcXM/haPBKVSQlDhGo27EVEB2dFXnbW+rwZJYXxt8rmDAs /n5w== 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=asmqIEkehVBlu4ghVcVYSD1s1d8czrslDCSII7LsD/Q=; b=sjTriuQjm/aRQJTtVGOHiK1BsUg//jpOy/LLR9mSpl+gRQv5whm68gjtAYD4FKME4E q46TCN5KrtJBaRAJPY5yOX6MJN+yb2fsMQBDYcYF5bXhJNh0fZRDkDhVI2Ywep2Pd3H7 AlVUsW33ziVZkIEixKk2lxcj9Nhy0HMUsKFaHEa4Upj9PsxS81p6ODUt2FU6ag8oEFZ/ AFqIwP1KHTu0oIbPX2ux0PNlfdly8YJL/yf5ct9IAYQ4eXx/0xk1yQtnN0XfGKZyTQPL fPnNx1Mbl+w0jEjtRUtiOiNga+UBKUGBfN/gTHFqnLKq8q29JOdcnHpyN/0H6M5kUVzW iukg== X-Gm-Message-State: ACrzQf2ji8uS3lWF+FUf3MQNcZEwrRew4+W5teUGXx4gi2WbGR12G910 bZoDRm/ZO99xROd/Kok00wc= X-Received: by 2002:a17:90b:1644:b0:20b:1cb4:2c9a with SMTP id il4-20020a17090b164400b0020b1cb42c9amr37817800pjb.193.1666058555658; Mon, 17 Oct 2022 19:02:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:35 -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 03/20] perf stat: Use evsel__is_hybrid() more Date: Mon, 17 Oct 2022 19:02:10 -0700 Message-Id: <20221018020227.85905-4-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?1746989124676295041?= X-GMAIL-MSGID: =?utf-8?q?1746989124676295041?= In the stat-display code, it needs to check if the current evsel is hybrid but it uses perf_pmu__has_hybrid() which can return true for non-hybrid event too. I think it's better to use evsel__is_hybrid(). Also remove a NULL check for the 'config' parameter in the hybrid_merge() since it's called after config->no_merge check. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5c47ee9963a7..4113aa86772f 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -704,7 +704,7 @@ static void uniquify_event_name(struct evsel *counter) counter->name = new_name; } } else { - if (perf_pmu__has_hybrid()) { + if (evsel__is_hybrid(counter)) { ret = asprintf(&new_name, "%s/%s/", counter->pmu_name, counter->name); } else { @@ -744,26 +744,14 @@ static void collect_all_aliases(struct perf_stat_config *config, struct evsel *c } } -static bool is_uncore(struct evsel *evsel) -{ - struct perf_pmu *pmu = evsel__find_pmu(evsel); - - return pmu && pmu->is_uncore; -} - -static bool hybrid_uniquify(struct evsel *evsel) -{ - return perf_pmu__has_hybrid() && !is_uncore(evsel); -} - static bool hybrid_merge(struct evsel *counter, struct perf_stat_config *config, bool check) { - if (hybrid_uniquify(counter)) { + if (evsel__is_hybrid(counter)) { if (check) - return config && config->hybrid_merge; + return config->hybrid_merge; else - return config && !config->hybrid_merge; + return !config->hybrid_merge; } return false; From patchwork Tue Oct 18 02:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734560wrs; Mon, 17 Oct 2022 19:04:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WRWijIscvjA/PeHLuAxICXOSJR0LiQxPEWcJzKcRFLmX+oxZSohzLNIN2fjgvRPrfvAwa X-Received: by 2002:a17:906:7952:b0:787:a14d:65a7 with SMTP id l18-20020a170906795200b00787a14d65a7mr527722ejo.108.1666058676167; Mon, 17 Oct 2022 19:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058676; cv=none; d=google.com; s=arc-20160816; b=h7bWJx7Zu5g8HamO0lJZcq7tD4cPo94qf/L4UE+XF75/ZYLXhksMdP8w4wDyN+UVtK CiTMZzTr5pBNrXoVJUaFk8JTtXSWjEAzsDuPXBD8sFFKodpUWwigd1zJ5t8lBU0gNLcb LkOa2GajBN06j32cXnJGQkVgt6+Me1OzcerLAxyxUhJc77TQgFeoBe3d4DU42kBhcN4i pq1uEjcbA2P7hhM/GgFTJTRMKW39pOteKiIhnNgTWMZSFp/rgQgCJDWfNKvwC/csxPvj v9tLrC5wsr9rhOyqxo3MXaE1Pbip4vfpEsxuB5XAV2LeG4g1H73uaXlz2mW3BqYMgOs2 8Rfg== 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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=vpxUiF9YmPyrJgJAq/x2nGv4+tb3cvaOWw2AS9HiOOtoZl++eod8gb5Ifsk2BLWLqq ItOGgEsBk4uuTZvhiG1JcRsLL0DxvVL2sAFjsvOY8Y6NSWDOS7X+rYA+zAGXRrZmQpTI ciRkPTvryvuOBROKKQTu2qQ6937SJ/pRn96ma9hJU72fTv+5UwjcvxhopCcdR5qoc70O V1PogfvQcgtu6qtiJie6pHizZ+crfIZO9Lz1FSoeFQFTZWgAd/8KIpNPJHDwe63+/Iu1 pa5raUetn7zxtR1ybAiaZ/mR2OCeHz+Hiqv0pXwKtOs9zV7owHUWcDbrEZDG8zGaVFeH b6RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ibsxQ4qB; 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 qf22-20020a1709077f1600b0073fc8e72882si10413249ejc.28.2022.10.17.19.04.11; Mon, 17 Oct 2022 19:04: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=ibsxQ4qB; 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 S230418AbiJRCCy (ORCPT + 99 others); Mon, 17 Oct 2022 22:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiJRCCj (ORCPT ); Mon, 17 Oct 2022 22:02:39 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7DF8B2D6; Mon, 17 Oct 2022 19:02:38 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so12620994pjf.5; Mon, 17 Oct 2022 19:02:38 -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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=ibsxQ4qBoZxH848d3SpvoFXpxXI2UgCDTV8wu9LIYcR8ZZh3CBW0lW1MfAV3EVXAEi jugMsD5VHEG3fp+tqbz2weVEpFBwQAMa/vQBwmeeSdXyevJXYmBB2rarrsmoT+nH5GJH JfKtypG3dvVntNsqJtqZEGCWfywwiE5dpoSEbm8qXzbFmlJtU5s9JRH9kzQi4zPdOwym 1hORTtqD7NSOYNfJLcwz1Dt3G9fWo+YrzUlbHA7vEbAHZOt86weqtg5CCisUEkvOO5XX hOb9ZGNBYhhiekQBPuVgtaNGsYfUW6mf52SSxR50Wws64BbnQ7BbmCU1yHi02g8lI6cu iPgw== 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=JbDmjiM+wxCKjeV/c/2pqTxL69Z7MugBph9/YEKmkSo=; b=rlYJQboyJeDfr3ewptmhFiBkkoaTGQF7ELfQrNwLgRyCd1vaU59+YlW/U69pmPkIyT nrDHXvd9gfACKJmjJdT1OMMgY0aK/3Ev3eHbo0QK6Y7t9aJu4x2FVrkPuHCrRZL8gCUI HphVpJuNdkTuancj9aO/wsgRbXSDathzqZNMf7libk33okOtWDxzvdsGMD1XPlxwlWvH aeuFvpBHdhDaDiakZ+43HZo4ATFRH9/+OWrRos+llKTETO0nZuVLYC4FHtx8h/s4z2cg QaxMR2xUC5hSW+smMy7oHfv2icNfUSRsEdJHRmGi+sy7Mi041BPfbxbH7oMllRl7KjTM xMcA== X-Gm-Message-State: ACrzQf2UTwUXqXky4YTziJQ0QVwafUb6UInk+KigidUkR/228qEg09SH kDuAals57d809MMMo6Yaf8k= X-Received: by 2002:a17:902:aa42:b0:17e:b779:dadb with SMTP id c2-20020a170902aa4200b0017eb779dadbmr622516plr.11.1666058557654; Mon, 17 Oct 2022 19:02:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:37 -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 04/20] perf stat: Add aggr id for global mode Date: Mon, 17 Oct 2022 19:02:11 -0700 Message-Id: <20221018020227.85905-5-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?1746989142261598270?= X-GMAIL-MSGID: =?utf-8?q?1746989142261598270?= To make the code simpler, I'd like to use the same aggregation code for the global mode. We can simply add an id function to return cpu 0 and use print_aggr(). No functional change intended. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 36 ++++++++++++++++++++++++++++++++++-- tools/perf/util/cpumap.c | 10 ++++++++++ tools/perf/util/cpumap.h | 6 +++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 265b05157972..75d16e9705a4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1330,6 +1330,12 @@ static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __ return aggr_cpu_id__node(cpu, /*data=*/NULL); } +static struct aggr_cpu_id perf_stat__get_global(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return aggr_cpu_id__global(cpu, /*data=*/NULL); +} + static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { @@ -1366,6 +1372,12 @@ static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_config *co return perf_stat__get_aggr(config, perf_stat__get_node, cpu); } +static struct aggr_cpu_id perf_stat__get_global_cached(struct perf_stat_config *config, + struct perf_cpu cpu) +{ + return perf_stat__get_aggr(config, perf_stat__get_global, cpu); +} + static bool term_percore_set(void) { struct evsel *counter; @@ -1395,6 +1407,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) return NULL; case AGGR_GLOBAL: + return aggr_cpu_id__global; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1420,6 +1433,7 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) } return NULL; case AGGR_GLOBAL: + return perf_stat__get_global_cached; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1535,6 +1549,16 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, vo return id; } +static struct aggr_cpu_id perf_env__get_global_aggr_by_cpu(struct perf_cpu cpu __maybe_unused, + void *data __maybe_unused) +{ + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + /* it always aggregates to the cpu 0 */ + id.cpu = (struct perf_cpu){ .cpu = 0 }; + return id; +} + static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, struct perf_cpu cpu) { @@ -1558,6 +1582,12 @@ static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *conf return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env); } +static struct aggr_cpu_id perf_stat__get_global_file(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return perf_env__get_global_aggr_by_cpu(cpu, &perf_stat.session->header.env); +} + static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) { switch (aggr_mode) { @@ -1569,8 +1599,9 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) return perf_env__get_core_aggr_by_cpu; case AGGR_NODE: return perf_env__get_node_aggr_by_cpu; - case AGGR_NONE: case AGGR_GLOBAL: + return perf_env__get_global_aggr_by_cpu; + case AGGR_NONE: case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1590,8 +1621,9 @@ static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode) return perf_stat__get_core_file; case AGGR_NODE: return perf_stat__get_node_file; - case AGGR_NONE: case AGGR_GLOBAL: + return perf_stat__get_global_file; + case AGGR_NONE: case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8486ca3bec75..60209fe87456 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -354,6 +354,16 @@ struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __maybe_unu return id; } +struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data __maybe_unused) +{ + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + /* it always aggregates to the cpu 0 */ + cpu.cpu = 0; + id.cpu = cpu; + return id; +} + /* setup simple routines to easily access node numbers given a cpu number */ static int get_max_num(char *path, int *max) { diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 4a6d029576ee..b2ff648bc417 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -133,5 +133,9 @@ struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data); * cpu. The function signature is compatible with aggr_cpu_id_get_t. */ struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data); - +/** + * aggr_cpu_id__global - Create an aggr_cpu_id for global aggregation. + * The function signature is compatible with aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__global(struct perf_cpu cpu, void *data); #endif /* __PERF_CPUMAP_H */ From patchwork Tue Oct 18 02:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3879 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734583wrs; Mon, 17 Oct 2022 19:04:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4rws8K6TWjBvDXKBFkLN36+1AcKEXNzijg4k/t7V+XLPABhtKZaoiV0ptDZRyfXH/fkIJR X-Received: by 2002:a17:906:ef8f:b0:78d:fa64:275b with SMTP id ze15-20020a170906ef8f00b0078dfa64275bmr457211ejb.663.1666058680133; Mon, 17 Oct 2022 19:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058680; cv=none; d=google.com; s=arc-20160816; b=aV1f5303+ffX03en2f3VXy3HdH/E+1rJISNIbkM9JTI5cg4XJOqBfnDM6fd5dY6lcH TUSgBqMp3hOYJ7gZrEWgHWb8vXeMolXOWlBlEyIJWe5AHJv8gxrRzAX/MIzOPBM8zfvU k7aDl5MpukZnXXy1UfLQgrOGs27V+tfGjPwTBv6rpP2bXK4OCagBDtqCcX8zKs7skgyl j8xTaZl5Ijo3ohn84I0mNZ4VIEtHozm3G0iEUBOqMjsdA4m/l1BB+1UxiIHvUwIKtVfr eDb2DBgnkzJyV3f/G8IRt+wk2Kr6BQV20lmN/OgW5FVD0pePo9JmLt/PYZwHTylexYkT Z2XQ== 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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=U9ekGjmOr1or+4LHIHHQNv17oWwgX69jcAF2l4a3OHHKBhwMLp4KvF7D5Pk0IvqzNA Om+DSV4xu1iqK53IlIY0Em2vqtz0JRtE96fd9XWTVVybkEP/6dimrxP+tlRVhq2jpdqK HHeQC7vJ1RZLG+HRBQu2OV7g9qpcBTacLC8uzwVO3wnUIyoWUGte/Ty5XOZBMgwUcQJI gs2rMwCi4Mt4M9bwmcpzMK28NndMlP/PXML638iM/3Vz7AYdv7k8VOO9pmJZeQqQx3yx hLikCZ3WEhMtFch/58fhL7Wl+d4WdgXOiUKBFYli25g2q0kEi1wrP+PZYokpeUfDoWvR pTJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZTrFRBXE; 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 sb32-20020a1709076da000b00787bacce740si12341910ejc.537.2022.10.17.19.04.15; Mon, 17 Oct 2022 19:04:40 -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=ZTrFRBXE; 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 S230442AbiJRCDB (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiJRCCm (ORCPT ); Mon, 17 Oct 2022 22:02:42 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 329F389960; Mon, 17 Oct 2022 19:02:40 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so12621048pjf.5; Mon, 17 Oct 2022 19:02:39 -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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=ZTrFRBXEC2zKC6kHIiLytn56MmdkparMQ87OCQoYHLrgs070ecDKWsGAnM38nYqqgz J8BJ6yLBzFfluljIm7H5mmL7K2dziL4FfbmoY9hj7Ny6nJxraQJqANt1x26KzZIvo0Wp /4tT5r8jjV82KNTqoyqo20jImmSYfLX07XOnwqfzGUcYczeFpZ3X2jx1KiWd0edXCSgC yZ7VfoYAeX5R4I1bajlmgB7qJ0G8IsJiSBouV61mwS8YQ3HPBkhtsrhb+fofYaaXS6Wc geVNMkyGYgmsYAnyw5pfft4iz5aRn6NlktCp6HNjZCagxHLR66wIYEsh4HN5PY/gGJ4h PzxA== 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=U/EF52FtpTXq1+8QCY2XPc41r5d2NZu8hH5dtQWtwyk=; b=5iw1fUXWCmyYdYri6V1OUt0u+ddPn7ALdjTXjqveYS36IYcnSjfot8xZvQPCUHqNA+ kO9dVIJaY/hT3ZHBBLOBp++oBpd1LsBHoHJiHDXdLBdApXpNvDFWzFDowWmkVdptc2Xg sU2t3ZUV7tQM4kSnQrYLqmL94/w8nqoo+XdKKCJLC5fQvSlK+Q8Iu3KuK4HdbvTcxnyt Xjf+V1d6X0jYIaP/0wEJVZAJIr1GNNNNBo+LxCaFz8Cq7v8vhi5GhPye9kvred/gtFLu nfdfx26wsvXOi3JGiyAaMc1lXS0eQZrQcrahSiMJsdTD3/2N9HWZmDQr/H+zqs5rj2Ab nmxQ== X-Gm-Message-State: ACrzQf32YRHb6R5iPLr3BaSu68t+8e9gjrDiOs3OVyJ+9yOd8dX0VaWZ 9Fr0suWsam23KQWqNL/kjqc= X-Received: by 2002:a17:90b:180f:b0:20d:4e7f:5f52 with SMTP id lw15-20020a17090b180f00b0020d4e7f5f52mr37194113pjb.119.1666058559549; Mon, 17 Oct 2022 19:02:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:39 -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 05/20] perf stat: Add cpu aggr id for no aggregation mode Date: Mon, 17 Oct 2022 19:02:12 -0700 Message-Id: <20221018020227.85905-6-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?1746989146596251680?= X-GMAIL-MSGID: =?utf-8?q?1746989146596251680?= Likewise, add an aggr_id for cpu for none aggregation mode. This is not used actually yet but later code will use to unify the aggregation code. No functional change intended. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 75d16e9705a4..b03b530fe9a6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1336,6 +1336,12 @@ static struct aggr_cpu_id perf_stat__get_global(struct perf_stat_config *config return aggr_cpu_id__global(cpu, /*data=*/NULL); } +static struct aggr_cpu_id perf_stat__get_cpu(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return aggr_cpu_id__cpu(cpu, /*data=*/NULL); +} + static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { @@ -1378,6 +1384,12 @@ static struct aggr_cpu_id perf_stat__get_global_cached(struct perf_stat_config * return perf_stat__get_aggr(config, perf_stat__get_global, cpu); } +static struct aggr_cpu_id perf_stat__get_cpu_cached(struct perf_stat_config *config, + struct perf_cpu cpu) +{ + return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); +} + static bool term_percore_set(void) { struct evsel *counter; @@ -1404,8 +1416,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) case AGGR_NONE: if (term_percore_set()) return aggr_cpu_id__core; - - return NULL; + return aggr_cpu_id__cpu; case AGGR_GLOBAL: return aggr_cpu_id__global; case AGGR_THREAD: @@ -1428,10 +1439,9 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) case AGGR_NODE: return perf_stat__get_node_cached; case AGGR_NONE: - if (term_percore_set()) { + if (term_percore_set()) return perf_stat__get_core_cached; - } - return NULL; + return perf_stat__get_cpu_cached; case AGGR_GLOBAL: return perf_stat__get_global_cached; case AGGR_THREAD: @@ -1541,6 +1551,26 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(struct perf_cpu cpu, vo return id; } +static struct aggr_cpu_id perf_env__get_cpu_aggr_by_cpu(struct perf_cpu cpu, void *data) +{ + struct perf_env *env = data; + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + if (cpu.cpu != -1) { + /* + * core_id is relative to socket and die, + * we need a global id. So we set + * socket, die id and core id + */ + id.socket = env->cpu[cpu.cpu].socket_id; + id.die = env->cpu[cpu.cpu].die_id; + id.core = env->cpu[cpu.cpu].core_id; + id.cpu = cpu; + } + + return id; +} + static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -1576,6 +1606,12 @@ static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *conf return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); } +static struct aggr_cpu_id perf_stat__get_cpu_file(struct perf_stat_config *config __maybe_unused, + struct perf_cpu cpu) +{ + return perf_env__get_cpu_aggr_by_cpu(cpu, &perf_stat.session->header.env); +} + static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, struct perf_cpu cpu) { @@ -1602,6 +1638,7 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) case AGGR_GLOBAL: return perf_env__get_global_aggr_by_cpu; case AGGR_NONE: + return perf_env__get_cpu_aggr_by_cpu; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: @@ -1624,6 +1661,7 @@ static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode) case AGGR_GLOBAL: return perf_stat__get_global_file; case AGGR_NONE: + return perf_stat__get_cpu_file; case AGGR_THREAD: case AGGR_UNSET: case AGGR_MAX: 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); From patchwork Tue Oct 18 02:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734642wrs; Mon, 17 Oct 2022 19:04:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6g6j7TcoXEbT4GBPxICSKz6xZgafGAewS+8G/FC0xo+rKxImJnTHMqDydui5j6dtpu+MOh X-Received: by 2002:a17:906:5daa:b0:791:8933:f9f0 with SMTP id n10-20020a1709065daa00b007918933f9f0mr482755ejv.335.1666058689921; Mon, 17 Oct 2022 19:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058689; cv=none; d=google.com; s=arc-20160816; b=N8P6V+68KvLrOUKrmSeWqbCYItRIXhbl1jSn05skZKC+WvMqfcLUyVZamIjvnI3NxV CVjmSjiz7fUgQXQgKWEog+BqfddwMKV+PT0rdTHP0ex7XPkv7AEKvg4wEmVulKMN6b2I HMbjWX1UNaHT+F9UJBqVnYYeYECPD2jelbFjn4tmG87Gt2V0QCe9vF1Swp6GznJXpwwI xNBMcVA4lECg1Bxdy/T7c9GCkTzK6jtLCwFJOtnUZWZNi3LM1sJZcbCBAcHgrLxQBylf IuNI30LXuawyKquwwJDg8Q8IENKXXw+8n+yx69VhUWL1/cHysDRicqfUFAgP/XVOabCi uV0Q== 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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=K5Wo524N6iq3SRNFk0eZ4xPV7qTE115X/1piKh6s4rJ8UBGwZEU/7P+i89DRZ/8I4A 2ufVX9Zsc3jg/pFLx5Qcc1um8EP+sAEdfOg/SSJVBrPH+ITt3FocMdwWdCDtszcv1cj6 9oEIUXai7FHxF0zJ7kjP0QCcozGgYhtpfzfRY6iiFGMTqwWDPbhSdw9ToGpbQm+S7C2O rnsQ/cpjvpIhM7Nf0ituSlkiIkuEU++Kznd6TGHEga9DdPcN34jzf47FqXWyjL2HWj0S E4CKu5kqWBS03gqE2tbphBLf9qZTwNptCORgwCEQ8rxM9hY6PBQEHgY2+PY2+USNIBhy ZWTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gC20X17c; 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 d24-20020a056402079800b004570e4887desi9324513edy.437.2022.10.17.19.04.25; Mon, 17 Oct 2022 19:04:49 -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=gC20X17c; 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 S230507AbiJRCDJ (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiJRCC6 (ORCPT ); Mon, 17 Oct 2022 22:02:58 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F2658BBB0; Mon, 17 Oct 2022 19:02:44 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so12679456pjl.0; Mon, 17 Oct 2022 19:02:44 -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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=gC20X17cP9M8w1boudX6rq/hky6XA6ioZRiVt17X/mFlXGMZJ2f0K8DaJH9WAqf6LH LXQhJM/c/o16N3eOSrh1Rsk1A+AEDQs2w55BP7aQRR5CTduFsNKx7Q/O85hviN3jdThs 782p1kOIgp27KSd1pAPAUmW+jhdJhD3FVLPc3gi16NYuoee4rkAfVKvxmH8qnYUFRqfD De9GYIz8C0kjre5SXoJHXI4pJHS9w4dpFHFceZvqDQx/0fr08+PZPJJ/92198le7sd4M NbuMsh905SpLg0tnDyeGiQqoELJoQtzf+SfeUzD5ySMyZ7lSAZzm01vlL17/4Ww8tz9W Hb6A== 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=O82+8QMAp8RP+N1H707IzqXEjvaKP67GyMX407VeP1E=; b=DaUtOVLV4ssKxdArNXRS+ZdKHwp25+dc1Hxj09dsscUcWDHCz435+z3D93XBn1xK7d QWOS3LO0T0edSkvFrq36rrGfgQ0b8MpoSUGNeBPzvzsj8mSqHg2mRc4rKEAwoWIKRyJR InDQFruIqKfbmsfzqnClczBZXzSUV9dSOVv6wNkyzCk1fVkuyvfBDzQCjtVEY3wJLP5J 2cg3Ij0UvECO1RW7TB9G7SMzREC9RS96Ws+zqEzskfdiqQXYvEn+LTcRYzvWKhGfOilz YFXFprwlibQhI2C75yMPRlZXemKHKTD2YDaaaT4YziQYfMqVFShG1XGxGlznBg7gNIuS k99A== X-Gm-Message-State: ACrzQf0Rl5uXrRqOTAJ3c8yjJYSUEHTJho2PsBI0XeovbFYdkjgj0hVk pfxXD4EBTKidgxSgPLQ2M3w= X-Received: by 2002:a17:902:7c91:b0:17f:6711:1fac with SMTP id y17-20020a1709027c9100b0017f67111facmr834165pll.118.1666058563165; Mon, 17 Oct 2022 19:02:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:42 -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 07/20] perf stat: Add struct perf_stat_aggr to perf_stat_evsel Date: Mon, 17 Oct 2022 19:02:14 -0700 Message-Id: <20221018020227.85905-8-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?1746989156439653850?= X-GMAIL-MSGID: =?utf-8?q?1746989156439653850?= The perf_stat_aggr struct is to keep aggregated counter values and the states according to the aggregation mode. The number of entries is depends on the mode and this is a preparation for the later use. Signed-off-by: Namhyung Kim --- tools/perf/util/stat.c | 34 +++++++++++++++++++++++++++------- tools/perf/util/stat.h | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 8ec8bb4a9912..c9d5aa295b54 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -133,15 +133,33 @@ static void perf_stat_evsel_id_init(struct evsel *evsel) static void evsel__reset_stat_priv(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; + struct perf_stat_aggr *aggr = ps->aggr; init_stats(&ps->res_stats); + + if (aggr) + memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } -static int evsel__alloc_stat_priv(struct evsel *evsel) + +static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) { - evsel->stats = zalloc(sizeof(struct perf_stat_evsel)); - if (evsel->stats == NULL) + struct perf_stat_evsel *ps; + + ps = zalloc(sizeof(*ps)); + if (ps == NULL) return -ENOMEM; + + if (nr_aggr) { + ps->nr_aggr = nr_aggr; + ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); + if (ps->aggr == NULL) { + free(ps); + return -ENOMEM; + } + } + + evsel->stats = ps; perf_stat_evsel_id_init(evsel); evsel__reset_stat_priv(evsel); return 0; @@ -151,8 +169,10 @@ static void evsel__free_stat_priv(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; - if (ps) + if (ps) { + zfree(&ps->aggr); zfree(&ps->group_data); + } zfree(&evsel->stats); } @@ -181,9 +201,9 @@ static void evsel__reset_prev_raw_counts(struct evsel *evsel) perf_counts__reset(evsel->prev_raw_counts); } -static int evsel__alloc_stats(struct evsel *evsel, bool alloc_raw) +static int evsel__alloc_stats(struct evsel *evsel, int nr_aggr, bool alloc_raw) { - if (evsel__alloc_stat_priv(evsel) < 0 || + if (evsel__alloc_stat_priv(evsel, nr_aggr) < 0 || evsel__alloc_counts(evsel) < 0 || (alloc_raw && evsel__alloc_prev_raw_counts(evsel) < 0)) return -ENOMEM; @@ -196,7 +216,7 @@ int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw) struct evsel *evsel; evlist__for_each_entry(evlist, evsel) { - if (evsel__alloc_stats(evsel, alloc_raw)) + if (evsel__alloc_stats(evsel, 0, alloc_raw)) goto out_free; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index b0899c6e002f..42453513ffea 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -8,6 +8,7 @@ #include #include "cpumap.h" #include "rblist.h" +#include "counts.h" struct perf_cpu_map; struct perf_stat_config; @@ -42,9 +43,27 @@ enum perf_stat_evsel_id { PERF_STAT_EVSEL_ID__MAX, }; +/* hold aggregated event info */ +struct perf_stat_aggr { + /* aggregated values */ + struct perf_counts_values counts; + /* number of entries (CPUs) aggregated */ + int nr; + /* whether any entry has failed to read/process event */ + bool failed; +}; + +/* per-evsel event stats */ struct perf_stat_evsel { + /* used for repeated runs */ struct stats res_stats; + /* evsel id for quick check */ enum perf_stat_evsel_id id; + /* number of allocated 'aggr' */ + int nr_aggr; + /* aggregated event values */ + struct perf_stat_aggr *aggr; + /* used for group read */ u64 *group_data; }; From patchwork Tue Oct 18 02:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734659wrs; Mon, 17 Oct 2022 19:04:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7onsn2eaH+g84gVOgOM0oITGefyQ2kkGfzrMMDwSsphi9jArwm1cNqax9BfmzahmySU5an X-Received: by 2002:a05:6402:847:b0:453:943b:bf4 with SMTP id b7-20020a056402084700b00453943b0bf4mr478328edz.301.1666058693388; Mon, 17 Oct 2022 19:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058693; cv=none; d=google.com; s=arc-20160816; b=dydrS5xV9Y9QnxyttqeTf4J/OGR/1kmE31+RIQ0cghu6EJgE9INhEO2wovJNBC6Iyg 8c06wZWhm6FTlAeTVLHY8umY/FNFThymFYfzYBidSNMMdMiGSET2V6idSuKdHb4WrDDm jfxxvfnv/sWYSfWNUsHr/TCeA9Jdw/USXgTswLMAzuVRnKQ0PPNyKsNgG4QjK4oDm40X e4dfGLLRJn6MFvOeS4fVEOIcx4xFWJP6onbSaZdtymCdgpKWqeqJ8hXXp+AuG/PKjLIP N7Sa4+/hSa5LTeZONbAESCm9Sj1MERcvCBV5diAmXUxKhweWtAMa8DKpbpxSZMGDqLrO mEnA== 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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=PwjA7CfdD0V9+B6jaXWCh/SQwv7sCPK9Yux7rzsHY84A3ONYf0cQboF94gsqeR/mG0 Tsf0tABl5i3Zwz4PhzgzPsrEmVDBeI4IERASQ3Bb7EWE9It5Aoi15yfy4ghVKiY11608 Rs4BK6AFuruIaQojoa66anW4STxG58ia4H6azYbRnOsp8ScJy2QuwBEEXXyiJ7+fwx6L jpkAU2uAIm3tuPSvuNz6NmbF57FXybjdRRQh9gHu/Iy2hX933S4DbeUBa+aC5aOQ4Xm+ lpOFeBTHca9Sic/oTJK8iZZlsWUIChAbqGtwHHNvPVKkr9iT35pOCxDodOjE/99DFOMB jDZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ggm0tMmo; 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 go12-20020a1709070d8c00b0078e319dcca7si7759737ejc.744.2022.10.17.19.04.29; Mon, 17 Oct 2022 19:04:53 -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=ggm0tMmo; 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 S231129AbiJRCDY (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbiJRCDE (ORCPT ); Mon, 17 Oct 2022 22:03:04 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9388C039; Mon, 17 Oct 2022 19:02:46 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id g28so12746385pfk.8; Mon, 17 Oct 2022 19:02:46 -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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=ggm0tMmo6pyzZqN5ivcwQIoAr1arw8s/NfPfGzCuDvGNev+E2ssNO8RgP8gavTe9s9 Nu9pGZMYbU88ApAkKSofkvXdqL9nv5BiGzqBRvGjohl72JXba9lr8f/q5u5sX9wqGY3I 2HxcvqQCio6wHBM4/4gyZOphiTY7F7gi1/WOo141TnkWUQ6YZR0oHN+8GpCrGnP4lVFf dYoeQEzS1o5FhfNaCDlOdkWePvyaXMbut8n04ho2d8egClGL6pL/UOyZiPLbq7UiyqXA djZglrSRScOBUXA3J+8FFztYdR2x6gcIKuHCJt2YzR5cQuCdwTQnFBRWLpWCAYT7kUgM uwRg== 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=O0E8rkAsDwyeX4tn3K6WoCLFrxZKVhY8mXbbIgxSuio=; b=sWOlZZ9Up+Wc5p2HoM6+/6/HMrwmkBLWQvbotKUcjtpZkXbG46aNOd1mTid1Ry4O+O DuS28Zh0c7qUPwigWeJ34PEKAxkHvZU/RZ1VEHFxiDseBgrmmo1LtWLaza1lDM7Sshvm 05vOJ8DHiwP1JKfy+UrkmPI0YFzKHtTHuqy+qSF53Ww4wPrnYW6gxeyrGO5I/ybHD9So Qb0KAzV4Uxf7LZZtEb98Qwi+/8m1D4vcxpesvAqJCd7WWsXNAxqHK++iHu/Rnyl2f9G8 JwMZ9t8GLKECYrbxHARDgyb2RgzYZ1iWyK5WbHXNFOCGMnRizhL/eNDUoVut2FA0FrtN ALvA== X-Gm-Message-State: ACrzQf1uO3ykARTL0dAhP+K+EE7TWXBfYZfXNfl95jjOVAOngu49mPQE YPOF3EXt4djvz+7bFZrktyw= X-Received: by 2002:a63:1e16:0:b0:430:5c4a:a3b5 with SMTP id e22-20020a631e16000000b004305c4aa3b5mr661662pge.37.1666058565360; Mon, 17 Oct 2022 19:02:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:44 -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 08/20] perf stat: Allocate evsel->stats->aggr properly Date: Mon, 17 Oct 2022 19:02:15 -0700 Message-Id: <20221018020227.85905-9-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?1746989160623056631?= X-GMAIL-MSGID: =?utf-8?q?1746989160623056631?= The perf_stat_config.aggr_map should have a correct size of the aggregation map. Use it to allocate aggr_counts. Also AGGR_NONE with per-core events can be tricky because it doesn't aggreate basically but it needs to do so for per-core events only. So only per-core evsels will have stats->aggr data. Note that other caller of evlist__alloc_stat() might not have stat_config or aggr_map. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-script.c | 4 ++-- tools/perf/builtin-stat.c | 6 +++--- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 2 +- tools/perf/util/stat.c | 9 +++++++-- tools/perf/util/stat.h | 3 ++- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7ca238277d83..d7ec8c1af293 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2049,7 +2049,7 @@ static void perf_sample__fprint_metric(struct perf_script *script, u64 val; if (!evsel->stats) - evlist__alloc_stats(script->session->evlist, false); + evlist__alloc_stats(&stat_config, script->session->evlist, /*alloc_raw=*/false); if (evsel_script(leader)->gnum++ == 0) perf_stat__reset_shadow_stats(); val = sample->period * evsel->scale; @@ -3632,7 +3632,7 @@ static int set_maps(struct perf_script *script) perf_evlist__set_maps(&evlist->core, script->cpus, script->threads); - if (evlist__alloc_stats(evlist, true)) + if (evlist__alloc_stats(&stat_config, evlist, /*alloc_raw=*/true)) return -ENOMEM; script->allocated = true; diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9053fd4d15a7..92a8e4512f98 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2121,7 +2121,7 @@ static int set_maps(struct perf_stat *st) perf_evlist__set_maps(&evsel_list->core, st->cpus, st->threads); - if (evlist__alloc_stats(evsel_list, true)) + if (evlist__alloc_stats(&stat_config, evsel_list, /*alloc_raw=*/true)) return -ENOMEM; st->maps_allocated = true; @@ -2568,10 +2568,10 @@ int cmd_stat(int argc, const char **argv) goto out; } - if (evlist__alloc_stats(evsel_list, interval)) + if (perf_stat_init_aggr_mode()) goto out; - if (perf_stat_init_aggr_mode()) + if (evlist__alloc_stats(&stat_config, evsel_list, interval)) goto out; /* diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 68f5a2a03242..21b7ac00d798 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -103,7 +103,7 @@ static int __compute_metric(const char *name, struct value *vals, if (err) goto out; - err = evlist__alloc_stats(evlist, false); + err = evlist__alloc_stats(/*config=*/NULL, evlist, /*alloc_raw=*/false); if (err) goto out; diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 097e05c796ab..5d0d3b239a68 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -889,7 +889,7 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e goto out_err; } - err = evlist__alloc_stats(evlist, false); + err = evlist__alloc_stats(/*config=*/NULL, evlist, /*alloc_raw=*/false); if (err) goto out_err; /* diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index c9d5aa295b54..374149628507 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -211,12 +211,17 @@ static int evsel__alloc_stats(struct evsel *evsel, int nr_aggr, bool alloc_raw) return 0; } -int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw) +int evlist__alloc_stats(struct perf_stat_config *config, + struct evlist *evlist, bool alloc_raw) { struct evsel *evsel; + int nr_aggr = 0; + + if (config && config->aggr_map) + nr_aggr = config->aggr_map->nr; evlist__for_each_entry(evlist, evsel) { - if (evsel__alloc_stats(evsel, 0, alloc_raw)) + if (evsel__alloc_stats(evsel, nr_aggr, alloc_raw)) goto out_free; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 42453513ffea..0980875b9be1 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -267,7 +267,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct runtime_stat *st); void perf_stat__collect_metric_expr(struct evlist *); -int evlist__alloc_stats(struct evlist *evlist, bool alloc_raw); +int evlist__alloc_stats(struct perf_stat_config *config, + struct evlist *evlist, bool alloc_raw); void evlist__free_stats(struct evlist *evlist); void evlist__reset_stats(struct evlist *evlist); void evlist__reset_prev_raw_counts(struct evlist *evlist); From patchwork Tue Oct 18 02:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734671wrs; Mon, 17 Oct 2022 19:04:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5FYZIGrHAWlgMsTYEyRYBjwKjB4ejQ1wgdeG22II1afxl8eOhieeAHYAWxYm5hXFZFtwHX X-Received: by 2002:a05:6a00:228f:b0:566:6ecd:29d9 with SMTP id f15-20020a056a00228f00b005666ecd29d9mr805774pfe.62.1666058694646; Mon, 17 Oct 2022 19:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058694; cv=none; d=google.com; s=arc-20160816; b=Bs69vKqoj4dgqOghOatXaxi36m1M2lHhRkPWAhjG+pLfL63vhiWuhdh6qYFFkz2Suw 2WBeK96BM7s8qxjtKcYCpQt5Pe6NClLmhadXmriz+NKdZmH3Rp2hXn3m8XC+vJVAsC76 L4KnUMXHdNeSOOsHappgaJzSv01bhMONkYnushVVvuvEsPdg4KHPegxXzq0RhoJx+ymw ChD02a8Cn3jO9GvipDVOixRjkAfLUWonKVmuTU2uOh72DZOtS+2XvM7/nFXXxaTuHH/x p5ucP36yWD3Sx0y34sLT/aiIgC9Iu/Ark6hCHFJsdel2Nw1VgzvO/SBM5KVOQdDP7YP+ c5BA== 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=1DhMNgMKGZ6uYXpwXDNAiQUjgYcGDDKTAVN1NlPzjyw=; b=y9blfxIw36YieF8NgQjVOClPBEy0hynyfdx+jRuwU+Sr4yGdpWUDMpXnsK7gTEs8mZ LIzNpssqdqpoCK282UF3NOhcdS1lSa7o4nDjszxrx6S5xn9iJ0H5La028i1g9Vd06Lq+ jUF9z043yGKd9zMtN6j8xn6yV8ZBtk5GdlQkrzl/0ASru0Am5Iq/S8E8NTDwIp6qFWwn KPTPGQgUTMmCrVzvIByIfKyinNRhgNTOL7Bqg294NjL+Yi631CxIlijWHLlUXK0WbiH4 CEQy6mXpw4kPAqyY/NzvG0+N9jYg5HYe6vdt3kQVk81FnXDAOAXTQSl3SmyblJjaCi18 l7+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OTgiygMX; 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 r19-20020a63ce53000000b0043c1cb75c22si13765041pgi.333.2022.10.17.19.04.41; Mon, 17 Oct 2022 19:04:54 -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=OTgiygMX; 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 S230503AbiJRCDc (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbiJRCDF (ORCPT ); Mon, 17 Oct 2022 22:03:05 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A46B38C459; Mon, 17 Oct 2022 19:02:48 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id 129so12058576pgc.5; Mon, 17 Oct 2022 19:02:48 -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=1DhMNgMKGZ6uYXpwXDNAiQUjgYcGDDKTAVN1NlPzjyw=; b=OTgiygMXuk2e5omQ1aiRCd5U6yCCO/EKxPR9loDsfLSvpKffghE98uymz3STxxzALR Auvf2SeJg/fZCK9udeJP8fJDlzq59s0d+MAh7jIqV/xkRmmeuKhjEf2yCWp74SRKq2N+ 8mkl/KGyfpxz/yOYv5OvEZmEK8MLBQR0K/JmAReGKrn4S5IOtobkTE8W9pT87phqbkgS Ms7BKZJMBJgtUFxmu3lPyMmZzIq0Uf8/OkZWoGDDbJQwXc2C/b+kqQvNVoSmaFOS6Gco CHLANAvQrsoDz2KAei1WIL535lBacckBUWJT1+1mQXzCWSjM5d5va4rlDpr2xvQaBpXS r7Zw== 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=1DhMNgMKGZ6uYXpwXDNAiQUjgYcGDDKTAVN1NlPzjyw=; b=TKfMx0i63G8i9ZO9Wsr8E5wK+sz/dlspbR2XNShgmQhlssIY7acrIqnBMz6+VJ5kwQ s8QFwoDDfcuia7BtCbq9jbH7CSUnMRX5ggPFpd+slRehdTA2aApsyHIj1uKHELeJjDC6 XZ3yxjQCM6kpuTKBtojdX7TrsLvFd6OpZ62D0PDFFgHTTJIMuHID3KWobmmenq9YDn4m mH7FjhnfCmOokRBTMFBCv8l5ECMfbWcDLqPkpml5w7MbB6lvqFEaY4loXGYw7HsLFOS9 6C9bbYKeLUn4E3dSB/jIPdritxXK/EV0tYqtCrfjeRk+TDNf/8TG12ZUwkwJdaLazIxg JVfg== X-Gm-Message-State: ACrzQf02eQCKfEL98eeBeCGZLfuEQF/W9jM4yKZ+H/TYkiwtlwEfct3N fXKkw/Yhj7rQSVUZ8jI8mLE= X-Received: by 2002:a65:6e4a:0:b0:438:874c:53fd with SMTP id be10-20020a656e4a000000b00438874c53fdmr651471pgb.355.1666058567180; Mon, 17 Oct 2022 19:02:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:46 -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 09/20] perf stat: Aggregate events using evsel->stats->aggr Date: Mon, 17 Oct 2022 19:02:16 -0700 Message-Id: <20221018020227.85905-10-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?1746989161359229351?= X-GMAIL-MSGID: =?utf-8?q?1746989161359229351?= Add a logic to aggregate counter values to the new evsel->stats->aggr. This is not used yet so shadow stats are not updated. But later patch will convert the existing code to use it. With that, we don't need to handle AGGR_GLOBAL specially anymore. It can use the same logic with counts, prev_counts and aggr_counts. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 3 -- tools/perf/util/evsel.c | 9 +--- .../scripting-engines/trace-event-python.c | 6 --- tools/perf/util/stat.c | 46 ++++++++++++++++--- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 92a8e4512f98..abede56d79b6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -963,9 +963,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) init_stats(&walltime_nsecs_stats); update_stats(&walltime_nsecs_stats, t1 - t0); - if (stat_config.aggr_mode == AGGR_GLOBAL) - evlist__save_aggr_prev_raw_counts(evsel_list); - evlist__copy_prev_raw_counts(evsel_list); evlist__reset_prev_raw_counts(evsel_list); perf_stat__reset_shadow_per_stat(&rt_stat); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index c9fef26d0702..cdde5b5f8ad2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1526,13 +1526,8 @@ void evsel__compute_deltas(struct evsel *evsel, int cpu_map_idx, int thread, if (!evsel->prev_raw_counts) return; - if (cpu_map_idx == -1) { - tmp = evsel->prev_raw_counts->aggr; - evsel->prev_raw_counts->aggr = *count; - } else { - tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); - *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count; - } + tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count; count->val = count->val - tmp.val; count->ena = count->ena - tmp.ena; diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 1f2040f36d4e..7bc8559dce6a 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1653,12 +1653,6 @@ static void python_process_stat(struct perf_stat_config *config, struct perf_cpu_map *cpus = counter->core.cpus; int cpu, thread; - if (config->aggr_mode == AGGR_GLOBAL) { - process_stat(counter, (struct perf_cpu){ .cpu = -1 }, -1, tstamp, - &counter->counts->aggr); - return; - } - for (thread = 0; thread < threads->nr; thread++) { for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { process_stat(counter, perf_cpu_map__cpu(cpus, cpu), diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 374149628507..99874254809d 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -387,6 +387,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, struct perf_counts_values *count) { struct perf_counts_values *aggr = &evsel->counts->aggr; + struct perf_stat_evsel *ps = evsel->stats; static struct perf_counts_values zero; bool skip = false; @@ -398,6 +399,44 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, if (skip) count = &zero; + if (!evsel->snapshot) + evsel__compute_deltas(evsel, cpu_map_idx, thread, count); + perf_counts_values__scale(count, config->scale, NULL); + + if (ps->aggr) { + struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); + struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); + struct perf_stat_aggr *ps_aggr; + int i; + + for (i = 0; i < ps->nr_aggr; i++) { + if (!aggr_cpu_id__equal(&aggr_id, &config->aggr_map->map[i])) + continue; + + ps_aggr = &ps->aggr[i]; + ps_aggr->nr++; + + /* + * When any result is bad, make them all to give + * consistent output in interval mode. + */ + if (count->ena == 0 || count->run == 0 || + evsel->counts->scaled == -1) { + ps_aggr->counts.val = 0; + ps_aggr->counts.ena = 0; + ps_aggr->counts.run = 0; + ps_aggr->failed = true; + } + + if (!ps_aggr->failed) { + ps_aggr->counts.val += count->val; + ps_aggr->counts.ena += count->ena; + ps_aggr->counts.run += count->run; + } + break; + } + } + switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: @@ -405,9 +444,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, case AGGR_SOCKET: case AGGR_NODE: case AGGR_NONE: - if (!evsel->snapshot) - evsel__compute_deltas(evsel, cpu_map_idx, thread, count); - perf_counts_values__scale(count, config->scale, NULL); if ((config->aggr_mode == AGGR_NONE) && (!evsel->percore)) { perf_stat__update_shadow_stats(evsel, count->val, cpu_map_idx, &rt_stat); @@ -469,10 +505,6 @@ int perf_stat_process_counter(struct perf_stat_config *config, if (config->aggr_mode != AGGR_GLOBAL) return 0; - if (!counter->snapshot) - evsel__compute_deltas(counter, -1, -1, aggr); - perf_counts_values__scale(aggr, config->scale, &counter->counts->scaled); - update_stats(&ps->res_stats, *count); if (verbose > 0) { From patchwork Tue Oct 18 02:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734799wrs; Mon, 17 Oct 2022 19:05:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YeE9A4XCzK6jPc7ip+veGRCaIyHd6Kowtyvb/RYTHRbE31RsGHsnFzMtphU3jUX1/kx5d X-Received: by 2002:a05:6402:370c:b0:453:9fab:1b53 with SMTP id ek12-20020a056402370c00b004539fab1b53mr530189edb.28.1666058712040; Mon, 17 Oct 2022 19:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058712; cv=none; d=google.com; s=arc-20160816; b=Zjj3wTNz7dqyX5G4bHdc2dTn012XDDx49qsSU+7VBJ1QcqHwfuZf3COUlXeaLeAXFW YK/8rMB7FHDnMe3tDoa9JOS4uPqOToPYseIyLvoTTObHGQV3t4W69xR8XW0gCi1pAyQm wv32PMf8IuqkF2lrzzmVfnILLW0UrnxNh7R58f1INDOp4tehFVJ+acLE0m0/vMbIYsvp +veXvJExTeu94pOcATXLTKGTw1Yw49NYtYYcIqM7snFBgvS49r4DRxXwpcq2HtBPcALp dBd2wAnmqbEGMQFoFAWPGHn3YRlWMrj+kGkAYPVyKNxLJhQjqKe0uBtyYtFfRRo5S6J0 bxsA== 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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=IRSf12/F3KhhN25AKGacRBswopvblZfFdL9C50mNW0coZRCAynObQ9pCQG5HIhkidq 3zy1BaSfBjE1zQaZ4HHZfSDY6g55U85r10jFd2LhUbLuzzOkbQO5IhmkSJGLVBUXGcNy ghl48HHIhKq1Xmiw6GlqxwiBkDHjaL2kbJPZVpqTRg5n52cjkI1SuluFv+7Z0lxXWKIW ZKhlMjfoNJz0hOQUGJv7hHG37T/mizwiPytRIuSrr2aDuBz5k+Hn724k33a6jq29fmKt VEIlZM8MP2CzLUkST/3lgjCzYAQo+MawQA3Oq7T/megy9jfC05MoAQKoTuhFIF5iCYar SCBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GOtlBAru; 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 k23-20020a508ad7000000b00458d1c48708si9227364edk.303.2022.10.17.19.04.46; Mon, 17 Oct 2022 19:05:12 -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=GOtlBAru; 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 S231184AbiJRCDd (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbiJRCDI (ORCPT ); Mon, 17 Oct 2022 22:03:08 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4329D8C47B; Mon, 17 Oct 2022 19:02:49 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id l6so12051308pgu.7; Mon, 17 Oct 2022 19:02:49 -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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=GOtlBAruGtyUlmZCBd0mozdiBCEJAZrxCoMmN9RuJYsOiaEr3K9+17PXsDtwoBVxvs AJ2d2EImfPf37t3cMPiWwLoVTX9XxiyayscH4j7GJdZRwUcrQj88Oelyysf33334NNUA wdJy4fI3SjWF8NrdW5nljbbgtrW61MdL5F3HNgnz17XkaKj8k3YoXeNn0Phraw4mlLMS gYHiEHSdwFgN/Lx65E9+qPXInDKTkfHVSrLtmi6nTn8mlzTh645g9gpUWfaDuXOYkIiY YhMu+gGmHzwDPK6cmw3II5yV5fb3TtjN3ogeyb8k1ul0TjOb16zvAkejXh0jYTV4HAj2 59zw== 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=nACLFNBsjYXmah7mo5IuPePokH3SR0lSD6pvQDkNzQs=; b=X3UDAI67gC4SDyVnHWChswC5Yjqf1P9bUoCCsES+RWBwz4TepWSdfmdov6xR8drtLQ PtcgeNcsttm8jkJ+28aNSAYW+v7RgzYWdDMjz/fvhzKxEzYRacLtJz9kV64RBRO/Hf5x Z5sVFQr7sUnyCZXZKgU1JTTPfrnnrECyKHFm3XjT4sxYuymNAmQ/Uu74TOOXeBm4xFs6 y/mJ9RZdFIbypPz8g3A3hhlJvPYc5bXDyLruUc1XkVxfwpxNHwsXIar3OCEHRqtkMf7J Zvsv9rk2gThpxLRrbEyzh7/qUytvmzvTovTcfZYfKeNg0vBVCCMUBb3BDFzgG4AMkaM+ aogA== X-Gm-Message-State: ACrzQf1YmW81CrRu0QKW/UyJKCsz8MxqlkGCMeJqgAtZgRFcGduVhHwR Fktr2lGswERRqX793ShlQg4= X-Received: by 2002:a63:4e18:0:b0:43c:2fc7:2eea with SMTP id c24-20020a634e18000000b0043c2fc72eeamr661184pgb.119.1666058568896; Mon, 17 Oct 2022 19:02:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:48 -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 10/20] perf stat: Factor out evsel__count_has_error() Date: Mon, 17 Oct 2022 19:02:17 -0700 Message-Id: <20221018020227.85905-11-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?1746989179533979876?= X-GMAIL-MSGID: =?utf-8?q?1746989179533979876?= It's possible to have 0 enabled/running time for some per-task or per-cgroup events since it's not scheduled on any CPU. Treating the whole event as failed would not work in this case. Thinking again, the code only existed when any CPU-level aggregation is enabled (like per-socket, per-core, ...). To make it clearer, factor out the condition check into the new evsel__count_has_error() function and add some comments. Signed-off-by: Namhyung Kim --- tools/perf/util/stat.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 99874254809d..dc075d5a0f72 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -381,6 +381,25 @@ static int check_per_pkg(struct evsel *counter, struct perf_counts_values *vals, return ret; } +static bool evsel__count_has_error(struct evsel *evsel, + struct perf_counts_values *count, + struct perf_stat_config *config) +{ + /* the evsel was failed already */ + if (evsel->err || evsel->counts->scaled == -1) + return true; + + /* this is meaningful for CPU aggregation modes only */ + if (config->aggr_mode == AGGR_GLOBAL) + return false; + + /* it's considered ok when it actually ran */ + if (count->ena != 0 && count->run != 0) + return false; + + return true; +} + static int process_counter_values(struct perf_stat_config *config, struct evsel *evsel, int cpu_map_idx, int thread, @@ -420,8 +439,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, * When any result is bad, make them all to give * consistent output in interval mode. */ - if (count->ena == 0 || count->run == 0 || - evsel->counts->scaled == -1) { + if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) { ps_aggr->counts.val = 0; ps_aggr->counts.ena = 0; ps_aggr->counts.run = 0; From patchwork Tue Oct 18 02:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734624wrs; Mon, 17 Oct 2022 19:04:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vW2bOKZx7cJ+2qzkKT+cok63L4cs9J6yAcQoLdTPk7t01ItHQ625i5mwLAgByD60aVzIE X-Received: by 2002:a05:6a00:27a0:b0:566:9cd9:3843 with SMTP id bd32-20020a056a0027a000b005669cd93843mr780438pfb.17.1666058685725; Mon, 17 Oct 2022 19:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058685; cv=none; d=google.com; s=arc-20160816; b=y2j32al85w/wLmcEev2LcdITiGmYQB3QyqsC/z5foSVvulEhcSjztfo9IteBXwwxHx nGirVTJRjAYgkdaVP9pjPk9cG4iq8Roz2IyWfXrqdkJ4UgOXmko0YY2lVgzdGzME2Qxx ZfMa/IyExA4n5av9JIURp/Bz4RkwHeoIX1seS4Qmu3buWmcutPM3PFwLKq2tYc+svaYh 23Dmd0X9FaWMTasd5odeuAmtRyQTXCFg+ldBqGf+IL9nA65MEF3aPlIECpxlrqlucR9G BlyIpgY6a4VydAIASbzF2kLYinGiozFs1ODY0iPm6TYUA5XdZSjD3xsCheQyse0oOfxL +jkA== 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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=eEIa+Twx3HtJ8KCuhgJ8bk/Dd5PqZ69IEOskhuzYFxpu/kMl0oVdOXxSJzRLoDvmlL oqnHoAASJX/k1DM8eCzjuqycjG/L1JvVejwKig1VBktOiulwZsV2DXzIXuj0ENhKWLqV lZQVEZGww4hSYSUyU1uMH7Jwb/3NA+FLgt16WmET0svEV/yfxojonQfn0Rq4MlQ2ea+m xfYtm40BXzwmWkw/5iMFaRs02TCkDGcGlDmBHoNYtiu3WDaeQLlnJ101Vjgp7i1/UOdB UB98LRNl/zMAdiIzdtpKzl/jRgnVGg9g3ARGVqQlroXCMI8A3/x92hn/OBVlQqPLSgbz jDcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VmAnUG4z; 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 b12-20020a6541cc000000b00464a9874658si14471039pgq.6.2022.10.17.19.04.32; Mon, 17 Oct 2022 19:04:45 -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=VmAnUG4z; 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 S230493AbiJRCD2 (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbiJRCDF (ORCPT ); Mon, 17 Oct 2022 22:03:05 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6FD8D0D1; Mon, 17 Oct 2022 19:02:51 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id e129so12045281pgc.9; Mon, 17 Oct 2022 19:02:51 -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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=VmAnUG4z5Z6AXUZcsN63rFYP0NsmchwMa/HFryoXD/HSSq+dJkary9Gg70Qt/685tH vkCaJWXPzwUIXlSLJOjXBEDrKoJMFdIn1xAKZFBVTM8qzEh0gdwBDO4SHGQIe49GHq25 lqZzKmBlf0+p9gxmZVNll8zaogCh86p/9dUCbhO4mHBRWlnbVqvXQENR6b2zGnbRV+RT nYPT8l84baJ/Iq06t0knKxAbL7G8a3giP3F/2JOZsHh8ihibt3LPGBlT4OeLNVsKoa7l CXG/pFXRdoVeK/EBbRFvDyFqJVZ/5TyHYrzwBUGg86VR1QhTc0CX33ttMl2N33BADo5b Z+Tw== 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=OFSeqc5wPOk9fULwPnm3VQika9Wjm0SthcR5M/scKqk=; b=Hvtv+xLFjXcDi+FcEZLv7OGJPlFQlch7eS6fMDtIpvhHd4MzwfRs3W4HY6kchtjlbj EDQ/+mS+5QyxcG+f3Vvka2xPo016J8jUuVNSOZkVz36c+st5v6ue7gia1+Xtu9tApytT LHjyAXre2s7k9GxzwSLuXiQEAmMVRpktyefFgmsLkLqRTuNzcCeA/f3j4zVCRqEPSwKw HjrN2LqynXdKXWaBpi7sP2zJcvTmrQN+ZDZosSxlv2OkvhDBdxGV9Jso2IW+hcuWjpMR TkpdjP0sFqIechTBP35Uwi5ruNUELLglXTc6PcQ6hLwO7JLgTONougVsL2I5NPwB7l/c d2yw== X-Gm-Message-State: ACrzQf1XSQB6/sfFejAzDg0FmNscjnxsSKOCL9cz7pp4H7C5AJKd9bfc jOfvgA/N6bD23q0OEE6T41g= X-Received: by 2002:a63:6a48:0:b0:43a:18ce:4e08 with SMTP id f69-20020a636a48000000b0043a18ce4e08mr670865pgc.432.1666058570704; Mon, 17 Oct 2022 19:02:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:50 -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 11/20] perf stat: Aggregate per-thread stats using evsel->stats->aggr Date: Mon, 17 Oct 2022 19:02:18 -0700 Message-Id: <20221018020227.85905-12-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?1746989152580557714?= X-GMAIL-MSGID: =?utf-8?q?1746989152580557714?= Per-thread aggregation doesn't use the CPU numbers but the logic should be the same. Initialize cpu_aggr_map separately for AGGR_THREAD and use thread map idx to aggregate counter values. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 31 +++++++++++++++++++++++++++++++ tools/perf/util/stat.c | 24 ++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index abede56d79b6..6777fef0d56c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1465,6 +1465,21 @@ static int perf_stat_init_aggr_mode(void) stat_config.aggr_get_id = aggr_mode__get_id(stat_config.aggr_mode); } + if (stat_config.aggr_mode == AGGR_THREAD) { + nr = perf_thread_map__nr(evsel_list->core.threads); + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + /* * The evsel_list->cpus is the base we operate on, * taking the highest cpu number to be the size of @@ -1674,6 +1689,22 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) 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 (stat_config.aggr_mode == AGGR_THREAD) { + int nr = perf_thread_map__nr(evsel_list->core.threads); + + stat_config.aggr_map = cpu_aggr_map__empty_new(nr); + if (stat_config.aggr_map == NULL) + return -ENOMEM; + + for (int s = 0; s < nr; s++) { + struct aggr_cpu_id id = aggr_cpu_id__empty(); + + id.thread_idx = s; + stat_config.aggr_map->map[s] = id; + } + return 0; + } + if (!get_id) return 0; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index dc075d5a0f72..5b04c9d16156 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -422,6 +422,24 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, evsel__compute_deltas(evsel, cpu_map_idx, thread, count); perf_counts_values__scale(count, config->scale, NULL); + if (config->aggr_mode == AGGR_THREAD) { + struct perf_counts_values *aggr_counts = &ps->aggr[thread].counts; + + /* + * Skip value 0 when enabling --per-thread globally, + * otherwise too many 0 output. + */ + if (count->val == 0 && config->system_wide) + return 0; + + ps->aggr[thread].nr++; + + aggr_counts->val += count->val; + aggr_counts->ena += count->ena; + aggr_counts->run += count->run; + goto update; + } + if (ps->aggr) { struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); @@ -436,8 +454,9 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ps_aggr->nr++; /* - * When any result is bad, make them all to give - * consistent output in interval mode. + * When any result is bad, make them all to give consistent output + * in interval mode. But per-task counters can have 0 enabled time + * when some tasks are idle. */ if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) { ps_aggr->counts.val = 0; @@ -455,6 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } +update: switch (config->aggr_mode) { case AGGR_THREAD: case AGGR_CORE: From patchwork Tue Oct 18 02:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734722wrs; Mon, 17 Oct 2022 19:05:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5v5vm+nFgm4hZyGpJW7g59dXlRvyIIjGaDc+Wpiu2MbxypNBKUJNfBIattrzuP+myjFlf0 X-Received: by 2002:a17:902:6b88:b0:17e:f177:400 with SMTP id p8-20020a1709026b8800b0017ef1770400mr660971plk.72.1666058701057; Mon, 17 Oct 2022 19:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058701; cv=none; d=google.com; s=arc-20160816; b=bpApoNIXOeRBWdhT+p6D1E8zMa3kNMdvD6M4gighiOzK77zUuArVBVNpCP6P18r016 DcJM0P+bTb6KL7a4p/O+oV52W1VrmOJv0eR5vyRk2HOOMQfzXuaOJGM1go0VmCV4AXGI ar2OhlMK7ynPP6enwOGbK56m5M3gA/oGEMdU1kB2+VeYn1fRYDkaSZwL5QUrtAsv+Obn ij3iQbQio+tqHztjgBjW9rx/Te0L3q/Br+QpnWPmkG1zy86NlN0fhQ4p4/z0wpElyF/0 wiYL7plO7RIHM9v19k1qkbsS0gt9JxyuElJZ95ayORMy9/bSFBLJEa4oKnYAuypkgmkz es/w== 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=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=gRTYy3xXPVauXV4GErLC8S9GuVHVuEpC7EyaFANLOlvGC9uy/HlWNnGRj0MYDOt+8i +nSgGyG/0RPH5zwZ2onJ5prulVBDfbTFS4igbKhMuiajL6b1mCoNa94LNZwzwEnpMGGv kRSXHc0+KqIgPh21+1BvtXduI2wVfMf0RmtIeE93+MGDiBpC06e6iSJcT6uFVg1yA+cd EFDcXjwrUlv0bB8T3ML7TGbsOh6IU0HUTtuytvOCQgeoFAcHRjBwHTeIZx833x6+yHMt SHgaQ61rK0vks/tT/3fhBuGoEraGTTNXTHtTtMpSsgiF1yCoNGFaH/y+j9aCrMUELoWu nVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RRCmWXoQ; 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 f68-20020a636a47000000b00460f2778434si13592617pgc.652.2022.10.17.19.04.48; Mon, 17 Oct 2022 19:05:01 -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=RRCmWXoQ; 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 S231214AbiJRCDx (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbiJRCDP (ORCPT ); Mon, 17 Oct 2022 22:03:15 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5CA78D0EA; Mon, 17 Oct 2022 19:02:53 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id o21so10057548ple.5; Mon, 17 Oct 2022 19:02:53 -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=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=RRCmWXoQWPtnH+4Ky1/XpCLaYx2vBLbMMXmwSd7IPEj9WWBYYoGU6A2pE6DXXBMZ8N wDAloXeoQ3Bi/zhVYXtQLWjX+QWrzK52erK/EnlrfIk41h89PM6umD1ktGcvEqZ5pMXP bwqD4l1L/hwkQf5dNXgq13ecX0ZQ/BtZxN3+RUqoSwE+luf45Rk90kRVfRWA/BjBghwS UJNkIf0BvaYQ/jyv+nZHh+V+2BNsHWSQoJesE3cjQuIcNyoqMTWUfbhIMLq0NdBsQBAM pe8f0RThFlZQ0QjsAHiOgbeL4AUItmYUJXMT8KFwESkTNcQG2dXg32vf2EBKwdXlWF8d 5LIQ== 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=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=2YXABTwFY+sZmFyz4Kh7YEKRGS50W8SZoaPN++igXW5E7SUv7s91wgMBNoV5BQOYdL z793PchlmgtySfy+HboZgUTua09f2VWP+qywtdlifWQFErv8yHp/PQ1Xj1NzvXCvDrw8 kJ2hqMkgjDyiMxnsgDiaMhBq9OYj6kimLXmw2zZYZm+WT1VtGapqQVa1vdeHR2PN/joI F1UOYCdMa0CaBA0aVW+k6DS3XwDZbbHK+USR42gmP/A+NJh+dKEEzybhUOACzTnu98c3 8zpB9O2pI0yPTP1gk3lORRycIC0Ajn5Hk4GbVUvkZWL42/qes7K4iOoqoRz8cr/CGkS0 Y/Rw== X-Gm-Message-State: ACrzQf1enHE9MkL8yqGYEFaeKSy8dN/SQMG8jmnyNW1VkC7nLrEwU6sg Vb0y3sfNZhOq176HSuL0KTo= X-Received: by 2002:a17:902:7295:b0:17d:5176:fe6e with SMTP id d21-20020a170902729500b0017d5176fe6emr578396pll.147.1666058572444; Mon, 17 Oct 2022 19:02:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:52 -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 12/20] perf stat: Allocate aggr counts for recorded data Date: Mon, 17 Oct 2022 19:02:19 -0700 Message-Id: <20221018020227.85905-13-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?1746989168298533918?= X-GMAIL-MSGID: =?utf-8?q?1746989168298533918?= In the process_stat_config_event() it sets the aggr_mode that means the earlier evlist__alloc_stats() cannot allocate the aggr counts due to the missing aggr_mode. Do it after setting the aggr_map using evlist__alloc_aggr_stats(). Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 20 +++++++++++++++----- tools/perf/util/stat.c | 39 +++++++++++++++++++++++++++++++-------- tools/perf/util/stat.h | 2 ++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 6777fef0d56c..2a6a5d0c5563 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1342,7 +1342,11 @@ static struct aggr_cpu_id perf_stat__get_cpu(struct perf_stat_config *config __m static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, aggr_get_id_t get_id, struct perf_cpu cpu) { - struct aggr_cpu_id id = aggr_cpu_id__empty(); + struct aggr_cpu_id id; + + /* per-process mode - should use global aggr mode */ + if (cpu.cpu == -1) + return get_id(config, cpu); if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) config->cpus_aggr_map->map[cpu.cpu] = get_id(config, cpu); @@ -2125,17 +2129,23 @@ int process_stat_config_event(struct perf_session *session, if (perf_cpu_map__empty(st->cpus)) { if (st->aggr_mode != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); - return 0; - } - - if (st->aggr_mode != AGGR_UNSET) + } else if (st->aggr_mode != AGGR_UNSET) { stat_config.aggr_mode = st->aggr_mode; + } if (perf_stat.data.is_pipe) perf_stat_init_aggr_mode(); else perf_stat_init_aggr_mode_file(st); + if (stat_config.aggr_map) { + int nr_aggr = stat_config.aggr_map->nr; + + if (evlist__alloc_aggr_stats(session->evlist, nr_aggr) < 0) { + pr_err("cannot allocate aggr counts\n"); + return -1; + } + } return 0; } diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 5b04c9d16156..1b9048115a18 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -141,6 +141,31 @@ static void evsel__reset_stat_priv(struct evsel *evsel) memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } +static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr) +{ + struct perf_stat_evsel *ps = evsel->stats; + + if (ps == NULL) + return 0; + + ps->nr_aggr = nr_aggr; + ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); + if (ps->aggr == NULL) + return -ENOMEM; + + return 0; +} + +int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) { + if (evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) + return -1; + } + return 0; +} static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) { @@ -150,16 +175,14 @@ static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr) if (ps == NULL) return -ENOMEM; - if (nr_aggr) { - ps->nr_aggr = nr_aggr; - ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr)); - if (ps->aggr == NULL) { - free(ps); - return -ENOMEM; - } + evsel->stats = ps; + + if (nr_aggr && evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) { + evsel->stats = NULL; + free(ps); + return -ENOMEM; } - evsel->stats = ps; perf_stat_evsel_id_init(evsel); evsel__reset_stat_priv(evsel); return 0; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 0980875b9be1..4c00f814bd79 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -275,6 +275,8 @@ void evlist__reset_prev_raw_counts(struct evlist *evlist); void evlist__copy_prev_raw_counts(struct evlist *evlist); void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); +int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); + int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); struct perf_tool; From patchwork Tue Oct 18 02:02:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734810wrs; Mon, 17 Oct 2022 19:05:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5PKOhrgQe6ZHloLWcM4MI13NtQI+DiFH1nnCiqnq4Km2lGv9p/Uee3UCKbhNH+FWBvWJE7 X-Received: by 2002:a17:90b:1e43:b0:20d:59b9:751b with SMTP id pi3-20020a17090b1e4300b0020d59b9751bmr37450523pjb.90.1666058713443; Mon, 17 Oct 2022 19:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058713; cv=none; d=google.com; s=arc-20160816; b=brbnIG7Da0yCmusmT0ec/a3YtTpO/0kOVdeOSC2ie1w5r67JxDdWhs+A3ale1pU0qj KBOn+zYx+qLj47ePEONqtnpfNSDuQ5yCSfbCOzUYKfDVEN/tae7mbrJTMgIH1ADM6lp9 7L4m2SWGLiKkpp6r3lVpTmfIT4XYj/LsGTzyLEApkdgGFywqOrbjU8KLW8G3s38dph2W FnJWWxiJjzPKkwO3SASJE0+elyLleUsrHv5/yCV8RqOq4y8DntiBjYTCCn0QBs0YPgEN YXfRjT8I3XJRiQBjoI1+IHQYmBn5sybijMe2aISoEynuLiHrGH1Xr1OHyHcQsnc7IQez X5Dw== 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=MimTLujqV6UiVtggvclgfKIAxzqzEE9ZfQLvshn5bEw=; b=rESO+z0xftJYTdF+ZoQCKkaHE+CEP3NJ8FbGzWZWI6vzdWTKt/YlWrY4FaLGMiIoZg ZQ/Ygz4vaEwi0UEOGL4SClW56RiEyzx35qrIm4462oY3QOYjOopz+0SYkAuqKjbCJgtN EhvDQC5iFnbd4PADWLSsI4dnmM1p/akKQ2fcZ8nVjX7gS3GguwqYxeQqUh6gDkFl+JRn qBU27ZhPKiV84rZV1aonlbj+WaCbdT3+HNY+dVLGkWdvbrE/wS8k60LCDFhBh0fYzZGo LixlMp/qcAlozraurTm+lBTcQotOM9OOhch/rArn5ky13YpDTbS9O6ESUufW2ey5ykUS X1Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DAKz5ea3; 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 d1-20020a17090ab30100b001f4fc7af64esi17978838pjr.101.2022.10.17.19.04.59; Mon, 17 Oct 2022 19:05:13 -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=DAKz5ea3; 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 S230470AbiJRCEO (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiJRCDT (ORCPT ); Mon, 17 Oct 2022 22:03:19 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06AA8D0FD; Mon, 17 Oct 2022 19:02:54 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id g28so12746616pfk.8; Mon, 17 Oct 2022 19:02:54 -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=MimTLujqV6UiVtggvclgfKIAxzqzEE9ZfQLvshn5bEw=; b=DAKz5ea30SrWcT7uhN7sNcCUTQDPiWNvnXT3B+pxgwRGK4ZPDMiF4MQH7Avvi5TkfW Y0dWDzdlX89H7Tu8pgJTy1DO8g00o2EcqRwWT2obChtGgTk6yUl2TzItc0/5YVve8NYp gl65yIDzN/hzZrV2BNqyAXrGXaii2bMQbfzaIt1QTnyazX1fg1TIkykxaR7xbIfingh0 vi13WZSbT6+nwV2GeidKRUVfgFMLk3hxep1fd44P6w7CYdpaJ5YIzNYOskRGkIiNXJg5 clXTacZQXPyglEhu+PO+D45Iy4npiuGIdB5ViRJ+ntF8Lmtzgwm8FZM3hsZvqjLwySE1 Y1yg== 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=MimTLujqV6UiVtggvclgfKIAxzqzEE9ZfQLvshn5bEw=; b=g90V5lbmgCh9qat0id923L3GRRTmpkSiq5SLa8YOwPjPvbdoCe9atBV+yfSbwwDPlW hkpUwu8muc01Ise4VOOyVBd8Wrm1XYwyiK82YoDLXPxYrT/6kqSFpzujoddfTtmKWKKO ZJyRVsuVPM3aY+Dk82yhefkEL1TSgnuYhiPC+xoSzb4gqJ64PX6B1rImiVsFOifT/87d m9fWJ/XftNXAfQJYJBVnqOr45dCSZDDJaYWEHs1No/eGGhsH7WkLKGRUQgOuM6kBA5kH FvKbLzRSzKXnUz9ksZObWrnjXGx8cViY9wl0fjbfZVuNzpdn9lnmLhHwDwAEoW4M1Vho 5psA== X-Gm-Message-State: ACrzQf0/BfANQuqERAmfReqbloZxbNkVRT/+C5zqQj9lWK5LegrlvCJg BBZFb+TeHTL6pMzVCdvjHR8= X-Received: by 2002:a63:1d22:0:b0:439:3e7c:8af7 with SMTP id d34-20020a631d22000000b004393e7c8af7mr671426pgd.78.1666058574090; Mon, 17 Oct 2022 19:02:54 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:53 -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 13/20] perf stat: Reset aggr counts for each interval Date: Mon, 17 Oct 2022 19:02:20 -0700 Message-Id: <20221018020227.85905-14-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?1746989181172301512?= X-GMAIL-MSGID: =?utf-8?q?1746989181172301512?= The evsel->stats->aggr->count should be reset for interval processing since we want to use the values directly for display. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 3 +++ tools/perf/util/stat.c | 20 +++++++++++++++++--- tools/perf/util/stat.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2a6a5d0c5563..bff28a199dfd 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -492,6 +492,8 @@ static void process_interval(void) diff_timespec(&rs, &ts, &ref_time); perf_stat__reset_shadow_per_stat(&rt_stat); + evlist__reset_aggr_stats(evsel_list); + read_counters(&rs); if (STAT_RECORD) { @@ -965,6 +967,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) evlist__copy_prev_raw_counts(evsel_list); evlist__reset_prev_raw_counts(evsel_list); + evlist__reset_aggr_stats(evsel_list); perf_stat__reset_shadow_per_stat(&rt_stat); } else { update_stats(&walltime_nsecs_stats, t1 - t0); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 1b9048115a18..a4066f0d3637 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -130,17 +130,23 @@ static void perf_stat_evsel_id_init(struct evsel *evsel) } } -static void evsel__reset_stat_priv(struct evsel *evsel) +static void evsel__reset_aggr_stats(struct evsel *evsel) { struct perf_stat_evsel *ps = evsel->stats; struct perf_stat_aggr *aggr = ps->aggr; - init_stats(&ps->res_stats); - if (aggr) memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } +static void evsel__reset_stat_priv(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + + init_stats(&ps->res_stats); + evsel__reset_aggr_stats(evsel); +} + static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr) { struct perf_stat_evsel *ps = evsel->stats; @@ -276,6 +282,14 @@ void evlist__reset_stats(struct evlist *evlist) } } +void evlist__reset_aggr_stats(struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) + evsel__reset_aggr_stats(evsel); +} + void evlist__reset_prev_raw_counts(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 4c00f814bd79..809f9f0aff0c 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -276,6 +276,7 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist); void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); +void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); From patchwork Tue Oct 18 02:02:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1735111wrs; Mon, 17 Oct 2022 19:06:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6o1ryL0fS2TCwcvK3MUWD+ahUWI9vGrAomCCetcsfHxJJmhaOBfecW5xYrgjCdY1Snt+rf X-Received: by 2002:a17:902:f142:b0:17f:749f:ba27 with SMTP id d2-20020a170902f14200b0017f749fba27mr844325plb.144.1666058770502; Mon, 17 Oct 2022 19:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058770; cv=none; d=google.com; s=arc-20160816; b=XEjKBt55QQWlIagybSVpKljvd40WJ/bI9+WCgTQXEHTm1dB71lcAwEnGLKt+o3vuqn y8IN8BoitH2Wa8oC7Dy5USbKV28q4loyTlHIgXMkg0IzBwrHBswFmoFzdjoWcI3YIqQ7 F4VZUsweU+dtZVhmNfkMEkQifOaO9wNRpD4+fEsouYu22vJI2VNkxbgg/haPW6ccBq4H IRJ9gsFSEeabp/uqi4BgHuhyJyy9sHbVUKLFw3n4HnwJVHqU6+jfsHoGuiAmqqVADHgN go1tcLSkhTYTpK2mwphbZy1UR5ckbaG/EE0579AA1gATtfA/fOFS6zcOYm4ZQkW3tdhJ Dmng== 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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=ZHo5CPWEEqfdkDeuYtAXlo1eqzWM5EXdN7AwFsAKCl+3eUQvS8lIiiYaVl/LTwZLMZ kW0Z1YXkL5g2W3Y8G+Uu1xXDrQ79cp/xmZQ6FUH+G0xMZTg7GLweZW36GILqZxEBleL8 Gk4QFVtYRRQZmp68lmTm8BwA01g+SyMwdZ9pZwxrOhwOIHZmVsJNjlf6shw0MlxG7SNU we19p2zqGUyQIhMfsOm2HvbF4dbbecS4oCu61Saa4BbA3O577ZZKKNa+1amuTXhf0e2K shn5E5QcJ1paEHpoeA8klGUbbqFHCI14RP5lqwtc1lhACw4haPvlFjWLW8PPnmYX5Sue Begg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=J5s0GVms; 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 v20-20020a056a00149400b00554f1b32131si14694410pfu.362.2022.10.17.19.05.57; Mon, 17 Oct 2022 19:06:10 -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=J5s0GVms; 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 S230519AbiJRCES (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbiJRCDZ (ORCPT ); Mon, 17 Oct 2022 22:03:25 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32588C017; Mon, 17 Oct 2022 19:02:57 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so12621481pjf.5; Mon, 17 Oct 2022 19:02:57 -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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=J5s0GVmsqS7aVyRIl9LUJmVXMfrxqFVu5oso9YVMKcfFZrOeJ5gAksIn1s86O59zwS iHyML14kB57RNpwPGY5nIbzOYWlVuo6H3uoEnzghuPR/nfNPnilV62RM1tBTte3H0L/m z7P6bnTznAUrWOLQEZLCC5wq9zabCT6u1l7eoDBjhlWdDaET3Z36fnkJrlB8tJqUXDR6 huc2RDDQEQh/LTi2E0NA41UsTWAj0QKW10GTtKJ2O4qArXFiORMNcbsge0ozGygAEDIH 59D3KTj+WMzL+eFZ84k6AvXGLY5Fprjw/+52MdLQw5zWoiCvCxAzvJnFZUAwdLDO5T87 5/nA== 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=vrftxqnxBQhQyNqtAur/XWhtXNA2wVab7OVanH9H7Pg=; b=BtveAeEs/ku1bbU65sOCGTpdpMHdRno+JybVbdZh+W0usBJG9xFRrgT158i36Zew0D JEfFPYxI+ok3OfC4c8QCRHy9s8qSD6IMKd7lvOH5gabse/RcdZPrh2suIH9lSm2bgD5O WKlxhDgcnVBmoJlr26VbdQ+0i3yAbO9EJW4duBguHrTJRb6KNf5KtP0lVtOmtL2+IQL7 Pd+7uAV66S2uLE6+mpd3lIL1nM6iYqWRjZNVyC4lQeNimJAf+bJcyVuiS8xfXdPfhVAs YMpQNbQxAb0AXaNM7gufwWxwJsGLJ/Gy7YzMxXrIc8MNm11RGZCRncNjKKdrTyxDIkny vCiw== X-Gm-Message-State: ACrzQf1GSVHYkkhqDIko7KhPlIDP+m9UQF5wfAvzYe/ZFF77TCpB4Yej Owv04MhnWNu4rXg7u9/pbv0= X-Received: by 2002:a17:902:f647:b0:183:cb8d:40a0 with SMTP id m7-20020a170902f64700b00183cb8d40a0mr864835plg.18.1666058575855; Mon, 17 Oct 2022 19:02:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:55 -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 14/20] perf stat: Split process_counters() Date: Mon, 17 Oct 2022 19:02:21 -0700 Message-Id: <20221018020227.85905-15-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?1746989241440975368?= X-GMAIL-MSGID: =?utf-8?q?1746989241440975368?= It'd do more processing with aggregation. Let's split the function so that it can be shared with by process_stat_round_event() too. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bff28a199dfd..838d29590bed 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -465,15 +465,19 @@ static int read_bpf_map_counters(void) return 0; } -static void read_counters(struct timespec *rs) +static int read_counters(struct timespec *rs) { - struct evsel *counter; - if (!stat_config.stop_read_counter) { if (read_bpf_map_counters() || read_affinity_counters(rs)) - return; + return -1; } + return 0; +} + +static void process_counters(void) +{ + struct evsel *counter; evlist__for_each_entry(evsel_list, counter) { if (counter->err) @@ -494,7 +498,8 @@ static void process_interval(void) perf_stat__reset_shadow_per_stat(&rt_stat); evlist__reset_aggr_stats(evsel_list); - read_counters(&rs); + if (read_counters(&rs) == 0) + process_counters(); if (STAT_RECORD) { if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL)) @@ -980,7 +985,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) * avoid arbitrary skew, we must read all counters before closing any * group leaders. */ - read_counters(&(struct timespec) { .tv_nsec = t1-t0 }); + if (read_counters(&(struct timespec) { .tv_nsec = t1-t0 }) == 0) + process_counters(); /* * We need to keep evsel_list alive, because it's processed @@ -2099,13 +2105,11 @@ static int process_stat_round_event(struct perf_session *session, union perf_event *event) { struct perf_record_stat_round *stat_round = &event->stat_round; - struct evsel *counter; struct timespec tsh, *ts = NULL; const char **argv = session->header.env.cmdline_argv; int argc = session->header.env.nr_cmdline; - evlist__for_each_entry(evsel_list, counter) - perf_stat_process_counter(&stat_config, counter); + process_counters(); if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL) update_stats(&walltime_nsecs_stats, stat_round->time); From patchwork Tue Oct 18 02:02:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1735114wrs; Mon, 17 Oct 2022 19:06:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6TED+bCVSGIMiCXnm8aZUibausVpONwJGLBtOizSJmHb0SQpBV1NMmhdCtYD8pPh9nBDg7 X-Received: by 2002:a63:b12:0:b0:44a:d193:6b16 with SMTP id 18-20020a630b12000000b0044ad1936b16mr670388pgl.604.1666058771073; Mon, 17 Oct 2022 19:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058771; cv=none; d=google.com; s=arc-20160816; b=XPLLLAmqvc953lCn/D9qNNcY0V0aALaIl/03X6vYZd5iFRiw7nBbMqEW30otp/7brR QykI2ClRgoZvudKa7cvajvANOaidtqAGdSvryoLXxw2U4/1uVOVB2DlqltmQidINUzph m90qDbz2VKdAEt+ZTB8bBHhJjPzi79fpNcUw59GpDurenyj6Yzkh2GewXnhHZJ9+jLMg /qf12ePQCZJVCHWvggMCfoVbWsfWqgvTZAzwzGq3jFqDsLFrR4JZYiPFdorjqdG9rtKS 5rKXC4rcIdnPW80unpNjPfyKuvPuSRixxoMiCA4Q8EnbSpsNd+a1vRmllHk84Jd2mzoE LEiw== 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=qh0QUQdjU786Z7DJp5sJdB8+R9ndATpxKX6sr4NESwA=; b=XDj1xVBn+jUhLQXfVu32EnLgMzvMGxCTHTOFbREuSY1vNlMfDbL8SgtIv0TTAMO7fJ M61L+3d0teDhpfqZnVdAKucBCaoG7XO9v2ENK4mEaR/xA6yOcK1FO5cnMxPJ+rjJGLeL yl5h1fCc6Zk8A/PLU6G8x8CvDYLfKcb//qN5GvAuLjelkPyPPrwlKPlH45c+iChXhrs6 bUDpOe9T9FP2Ynj0Cc5g2aqjyO3w2W3NHbA0Y1atcsoLocffpexE+o+Fd5imIuI58j8S p4oB6je9PyRt8VcFg150LXb4+xd9yM4miUOgc3zdhalfNiV6N+Gyn+YF4ui9ZMkAI8eI 1qsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A8LGa8Lb; 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 f20-20020a056a0022d400b0052f60f7e0bcsi15014182pfj.346.2022.10.17.19.05.58; Mon, 17 Oct 2022 19:06:11 -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=A8LGa8Lb; 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 S231137AbiJRCEX (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbiJRCDZ (ORCPT ); Mon, 17 Oct 2022 22:03:25 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8B678E0EC; Mon, 17 Oct 2022 19:02:58 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id b2so12468315plc.7; Mon, 17 Oct 2022 19:02:58 -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=qh0QUQdjU786Z7DJp5sJdB8+R9ndATpxKX6sr4NESwA=; b=A8LGa8LbnhkCTvZemwwCZbmRXxGO/brwj28YYDkZL4WMXer+JTEkh24IayF06rDJCE pUn+LcSKIdnLp+E+kqgJoLfaAqyUZy+ES10hyj9xQyhCRVG9C9n78iy8iwAs8fhAQR2y QlZEVAcjnnv9mp8iL0EUerbT3HcXbD2+J9Adut6Qya7gaDW7uM6kARb9Ahp98aUX+IaR 8fqyXd+yrdyUTNc/kr7HQyK3YfNJt+VmaBtbLBAHblD5FiJmuTacctycy2zMlQ8RsG/B 8W4IdXs0gk3+7/CyG90H38UlAw/1p9WuA/b3/CG06Uj+HK3Zwonc4bGlecbIAMyIF4Sq cXGA== 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=qh0QUQdjU786Z7DJp5sJdB8+R9ndATpxKX6sr4NESwA=; b=KKb9kqmF+tq900GnM4kCGRNaRCVRyEPC28+kgFdknnkcQexa00ICMcM96vxXQtrJrU vc2OaEeLRIvM9XBHO6IIYnxcOj9x8XfFwfpBxUB8ewDenVbfqWAVUoiKOpvDfbdS/ihu p6RdaWV5j4tJOqlNjJUK+tAej8AFAj8KPFr1B6jep2gdtc0KeF2uDMF4S3MvLP37kFHD CDlfByrTSUK1ewftvIfq7d56MlWox2fkW6VQprC6/6DvMmqyVrShIXab8Ce4eRtbYEQK AdL5lnEZfMfcJI8So3QHli9I9RTG1jeQHjNNv2hhbX3YtVlpf4HiDnDpXue6eR+gUjbs YqJw== X-Gm-Message-State: ACrzQf0ISsNTNZqs+opPfXCeQ34E1BCrAfqboCsWSh+bxfRqTByLqWLM nvTTdICfXQOj+0cIBMgsoGc= X-Received: by 2002:a17:90a:74c2:b0:20a:f63c:2464 with SMTP id p2-20020a17090a74c200b0020af63c2464mr864009pjl.224.1666058577629; Mon, 17 Oct 2022 19:02:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:57 -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 15/20] perf stat: Add perf_stat_merge_counters() Date: Mon, 17 Oct 2022 19:02:22 -0700 Message-Id: <20221018020227.85905-16-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?1746989242082140183?= X-GMAIL-MSGID: =?utf-8?q?1746989242082140183?= The perf_stat_merge_counters() is to aggregate the same events in different PMUs like in case of uncore or hybrid. The same logic is in the stat-display routines but I think it should be handled when it processes the event counters. As it works on the aggr_counters, it doesn't change the output yet. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 2 + tools/perf/util/stat.c | 96 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.h | 2 + 3 files changed, 100 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 838d29590bed..371d6e896942 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -486,6 +486,8 @@ static void process_counters(void) pr_warning("failed to process counter %s\n", counter->name); counter->err = 0; } + + perf_stat_merge_counters(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index a4066f0d3637..aff1e7390585 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -595,6 +595,102 @@ int perf_stat_process_counter(struct perf_stat_config *config, return 0; } +static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias) +{ + struct perf_stat_evsel *ps_a = evsel->stats; + struct perf_stat_evsel *ps_b = alias->stats; + int i; + + if (ps_a->aggr == NULL && ps_b->aggr == NULL) + return 0; + + if (ps_a->nr_aggr != ps_b->nr_aggr) { + pr_err("Unmatched aggregation mode between aliases\n"); + return -1; + } + + for (i = 0; i < ps_a->nr_aggr; i++) { + struct perf_counts_values *aggr_counts_a = &ps_a->aggr[i].counts; + struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts; + + /* NB: don't increase aggr.nr for aliases */ + + aggr_counts_a->val += aggr_counts_b->val; + aggr_counts_a->ena += aggr_counts_b->ena; + aggr_counts_a->run += aggr_counts_b->run; + } + + return 0; +} +/* events should have the same name, scale, unit, cgroup but on different PMUs */ +static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b) +{ + if (strcmp(evsel__name(evsel_a), evsel__name(evsel_b))) + return false; + + if (evsel_a->scale != evsel_b->scale) + return false; + + if (evsel_a->cgrp != evsel_b->cgrp) + return false; + + if (strcmp(evsel_a->unit, evsel_b->unit)) + return false; + + if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b)) + return false; + + return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); +} + +static void evsel__merge_aliases(struct evsel *evsel) +{ + struct evlist *evlist = evsel->evlist; + struct evsel *alias; + + alias = list_prepare_entry(evsel, &(evlist->core.entries), core.node); + list_for_each_entry_continue(alias, &evlist->core.entries, core.node) { + /* Merge the same events on different PMUs. */ + if (evsel__is_alias(evsel, alias)) { + evsel__merge_aggr_counters(evsel, alias); + alias->merged_stat = true; + } + } +} + +static bool evsel__should_merge_hybrid(struct evsel *evsel, struct perf_stat_config *config) +{ + struct perf_pmu *pmu; + + if (!config->hybrid_merge) + return false; + + pmu = evsel__find_pmu(evsel); + return pmu && pmu->is_hybrid; +} + +static void evsel__merge_stats(struct evsel *evsel, struct perf_stat_config *config) +{ + /* this evsel is already merged */ + if (evsel->merged_stat) + return; + + if (evsel->auto_merge_stats || evsel__should_merge_hybrid(evsel, config)) + evsel__merge_aliases(evsel); +} + +/* merge the same uncore and hybrid events if requested */ +void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist) +{ + struct evsel *evsel; + + if (config->no_merge) + return; + + evlist__for_each_entry(evlist, evsel) + evsel__merge_stats(evsel, config); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 809f9f0aff0c..728bbc823b0d 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -280,6 +280,8 @@ void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); +void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); + struct perf_tool; union perf_event; struct perf_session; From patchwork Tue Oct 18 02:02:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1737241wrs; Mon, 17 Oct 2022 19:13:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DKMuOULTyglVSURN12b6kdpqSnyWy8DEDN7+6toaI2ghTx+wykrFZOsS6skKnN2K2hYhs X-Received: by 2002:a17:906:328c:b0:780:7574:ced2 with SMTP id 12-20020a170906328c00b007807574ced2mr523293ejw.634.1666059198686; Mon, 17 Oct 2022 19:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666059198; cv=none; d=google.com; s=arc-20160816; b=vPKYur1ZarDTXkUQPfnfxsXip3ra1khEgGw54hLFT5uPmltaYeCAvCk6PoS08IQD33 jK/Mox3lqXTiEa72g0kioImG5YHLu4D8Gr5z+ZaaDn1aRls7e51oZHpTvCsis9CA/lhV thYo6IPTMwVKdy52ISeHciTiXqNQoKryWT8LwP0+QOBnOyB9sbWIIHWKlS3AM4H91EgY DS880DQseBnPxHQDh6Qicj+7UcIHu222LhEzcmCWQE2jc2Syd9kh2oxn38H9ceEygROD AfszwEsTzX9CeiLhzBlh5oc0IITJfqIvCqtV4lb6fNw+9WWVJCtQZxUJ0LXEvcW4S8/d iTpA== 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=5WeyysPuKEEsCMTvHH/EnyiCA29OXlA8FDxwFK62GCs=; b=kJ7wqu8h4loIzOC6UCYeldGFpoVWOgcMVWkMCmNP5KGD2OzrsDQuuIOrekhBODrNUQ A4vW83C2R4c5aWydj1dSsrY0myWqDDYfvgP8tN6dW8RX/rd9I1gic+VtDYUEI83WBBBR ckb3tVo0IApqazAXRIiF+IuIdw2Tn9q5T859+KXDQLl1/tDqKOyQzqux8bFGjwnTG9fV RYcFsyvEgAcr6GMf5hlHgQ7u5zmIncPAmABwewoE7j2mctalcnSlsceIkEAw/PdWBWbh OaKpvUOuAPmtUcgdDsRCU2ibGuNJjZJTGrqEMtackU9qiEc2y5VGliS8nKn/Y6nuAeR2 Rfhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KRmnk0Ci; 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 nc9-20020a1709071c0900b0078e27ef9501si8871730ejc.750.2022.10.17.19.12.53; Mon, 17 Oct 2022 19:13:18 -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=KRmnk0Ci; 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 S231183AbiJRCEa (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbiJRCD1 (ORCPT ); Mon, 17 Oct 2022 22:03:27 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A6F08E442; Mon, 17 Oct 2022 19:03:00 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id f23so12468857plr.6; Mon, 17 Oct 2022 19:03:00 -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=5WeyysPuKEEsCMTvHH/EnyiCA29OXlA8FDxwFK62GCs=; b=KRmnk0Cin866fAIogyaUmmnovwsXbKtc/TjuQIWfi74mXqm5PptxVE632JUaH0zqHe 30EYPit+oFi+SljqTPGi+wyvEfxdeC8wKCu250FEGchTM2j36jmx0q/Uej6MaXqA44Sj k1Qz2ZX9Sl4OnWdA72iNm78iV7X+zP1EEIQN+nnl0Yicbfy9DK7BqU3E3dwor3GWwSXe Yz/WrE7DkqswVhA3FHMIBne/XLqexT1Re069qgW1fI+SfzQLzPe4zNO+EYslD3ammo2C hJQAGVdCktBFfHzNIezjBsUkIN1Y3sC73szF8C38GWT8buX8mHb7OsZTXEarpdxSAW4Q f2qQ== 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=5WeyysPuKEEsCMTvHH/EnyiCA29OXlA8FDxwFK62GCs=; b=W+/0vBmjPM8rLt8f6dY3QZruagyVUyl5h0ghHEfFYuyErNHgHYiKK3e/E6nL7NZoXJ YbUWQLywe6ZWpSMFYTccweZOsPH2TXSAMfH4SAiV5nHNSEhOQ6CaiPHhBsARhTJPOkTr 2ErmzObTmF7QvNHe2R8l2aASgYxhzHSsjz7jQos0mGn75Rhd9HIoJofaHhJHJ0qdVEva TJt24B7wOwyvHiVBbq4i5IrMngP70oo18gFc7ax+QOdtrJZLVZG6ryWa+M5cNgudjCKc nEtBaswCK0oI7bvNIWj+KJUv5Rvl+eTtxhXDjHcz5KVCom83ppgytJHhGYWclERkPmDU 0d/A== X-Gm-Message-State: ACrzQf04oN5LvOv/n+EUN1d/OBFpmX3qrOzZoOf5P21XlYUcpH5AW8mW N8upWoYV/7tvY5UrCi+O8D0= X-Received: by 2002:a17:90b:4f4d:b0:20d:a08e:3876 with SMTP id pj13-20020a17090b4f4d00b0020da08e3876mr30792974pjb.0.1666058579341; Mon, 17 Oct 2022 19:02:59 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:59 -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 16/20] perf stat: Add perf_stat_process_percore() Date: Mon, 17 Oct 2022 19:02:23 -0700 Message-Id: <20221018020227.85905-17-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?1746989690478400164?= X-GMAIL-MSGID: =?utf-8?q?1746989690478400164?= The perf_stat_process_percore() is to aggregate counts for an event per-core even if the aggr_mode is AGGR_NONE. This is enabled when user requested it on the command line. To handle that, it keeps the per-cpu counts at first. And then it aggregates the counts that have the same core id in the aggr->counts and updates the values for each cpu back. Later, per-core events will skip one of the CPUs unless percore-show-thread option is given. In that case, it can simply print all cpu stats with the updated (per-core) values. Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 1 + tools/perf/util/stat.c | 71 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/stat.h | 3 ++ 3 files changed, 75 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 371d6e896942..d6a006e41da0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -488,6 +488,7 @@ static void process_counters(void) } perf_stat_merge_counters(&stat_config, evsel_list); + perf_stat_process_percore(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index aff1e7390585..26c48ef7ca92 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -691,6 +691,77 @@ void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *ev evsel__merge_stats(evsel, config); } +static void evsel__update_percore_stats(struct evsel *evsel, struct aggr_cpu_id *core_id) +{ + struct perf_stat_evsel *ps = evsel->stats; + struct perf_counts_values counts = { 0, }; + struct aggr_cpu_id id; + struct perf_cpu cpu; + int idx; + + /* collect per-core counts */ + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + id = aggr_cpu_id__core(cpu, NULL); + if (!aggr_cpu_id__equal(core_id, &id)) + continue; + + counts.val += aggr->counts.val; + counts.ena += aggr->counts.ena; + counts.run += aggr->counts.run; + } + + /* update aggregated per-core counts for each CPU */ + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + id = aggr_cpu_id__core(cpu, NULL); + if (!aggr_cpu_id__equal(core_id, &id)) + continue; + + aggr->counts.val = counts.val; + aggr->counts.ena = counts.ena; + aggr->counts.run = counts.run; + + aggr->used = true; + } +} + +/* we have an aggr_map for cpu, but want to aggregate the counters per-core */ +static void evsel__process_percore(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + struct aggr_cpu_id core_id; + struct perf_cpu cpu; + int idx; + + if (!evsel->percore) + return; + + perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) { + struct perf_stat_aggr *aggr = &ps->aggr[idx]; + + if (aggr->used) + continue; + + core_id = aggr_cpu_id__core(cpu, NULL); + evsel__update_percore_stats(evsel, &core_id); + } +} + +/* process cpu stats on per-core events */ +void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist) +{ + struct evsel *evsel; + + if (config->aggr_mode != AGGR_NONE) + return; + + evlist__for_each_entry(evlist, evsel) + evsel__process_percore(evsel); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 728bbc823b0d..d23f8743e442 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -51,6 +51,8 @@ struct perf_stat_aggr { int nr; /* whether any entry has failed to read/process event */ bool failed; + /* to mark this data is processed already */ + bool used; }; /* per-evsel event stats */ @@ -281,6 +283,7 @@ void evlist__reset_aggr_stats(struct evlist *evlist); int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); +void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist); struct perf_tool; union perf_event; From patchwork Tue Oct 18 02:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1736418wrs; Mon, 17 Oct 2022 19:10:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qcCsYZzLQeIYxmX+mSf1TuPKzpP7womKZ9zfHOL+Ab7ewngJUgFLDz3BDH0mtO2xsojzv X-Received: by 2002:a17:907:25c5:b0:782:978d:c3da with SMTP id ae5-20020a17090725c500b00782978dc3damr479410ejc.623.1666059028324; Mon, 17 Oct 2022 19:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666059028; cv=none; d=google.com; s=arc-20160816; b=cx+BQ+uNNwiPKP78A8Cw0NRzrwM0p806iCe8isPJpJ6p68HXyuoeRfkU5cp8yNDyUj S44hoXHQA0B6GF9zmdLWut0qayGm3qqlmyQcmlf2PPIhvWIntO+pzKiaOFiiBpaQCdIt idGw7qLhTHBfsfVBcFRfj03vdshiXGNZBAbwW3FTL/AQcZwI5Sgg2/ABHU8tw9Oay5uL aID+FbgTt2RXAY0hPwn+0HNlvb9l3SNpvk2Hzaug/V3aBR+wfZbUG5ETkI9u0+JMdEGI yGDuPLyb9KU0S2vzwxFfp1CBuvnnUcm9kPsdf5BYjW2pLlY1ePF+LtVvhi4AGnIxH3Ui mZgw== 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=Eqf99fYG2bxqOCUE0EsbHGsdrtUHS7k4C0PA8A7LPhA=; b=A6nnEunQUnm7X2l3W+hBHvHvHG9B4KuIGIJxxcx6VLAwnaZS+a6wqdf4V3lJqZVENy MtTCe7dSiwoBoxoXLSErCenq3hjisLxRWQMpcTJbpj/c8zrSO/moqpNXzQoJ3W4ZYbaC GTuybP/uqj1iY2BVImxYyhdoEJ3zclCwxxWldc6LTHPXhOuVXtFHuF+b3evDF+Sbsc2X BxYD3ftoQGDJy/9pRvX6OXATenriymUcyHgECSmaG72Dgiy7O0Fpn+ZXxCbM2//bjL+B uX99p2qpsJ//JxORdmmoDcBCXDoKf8t0afmoC8ucym3XOpoRlGLxE2N9k43h0XQXmeHy 1apQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=krDtDn29; 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 f7-20020a056402354700b0043d00293d23si11281074edd.391.2022.10.17.19.10.03; Mon, 17 Oct 2022 19:10:28 -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=krDtDn29; 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 S231222AbiJRCE6 (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231237AbiJRCD4 (ORCPT ); Mon, 17 Oct 2022 22:03:56 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 879298E455; Mon, 17 Oct 2022 19:03:02 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so15973717pjg.1; Mon, 17 Oct 2022 19:03:01 -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=Eqf99fYG2bxqOCUE0EsbHGsdrtUHS7k4C0PA8A7LPhA=; b=krDtDn294PHFNxNUjn3QOGC128mXt4iEr8yQacbsB4ANbJQfKuosMJ8HzlOc/7jy8X PhnLHfdIdKFOArFh2qxy5Fvc2SQ+pjC3adAqBXGnF2rTFHbTUaGrnsP4QuIf7V7rvoZZ Gl3pSs99C49Rv45o0RpLZaYg2zD3Kn/1qBb87iYoIfT2wojwfF9kXpjEgYNCCjsQUN7k J0m9LFocsfjSXxSgR8NaFr96yNv2XTCGMgcQ9fNA3IOTULcEJCBfbSphBNYnTejfnn6g PqfJ0ZI7Erq2CqCMRMGzGuLgl/hjxZCmdBrS9uAcyn7W4nPWr3VGxap3iZ1mX7j6bEtO A3yA== 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=Eqf99fYG2bxqOCUE0EsbHGsdrtUHS7k4C0PA8A7LPhA=; b=V9/2zdQSMvnQ6lDMHtMDY+mk2vBlR+0FaAJh0hpNrqsCg+N8ksKzT/308nB6akCPzf eTOnylJ8+56r2oklt7fXm0uQHGUpgqVZFtnFbYN8+RcBs0VyiwJ/AXUrpLD4O+fui8nP EoW2mKhqV+DUW5OEJcHKqZogJfNUjL6s6M5KPLE8UR7WAKBtPqSqRNebf8pX2+1PsA5S TlxFUlH5KI0dvOKLWSCRXHh2sPdiWxenAyPycrtxZB+K13489V+utpMk21N82Hi9TCoQ hDbksmf6Tj2F1yT2CqLkuHO/CEJ88enCSFvOq0Db2ZkxbPOdGoo1li4fHzf926ciyOic v+Dw== X-Gm-Message-State: ACrzQf33Mk6Yz6D9f9ls+1Xcve7FzAHLQgta6WwB5rBO2xBVCthDewrs J5wQUZXGso/rwepY6JiqK9s= X-Received: by 2002:a17:90b:1b4d:b0:20d:7bbf:46f0 with SMTP id nv13-20020a17090b1b4d00b0020d7bbf46f0mr844247pjb.77.1666058581153; Mon, 17 Oct 2022 19:03:01 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:03:00 -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 17/20] perf stat: Add perf_stat_process_shadow_stats() Date: Mon, 17 Oct 2022 19:02:24 -0700 Message-Id: <20221018020227.85905-18-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?1746989511468317096?= X-GMAIL-MSGID: =?utf-8?q?1746989511468317096?= This function updates the shadow stats using the aggregated counts uniformly since it uses the aggr_counts for the every aggr mode. It'd have duplicate shadow stats for each items for now since the display routines will update them once again. But that'd be fine as it shows the average values and it'd be gone eventually. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 1 + tools/perf/util/stat.c | 50 ++++++++++++++++++++------------------- tools/perf/util/stat.h | 1 + 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d6a006e41da0..d7c52cef70a3 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -489,6 +489,7 @@ static void process_counters(void) perf_stat_merge_counters(&stat_config, evsel_list); perf_stat_process_percore(&stat_config, evsel_list); + perf_stat_process_shadow_stats(&stat_config, evsel_list); } static void process_interval(void) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 26c48ef7ca92..c0955a0427ab 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -474,7 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, aggr_counts->val += count->val; aggr_counts->ena += count->ena; aggr_counts->run += count->run; - goto update; + return 0; } if (ps->aggr) { @@ -511,32 +511,10 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } -update: - switch (config->aggr_mode) { - case AGGR_THREAD: - case AGGR_CORE: - case AGGR_DIE: - case AGGR_SOCKET: - case AGGR_NODE: - case AGGR_NONE: - if ((config->aggr_mode == AGGR_NONE) && (!evsel->percore)) { - perf_stat__update_shadow_stats(evsel, count->val, - cpu_map_idx, &rt_stat); - } - - if (config->aggr_mode == AGGR_THREAD) { - perf_stat__update_shadow_stats(evsel, count->val, - thread, &rt_stat); - } - break; - case AGGR_GLOBAL: + if (config->aggr_mode == AGGR_GLOBAL) { aggr->val += count->val; aggr->ena += count->ena; aggr->run += count->run; - case AGGR_UNSET: - case AGGR_MAX: - default: - break; } return 0; @@ -762,6 +740,30 @@ void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *e evsel__process_percore(evsel); } +static void evsel__update_shadow_stats(struct evsel *evsel) +{ + struct perf_stat_evsel *ps = evsel->stats; + int i; + + if (ps->aggr == NULL) + return; + + for (i = 0; i < ps->nr_aggr; i++) { + struct perf_counts_values *aggr_counts = &ps->aggr[i].counts; + + perf_stat__update_shadow_stats(evsel, aggr_counts->val, i, &rt_stat); + } +} + +void perf_stat_process_shadow_stats(struct perf_stat_config *config __maybe_unused, + struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) + evsel__update_shadow_stats(evsel); +} + int perf_event__process_stat_event(struct perf_session *session, union perf_event *event) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index d23f8743e442..3d413ba8c68a 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -284,6 +284,7 @@ int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist); +void perf_stat_process_shadow_stats(struct perf_stat_config *config, struct evlist *evlist); struct perf_tool; union perf_event; From patchwork Tue Oct 18 02:02:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1735197wrs; Mon, 17 Oct 2022 19:06:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5b1F9uLDbFgNHbnw4KN0f6E1tis/HqGysBEkSiTnTzr8C1GdUYN7l2Vh7FxKs7e4qAZO3C X-Received: by 2002:a17:90a:4fe4:b0:20a:629c:e854 with SMTP id q91-20020a17090a4fe400b0020a629ce854mr37477470pjh.30.1666058789559; Mon, 17 Oct 2022 19:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058789; cv=none; d=google.com; s=arc-20160816; b=qjj7G34xTYimV2eImW6Mm/sKqSH7R/r0crmGbaH5c0jB1ME4oM9cCe3hAqghxLnPVb Zivfk2MY3vCUOb+VvBtwTAegYqMY6qNiQCX/xw5fRk4m6jS9kvZMcLtNr8jnC4pyiZkz VR1GQdJau11HtaKWGrjd5GLL5DfbY0fvTFlEFiwsOhoLcFQJx4z+lT4u5EmQaG/qwmaT v03/vnf11zQayKQE9oe6497cKFt3IxUW9pKIHKCVAlyD0DOXgUVISEZsS7mQ0A7m4iXg 4e7AZ8bmS+4pT+22T6X8O+6Kq0n5KrBlu+trRCsMlITI6jmv96QiG7ZK1LVa3aeCLYS8 1SSA== 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=WTApGJWH5ZFKT+wn0YmeclzL/CT3nVPh/YrDotMMJ2g=; b=gc3feKfCHpe2xvaINETlgBlbFJCehAdkrfQBClkvdg5gLJghkyecJ6BJjmt8aKlKJv YgTcpe2R+Zohw3Ha06shOjLtyWRJyXuYlicITGhH2+tZjCMi+1AHV4VRUP9A75adjGEG sYx4WHHMnaqA1x6Jf7nQQvWgZLSgWZikvlNP9oGbGWRKUG2hLhHKJ6xicpOgghEm78Xy JV+YYMiXw49mKVQ3KKh41C6f6y+purlEnKpWmviTk9IT7ZYKUFz9krdfhkbvChCU3NQT x5NZwtMN1IL+alE2d294Ek1KYpxjKw+rT8COELoTljsFHvHzmCa31dhnsxv2f6q2xb1w dWcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CjonoIMS; 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 k138-20020a628490000000b00562dda10caesi12732079pfd.245.2022.10.17.19.06.17; Mon, 17 Oct 2022 19:06:29 -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=CjonoIMS; 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 S231172AbiJRCE1 (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbiJRCD1 (ORCPT ); Mon, 17 Oct 2022 22:03:27 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED1AF8C01E; Mon, 17 Oct 2022 19:03:04 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id cl1so12543928pjb.1; Mon, 17 Oct 2022 19:03:04 -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=WTApGJWH5ZFKT+wn0YmeclzL/CT3nVPh/YrDotMMJ2g=; b=CjonoIMSTcgoZ3aAC/OFaa9lEA+P4tkutLX2VZz4nwETZ7yetqYNuUcM9HCIxw+y/w BwX1lLFjWUr/H97d2JexbDom4Fa6NZbQomZ+IAEsSPbDDX3ksCNvNCyEBZfZxs5ImyUX ag5xoFg6BRD7V9/A/u2tfVbDkeHhUQf84t4bWaJOR6fSNo1mjaGDJCOvVCATCUB/vu/1 S5l4ENfS1yWCFwH0vJSvLT+iJBym7C46M2/1CfCOewh8JIui+kQFvGj3D8b3HgzEkjPh tDtefASv3sgHgAVqS4CeQkRgPqmFaxAvIC3edRcq5GrziTHhhNb+M+1PCj1Mp/JlEgQ2 Uqiw== 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=WTApGJWH5ZFKT+wn0YmeclzL/CT3nVPh/YrDotMMJ2g=; b=kaEikbQgb+9Ke9XLbzvUBvEQj0ifU5sfw5OXmvszi8foQKRTeIBJrWVIKsEva1Yod2 7EcjAGMhH3hISjYKiAZsQjCNdDPAJqzH3AdSbtvftZSy5tgMZC0GsyargMsTYOc97iXO rmauUqaiz/lHlg4QffUOk5PKIYZpg4xOvvEDEUaCXMjDpiqH1WEA1tZNy4dGiTJFIPaL axrckdbCQqnZCCG19ro2kz4JCFClPmONUwBsqsGDt0uCDa6gZiCtcI2q1X+uQKAno3hK mDUSAY0sifpycaRctM84Dlauim4Lpi/KHkviT3lfM9tpQpU2lp/PDrLRLRQKhR0iNQKV cTcA== X-Gm-Message-State: ACrzQf22QNnN8PE4JkorXwyQH+iAis4qaPtN5FWvqKxljqYaO5Rfmpfm 2gUmWj/QGXhQT04E+TeUaKA= X-Received: by 2002:a17:90b:1b47:b0:20d:cdf2:c02e with SMTP id nv7-20020a17090b1b4700b0020dcdf2c02emr824139pjb.233.1666058583387; Mon, 17 Oct 2022 19:03:03 -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.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:03:02 -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 18/20] perf stat: Display event stats using aggr counts Date: Mon, 17 Oct 2022 19:02:25 -0700 Message-Id: <20221018020227.85905-19-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?1746989261139696102?= X-GMAIL-MSGID: =?utf-8?q?1746989261139696102?= Now aggr counts are ready for use. Convert the display routines to use the aggr counts and update the shadow stat with them. It doesn't need to aggregate counts or collect aliases anymore during the display. Get rid of now unused struct perf_aggr_thread_value. Note that there's a difference in the display order among the aggr mode. For per-core/die/socket/node aggregation, it shows relevant events in the same unit together, whereas global/thread/no aggregation it shows the same events for different units together. So it still uses separate codes to display them due to the ordering. One more thing to note is that it breaks per-core event display for now. The next patch will fix it to have identical output as of now. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/stat-display.c | 421 ++++----------------------------- tools/perf/util/stat.c | 5 - tools/perf/util/stat.h | 9 - 3 files changed, 49 insertions(+), 386 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 4113aa86772f..bfae2784609c 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -442,31 +442,6 @@ static void print_metric_header(struct perf_stat_config *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } -static int first_shadow_map_idx(struct perf_stat_config *config, - struct evsel *evsel, const struct aggr_cpu_id *id) -{ - struct perf_cpu_map *cpus = evsel__cpus(evsel); - struct perf_cpu cpu; - int idx; - - if (config->aggr_mode == AGGR_NONE) - return perf_cpu_map__idx(cpus, id->cpu); - - if (config->aggr_mode == AGGR_THREAD) - return id->thread_idx; - - if (!config->aggr_get_id) - return 0; - - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - struct aggr_cpu_id cpu_id = config->aggr_get_id(config, cpu); - - if (aggr_cpu_id__equal(&cpu_id, id)) - return idx; - } - return 0; -} - static void abs_printout(struct perf_stat_config *config, struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg) { @@ -537,7 +512,7 @@ static bool is_mixed_hw_group(struct evsel *counter) static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int nr, struct evsel *counter, double uval, char *prefix, u64 run, u64 ena, double noise, - struct runtime_stat *st) + struct runtime_stat *st, int map_idx) { struct perf_stat_output_ctx out; struct outstate os = { @@ -648,8 +623,7 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int print_running(config, run, ena); } - perf_stat__print_shadow_stats(config, counter, uval, - first_shadow_map_idx(config, counter, &id), + perf_stat__print_shadow_stats(config, counter, uval, map_idx, &out, &config->metric_events, st); if (!config->csv_output && !config->metric_only && !config->json_output) { print_noise(config, counter, noise); @@ -657,34 +631,6 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int } } -static void aggr_update_shadow(struct perf_stat_config *config, - struct evlist *evlist) -{ - int idx, s; - struct perf_cpu cpu; - struct aggr_cpu_id s2, id; - u64 val; - struct evsel *counter; - struct perf_cpu_map *cpus; - - for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; - evlist__for_each_entry(evlist, counter) { - cpus = evsel__cpus(counter); - val = 0; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpu); - if (!aggr_cpu_id__equal(&s2, &id)) - continue; - val += perf_counts(counter->counts, idx, 0)->val; - } - perf_stat__update_shadow_stats(counter, val, - first_shadow_map_idx(config, counter, &id), - &rt_stat); - } - } -} - static void uniquify_event_name(struct evsel *counter) { char *new_name; @@ -721,137 +667,51 @@ static void uniquify_event_name(struct evsel *counter) counter->uniquified_name = true; } -static void collect_all_aliases(struct perf_stat_config *config, struct evsel *counter, - void (*cb)(struct perf_stat_config *config, struct evsel *counter, void *data, - bool first), - void *data) +static bool hybrid_uniquify(struct evsel *evsel, struct perf_stat_config *config) { - struct evlist *evlist = counter->evlist; - struct evsel *alias; - - alias = list_prepare_entry(counter, &(evlist->core.entries), core.node); - list_for_each_entry_continue (alias, &evlist->core.entries, core.node) { - /* Merge events with the same name, etc. but on different PMUs. */ - if (!strcmp(evsel__name(alias), evsel__name(counter)) && - alias->scale == counter->scale && - alias->cgrp == counter->cgrp && - !strcmp(alias->unit, counter->unit) && - evsel__is_clock(alias) == evsel__is_clock(counter) && - strcmp(alias->pmu_name, counter->pmu_name)) { - alias->merged_stat = true; - cb(config, alias, data, false); - } - } + return evsel__is_hybrid(evsel) && !config->hybrid_merge; } -static bool hybrid_merge(struct evsel *counter, struct perf_stat_config *config, - bool check) +static void uniquify_counter(struct perf_stat_config *config, struct evsel *counter) { - if (evsel__is_hybrid(counter)) { - if (check) - return config->hybrid_merge; - else - return !config->hybrid_merge; - } - - return false; -} - -static bool collect_data(struct perf_stat_config *config, struct evsel *counter, - void (*cb)(struct perf_stat_config *config, struct evsel *counter, void *data, - bool first), - void *data) -{ - if (counter->merged_stat) - return false; - cb(config, counter, data, true); - if (config->no_merge || hybrid_merge(counter, config, false)) + if (config->no_merge || hybrid_uniquify(counter, config)) uniquify_event_name(counter); - else if (counter->auto_merge_stats || hybrid_merge(counter, config, true)) - collect_all_aliases(config, counter, cb, data); - return true; -} - -struct aggr_data { - u64 ena, run, val; - struct aggr_cpu_id id; - int nr; - int cpu_map_idx; -}; - -static void aggr_cb(struct perf_stat_config *config, - struct evsel *counter, void *data, bool first) -{ - struct aggr_data *ad = data; - int idx; - struct perf_cpu cpu; - struct perf_cpu_map *cpus; - struct aggr_cpu_id s2; - - cpus = evsel__cpus(counter); - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - struct perf_counts_values *counts; - - s2 = config->aggr_get_id(config, cpu); - if (!aggr_cpu_id__equal(&s2, &ad->id)) - continue; - if (first) - ad->nr++; - counts = perf_counts(counter->counts, idx, 0); - /* - * When any result is bad, make them all to give - * consistent output in interval mode. - */ - if (counts->ena == 0 || counts->run == 0 || - counter->counts->scaled == -1) { - ad->ena = 0; - ad->run = 0; - break; - } - ad->val += counts->val; - ad->ena += counts->ena; - ad->run += counts->run; - } } static void print_counter_aggrdata(struct perf_stat_config *config, struct evsel *counter, int s, char *prefix, bool metric_only, - bool *first, struct perf_cpu cpu) + bool *first) { - struct aggr_data ad; FILE *output = config->output; u64 ena, run, val; - int nr; - struct aggr_cpu_id id; double uval; + struct perf_stat_evsel *ps = counter->stats; + struct perf_stat_aggr *aggr = &ps->aggr[s]; + struct aggr_cpu_id id = config->aggr_map->map[s]; + double avg = aggr->counts.val; - ad.id = id = config->aggr_map->map[s]; - ad.val = ad.ena = ad.run = 0; - ad.nr = 0; - if (!collect_data(config, counter, aggr_cb, &ad)) + if (counter->supported && aggr->nr == 0) return; - if (perf_pmu__has_hybrid() && ad.ena == 0) - return; + uniquify_counter(config, counter); + + val = aggr->counts.val; + ena = aggr->counts.ena; + run = aggr->counts.run; - nr = ad.nr; - ena = ad.ena; - run = ad.run; - val = ad.val; if (*first && metric_only) { *first = false; - aggr_printout(config, counter, id, nr); + aggr_printout(config, counter, id, aggr->nr); } if (prefix && !metric_only) fprintf(output, "%s", prefix); uval = val * counter->scale; - if (cpu.cpu != -1) - id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); - printout(config, id, nr, counter, uval, - prefix, run, ena, 1.0, &rt_stat); + printout(config, id, aggr->nr, counter, uval, + prefix, run, ena, avg, &rt_stat, s); + if (!metric_only) fputc('\n', output); } @@ -869,8 +729,6 @@ static void print_aggr(struct perf_stat_config *config, if (!config->aggr_map || !config->aggr_get_id) return; - aggr_update_shadow(config, evlist); - /* * With metric_only everything is on a single line. * Without each counter has its own line. @@ -881,188 +739,36 @@ static void print_aggr(struct perf_stat_config *config, first = true; evlist__for_each_entry(evlist, counter) { + if (counter->merged_stat) + continue; + print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, (struct perf_cpu){ .cpu = -1 }); + prefix, metric_only, + &first); } if (metric_only) fputc('\n', output); } } -static int cmp_val(const void *a, const void *b) -{ - return ((struct perf_aggr_thread_value *)b)->val - - ((struct perf_aggr_thread_value *)a)->val; -} - -static struct perf_aggr_thread_value *sort_aggr_thread( - struct evsel *counter, - int *ret, - struct target *_target) -{ - int nthreads = perf_thread_map__nr(counter->core.threads); - int i = 0; - double uval; - struct perf_aggr_thread_value *buf; - - buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value)); - if (!buf) - return NULL; - - for (int thread = 0; thread < nthreads; thread++) { - int idx; - u64 ena = 0, run = 0, val = 0; - - perf_cpu_map__for_each_idx(idx, evsel__cpus(counter)) { - struct perf_counts_values *counts = - perf_counts(counter->counts, idx, thread); - - val += counts->val; - ena += counts->ena; - run += counts->run; - } - - uval = val * counter->scale; - - /* - * Skip value 0 when enabling --per-thread globally, - * otherwise too many 0 output. - */ - if (uval == 0.0 && target__has_per_thread(_target)) - continue; - - buf[i].counter = counter; - buf[i].id = aggr_cpu_id__empty(); - buf[i].id.thread_idx = thread; - buf[i].uval = uval; - buf[i].val = val; - buf[i].run = run; - buf[i].ena = ena; - i++; - } - - qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val); - - if (ret) - *ret = i; - - return buf; -} - -static void print_aggr_thread(struct perf_stat_config *config, - struct target *_target, - struct evsel *counter, char *prefix) -{ - FILE *output = config->output; - int thread, sorted_threads; - struct aggr_cpu_id id; - struct perf_aggr_thread_value *buf; - - buf = sort_aggr_thread(counter, &sorted_threads, _target); - if (!buf) { - perror("cannot sort aggr thread"); - return; - } - - for (thread = 0; thread < sorted_threads; thread++) { - if (prefix) - fprintf(output, "%s", prefix); - - id = buf[thread].id; - printout(config, id, 0, buf[thread].counter, buf[thread].uval, - prefix, buf[thread].run, buf[thread].ena, 1.0, - &rt_stat); - fputc('\n', output); - } - - free(buf); -} - -struct caggr_data { - double avg, avg_enabled, avg_running; -}; - -static void counter_aggr_cb(struct perf_stat_config *config __maybe_unused, - struct evsel *counter, void *data, - bool first __maybe_unused) -{ - struct caggr_data *cd = data; - struct perf_counts_values *aggr = &counter->counts->aggr; - - cd->avg += aggr->val; - cd->avg_enabled += aggr->ena; - cd->avg_running += aggr->run; -} - -/* - * Print out the results of a single counter: - * aggregated counts in system-wide mode - */ -static void print_counter_aggr(struct perf_stat_config *config, - struct evsel *counter, char *prefix) -{ - bool metric_only = config->metric_only; - FILE *output = config->output; - double uval; - struct caggr_data cd = { .avg = 0.0 }; - - if (!collect_data(config, counter, counter_aggr_cb, &cd)) - return; - - if (prefix && !metric_only) - fprintf(output, "%s", prefix); - - uval = cd.avg * counter->scale; - printout(config, aggr_cpu_id__empty(), 0, counter, uval, prefix, cd.avg_running, - cd.avg_enabled, cd.avg, &rt_stat); - if (!metric_only) - fprintf(output, "\n"); -} - -static void counter_cb(struct perf_stat_config *config __maybe_unused, - struct evsel *counter, void *data, - bool first __maybe_unused) -{ - struct aggr_data *ad = data; - - ad->val += perf_counts(counter->counts, ad->cpu_map_idx, 0)->val; - ad->ena += perf_counts(counter->counts, ad->cpu_map_idx, 0)->ena; - ad->run += perf_counts(counter->counts, ad->cpu_map_idx, 0)->run; -} - -/* - * Print out the results of a single counter: - * does not use aggregated count in system-wide - */ static void print_counter(struct perf_stat_config *config, struct evsel *counter, char *prefix) { - FILE *output = config->output; - u64 ena, run, val; - double uval; - int idx; - struct perf_cpu cpu; - struct aggr_cpu_id id; - - perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { - struct aggr_data ad = { .cpu_map_idx = idx }; - - if (!collect_data(config, counter, counter_cb, &ad)) - return; - val = ad.val; - ena = ad.ena; - run = ad.run; + bool metric_only = config->metric_only; + bool first = false; + int s; - if (prefix) - fprintf(output, "%s", prefix); + /* AGGR_THREAD doesn't have config->aggr_get_id */ + if (!config->aggr_map) + return; - uval = val * counter->scale; - id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); - printout(config, id, 0, counter, uval, prefix, - run, ena, 1.0, &rt_stat); + if (counter->merged_stat) + return; - fputc('\n', output); + for (s = 0; s < config->aggr_map->nr; s++) { + print_counter_aggrdata(config, counter, s, + prefix, metric_only, + &first); } } @@ -1081,6 +787,7 @@ static void print_no_aggr_metric(struct perf_stat_config *config, u64 ena, run, val; double uval; struct aggr_cpu_id id; + struct perf_stat_evsel *ps = counter->stats; int counter_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); if (counter_idx < 0) @@ -1093,13 +800,13 @@ static void print_no_aggr_metric(struct perf_stat_config *config, aggr_printout(config, counter, id, 0); first = false; } - val = perf_counts(counter->counts, counter_idx, 0)->val; - ena = perf_counts(counter->counts, counter_idx, 0)->ena; - run = perf_counts(counter->counts, counter_idx, 0)->run; + val = ps->aggr[counter_idx].counts.val; + ena = ps->aggr[counter_idx].counts.ena; + run = ps->aggr[counter_idx].counts.run; uval = val * counter->scale; printout(config, id, 0, counter, uval, prefix, - run, ena, 1.0, &rt_stat); + run, ena, 1.0, &rt_stat, counter_idx); } if (!first) fputc('\n', config->output); @@ -1135,8 +842,8 @@ static void print_metric_headers(struct perf_stat_config *config, }; bool first = true; - if (config->json_output && !config->interval) - fprintf(config->output, "{"); + if (config->json_output && !config->interval) + fprintf(config->output, "{"); if (prefix && !config->json_output) fprintf(config->output, "%s", prefix); @@ -1379,31 +1086,6 @@ static void print_footer(struct perf_stat_config *config) "the same PMU. Try reorganizing the group.\n"); } -static void print_percore_thread(struct perf_stat_config *config, - struct evsel *counter, char *prefix) -{ - int s; - struct aggr_cpu_id s2, id; - struct perf_cpu_map *cpus; - bool first = true; - int idx; - struct perf_cpu cpu; - - cpus = evsel__cpus(counter); - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpu); - for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; - if (aggr_cpu_id__equal(&s2, &id)) - break; - } - - print_counter_aggrdata(config, counter, s, - prefix, false, - &first, cpu); - } -} - static void print_percore(struct perf_stat_config *config, struct evsel *counter, char *prefix) { @@ -1416,15 +1098,14 @@ static void print_percore(struct perf_stat_config *config, return; if (config->percore_show_thread) - return print_percore_thread(config, counter, prefix); + return print_counter(config, counter, prefix); for (s = 0; s < config->aggr_map->nr; s++) { if (prefix && metric_only) fprintf(output, "%s", prefix); print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, (struct perf_cpu){ .cpu = -1 }); + prefix, metric_only, &first); } if (metric_only) @@ -1469,17 +1150,13 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf print_aggr(config, evlist, prefix); break; case AGGR_THREAD: - evlist__for_each_entry(evlist, counter) { - print_aggr_thread(config, _target, counter, prefix); - } - break; case AGGR_GLOBAL: if (config->iostat_run) iostat_print_counters(evlist, config, ts, prefix = buf, - print_counter_aggr); + print_counter); else { evlist__for_each_entry(evlist, counter) { - print_counter_aggr(config, counter, prefix); + print_counter(config, counter, prefix); } if (metric_only) fputc('\n', config->output); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index c0955a0427ab..0316557adce9 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -565,11 +565,6 @@ int perf_stat_process_counter(struct perf_stat_config *config, evsel__name(counter), count[0], count[1], count[2]); } - /* - * Save the full runtime - to allow normalization during printout: - */ - perf_stat__update_shadow_stats(counter, *count, 0, &rt_stat); - return 0; } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 3d413ba8c68a..382a1ab92ce1 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -224,15 +224,6 @@ static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rus struct evsel; struct evlist; -struct perf_aggr_thread_value { - struct evsel *counter; - struct aggr_cpu_id id; - double uval; - u64 val; - u64 run; - u64 ena; -}; - bool __perf_stat_evsel__is(struct evsel *evsel, enum perf_stat_evsel_id id); #define perf_stat_evsel__is(evsel, id) \ From patchwork Tue Oct 18 02:02:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3890 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1735623wrs; Mon, 17 Oct 2022 19:07:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4I1QwMwIHXrP7of9QtHORYQcPknFrep6/4s2xgy15u9PUJ9S/PWiNbbM4MkqRwKvfNO0c2 X-Received: by 2002:a63:4b4c:0:b0:45a:5f8:b49d with SMTP id k12-20020a634b4c000000b0045a05f8b49dmr664776pgl.490.1666058866524; Mon, 17 Oct 2022 19:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058866; cv=none; d=google.com; s=arc-20160816; b=ZFeFeoUsidFJWtHZzfOELQZ+xXPWJ0lkL7CHwTH021k3SPpXM7q+QUbFTEY3UazgiF 0+z1Zefd5OopV+pIG/Zxp8m3Oto1vyVh9u/lNMVBxOrTbzNCVpUK4BJabKXV5a+6rSse EwDHzHkrecusgN14DmGvkSFKnqUsL4F6DoepAWsEzDhBfwt3WypEFeiFqyDdp2MOLwvr RL/P9y1HyT8f/NNpy5AGE1BP6H6144FZuw4QAq2StJh91UiIHFfoFok55jzdGU7wx15y hoZw1VcRsNUZ0sF3QeWZEJPpyw8n2fFBC/L2wVUpCzAfTZiobP4gPEepqt2DNs6yGJIM SnCw== 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=OOCN0yzE3IzitqInAT6jHn/hIk/AewZCdKuWlAq5o8w=; b=bxpET/yhyAEEM9k5y1tUZRTY5y3U8fyxekucDXHaiTwNk+UzuyWWohYz4hnDXo/MXj 461T+ezOBagfFkBpKQq0Qz6jQKLVXOknLh6OCJJJdXnEi5aVM4B/lSN398g38kn1ReVN VqvjEA3YpMG7Q/2tR2PmtmgWuQqBTUFF7cHXRH0LDh0gcD4rki3qElaJmTw2QOmmFl84 glDvAxvbfsz1Fp/XHThQrF3c17bFWOiX3ovK3qajtJ6es/iV8z9t6m79BhtBYUVnYXov O10C6dTEmSoxMmLp+uwwpfg8euFK3GCm1GYPJn7cRwAyF7zJ2VNQYuufGb4tQ5jfRMUW cpVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QFMbmLS0; 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 l7-20020a170903120700b001786399ba31si15223343plh.590.2022.10.17.19.07.32; Mon, 17 Oct 2022 19:07:46 -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=QFMbmLS0; 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 S231195AbiJRCEg (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231206AbiJRCDw (ORCPT ); Mon, 17 Oct 2022 22:03:52 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52B1C8E709; Mon, 17 Oct 2022 19:03:07 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id h185so12041730pgc.10; Mon, 17 Oct 2022 19:03:06 -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=OOCN0yzE3IzitqInAT6jHn/hIk/AewZCdKuWlAq5o8w=; b=QFMbmLS0UBISIKTM+y6Oi/q4ytSvyFzHWqzFqiH7fU0HbmXjN17XFMfh9L2HnYAYh6 8TSe6TGD3mk5/Uz4D0a2kLGqvl8LcqRJU26M9rOF8fJBA91kcWUg6MD1WMRSnIGHjIHM 0Jv0cRzmbySKpqeDvI9aKpQy34mg08BVifHhVr9sL92l9sc6KLTPof11tlxR+rJbz4HS aj/YaPs5+eBVgpj0G/IYnaFucZzHfBnso6iWgmKXTeqfW7tAuMonbr/fbtWwgYgPVBnm Dc3pDZw6SxkwEAXOcBoMsRGZ+XjUi41aX0+3LdbVcA/GMD4tnjRQQiluHl2kK6uDcnI+ HWcw== 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=OOCN0yzE3IzitqInAT6jHn/hIk/AewZCdKuWlAq5o8w=; b=bTpgwnAz7Rqmn1Pjg8vqAwVAjoVRFsO6PzEioesfPCYfjjIyAm9gfpfuzup4tgGfrD zaVUPyG8MHrG5qOqtYQCm77xYMzc478TeDfGNTDE+CxEJ5TN6qnjHk2LQYIhN2aquVnB 6iuwDokR1rEQ4i4PP7ugG67yxRFjCpKW280IM6870UQi4p+l/tCpxop1d/DthJcEPrvI zGlb7ZE2k3iEVTmb8zL+n+p5p4v7AzCrPxsytobWOTenRWt+Wlp6ifnggngRCaT4GIet hNmlue9Yb8iugU/HfII9tNxULBytQWBtrvuwpzgDYpmiEZQ1IqjBL5KZk4EUK3EUycCW 92Hg== X-Gm-Message-State: ACrzQf1PMaYkdvvR+59rREM27ov5PNOwCzk8cIswUxfq4jTCh3y8JnKp b4i2XfQXylc2ePlIM+jk25w= X-Received: by 2002:a63:5a44:0:b0:431:fa3a:f92c with SMTP id k4-20020a635a44000000b00431fa3af92cmr636401pgm.471.1666058585500; Mon, 17 Oct 2022 19:03:05 -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.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:03:04 -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 19/20] perf stat: Display percore events properly Date: Mon, 17 Oct 2022 19:02:26 -0700 Message-Id: <20221018020227.85905-20-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?1746989342103313424?= X-GMAIL-MSGID: =?utf-8?q?1746989342103313424?= The recent change in the perf stat broke the percore event display. Note that the aggr counts are already processed so that the every sibling thread in the same core will get the per-core counter values. Check percore evsels and skip the sibling threads in the display. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 16 ---------------- tools/perf/util/stat-display.c | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d7c52cef70a3..9d35a3338976 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1404,18 +1404,6 @@ static struct aggr_cpu_id perf_stat__get_cpu_cached(struct perf_stat_config *con return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); } -static bool term_percore_set(void) -{ - struct evsel *counter; - - evlist__for_each_entry(evsel_list, counter) { - if (counter->percore) - return true; - } - - return false; -} - static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) { switch (aggr_mode) { @@ -1428,8 +1416,6 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) case AGGR_NODE: return aggr_cpu_id__node; case AGGR_NONE: - if (term_percore_set()) - return aggr_cpu_id__core; return aggr_cpu_id__cpu; case AGGR_GLOBAL: return aggr_cpu_id__global; @@ -1453,8 +1439,6 @@ static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) case AGGR_NODE: return perf_stat__get_node_cached; case AGGR_NONE: - if (term_percore_set()) - return perf_stat__get_core_cached; return perf_stat__get_cpu_cached; case AGGR_GLOBAL: return perf_stat__get_global_cached; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bfae2784609c..657434cd29ee 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1091,7 +1091,8 @@ static void print_percore(struct perf_stat_config *config, { bool metric_only = config->metric_only; FILE *output = config->output; - int s; + struct cpu_aggr_map *core_map; + int s, c, i; bool first = true; if (!config->aggr_map || !config->aggr_get_id) @@ -1100,13 +1101,35 @@ static void print_percore(struct perf_stat_config *config, if (config->percore_show_thread) return print_counter(config, counter, prefix); - for (s = 0; s < config->aggr_map->nr; s++) { + core_map = cpu_aggr_map__empty_new(config->aggr_map->nr); + if (core_map == NULL) { + fprintf(output, "Cannot allocate per-core aggr map for display\n"); + return; + } + + for (s = 0, c = 0; s < config->aggr_map->nr; s++) { + struct perf_cpu curr_cpu = config->aggr_map->map[s].cpu; + struct aggr_cpu_id core_id = aggr_cpu_id__core(curr_cpu, NULL); + bool found = false; + + for (i = 0; i < c; i++) { + if (aggr_cpu_id__equal(&core_map->map[i], &core_id)) { + found = true; + break; + } + } + if (found) + continue; + if (prefix && metric_only) fprintf(output, "%s", prefix); print_counter_aggrdata(config, counter, s, prefix, metric_only, &first); + + core_map->map[c++] = core_id; } + free(core_map); if (metric_only) fputc('\n', output); From patchwork Tue Oct 18 02:02:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1737076wrs; Mon, 17 Oct 2022 19:12:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4KYJ3h+E2szSD7SbaE9Xz2KxtCnKYNS59ZZxYmeg8WUlhbheLy0Kr9+wLH0zKX6xuorgC7 X-Received: by 2002:a17:906:8a4b:b0:78d:d475:ff74 with SMTP id gx11-20020a1709068a4b00b0078dd475ff74mr477721ejc.131.1666059170266; Mon, 17 Oct 2022 19:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666059170; cv=none; d=google.com; s=arc-20160816; b=bhiTA+Bqey1lOJWXi/umKVbnssvh3hXAAwZgfZtbC1S+4CDn1wAkXYBhUkM5ArmFqq esBY1bXXuzc+MqGhnlRZqZd4i94h+y9gTrfcdInuMto733Amqjom7gbDDpk6fBo6d/7P h86DvHhOF3hdtzfCzsPj7jg3ZQyf34Zkx9VWoRNC2Gi8132t4Ld5+1uiLkXfV5gJfYTc y1iv3R5kZQB5Z7jsbsNIgQaRZb3QuoM8jUtHyb20A0vWmMRhIfymqlVWpMW3T2wiqYvl jp/ao2Amt2c7PGpfg9gAuVPYCkctFTvFjbIfWf/O+fZQZjBNS2mlNw20WHzE+v1DPTAM qp+w== 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=1udheg5sHf0ONuxdfUoe8f9Q18ghdgubAqjN0gANnY8=; b=GCjk0QzzohFAK+iCh9DDHvlJpN/bp7M9vzrWsm0bR/4Fk6PoRyYgnDtiLgidXf67j8 gHboLhWzOvuO7BlJmef4l6ZtwZ9zpoWVLQ0oRqosiCKUnN5PUfq0fmY3ULeae9GnPKbH cKTYtmLoJUQKpwYQYbHaihR+VwjtCpmefvR+12EjbuNGpLa7LUCn85VkM2YcGrn2sc6W tV+goBX3WAxIHu9vSB2+RpT5W/RTkNx5ZRDFIG/yLtL5H6qMySIkP/3a7wYz+8iLMe9h rzD8x1Tul0bTLH/2VNS4JyemfM2joeLKK03vz6a7iCtyTv5KxUz78RyJVsMbH44UGMwh wXCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Rm62ohz+; 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 s5-20020a17090699c500b0078d878d8fb7si11110824ejn.920.2022.10.17.19.12.25; Mon, 17 Oct 2022 19:12:50 -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=Rm62ohz+; 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 S231204AbiJRCEq (ORCPT + 99 others); Mon, 17 Oct 2022 22:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230517AbiJRCDy (ORCPT ); Mon, 17 Oct 2022 22:03:54 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA4468E797; Mon, 17 Oct 2022 19:03:08 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id l1so12436037pld.13; Mon, 17 Oct 2022 19:03:08 -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=1udheg5sHf0ONuxdfUoe8f9Q18ghdgubAqjN0gANnY8=; b=Rm62ohz+DFBI6eZQNjQVIT9ILFhku/7CucD+oEe1lTPx2nneIj61QVcgLbQVNJS8wr SEAQOVT8IZtMNyzvXNmWihYWZ0qt27WRRfZLVI/W4LYnuQVN6E4pMpV6FJpId5XnQ5Jd EQj1A8vk8Rl6FwzGC4TsGaWpeHnmll90JApdakBxscK8vmwvGhXyDC54lfYV7X00+ob7 A/n1gZs7KO4oZJcyLC5fYzEJ9ZxfU1XMkFId6dm4pNFqg4dK3SgOB07ZNop+y7K6K9tF Wmu+EEffujOLcEZyjNB4kyXeFMEMN5AHUrfaoRE8lMrz77njT/2pDwm46SnddKCyDqSI pBzQ== 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=1udheg5sHf0ONuxdfUoe8f9Q18ghdgubAqjN0gANnY8=; b=mxW1JyQxjJuWDBU0q9ewvC+t9hbo1zWc6Hfu4RU6lBoYIFFb1SH4Rax/BIdID1JqCS vL0yX+cIhcuOAVcGCBa0+MYZzjdv9yPp1iTTCkXnyWxUPHtTvocghpLAw8ntwumyudLp zRlUujT5eNlsFxK4cvCN9nSMt2nKXXAfvVO+FJA+0KcarmoqtmReHBAfNZ6kIuITeJwI URbq5SVhr7/rXPZ9ZQuTIPLueF2yHjlcH0qyZ5q/oDaULzmyaWL4RqZng+7ljZR2nhNn aJKpclP1jEMGG0JUW3XvNJgZo08nnetu+jC+KH2eP4yuwWDYvXEbzTUMa2NgZYEEuKbM buBg== X-Gm-Message-State: ACrzQf32l5ZVYaRpLUpejTs3pycydpfZ+uWhSbSncO94Ff+8xYBkJMhT NX3k7ivpHQ2HTmTH7mWoVlU= X-Received: by 2002:a17:903:11cd:b0:170:cde8:18b7 with SMTP id q13-20020a17090311cd00b00170cde818b7mr651563plh.165.1666058587516; Mon, 17 Oct 2022 19:03:07 -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.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:03:06 -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 20/20] perf stat: Remove unused perf_counts.aggr field Date: Mon, 17 Oct 2022 19:02:27 -0700 Message-Id: <20221018020227.85905-21-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?1746989660152762152?= X-GMAIL-MSGID: =?utf-8?q?1746989660152762152?= The aggr field in the struct perf_counts is to keep the aggregated value in the AGGR_GLOBAL for the old code. But it's not used anymore. Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/util/counts.c | 1 - tools/perf/util/counts.h | 1 - tools/perf/util/stat.c | 39 ++++++--------------------------------- 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c index 7a447d918458..11cd85b278a6 100644 --- a/tools/perf/util/counts.c +++ b/tools/perf/util/counts.c @@ -48,7 +48,6 @@ void perf_counts__reset(struct perf_counts *counts) { xyarray__reset(counts->loaded); xyarray__reset(counts->values); - memset(&counts->aggr, 0, sizeof(struct perf_counts_values)); } void evsel__reset_counts(struct evsel *evsel) diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index 5de275194f2b..42760242e0df 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -11,7 +11,6 @@ struct evsel; struct perf_counts { s8 scaled; - struct perf_counts_values aggr; struct xyarray *values; struct xyarray *loaded; }; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 0316557adce9..3a432a949d46 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -308,8 +308,6 @@ static void evsel__copy_prev_raw_counts(struct evsel *evsel) *perf_counts(evsel->prev_raw_counts, idx, thread); } } - - evsel->counts->aggr = evsel->prev_raw_counts->aggr; } void evlist__copy_prev_raw_counts(struct evlist *evlist) @@ -320,26 +318,6 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist) evsel__copy_prev_raw_counts(evsel); } -void evlist__save_aggr_prev_raw_counts(struct evlist *evlist) -{ - struct evsel *evsel; - - /* - * To collect the overall statistics for interval mode, - * we copy the counts from evsel->prev_raw_counts to - * evsel->counts. The perf_stat_process_counter creates - * aggr values from per cpu values, but the per cpu values - * are 0 for AGGR_GLOBAL. So we use a trick that saves the - * previous aggr value to the first member of perf_counts, - * then aggr calculation in process_counter_values can work - * correctly. - */ - evlist__for_each_entry(evlist, evsel) { - *perf_counts(evsel->prev_raw_counts, 0, 0) = - evsel->prev_raw_counts->aggr; - } -} - static size_t pkg_id_hash(const void *__key, void *ctx __maybe_unused) { uint64_t *key = (uint64_t *) __key; @@ -442,7 +420,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, int cpu_map_idx, int thread, struct perf_counts_values *count) { - struct perf_counts_values *aggr = &evsel->counts->aggr; struct perf_stat_evsel *ps = evsel->stats; static struct perf_counts_values zero; bool skip = false; @@ -511,12 +488,6 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, } } - if (config->aggr_mode == AGGR_GLOBAL) { - aggr->val += count->val; - aggr->ena += count->ena; - aggr->run += count->run; - } - return 0; } @@ -541,13 +512,10 @@ static int process_counter_maps(struct perf_stat_config *config, int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter) { - struct perf_counts_values *aggr = &counter->counts->aggr; struct perf_stat_evsel *ps = counter->stats; - u64 *count = counter->counts->aggr.values; + u64 *count; int ret; - aggr->val = aggr->ena = aggr->run = 0; - if (counter->per_pkg) evsel__zero_per_pkg(counter); @@ -558,6 +526,11 @@ int perf_stat_process_counter(struct perf_stat_config *config, if (config->aggr_mode != AGGR_GLOBAL) return 0; + /* + * GLOBAL aggregation mode only has a single aggr counts, + * so we can use ps->aggr[0] as the actual output. + */ + count = ps->aggr[0].counts.values; update_stats(&ps->res_stats, *count); if (verbose > 0) {