From patchwork Fri Jan 19 16:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 189607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1128218dyb; Fri, 19 Jan 2024 08:40:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFofX4TKKEdZvQ0f8h75rUO+CoJTZUhpYKQ9plyPbrGzvNc4VUyFLO0GEkUSYL+znSR1Z2s X-Received: by 2002:a17:906:9807:b0:a2f:7ba2:2fe8 with SMTP id lm7-20020a170906980700b00a2f7ba22fe8mr24182ejb.106.1705682432178; Fri, 19 Jan 2024 08:40:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705682432; cv=pass; d=google.com; s=arc-20160816; b=FULJUKXmQdcaCdbOUR4Z7nr+UKolh9t51d5N/Qzhc0EWxlD/J4D5SEGZPBYskQH4qa 7wMmbJvlwXWWCLRXwH3NKXPXMqEqcRMxrqRaCMAyN1k/N2bAAYZ47LjT/Ih9Sxlj5+RM v+Cil6Im1bbsOvPH8EPkQ7II7GIuvJve0a4dZcWXm27gYQJ1+nhIgLlVO03q73GtPAM9 zRJ1tA0bZPjF0IPci1IaKBaZOKjc+JZUn1PJoQK3HyVmhDEPeB6VSX9JccXkk9epf+xx fqXu2wjSiOiP2T8cz1Fm3N6ImLzTM9lFNVrlXy6/Ufdstz0Kn1Bpj2qoeRvYX554eMti LVgQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=kqGvfXDLakOEb2Dz85eCJnVf7vhXUSvdTkHhNoRUn5M=; fh=G91xSwRmDhPqekiiQQapZLC6wvNZ0cm3WTKASgdYN18=; b=LNMb+aZFxZW1z3xhLcZuILc4JWma0mAEY1Dl9DxvJK/S9KAKtbtEd+o6h6QPQKSSio m7tmPJ4Nh0jMgiSK7Ndc5K51cdgqD5mea7nwTi2MFxbE2IhyPL0HYKc9FqdMKPtyzMqI Txi+8fmc4OI9LSw+4pSDeliwU3qqq2BBTL0cylDgiaqi8XELCUTUa+HyFrM61G4bv3Vk E8x//Bur7bek8FYkZHlxRYAPwSG/ko59SQeY7C+hS/F7snoupPwZihQPQBgVHkpRAebB j6zTvd6njf5nQB7iw5rd2g2c0zhWRK+pdTEEmDgC15R1gs3vyaH8iU9gXDVV7S5jZdlg +rmA== 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-31371-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31371-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id op20-20020a170906bcf400b00a2b9d6ecbbcsi7896095ejb.960.2024.01.19.08.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 08:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31371-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-31371-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31371-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C2C1B1F25191 for ; Fri, 19 Jan 2024 16:40:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5018C55E45; Fri, 19 Jan 2024 16:39:58 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E85155785; Fri, 19 Jan 2024 16:39:54 +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=1705682396; cv=none; b=t99A5ywsr6Qo/P8SEzzI1znxozmMDmdOVMAAXB6TDRAMfveTtY7FlAKdmKbBXGVWocnZTKwNUftCMSCZ274RpDHy4UqLYc1U7akrryEFcVAGle6fD5wKTDawzCoR9NYq8VEJOCoyMn14YyiErPdyut07G9pRYdC/yB+3IXxeol0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705682396; c=relaxed/simple; bh=lBmSUPtkwtCMjZIkdsZPZkuixbOXHdWTZ6M2mQb6yPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JH2oJFuXL4kzx1N/HOuYXjF4+9hA34plqLH2p8aoElIB2z/nJZKeGtVkD1EFrdzTep//iaRwn8EXSQWyIlZqKsAMLhoeZGMKCrg9PG1sOyfJTstBVl/hbmSABhPx3yu9O6yZZdPB8q6znOkybrT/m2XauFy1JIa9WXZimleW2OM= 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 CC8D311FB; Fri, 19 Jan 2024 08:40:38 -0800 (PST) Received: from e126817.. (e126817.cambridge.arm.com [10.2.3.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 168413F73F; Fri, 19 Jan 2024 08:39:49 -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 1/1] perf: Support PERF_SAMPLE_READ with inherit_stat Date: Fri, 19 Jan 2024 16:39:24 +0000 Message-ID: <20240119163924.2801678-2-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119163924.2801678-1-ben.gainey@arm.com> References: <20240119163924.2801678-1-ben.gainey@arm.com> 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: 1788537662134248327 X-GMAIL-MSGID: 1788537662134248327 This change allows events to use PERF_SAMPLE READ with inherit so long as both inherit_stat and PERF_SAMPLE_TID are set. In this configuration, and event will be inherited into any child processes / threads, allowing convenient profiling of a multi-process or multi-threaded application, whilst allowing profiling tools to collect per-thread samples, in particular of groups of counters. Signed-off-by: Ben Gainey --- kernel/events/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 9efd0d7775e7c..4b603463d888f 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11988,10 +11988,13 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, local64_set(&hwc->period_left, hwc->sample_period); /* - * We currently do not support PERF_SAMPLE_READ on inherited events. + * We do not support PERF_SAMPLE_READ on inherited events unless + * inherit_stat and PERF_SAMPLE_TID are also selected, which allows + * inherited events to collect per-thread samples. * See perf_output_read(). */ - if (attr->inherit && (attr->sample_type & PERF_SAMPLE_READ)) + if (attr->inherit && (attr->sample_type & PERF_SAMPLE_READ) + && !(attr->inherit_stat && (attr->sample_type & PERF_SAMPLE_TID))) goto err_ns; if (!has_branch_stack(event))