Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp256831rdb; Thu, 8 Feb 2024 05:19:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsv6Ypw1IDlr8qN5vbywkqT9OkV7NMZ0bPAvtFwFFsD1te6AVzmvUQ3PifKg8D2l5yyrpm X-Received: by 2002:a05:6358:528f:b0:178:7701:2860 with SMTP id g15-20020a056358528f00b0017877012860mr6860111rwa.14.1707398367678; Thu, 08 Feb 2024 05:19:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707398367; cv=pass; d=google.com; s=arc-20160816; b=MFQ+owCTJMjB2tI3DURHfHPd7jZyFz/zjvy5dJw7mr2cfdL4SNxUrYvVAQ7HaLYBRs ofbGyAkS4j88HiSdtfqNQ3lgqFpKgMYZQMaLXa0pJJYz3aeVNxTtCJ+secJAjS6nwiOn 3LuAxDa3pKNxH87WbhcHEndD4czzFmKb04QFy/Mw/KypXLli2X4FCexQ7zxl6Fi6EMmw fqA5pGC6+h57XEZ4YeWlWSRGzd8P2azY8O5eRl2aqRCNMjdPv2RwWiGDqDOR4Ida4vUn EenEO6uDXto3E7F7ufDCmqgVdl9IoTvqOY6OnLu7PijbH9F0Ky6YkY/WF08uwzOn53H7 +KWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=GAubby860AUT4uSauxxOeVGQnChHrbCD67EBkMRHTDQ=; fh=CVdhTR8bjrVerL4L5dhOd9JFuIlsKHrgWhzbN3Z0Rg0=; b=ExLHwpC5BFrAMC4nvdDRaQb8dQm9vz0ngrI83WVGejtN3r082GMV2vii0ImOlJac1n IaIwrTtYDr4EGOSu5PRdPPt7jAjTRxKWkEZxZ/T7MkQvs7wUtP/fN5ZpRhYG+GIoaBfy 7CWGsDGFLNmfKUAoG+fQ3+deKPmVHZO1YANesRvVCjx32rKHDYM6YUedTO7TOEqd/VZp xyYEqQNPsKE+0LjVDv4YBdqfik9SXQvZUGKBTWsvXLlkeEIQMS+s0FCNFv0opFTifECm +Q5gHSlTe0S3zNB1GE7HYFMt6GrQVcvNOiyQXFRx0su1WlizfbRJJ3OmRomWvp8RR9ky Be5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVR9oyl/m3K9q3kEF91QHvAtS56ujvdjCGwnpBecIzIzrkokK2zqb2klGerVh9PAbSsPSmnKUOpuv9Ggaxq2BBUF2qi1xKvnVw3mMD91w== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c21-20020aa78c15000000b006e05cb7fd6csi3857631pfd.243.2024.02.08.05.19.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:19:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58129-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58129-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C29428FE78 for ; Thu, 8 Feb 2024 13:17:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A60076C79; Thu, 8 Feb 2024 13:11:17 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5535A762E2; Thu, 8 Feb 2024 13:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397876; cv=none; b=uKyA8CxCjjSAcmun9zve4+zXh0E1+t5R9y6qWfRWF05ArBt77c77sYYKsQvmkFgWXwQAh0926bBfeb3ZIlYdvmLh6teNkNOUVtfNy9NrpMcIzhX4S2XqNTMbQB/Rio8fHUOPYrWCfeDzXtvo/pxCDkB0pOnp/ahFSpL+Hk+5d74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397876; c=relaxed/simple; bh=mjugEGPZ/9rXzehutbCHuWqGzgqqqVqeOkObNnV6wFg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DTA0eUtxyLPS+bp3nYsQ8R3aj/hTjifFZMSozrbxFmHSNvOpHrtcAel34nkL6uLSW/yc+tk/fWLJ4+b10PBqTUQqtTLpT0tnKOtc8vYpQdODNBWih7E8uq+OmDXlqV/kIYqMg7XddkC3F0tvk15F9zhZ5u05FlLlAPHpvSZArKo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BA7991FB; Thu, 8 Feb 2024 05:11:54 -0800 (PST) Received: from e126817.cambridge.arm.com (e126817.cambridge.arm.com [10.2.3.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C59663F5A1; Thu, 8 Feb 2024 05:11:10 -0800 (PST) From: Ben Gainey To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, james.clark@arm.com, Ben Gainey Subject: [PATCH v2 0/4] perf: Support PERF_SAMPLE_READ with inherit_stat Date: Thu, 8 Feb 2024 13:10:46 +0000 Message-ID: <20240208131050.2406183-1-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 `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. 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. 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 | 53 +++++++++++++++++-------- tools/lib/perf/evlist.c | 1 + tools/lib/perf/evsel.c | 48 ++++++++++++++++++++++ tools/lib/perf/include/internal/evsel.h | 48 +++++++++++++++++++++- tools/perf/util/evsel.c | 15 ++++++- tools/perf/util/evsel.h | 1 + tools/perf/util/session.c | 11 +++-- 8 files changed, 154 insertions(+), 24 deletions(-) -- 2.43.0