Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1501191lqp; Fri, 22 Mar 2024 18:23:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4McivvM7JQJ+mdCChpjEdr6DKeDh8PPLWVetdSyaXG7JIsVJkY8v/ISgeGJt4k2gpjaQ5Q7tNvYiLf4OUND0iH9vnzXerVD9taEIZHA== X-Google-Smtp-Source: AGHT+IGvn9n82RXZllecq0KKF/C2Gd9JZDXTgV1yvntlF1B5ul6JSYEaNIVZLGFfseIEHjJMKjxZ X-Received: by 2002:a05:6a00:14d3:b0:6e6:b71f:e80b with SMTP id w19-20020a056a0014d300b006e6b71fe80bmr1803831pfu.7.1711156980657; Fri, 22 Mar 2024 18:23:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711156980; cv=pass; d=google.com; s=arc-20160816; b=E+fZrO4YwQZyBDCqkStnIgVNBKO1rMOW5esQlmQqpjszlANu93aYKjCE4eWgN7T54O L6B3PzJWOK7PMpw6h8U+aryjM5FiTLJj+Io9fVVueJaCyXMnNGhgFfXGHVusbJOUu9Vm dQco1/oCxsAb0QKOV38YnM1oZnueTU3itgCf52aSKAUQkcYW4kVM56+9fJ45BrCYr96j BVQEXxejCPonPQScpESVeUejn0rixEtbgTK51nsuranOSmcllAE0KH8/cet6eBy7MFHN TR7omzIqVPcdCntcV5YNres9K36BZKW5WMqgjugMLJ3CF1as/aswleysSrulq3SJ+cxo DKDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=N+0aYMbrnVXpxfNyD1kFQ/0ZCzbVxGiIosenue/Nirk=; fh=+RrKBW36bL6/1Xl/phHWrDbPrm9DIshqJ7FOl4gLLDM=; b=VU26sQDpZi0i7MTHuPrUqcK/6EyVSmK8D3uSR8JGPged7uwN7Gdxfgbs63JjMfJ7Db 6dmrb9ZrAhtQJuq4gDOMuJ7x2Oz3SKmFnx5QCIdVspoIAWF/9ORmXMkAhImA/IvfSK7K nM7iibFDSzmUGVLX6FDNjgHwrOZPERqFCEZ1Chx4YJuUTLmav8j+UJL017j5vXL8EZRt eTKIl7c+aiuL7S/wWAP8iBxRwmvYKm9kUV0THiumaX9Cf3UEhEt/Zcrl6MjzRO/q7cKm sw8UkiGFy9JAPxjd2c6OLOWP7sBEgG4iJt0M1G95oel3JF8kFhpgQjKSzpPeUFFp+Jgw dmMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id g68-20020a636b47000000b005e468d36711si2913104pgc.652.2024.03.22.18.23.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 18:23:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5835CB22786 for ; Sat, 23 Mar 2024 01:22:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E548138A; Sat, 23 Mar 2024 01:22:51 +0000 (UTC) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 19A6FA48; Sat, 23 Mar 2024 01:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711156970; cv=none; b=uHF2iqIvQr/M4OWDN3UbL3KlJc53qrNbtqkb8gwpV5N9Kw5IaYOJWPmZiUNBc+XdKGNDwCHT32/gXrPBkQ/w/eD7ajGhVkyiWmHKgWQFH+XUODFjWp7DnqacLkgy02aGLom52BweGyf0+KfeqnQF6esfKfqj3JKiXME/T1WENZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711156970; c=relaxed/simple; bh=g+qmIKlNwWrQDYzprQZoIGrFsxp3GGvahsrx0ZcmM2c=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=XhG0voiHRJWA3YQ/oP4xky/q2x6J6OMUnj+XX4JCQcLFBl+6pxDyj5zhcb9t3dbdWD/AzGyzZZMbmYgpKQgS1VjulnVpQuWIXzu7cI34DddcmeD58sB3CSbjVja6W+MiJjUuE/EKvUzSf/iStHaxl7JAsCkA0w2IKClTldCc6R0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5d81b08d6f2so1892310a12.0; Fri, 22 Mar 2024 18:22:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711156968; x=1711761768; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N+0aYMbrnVXpxfNyD1kFQ/0ZCzbVxGiIosenue/Nirk=; b=EDPLxeo3kmayxWMmehLbScRDb8PkotJoZjt6yr1iia7DuoVQB8lpDm7q1NknLqte3I +PENvAZOSdYvWv/FJFsj29rcXsxmewT+ikJCLIzA7SlmIPiH0b+vkxI9LHxOY8gNqwKX 8aru82CtkAuwOUN4XnITmkq3hKVxkkbBVJT0CS70DLWakUHhrzsmOAfehYqbCvTTLuwd w29xNNUlf1NPXMAKXM5Dnmy/avDTAlXEW5W5KK6oE8kEdH6aJPFWGoK9fHmg9jmROCzh h91szPAYtxAojkpyj0eveN3ercn3GI9ZDhTQgur5rUxSW8mhu0lvJG5sSo2hxOahCkRy KRkg== X-Forwarded-Encrypted: i=1; AJvYcCWnbsJvjNXXg5j2pdBuAvok21EOWHmdlfnvli/qlaLP4m20Wg0SE9owfg2iKiQoJrz3e5U1aCHAEfpStB6hS61NQ02pOqysuuBje2h0WrrvaCGDQFoaIS/31SoItSJust60+DB8xK+i2UcxrvmWVQ== X-Gm-Message-State: AOJu0YwUMWwvGeKnJNRRdxHQjtPUmoHUE61raeRlE9NyR4St7a4LS+0Y Qj3BaMVYr+JRzjk6GDfU1smBogQ/zJU++jxtm6dqzzU833dRbWGQFqIv0ZmK6cJUjsNdsJZPa34 aG0EfxnQbfU5zG0us1NnR/2OxZzM= X-Received: by 2002:a05:6a20:be11:b0:1a3:ab6f:ca83 with SMTP id ge17-20020a056a20be1100b001a3ab6fca83mr1173045pzb.46.1711156968170; Fri, 22 Mar 2024 18:22:48 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240322164237.203358-1-ben.gainey@arm.com> In-Reply-To: <20240322164237.203358-1-ben.gainey@arm.com> From: Namhyung Kim Date: Fri, 22 Mar 2024 18:22:36 -0700 Message-ID: Subject: Re: [PATCH v4 0/4] perf: Support PERF_SAMPLE_READ with inherit_stat To: Ben Gainey Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, james.clark@arm.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 22, 2024 at 9:42=E2=80=AFAM Ben Gainey wro= te: > > This change allows events to use PERF_SAMPLE READ with inherit so long > as both inherit_stat and PERF_SAMPLE_TID are set. > > Currently it is not possible to use PERF_SAMPLE_READ with inherit. This > restriction assumes the user is interested in collecting aggregate > statistics as per `perf stat`. It prevents a user from collecting > per-thread samples using counter groups from a multi-threaded or > multi-process application, as with `perf record -e '{....}:S'`. Instead > users must use system-wide mode, or forgo the ability to sample counter > groups. System-wide mode is often problematic as it requires specific > permissions (no CAP_PERFMON / root access), or may lead to capture of > significant amounts of extra data from other processes running on the > system. > > Perf already supports the ability to collect per-thread counts with > `inherit` via the `inherit_stat` flag. This patch changes I'm not sure about this part. IIUC inherit and inherit_stat is not for per-thread counts, it only supports per-process (including children) events. > `perf_event_alloc` relaxing the restriction to combine `inherit` with > `PERF_SAMPLE_READ` so that the combination will be allowed so long as > `inherit_stat` and `PERF_SAMPLE_TID` are enabled. Anyway, does it really need 'inherit_stat'? I think it's only for counting use cases (e.g. 'perf stat') not for sampling. Also technically, it can have PERF_SAMPLE_STREAM_ID instead of PERF_SAMPLE_TID to distinguish the counter values. > > In this configuration stream ids (such as may appear in the read_format > field of a PERF_RECORD_SAMPLE) are no longer globally unique, rather > the pair of (stream id, tid) uniquely identify each event. Tools that > rely on this, for example to calculate a delta between samples, would > need updating to take this into account. Previously valid event > configurations (system-wide, no-inherit and so on) where each stream id > is the identifier are unaffected. I think you meant PERF_SAMPLE_ID not PERF_SAMPLE_STREAM_ID. IIUC the stream id is already unique. Thanks, Namhyung > > > Changes since v3: > - Cleaned up perf test data changes incorrectly included into this > series from elsewhere. > > Changes since v2: > - Rebase on v6.8 > - Respond to James Clarke's feedback; fixup some typos and move some > repeated checks into a helper macro. > - Cleaned up checkpatch lints. > - Updated perf test; fixed evsel handling so that existing tests pass > and added new tests to cover the new behaviour. > > Changes since v1: > - Rebase on v6.8-rc1 > - Fixed value written into sample after child exists. > - Modified handling of switch-out so that context with these events > take the slow path, so that the per-event/per-thread PMU state is > correctly switched. > - Modified perf tools to support this mode of operation. > > Ben Gainey (4): > perf: Support PERF_SAMPLE_READ with inherit_stat > tools/perf: Track where perf_sample_ids need per-thread periods > tools/perf: Correctly calculate sample period for inherited > SAMPLE_READ values > tools/perf: Allow inherit + inherit_stat + PERF_SAMPLE_READ when > opening events > > include/linux/perf_event.h | 1 + > kernel/events/core.c | 62 ++++++++++---- > tools/lib/perf/evlist.c | 1 + > tools/lib/perf/evsel.c | 48 +++++++++++ > tools/lib/perf/include/internal/evsel.h | 55 ++++++++++++- > .../test-record-group-sampling-inherit-stat | 62 ++++++++++++++ > tools/perf/util/evsel.c | 82 ++++++++++++++++++- > tools/perf/util/evsel.h | 1 + > tools/perf/util/session.c | 11 ++- > 9 files changed, 301 insertions(+), 22 deletions(-) > create mode 100644 tools/perf/tests/attr/test-record-group-sampling-inhe= rit-stat > > -- > 2.44.0 >