From patchwork Fri Sep 16 18:41:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12978798 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72076ECAAD8 for ; Fri, 16 Sep 2022 18:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiIPSlm (ORCPT ); Fri, 16 Sep 2022 14:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230176AbiIPSlk (ORCPT ); Fri, 16 Sep 2022 14:41:40 -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 37555B7778; Fri, 16 Sep 2022 11:41:37 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id y11so4947197pjv.4; Fri, 16 Sep 2022 11:41:37 -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; bh=RKJpmxEL/4rrX7/TLn5cIPoVCbxvKy1MHz9MxjM0RFM=; b=kqKDflP5KyjFkk+STZbQ9veV9qUodqQnSJrLbvm2QusLk+5QJiu24FX5lZm5xJymmw rFp6Sc4frts5Pr8ZxC7RWKAdA86WtEolAPx8uZDw9qte+KTqFh+da4XlWp7x0XYX2Y/t gb/TTZuHH5fOJa3CQljKlMXN/znRjmdfdDTz78yaLIAVZpN/5aJCB1WkvwmoyvsKORT2 tIrLenD+ccbdTL0ulud7i4ion7lFxIF34YyHYrzG+jlVRWMEeBpZQQj4KX4QdcVgX34c Tauxq8ofBOouUVDEkb4W7WzdwSSgDyELDBjjC5/e7EbBFHwxMx4hjMXMZ6ehG0y+OEdE cCNw== 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; bh=RKJpmxEL/4rrX7/TLn5cIPoVCbxvKy1MHz9MxjM0RFM=; b=bPH5Y+Y7bqhh++cKmAUEgHe1UVgcP0zod1tikW+B3H7rbHMHclMdJBz/xaAKZQeJwL G9O6iRZMADidpKapUpqlG3U7WAhuhyLh8XIlS2bWnwt2CHr8cwpz7lX6V3oWvNYofhbf x7iaSb2QrCtwTVTksZUMqrrc9nVHncyC4jr4yCEvahpVyVLh5iPKm/O4NOWnA9yfORky JUzUIaoCFOt1guD3wCoB1eRRbKFKRZ0ZDD/QCVVpSif5Hnj0jwJAojYNdvX/Kcmcd7IM TsmgOAuiOawKzaMiZVvsaUjdgWP8OH+S54UdEmTW6n2KqIeyTky4vYr0YX0cOf6+iE+a xamQ== X-Gm-Message-State: ACrzQf3PuvRKdgvsKYI5HTfYEdNWjewzZhBOEaaIb0VXH0gJylLuBJSZ qTgLtYmIRfuzmLAeS41Simg= X-Google-Smtp-Source: AMsMyM7cE9dYo6XVjGP7XmqtjsqZSdjYOy/E4eDebiQD3QkX60Wz7SwtjGOsGVQBZbq8oIiL+gNP/g== X-Received: by 2002:a17:902:ebd2:b0:174:3e94:d01 with SMTP id p18-20020a170902ebd200b001743e940d01mr1220417plg.112.1663353696952; Fri, 16 Sep 2022 11:41:36 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:2952:dee7:a35e:6428]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b0016dcbdf9492sm15093004plr.92.2022.09.16.11.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:41:36 -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, Song Liu , bpf@vger.kernel.org Subject: [PATCH 1/4] perf stat: Fix BPF program section name Date: Fri, 16 Sep 2022 11:41:29 -0700 Message-Id: <20220916184132.1161506-2-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog In-Reply-To: <20220916184132.1161506-1-namhyung@kernel.org> References: <20220916184132.1161506-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org It seems the recent libbpf got more strict about the section name. I'm seeing a failure like this: $ sudo ./perf stat -a --bpf-counters --for-each-cgroup ^. sleep 1 libbpf: prog 'on_cgrp_switch': missing BPF prog type, check ELF section name 'perf_events' libbpf: prog 'on_cgrp_switch': failed to load: -22 libbpf: failed to load object 'bperf_cgroup_bpf' libbpf: failed to load BPF skeleton 'bperf_cgroup_bpf': -22 Failed to load cgroup skeleton The section name should be 'perf_event' (without the trailing 's'). Although it's related to the libbpf change, it'd be better fix the section name in the first place. Fixes: 944138f048f7 ("perf stat: Enable BPF counter with --for-each-cgroup") Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c index 292c430768b5..c72f8ad96f75 100644 --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c @@ -176,7 +176,7 @@ static int bperf_cgroup_count(void) } // This will be attached to cgroup-switches event for each cpu -SEC("perf_events") +SEC("perf_event") int BPF_PROG(on_cgrp_switch) { return bperf_cgroup_count(); From patchwork Fri Sep 16 18:41:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12978799 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87AA5ECAAA1 for ; Fri, 16 Sep 2022 18:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbiIPSlp (ORCPT ); Fri, 16 Sep 2022 14:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiIPSll (ORCPT ); Fri, 16 Sep 2022 14:41:41 -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 7A642B775F; Fri, 16 Sep 2022 11:41:39 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so544399pjq.3; Fri, 16 Sep 2022 11:41: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; bh=aYClvGhuMnA9RUqYwgEhtJ6BEKGPrGUBP0eUxyj+8BA=; b=Bv7QI1G3rAnYAjM0CzVR37ATOBMvjLeW+Y2AM/ukkDRYyYdC8xverfBtTVH2w1HC1y FZvgjIIAwjRqJtocGyKvv7yJo6E1WIl5d9iWPVw+JvxcSzpXIcu0ama30KrB+1eithAC gnQ1qND5noF7Ofd2d2sv/ljNVRaivTDkAx3pEQ7FaBRdjYXWJmeyLIyYBxS+ETd7V/Yc 8514W0XpksGtMi7TkXOnzt7tdREHuysDsaa6xDCJ0fNKWH2SseY0dAkbDl2/bzJO2iGH Ef2XV81y9pvxoiuhky1AvDWSO4jHs6MRZDHj3srLiwyDOntZJqS3ksDRFkXcj/oXf10O F7hw== 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; bh=aYClvGhuMnA9RUqYwgEhtJ6BEKGPrGUBP0eUxyj+8BA=; b=FxMBM+swlP3LRtVMeG4HJJJeBVUPl8TkWxit7DLTD88SdVDZJDtMEVkIsTChZvdMfA 7/3Oe8WAzd+mN0R5z/bmwjqVh/MajxvESB1L3djlXXKJrzzHx6eWsjnwEpVthP+bh2tR MBp+yummv/IIj5FxR7U895prIYf4xOY2We4e98f9i1MqTpWyroR8AkLqsT4856PQVXaE Zt3BVAn7EdEMaeNATQwip74l1yhDRoXWZHQ0OT9/5oubn6dZpqE0yXw8qkEdai37o6HF WINdnlDGLXsZ7GhRBD820f5tgXv0ux67poAZZWXTMzJR472I0N2+2CfJwaHVyiDqmzSC SSmw== X-Gm-Message-State: ACrzQf1wCim5HhhAeIehk4WTfYh+dEtFplXJnWK7gjefvG9oLIBT+Y+j rEjVRdHd2JvdpQszs33r3Lg= X-Google-Smtp-Source: AMsMyM7SDRjPHoJb2KSCDwfLuaL+o+TvAsxvwzsZcPU69iOE2Kz54jPDdWNx2YH2T0vRyVmhfypLbA== X-Received: by 2002:a17:90a:c258:b0:202:b93b:cb89 with SMTP id d24-20020a17090ac25800b00202b93bcb89mr17323928pjx.126.1663353698155; Fri, 16 Sep 2022 11:41:38 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:2952:dee7:a35e:6428]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b0016dcbdf9492sm15093004plr.92.2022.09.16.11.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:41: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, Song Liu , bpf@vger.kernel.org Subject: [PATCH 2/4] perf stat: Fix cpu map index in bperf cgroup code Date: Fri, 16 Sep 2022 11:41:30 -0700 Message-Id: <20220916184132.1161506-3-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog In-Reply-To: <20220916184132.1161506-1-namhyung@kernel.org> References: <20220916184132.1161506-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org The previous cpu map introduced a bug in the bperf cgroup counter. This results in a failure when user gives a partial cpu map starting from non-zero. $ sudo ./perf stat -C 1-2 --bpf-counters --for-each-cgroup ^. sleep 1 libbpf: prog 'on_cgrp_switch': failed to create BPF link for perf_event FD 0: -9 (Bad file descriptor) Failed to attach cgroup program To get the FD of an evsel, it should use a map index not the CPU number. Fixes: 0255571a1605 ("perf cpumap: Switch to using perf_cpu_map API") Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_counter_cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c index 63b9db657442..97c69a249c6e 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -95,7 +95,7 @@ static int bperf_load_program(struct evlist *evlist) perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) { link = bpf_program__attach_perf_event(skel->progs.on_cgrp_switch, - FD(cgrp_switch, cpu.cpu)); + FD(cgrp_switch, i)); if (IS_ERR(link)) { pr_err("Failed to attach cgroup program\n"); err = PTR_ERR(link); @@ -123,7 +123,7 @@ static int bperf_load_program(struct evlist *evlist) map_fd = bpf_map__fd(skel->maps.events); perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) { - int fd = FD(evsel, cpu.cpu); + int fd = FD(evsel, j); __u32 idx = evsel->core.idx * total_cpus + cpu.cpu; err = bpf_map_update_elem(map_fd, &idx, &fd, From patchwork Fri Sep 16 18:41:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12978800 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 284A2C6FA82 for ; Fri, 16 Sep 2022 18:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbiIPSlr (ORCPT ); Fri, 16 Sep 2022 14:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230198AbiIPSlp (ORCPT ); Fri, 16 Sep 2022 14:41:45 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D55B8A61; Fri, 16 Sep 2022 11:41:40 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id a5-20020a17090aa50500b002008eeb040eso1949576pjq.1; Fri, 16 Sep 2022 11:41:40 -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; bh=S51SKuYdeuTsRRYFc57qnPOm5scEn4uyaX1X5OZJqXg=; b=SUYSa3v/Hh/ODahaeWcAlNfsoFCjpIsVcDK/QlgdMmhdeJzHWNalekeCrrX1ajoPFG mkufsAHSMQBEV1/7qTzRwYlH+Bwb4Jow22v9+3iF1ZoSmjsrP+9PxzU8I/ZNC0zsqC47 wA1v0PeCNGAJT/3CNVRw8PZ0AQJtOpRlyFLNxSeA4LvqUHNE+w2fLFgge75vMV7193mv 8XQsyT4M2Q5PN97qsP30rxuKJukUOehTLOu6Jnq4Yj9ega25UM3KzOIG/k95ydiXwzs0 t5VXhh7AR33RbjnpMubpKhfIOmmQgaVO9RBenBYJrPSUjUCEt6cpk88yl/ituZkNgtSt oRXQ== 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; bh=S51SKuYdeuTsRRYFc57qnPOm5scEn4uyaX1X5OZJqXg=; b=sb9KRi1a5eJMroVRjsjLWjIQv8VG/sia2xkDJkcYfalFA6lqAu8y7nJy6Vh1/mIhEM tjfD+ej4s5TlUsaPv4Kz9f3Sj4XAJ5nQQszQF65kxyXnxNxG4xfnhTCZp0SbIw3B+HbH dbU6HYXP6mgR+txuwdtFLkkT8pebhb5FjLyTFVie2VbSsvL51HmT58biDI+Vi/uXA3ry 9MmsKAK4MnSrFFry7c3aIB6UIQCOro07cS6i2uMdwuDDPnm+Wq4wpWjOq9hYjfBVB/w8 enpeW2COgpY9H8K8jemR5wvgwA8Oe12S16xmolFAr96pQUopxPIdnZtNwrEsQnOKbdvN rENg== X-Gm-Message-State: ACrzQf111DvAiX03svxiiQLdQaup1Ijcks4wS+AgDrNSSmwxwL5vGdBl fIL6EEMQukoAbXHf1dcmxq8= X-Google-Smtp-Source: AMsMyM6Gim4Anfc/fLrNawDc8gKVSjDMZThysib63c8gE8xSEIqrZDwsy1tAsMby93CkY4RxPz2QIw== X-Received: by 2002:a17:902:e844:b0:178:4930:8aa5 with SMTP id t4-20020a170902e84400b0017849308aa5mr1154677plg.69.1663353699408; Fri, 16 Sep 2022 11:41:39 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:2952:dee7:a35e:6428]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b0016dcbdf9492sm15093004plr.92.2022.09.16.11.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:41: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, Song Liu , bpf@vger.kernel.org Subject: [PATCH 3/4] perf stat: Use evsel->core.cpus to iterate cpus in BPF cgroup counters Date: Fri, 16 Sep 2022 11:41:31 -0700 Message-Id: <20220916184132.1161506-4-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog In-Reply-To: <20220916184132.1161506-1-namhyung@kernel.org> References: <20220916184132.1161506-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org If it mixes core and uncore events, each evsel would have different cpu map. But it assumed they are same with evlist's all_cpus and accessed by the same index. This resulted in a crash like below. $ perf stat -a --bpf-counters --for-each_cgroup ^. -e cycles,imc/cas_count_read/ sleep 1 Segmentation fault While it's not recommended to use uncore events for cgroup aggregation, it should not crash. Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_counter_cgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c index 97c69a249c6e..3c2df7522f6f 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -115,14 +115,14 @@ static int bperf_load_program(struct evlist *evlist) evsel->cgrp = NULL; /* open single copy of the events w/o cgroup */ - err = evsel__open_per_cpu(evsel, evlist->core.all_cpus, -1); + err = evsel__open_per_cpu(evsel, evsel->core.cpus, -1); if (err) { pr_err("Failed to open first cgroup events\n"); goto out; } map_fd = bpf_map__fd(skel->maps.events); - perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) { + perf_cpu_map__for_each_cpu(cpu, j, evsel->core.cpus) { int fd = FD(evsel, j); __u32 idx = evsel->core.idx * total_cpus + cpu.cpu; @@ -269,7 +269,7 @@ static int bperf_cgrp__read(struct evsel *evsel) goto out; } - perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) { + perf_cpu_map__for_each_cpu(cpu, i, evsel->core.cpus) { counts = perf_counts(evsel->counts, i, 0); counts->val = values[cpu.cpu].counter; counts->ena = values[cpu.cpu].enabled; From patchwork Fri Sep 16 18:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 12978801 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B473ECAAD8 for ; Fri, 16 Sep 2022 18:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbiIPSlv (ORCPT ); Fri, 16 Sep 2022 14:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbiIPSlq (ORCPT ); Fri, 16 Sep 2022 14:41:46 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A383CB8A52; Fri, 16 Sep 2022 11:41:41 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id ge9so10362528pjb.1; Fri, 16 Sep 2022 11:41:41 -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; bh=0/bkNBIX3FOAe3t6O/p7ZuS8G0HQozWMCrCw3+mytvI=; b=GvEkctg++Q6fJds7LzttNVl0aKX4dNXXNkoMO0dhUrNIjoZ9wvpwE+Hd9/C1fZiJXL bDXHvObELfjOqhy9FrzfJE730SLk9vD2A2m5uvjZo93kZixkWCrgBTFdg8V6EqUDv/a2 0pLvmgGeWMYD5KmbPTR5IzfOGw6wsoZUPgzLe4ZQyS7vYuwOuzeJPaf4WyzyQYD6n9xM m8WLYBFjQampXy0PM7+SO7gV2ECyPCHx4LmSMam3RwNBJ20+0ZoeDJBS2bXBM4jsaiph JGbTS+47OTz1mnCyc62iCu29Mkj7bf3JtS3Q9egCkhIA4kwpwTy8ZW+lHhgVLAEwmmXC KQhw== 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; bh=0/bkNBIX3FOAe3t6O/p7ZuS8G0HQozWMCrCw3+mytvI=; b=jxOMmMxMSIkKC0j3L1UADTb0m4knNptCB/YOwOcFvSi4Zk4EcsARbcxLFYDdNgeWII coJcLdBuV373oNJDrQMpVeibeN2rNiFRoDwVpSpGTYFLRxpWHUsEBgbg5DTf3OCB+dmF +cQooU5mMkgkpWPFrMWrCWYLmiiYTtaiHE9omq/Miy+NEXUvPpAfcVXckMHDM68xFRVA dqWN5qePXgqR6eWrjg0OcCCFnBKNpoDDujVrJ6dD40NwWzbZmijKWwAEaen514GVJLDX a4ehg2/tqiytuLUQi5rkaEqSB0+aiqxR4OWsNa+xSbnY4dABjhmP3m3kmRCRFi6zTMtw kLgA== X-Gm-Message-State: ACrzQf1nPUH7q1SPrFSfvhCvkcOKf3KXUPbcKUDVFPrlU45V3e1LVGC1 +4AiHw1yeLxFNkxgvIY1g2Gzc3Mxm9k= X-Google-Smtp-Source: AMsMyM7jcgvmzEsZVo12t0OpJ0R1AciFz3zwCi5TRJg0s+6ib/GU+qgvBWSJXeDOaB7b7chBonw2uw== X-Received: by 2002:a17:90b:4c45:b0:202:6308:d9c4 with SMTP id np5-20020a17090b4c4500b002026308d9c4mr6982509pjb.40.1663353700675; Fri, 16 Sep 2022 11:41:40 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:2952:dee7:a35e:6428]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b0016dcbdf9492sm15093004plr.92.2022.09.16.11.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 11:41: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, Song Liu , bpf@vger.kernel.org Subject: [PATCH 4/4] perf test: Add a new test for perf stat cgroup BPF counter Date: Fri, 16 Sep 2022 11:41:32 -0700 Message-Id: <20220916184132.1161506-5-namhyung@kernel.org> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog In-Reply-To: <20220916184132.1161506-1-namhyung@kernel.org> References: <20220916184132.1161506-1-namhyung@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org $ sudo ./perf test -v each-cgroup 96: perf stat --bpf-counters --for-each-cgroup test : --- start --- test child forked, pid 79600 test child finished with 0 ---- end ---- perf stat --bpf-counters --for-each-cgroup test: Ok Signed-off-by: Namhyung Kim --- .../tests/shell/stat_bpf_counters_cgrp.sh | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 tools/perf/tests/shell/stat_bpf_counters_cgrp.sh diff --git a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh new file mode 100755 index 000000000000..d724855d097c --- /dev/null +++ b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# perf stat --bpf-counters --for-each-cgroup test +# SPDX-License-Identifier: GPL-2.0 + +set -e + +test_cgroups= +if [ "$1" = "-v" ]; then + verbose="1" +fi + +# skip if --bpf-counters --for-each-cgroup is not supported +check_bpf_counter() +{ + if ! perf stat -a --bpf-counters --for-each-cgroup / true > /dev/null 2>&1; then + if [ "${verbose}" = "1" ]; then + echo "Skipping: --bpf-counters --for-each-cgroup not supported" + perf --no-pager stat -a --bpf-counters --for-each-cgroup / true || true + fi + exit 2 + fi +} + +# find two cgroups to measure +find_cgroups() +{ + # try usual systemd slices first + if [ -d /sys/fs/cgroup/system.slice -a -d /sys/fs/cgroup/user.slice ]; then + test_cgroups="system.slice,user.slice" + return + fi + + # try root and self cgroups + local self_cgrp=$(grep perf_event /proc/self/cgroup | cut -d: -f3) + if [ -z ${self_cgrp} ]; then + # cgroup v2 doesn't specify perf_event + self_cgrp=$(grep ^0: /proc/self/cgroup | cut -d: -f3) + fi + + if [ -z ${self_cgrp} ]; then + test_cgroups="/" + else + test_cgroups="/,${self_cgrp}" + fi +} + +# As cgroup events are cpu-wide, we cannot simply compare the result. +# Just check if it runs without failure and has non-zero results. +check_system_wide_counted() +{ + local output + + output=$(perf stat -a --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, sleep 1 2>&1) + if echo ${output} | grep -q -F "&1) + if echo ${output} | grep -q -F "