From patchwork Thu Feb 8 13:10:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 20109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp159806dyd; Thu, 8 Feb 2024 05:19:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6CErABbufXhdIZd1346elay6Tug80Zp123iQf9eqshaF6lwdEwqQeWidZCKBxU7UvBTa1 X-Received: by 2002:a17:90a:2f47:b0:296:a375:cb86 with SMTP id s65-20020a17090a2f4700b00296a375cb86mr5138347pjd.14.1707398376461; Thu, 08 Feb 2024 05:19:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707398376; cv=pass; d=google.com; s=arc-20160816; b=Qz3f12GN5y5cjsr9ETIQ3dWnws8riYl9pmS6qqCZ/HsbWsjOcbnW1DzPPxjq86fqHQ cpXP+HTw3cYbTCMoJJqG17BRxQZ+wMeNTTp0kxb+SaufC94p/y7p2jZ4/CXaOh3yNKfo 1EjePgIZONnMSLK2bL/qivoT+sJMygIQZ0YHOOdFRjFQ4x4EIvDTJGopwV+SrP3YmLDo sSDFluhrmNVAYZjHD9lRimIHA46T/RQfT8GRe9okqTgwmK+xjnQGBXeijBusJ5YUscq8 xZ073WwZpuS9ipD5c5GUU3ThZ26cSPmXEP3SgILBt+FYfEbVTDtN22IiJC/ipjNh5/6Z ykfg== 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=MY/VYTOcy9UlYRSN2NYqKjA4/b0Z/bCvXx7jGhF5WHo=; b=FpKWuphYLx5aOV3LLZ8zO9p7oc9MdvZhzUwdzmSVKKdcvxJwf9sFc/EesKczIfbMMB hXW4MAdwnS3TCxZDsNnTq35cixAloxmch39ju/7nP0xVftQzVpow3K0RihfJuZi6fA02 RjUBHMmefy5S8dJJd75RxhBxKFRs1ETygZUtMvZO+f6oFB5EbXZtTEFxcc3hDIpg0/7N v2NEOek77yjwRgA1f9REWqYCqvuv6NnkQqNLyT/YBBoR9aqd+VDE1RHSdbFNeyGcWHWx vhQRdsNvIxoFGne2cxeEv82Y0JHf8eCSL+j+OmR517+TgnkS71Ag2repFUBT6U1Dn1Mj HGfw==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58129-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCW74v27Zovij66PEI0HuCCkxAsOFub5zSim4on22KqkWzIP/SFbK1lwXYBVSRRmfIOUYf3Q8R6+ODLeFNau4ErHRExnPA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id qa16-20020a17090b4fd000b00296fe7f9b81si725430pjb.16.2024.02.08.05.19.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:19:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58129-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58129-ouuuleilei=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 976B3282F3D for ; Thu, 8 Feb 2024 13:18:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FAD678B4E; Thu, 8 Feb 2024 13:11:18 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790336960344670805 X-GMAIL-MSGID: 1790336960344670805 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(-)