From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D21712FD7C3 for ; Tue, 19 May 2026 05:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779166933; cv=none; b=k/uLrzG20slhWRCBVuLrj7gUWKNsU0pF9BMDYrHZi+Q1fzNLSjuSJoYOxNFTMrC3ujXjsXHIE9C1qzPN6HCMqP+5kGA/pGnWkmDVX6m/chIGXJbOz7KBqmgnHqD9Hinc0tG5EhE8UgmXK4HBg30iPamY5tRyi58g72GTA9wH6f8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779166933; c=relaxed/simple; bh=OcP1NgA2NxIksA2y9tdgsVvq26r3piLHRjjkj3eRQAY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qSDgURQ7iQtkxwdiwCVeo5OoVw2kliQdyb+8Av8vv5xD+aBBTmjgliLYrpUwtEKwQBigAKAvc0vP2ame6BqL8TwPiXLhqIwU2uLfiGuxJ8xa9JHEDJzaYiEvQCqN6w0gTaqpBUkNcegp11JlhaJQIQD++qD1i3RgZqk8q6afE7o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=C9mFHz5G; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="C9mFHz5G" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-132d631edaaso19328726c88.0 for ; Mon, 18 May 2026 22:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779166930; x=1779771730; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GbLm2oZLKqhvgpwkQ11BIiKN7n0arf5bkU5LkbUJH8U=; b=C9mFHz5G1Nyp/Fl61psX/AnTovh2Puv/0ocoU3gl5A7/4y2/pnHd331ng4U1m5E1SZ PYDfuq//ubIA4cq9j6zqR2ep0KOLKcQ9bcsnQOypiFsaO/J2rCy7ql4q/okbnK8IBcZ9 3+MIT2JwRk12dHu/iy2nEhQBYGuGtHkIppVo22FFCupUU9+uRUMu/6pOGFH3jRITvpdw fFeJ6ZXVxudmRHRb9OTRdFGsVc/x3fMrg3kYM0/2atr00C75HMpFTegDvJSScC9v0AgO n9QY1IpXLtbZMTU9P1S3pTI+fBUBRMv67dhxsOfiMsuC+HmV2HL3s9FubjkwFfJSiUA7 TGiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779166930; x=1779771730; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GbLm2oZLKqhvgpwkQ11BIiKN7n0arf5bkU5LkbUJH8U=; b=IS8VsC1F8RWAvAVbeiTpDJ+WY9mFWQworHr/wB+KjacCVP5sBUhf96mDJoOrsrikUQ 1z6JxwqLljJUpOpseAHtMKEuCxrXRIPTNTBSF76hiNzko/SNfLE3ABeT27sORHL85rHo DMU3wgoS2NR4cic1tsBK7u5l/rBWd9D+WXfgyeNlm6qYAbfLZBPmanfisT4RVoKgS4av 0MZCh/wAYi/Gp/4AXxZEC6GuoRI0POwh8NuvAhT0mbGqdy7pkzvXJvqJ1fhbMjndzixC XtPwjdtYEG56HMloEDEzJ7YMf61NVuwh0YynlGw20ksz8HLYK8vg/vecUwApAB+aCGgg M9Yw== X-Forwarded-Encrypted: i=1; AFNElJ9s4YnqJVpk5ro/eUJ6LblXfKAyg9vl3k1IAlgvkUjTVyaJ9lol4A0tIHM+dOcv/mWX4PQr+w9rPSeNiag=@vger.kernel.org X-Gm-Message-State: AOJu0YwJNTLz5oeyIKCTTw+RZMECLGOIo3vfKQUXqHeT1E+NNPEigGzl OMsivpnkyhxVHbv5vyVXdB8VhWTSEro/PVYY+kM8R66Jr0eYQ9HLkDSQVQKrYDPegPctLm2Qbvv Z1zGgATFdvg== X-Received: from dlbsj9.prod.google.com ([2002:a05:7022:f909:b0:132:8d92:4d65]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:505:b0:12d:c039:6599 with SMTP id a92af1059eb24-1350483f18dmr7201841c88.22.1779166929643; Mon, 18 May 2026 22:02:09 -0700 (PDT) Date: Mon, 18 May 2026 22:01:48 -0700 In-Reply-To: <20260519015108.3094513-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260519015108.3094513-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.631.ge1b05301d1-goog Message-ID: <20260519050150.3144907-1-irogers@google.com> Subject: [PATCH v3 0/2] Fix cgroup metric association with BPF counters From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, skanev@google.com Content-Type: text/plain; charset="UTF-8" This series fixes an issue where cgroup metrics were not being correctly associated and reported (showing `nan %`) when using BPF counters (i.e., with `--bpf-counters`). The root cause is that cgroup BPF counters only open the "leader" events (for the first cgroup) and leave "follower" events unopened. Unopened events have their `supported` flag set to `false` by default. During metric calculation, `prepare_metric` checks `evsel->supported` and discards the value (setting it to `NAN`) if it is `false`, leading to `nan %` in the output. The first patch fixes this by propagating the `supported` flag from the leader events to the follower events in `bperf_load_program`. The second patch adds a new shell test (`stat_metrics_cgrp.sh`) to permanently cover this scenario (testing both with and without BPF counters) and prevent regressions. Reported-by: Svilen Kanev Changes since v2: - Use `--metrics=insn_per_cycle` for the system-wide capability check in `check_system_wide` to ensure both cycles and instructions are supported. - Use exact cgroup field matching with surrounding commas (`,${cgrp},`) in the `grep` check to prevent false positives when matching the root cgroup (`/`). - Only enforce metric validation if both `cycles` and `instructions` counts are numeric and non-zero, preventing false failures on idle cgroups. - Wrap long lines and fix trailing whitespace in the test script to comply with style guidelines. Changes since v1: - Fix commit message for patch 2 to remove the mention of insn_per_cycle check (which was simplified out). - Quote variables in shell script to prevent word splitting. - Use grep -F in shell script for literal matching of cgroup names containing dots. Ian Rogers (2): perf stat: Propagate supported flag to follower cgroup BPF events perf test: Add stat metrics --for-each-cgroup test tools/perf/tests/shell/stat_metrics_cgrp.sh | 174 ++++++++++++++++++++ tools/perf/util/bpf_counter_cgroup.c | 15 ++ 2 files changed, 189 insertions(+) create mode 100755 tools/perf/tests/shell/stat_metrics_cgrp.sh -- 2.54.0.631.ge1b05301d1-goog