From patchwork Thu Feb 8 13:10:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 198402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp159894dyd; Thu, 8 Feb 2024 05:19:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKZ6Mfg+HGsRzCzhuWkUBePOJJlq1xKL1jDRXoRwaQq5CXLB5WqIJFyHkRDW++q6yum0co X-Received: by 2002:a17:90a:3986:b0:296:9d63:30d4 with SMTP id z6-20020a17090a398600b002969d6330d4mr6623228pjb.28.1707398384207; Thu, 08 Feb 2024 05:19:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707398384; cv=pass; d=google.com; s=arc-20160816; b=Wsuk2De3L+3J7Kj/MzDQ8EWU72s0GH0mETMc/tN0jOqZ2fabi+ZVT6uW5m6k7RDq0i 2KQAmhtJpmzYgk0hoPRGbXvIzR4QsJaEQZcWYw0c25ZsnSJpQtLLVSQxTijwvQPJpxM7 FdCKOTXW/fcHgHYMjm14L7gFkl4VvfSTg5NYW0VZiUwIfTqKQpMh0hdXo1C4xMmf6Y6U hCb3wCj5KW5duvP2NRsfzf0GHNndxIfD4zaq+QbGlkiEs4m+1NtT7x0GL5Lt/6gKmrE+ ROEkMNxSITGPj2orQrgObH6fmKcd1Mu0CxCYFwD9jUREsLmNOkue9bQp8XeRq8qCIV9W bG2g== 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=S45b7lr//tBXMKQTMZXdIx6Y41Tu6r8+HR6Y43TQN9c=; fh=bNAtDEi6g93DxOPCCBaSWIQwBEyQ1/fPUK2U/LL+hGA=; b=RPhzoClFz/g9iydhgkO+GRH85LcYwhZGuUnxub0Vk8hrwR9qtlXSsnKXIEjPHCxldN kaj8dD3OZJVscEgsDDBZ0F8839KMwRs4OacnPEDmxXvhUbA0IB3oeAdb6gQ/D5nom+D7 e9Z3BmoVyMcvvDlGy3cclZ0YwdDj2uzdZsYDzBRVehcfw0MpveGs1gPGZ4c4OJqdUsOi RM5MH1Dt0yUvBeohJliz3bc6/yQEK+C+rA2CaQ3I4CVoz8+FEWf6h9WSUFD12sIHD5Ij dvt5hB5vpnR8cuu5Las05hD7jXCqbxeKkDpk7YixsHF0gVKS3yjb/AINm88RHOmeroT+ 0fNA==; 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-58130-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58130-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXg3xUnhLQeWRUAzjSYPaF8vdgzfuCEcQXlwt2JeKikamMHKs9B4t4fAbkp4+ffcrk1ktGunyudQc68zt6Yd/VumSdBJA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q7-20020a17090a9f4700b00296fd518c20si804039pjv.80.2024.02.08.05.19.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:19:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58130-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-58130-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58130-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 0F917284D22 for ; Thu, 8 Feb 2024 13:18:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9899979925; Thu, 8 Feb 2024 13:11:19 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0793443ACD; Thu, 8 Feb 2024 13:11:14 +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=1707397877; cv=none; b=dTxAjvIIxrSQ7e3OrGgX0EBs+nPxf/GNmhEIRfqsTY94cLYALPv4xjFaH1Eh43jeHGeuZhoy2bFYWj0kaVcqrMR7QXjGAYMID/p8j0neZ9wX6CVnfmEB7g0HkKQMn+WW+cOsyonNer+Vp2Y9uHu3+C93DzmOjzJjTfiKJQhpzLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397877; c=relaxed/simple; bh=fqu6mN5K4lFFy3zTNhV7f/rrnImkgY46BLOzGCAKBEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qg9kTAHLm9Kn6l1Jr7vezyRqSg5p/+N4lAyOAgU9cK9clPWNUYsqahjb4zYbqoieyTWJ/IdijL2a9mp4WXEX14LwX4RrPO2/puMta60xHxQ/zY4a0JjxD9XTRPYTnxDwF7Y7kz0cJ6aadh6qmkPOIBUoU+5y48JHGJWo5Eygqo4= 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 A3FD0DA7; Thu, 8 Feb 2024 05:11:56 -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 B1CE03F5A1; Thu, 8 Feb 2024 05:11:12 -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 1/4] perf: Support PERF_SAMPLE_READ with inherit_stat Date: Thu, 8 Feb 2024 13:10:47 +0000 Message-ID: <20240208131050.2406183-2-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208131050.2406183-1-ben.gainey@arm.com> References: <20240208131050.2406183-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: 1790336960344670805 X-GMAIL-MSGID: 1790336968208016928 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 multiprocess or multithreaded application, whilst allowing profiling tools to collect per-thread samples, in particular of groups of counters. Signed-off-by: Ben Gainey --- include/linux/perf_event.h | 1 + kernel/events/core.c | 53 ++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index d2a15c0c6f8a..7d405dff6694 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -932,6 +932,7 @@ struct perf_event_context { int nr_task_data; int nr_stat; + int nr_stat_read; int nr_freq; int rotate_disable; diff --git a/kernel/events/core.c b/kernel/events/core.c index f0f0f71213a1..dac7093b3608 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1795,8 +1795,11 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx) ctx->nr_events++; if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT) ctx->nr_user++; - if (event->attr.inherit_stat) + if (event->attr.inherit_stat) { ctx->nr_stat++; + if (event->attr.inherit && (event->attr.sample_type & PERF_SAMPLE_READ)) + ctx->nr_stat_read++; + } if (event->state > PERF_EVENT_STATE_OFF) perf_cgroup_event_enable(event, ctx); @@ -2019,8 +2022,11 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx) ctx->nr_events--; if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT) ctx->nr_user--; - if (event->attr.inherit_stat) + if (event->attr.inherit_stat) { ctx->nr_stat--; + if (event->attr.inherit && (event->attr.sample_type & PERF_SAMPLE_READ)) + ctx->nr_stat_read--; + } list_del_rcu(&event->event_entry); @@ -3529,11 +3535,17 @@ perf_event_context_sched_out(struct task_struct *task, struct task_struct *next) perf_ctx_disable(ctx, false); /* PMIs are disabled; ctx->nr_pending is stable. */ - if (local_read(&ctx->nr_pending) || + if (ctx->nr_stat_read || + next_ctx->nr_stat_read || + local_read(&ctx->nr_pending) || local_read(&next_ctx->nr_pending)) { /* * Must not swap out ctx when there's pending * events that rely on the ctx->task relation. + * + * Likewise, when a context contains inherit+inherit_stat+SAMPLE_READ + * events they should be switched out using the slow path + * so that they are treated as if they were distinct contexts. */ raw_spin_unlock(&next_ctx->lock); rcu_read_unlock(); @@ -3545,6 +3557,7 @@ perf_event_context_sched_out(struct task_struct *task, struct task_struct *next) perf_ctx_sched_task_cb(ctx, false); perf_event_swap_task_ctx_data(ctx, next_ctx); + perf_event_sync_stat(ctx, next_ctx); perf_ctx_enable(ctx, false); @@ -3559,8 +3572,6 @@ perf_event_context_sched_out(struct task_struct *task, struct task_struct *next) RCU_INIT_POINTER(next->perf_event_ctxp, ctx); do_switch = 0; - - perf_event_sync_stat(ctx, next_ctx); } raw_spin_unlock(&next_ctx->lock); raw_spin_unlock(&ctx->lock); @@ -4533,8 +4544,13 @@ static void __perf_event_read(void *info) raw_spin_unlock(&ctx->lock); } -static inline u64 perf_event_count(struct perf_event *event) +static inline u64 perf_event_count(struct perf_event *event, bool from_sample) { + if (from_sample && event->attr.inherit && + event->attr.inherit && + (event->attr.sample_type & PERF_SAMPLE_TID)) { + return local64_read(&event->count); + } return local64_read(&event->count) + atomic64_read(&event->child_count); } @@ -5454,7 +5470,7 @@ static u64 __perf_event_read_value(struct perf_event *event, u64 *enabled, u64 * mutex_lock(&event->child_mutex); (void)perf_event_read(event, false); - total += perf_event_count(event); + total += perf_event_count(event, false); *enabled += event->total_time_enabled + atomic64_read(&event->child_total_time_enabled); @@ -5463,7 +5479,7 @@ static u64 __perf_event_read_value(struct perf_event *event, u64 *enabled, u64 * list_for_each_entry(child, &event->child_list, child_list) { (void)perf_event_read(child, false); - total += perf_event_count(child); + total += perf_event_count(child, false); *enabled += child->total_time_enabled; *running += child->total_time_running; } @@ -5545,14 +5561,14 @@ static int __perf_read_group_add(struct perf_event *leader, /* * Write {count,id} tuples for every sibling. */ - values[n++] += perf_event_count(leader); + values[n++] += perf_event_count(leader, false); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(leader); if (read_format & PERF_FORMAT_LOST) values[n++] = atomic64_read(&leader->lost_samples); for_each_sibling_event(sub, leader) { - values[n++] += perf_event_count(sub); + values[n++] += perf_event_count(sub, false); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(sub); if (read_format & PERF_FORMAT_LOST) @@ -6132,7 +6148,7 @@ void perf_event_update_userpage(struct perf_event *event) ++userpg->lock; barrier(); userpg->index = perf_event_index(event); - userpg->offset = perf_event_count(event); + userpg->offset = perf_event_count(event, false); if (userpg->index) userpg->offset -= local64_read(&event->hw.prev_count); @@ -7200,7 +7216,7 @@ static void perf_output_read_one(struct perf_output_handle *handle, u64 values[5]; int n = 0; - values[n++] = perf_event_count(event); + values[n++] = perf_event_count(event, true); if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) { values[n++] = enabled + atomic64_read(&event->child_total_time_enabled); @@ -7245,7 +7261,7 @@ static void perf_output_read_group(struct perf_output_handle *handle, (leader->state == PERF_EVENT_STATE_ACTIVE)) leader->pmu->read(leader); - values[n++] = perf_event_count(leader); + values[n++] = perf_event_count(leader, true); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(leader); if (read_format & PERF_FORMAT_LOST) @@ -7260,7 +7276,7 @@ static void perf_output_read_group(struct perf_output_handle *handle, (sub->state == PERF_EVENT_STATE_ACTIVE)) sub->pmu->read(sub); - values[n++] = perf_event_count(sub); + values[n++] = perf_event_count(sub, false); if (read_format & PERF_FORMAT_ID) values[n++] = primary_event_id(sub); if (read_format & PERF_FORMAT_LOST) @@ -12010,10 +12026,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)) @@ -13037,7 +13056,7 @@ static void sync_child_event(struct perf_event *child_event) perf_event_read_event(child_event, task); } - child_val = perf_event_count(child_event); + child_val = perf_event_count(child_event, false); /* * Add back the child's count to the parent's count: From patchwork Thu Feb 8 13:10:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 198403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp159955dyd; Thu, 8 Feb 2024 05:19:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVmAEn/H7jKZ6Lbb0U19b0TzSqL6rJlO6lFt4g6vetuk9IqDRHxR1qvNdWjz0HHjmyIUBQ X-Received: by 2002:a4a:ea2b:0:b0:59a:4a57:edb3 with SMTP id y11-20020a4aea2b000000b0059a4a57edb3mr9911386ood.5.1707398390906; Thu, 08 Feb 2024 05:19:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707398390; cv=pass; d=google.com; s=arc-20160816; b=RMx2ozYlAHTURiSoS3LvIA4C9arwwC/NsB6q1TIDb8n7cIr8H9RuGJBNO3f4vCbv8U XM42cB+jvBBIcordqV/LZWZtj4j0462ZRsOi2mYg8rzEuSX8479rN7zI3X0OWZKfYCvY 1bLmBPAaAS9lj1V3J/b3hM9GR9+K6UweKHX7l3mDvLAn8R6o/Yi3WhPt/0q2Oe3U8psR N982Xm51kj+rjCxHTZxICD7Q5gkbNhRm6H3G76SI8c3EOu1gjv+iawaiwAe05dSaQGK2 THhrILBtHI3pyykDwNBJ8WR7614V5zJPWCUDGe/NpKLC0OiBuagw8qGnP4/S3xIYss8X xcBQ== 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=JLf24BWHySyebw8rVUE/BraNQm4f91ItpApV8HGt68M=; fh=+/EQL9zpivyTj6alztGjZXrLeiGOSIN5zBv0Fmi310I=; b=rAjLlfEZLKb2geBZzjfDxPNSL7akJVFYKadGvB5e0VlX4dkycGNwXazehwa7GkUHPt Vaw/C3k+LfIQF4kDFSlk6qvCkxUkj8oOepj+HiiHabkTU8S8YiVuJMhavoxXtadaUJH3 0ayHFIo3RWlBlgaRBDeUSUSZIjBzpegTktcBYAQrTfqdM3fE4ZyIhjpU7tObS29OeUqo +Po1PzPNHvkmmZ4/RVV804jLkRYTx5SyD4uYEyopTrDu+8FOfDyHCcSnyXZjQN9GvaXf 4WdcH7lt1lZFZ+zWSciCj2viOMDKxXN2NmutriJJ0MTvgsPzIUL1QKPTR1VjaKKML2Ky WaOQ==; 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-58131-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58131-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUI8fNT7aBEk7LyHxDzZOh2DyVrJHttWxSgpcEmCDWQI81JnhJYe7T36OJISFGFptxoYKsi6vFJD/yw+rKHDbOQNiL0Zg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h34-20020a635322000000b005dc427abe3bsi1498659pgb.356.2024.02.08.05.19.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:19:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58131-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-58131-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58131-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 9E64C288AFC for ; Thu, 8 Feb 2024 13:18:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED60779954; Thu, 8 Feb 2024 13:11:20 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC06876413; Thu, 8 Feb 2024 13:11:16 +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=1707397879; cv=none; b=TkGv8fvJEawnO6iVrwud/NTWMksUd6z84DxHfA28Yvl3kdqS6aMv6r2/Qy368HYg5Bm/vvOSCmCXkBpkTa1LZhN2/PZo9EdQu/Okj/L/sjk7DF0qQ80hNHR/fXIvEsEVONXmJVqI7i25kHw49nsa1ItaWvDukquKqBTMiFS2lEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397879; c=relaxed/simple; bh=Je/B4EVJ1QmkamUOgXw0RNyKBh1iaAjN/ZC5BiEcIWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BfhRl5K0waUP8pEO2TEr7nJEVEc6jKXFXgcB59o5NyX6iQP4TydTnNt9wGU7Dkb17sc5p2+t+shIFfry70tjuX5FB/h3sAozcHFhtG68Ltsr/pWP0b8J+WvLwD87iFw+8UPy2d8k1297WTvcsSwSc1zxKsURE92k99XaxagVZGw= 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 90781152B; Thu, 8 Feb 2024 05:11:58 -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 9D49A3F5A1; Thu, 8 Feb 2024 05:11:14 -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 2/4] tools/perf: Track where perf_sample_ids need per-thread periods Date: Thu, 8 Feb 2024 13:10:48 +0000 Message-ID: <20240208131050.2406183-3-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208131050.2406183-1-ben.gainey@arm.com> References: <20240208131050.2406183-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: 1790336975270311387 X-GMAIL-MSGID: 1790336975270311387 When PERF_SAMPLE_READ is used with inherit+inherit_stat the perf_sample_id is no longer globally unique, but instead is unique per each inherited thread. Track this fact in perf_sample_ids as it will be needed to correctly calculate the period. Signed-off-by: Ben Gainey --- tools/lib/perf/evlist.c | 1 + tools/lib/perf/evsel.c | 7 +++++++ tools/lib/perf/include/internal/evsel.h | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 058e3ff10f9b..c585c49491a5 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -255,6 +255,7 @@ static void perf_evlist__id_hash(struct perf_evlist *evlist, sid->id = id; sid->evsel = evsel; + sid->period_per_thread = perf_evsel__attr_has_per_thread_sample_period(evsel); hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS); hlist_add_head(&sid->node, &evlist->heads[hash]); } diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index c07160953224..dd60ee0557d8 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -537,6 +537,13 @@ void perf_evsel__free_id(struct perf_evsel *evsel) evsel->ids = 0; } +bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel) +{ + return (evsel->attr.sample_type & PERF_SAMPLE_READ) + && evsel->attr.inherit + && evsel->attr.inherit_stat; +} + void perf_counts_values__scale(struct perf_counts_values *count, bool scale, __s8 *pscaled) { diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 5cd220a61962..97658f1c9ca3 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -36,6 +36,11 @@ struct perf_sample_id { /* Holds total ID period value for PERF_SAMPLE_READ processing. */ u64 period; + + /* When inherit+inherit_stat is combined with PERF_SAMPLE_READ, the + * period value is per (sample_id, thread) tuple, rather than per + * sample_id. */ + bool period_per_thread; }; struct perf_evsel { @@ -88,4 +93,6 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter); int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); void perf_evsel__free_id(struct perf_evsel *evsel); +bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel); + #endif /* __LIBPERF_INTERNAL_EVSEL_H */ From patchwork Thu Feb 8 13:10:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 198398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp159414dyd; Thu, 8 Feb 2024 05:18:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVdJwNrI1qgeBSExb/vVteMuzLzrxfL7+6PSWdn+E3gTP/0KXLtq9rhxK020b77G83lgxbjx8ie5vkpaHm4tnbLLMnjlQ== X-Google-Smtp-Source: AGHT+IFdDVpSNO6SZjuB8z/fiudlWwisxKRtLRSofHD/H1BFqtLf/svo0RXrRWH8wZlLN26PxZCH X-Received: by 2002:a0c:db94:0:b0:68c:aa0e:95bc with SMTP id m20-20020a0cdb94000000b0068caa0e95bcmr7615555qvk.45.1707398334232; Thu, 08 Feb 2024 05:18:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707398334; cv=pass; d=google.com; s=arc-20160816; b=XJqvN3GTD6Gn4ZRs4ZYBY9jN3XAvYq7YrN+IlD5vs4c8k9oo19xGYG2wpVxeEsBfu5 y0QxeUqZbS0SUO+DrKPA4Zx8p0TKbh2c4DptkNMdSCAVAPrOmCBbmVUBWYN7WwzY4xBI 62hxaHlnt7KYZaJFjKbOpWC2F12RtswTYLPkhtyiiWbMaAnE0ndam8weiLNK+EHvatSB 3Y0/Bbs4YiaCEZ6luklFet8oM07gfhWAwsu19U5/KbRjc1dpUZxAiPDvtuuM62lvyRTg kUxUir4nchoO93SEYeEDA0QdMj8DRYZjbo9EsCOBA+3vqXr07yzTXZfYvIM+XX0vIW5H ReLQ== 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=EJC6SqAQpIlpX34jY2FuX57bCCLx2hQe3qGopN8IBR0=; fh=Bw114dCKjMYBSbQF3OsCmh5Lgqkk4R6oogr0DSaV89Y=; b=rKRqD9inlyzL3OXxzqPHEyGqyM/vLMGuOiVYOpSlv27q3L4n06af7tIiJIbtIsIxLQ x/G6D+O3ctlKhqgqtXjsO7KEL6/m8jhUt8KKNIoRtgpeahfZG0QhDFOvgHpzICNNO5xi TNtmDpXMa+ybBgEScqgyD8ALdwG7CC+wLp9TbeCLEJXUGhNhMj6A1I8K2CcX9yXz8bf3 LWQxon7jgSfuCtIik7QAht/TqFnRVROICuQwhwK4OfEIqZuWevUDGkYK0eLTFuNI576x nkM3mb/aAhXeD2jxB9F6qJY9mQpcxJ/F+ALu1C5QX1zB7lznfb0iWV3NLsf+l0O7pgev L6hw==; 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-58132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58132-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVbZKzZsFQ3MawYGsx+4mEbZXOSrJZJHtIjIQg5vVfuR0ZvRSu1xqvDYptEKCx6tCMTlnbdroq8Si8hcRwSH2cRNVh3AQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x10-20020ae9f80a000000b0078598438c33si3231396qkh.296.2024.02.08.05.18.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:18:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-58132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58132-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 00C5E1C22C55 for ; Thu, 8 Feb 2024 13:18:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 009FD79956; Thu, 8 Feb 2024 13:11:23 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFA2F76C75; Thu, 8 Feb 2024 13:11:18 +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=1707397880; cv=none; b=bt5i0EjJUS0if+24nmMIFdQvb4t7FWtmi24cs/uQ9f4+6xON7Pi7uG6U2lRFJcoIOJFy6ehjfCJZhHaDjU016s+sV+qfklD5RsiVAHVe68hbvo2OrJE16NFHjsAX1czQl4gC2DIQZLqRjxJ0leFN8Ilo8QbGv+mJCA39D66OOK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397880; c=relaxed/simple; bh=Ry30vTKwYooMTl9Mf53QWiWzOCZr0ih4rljkclS4P3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mhQO2lSe1OQ9ZNE/3QRYNpUwbE5WbgFwDbJqhtYzTNfxC30OOzDMFz8EE+C9GWWPk5ymN3pAv29ZPb+NtavhkO3eFnPatLI6LkTyQqiEXYpKD+NqktViTMvfLcdkjrgeOZpgWM/RO43wqYqSoMX+3GLFkKYPAFbeUjmwFEc/RIY= 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 7AA4C153B; Thu, 8 Feb 2024 05:12:00 -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 88F893F5A1; Thu, 8 Feb 2024 05:11:16 -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 3/4] tools/perf: Correctly calculate sample period for inherited SAMPLE_READ values Date: Thu, 8 Feb 2024 13:10:49 +0000 Message-ID: <20240208131050.2406183-4-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208131050.2406183-1-ben.gainey@arm.com> References: <20240208131050.2406183-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: 1790336915931903787 X-GMAIL-MSGID: 1790336915931903787 Calculate the per-thread period when using PERF_SAMPLE_READ with inherit+inherit_stat. Stores a per-thread period per perf_sample_id, hashed by tid. For other configurations, maintain a global period per perf_sample_id. Signed-off-by: Ben Gainey --- tools/lib/perf/evsel.c | 41 +++++++++++++++++++++++++ tools/lib/perf/include/internal/evsel.h | 41 +++++++++++++++++++++++-- tools/perf/util/session.c | 11 +++++-- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index dd60ee0557d8..4e173151e183 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, int idx) { INIT_LIST_HEAD(&evsel->node); + INIT_LIST_HEAD(&evsel->period_per_thread_periods); evsel->attr = *attr; evsel->idx = idx; evsel->leader = evsel; @@ -531,10 +533,17 @@ int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) void perf_evsel__free_id(struct perf_evsel *evsel) { + struct perf_sample_id_period *pos, *n; + xyarray__delete(evsel->sample_id); evsel->sample_id = NULL; zfree(&evsel->id); evsel->ids = 0; + + perf_evsel_for_each_per_thread_period_safe(evsel, n, pos) { + list_del_init(&pos->node); + zfree(pos); + } } bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel) @@ -544,6 +553,38 @@ bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel) && evsel->attr.inherit_stat; } +u64 * perf_sample_id__get_period_storage(struct perf_sample_id * sid, u32 tid) +{ + struct hlist_head *head; + struct perf_sample_id_period *res; + int hash; + + if (!sid->period_per_thread) + return &sid->period; + + hash = hash_32(tid, PERF_SAMPLE_ID__HLIST_BITS); + head = &sid->periods[hash]; + + hlist_for_each_entry(res, head, hnode) + if (res->tid == tid) + return &res->period; + + if (sid->evsel == NULL) + return NULL; + + res = zalloc(sizeof(struct perf_sample_id_period)); + if (res == NULL) + return NULL; + + INIT_LIST_HEAD(&res->node); + res->tid = tid; + + list_add_tail(&res->node, &sid->evsel->period_per_thread_periods); + hlist_add_head(&res->hnode, &sid->periods[hash]); + + return &res->period; +} + void perf_counts_values__scale(struct perf_counts_values *count, bool scale, __s8 *pscaled) { diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 97658f1c9ca3..0fd8597c1340 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -11,6 +11,31 @@ struct perf_thread_map; struct xyarray; +/** + * The per-thread accumulated period storage node. + */ +struct perf_sample_id_period { + struct list_head node; + struct hlist_node hnode; + /* The thread that the values belongs to */ + u32 tid; + /* Holds total ID period value for PERF_SAMPLE_READ processing. */ + u64 period; +}; + +/** + * perf_evsel_for_each_per_thread_period_safe - safely iterate thru all the period_per_thread_periods + * @evlist:perf_evsel instance to iterate + * @item: struct perf_sample_id_period iterator + * @tmp: struct perf_sample_id_period temp iterator + */ +#define perf_evsel_for_each_per_thread_period_safe(evsel, tmp, item) \ + list_for_each_entry_safe(item, tmp, &(evsel)->period_per_thread_periods, node) + + +#define PERF_SAMPLE_ID__HLIST_BITS 4 +#define PERF_SAMPLE_ID__HLIST_SIZE (1 << PERF_SAMPLE_ID__HLIST_BITS) + /* * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are * more than one entry in the evlist. @@ -19,6 +44,7 @@ struct perf_sample_id { struct hlist_node node; u64 id; struct perf_evsel *evsel; + /* * 'idx' will be used for AUX area sampling. A sample will have AUX area * data that will be queued for decoding, where there are separate @@ -34,8 +60,14 @@ struct perf_sample_id { pid_t machine_pid; struct perf_cpu vcpu; - /* Holds total ID period value for PERF_SAMPLE_READ processing. */ - u64 period; + union { + /* Holds total ID period value for PERF_SAMPLE_READ processing (when period is not + * per-thread). */ + u64 period; + /* Holds total ID period value for PERF_SAMPLE_READ processing (when period is + * per-thread). */ + struct hlist_head periods[PERF_SAMPLE_ID__HLIST_SIZE]; + }; /* When inherit+inherit_stat is combined with PERF_SAMPLE_READ, the * period value is per (sample_id, thread) tuple, rather than per @@ -63,6 +95,9 @@ struct perf_evsel { u32 ids; struct perf_evsel *leader; + /* Where period_per_thread is true, stores the per-thread values */ + struct list_head period_per_thread_periods; + /* parse modifier helper */ int nr_members; /* @@ -95,4 +130,6 @@ void perf_evsel__free_id(struct perf_evsel *evsel); bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel); +u64 * perf_sample_id__get_period_storage(struct perf_sample_id * sid, u32 tid); + #endif /* __LIBPERF_INTERNAL_EVSEL_H */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 199d3e8df315..22a8598ee849 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1478,14 +1478,19 @@ static int deliver_sample_value(struct evlist *evlist, { struct perf_sample_id *sid = evlist__id2sid(evlist, v->id); struct evsel *evsel; + u64 * storage = NULL; if (sid) { + storage = perf_sample_id__get_period_storage(sid, sample->tid); + } + + if (storage) { sample->id = v->id; - sample->period = v->value - sid->period; - sid->period = v->value; + sample->period = v->value - *storage; + *storage = v->value; } - if (!sid || sid->evsel == NULL) { + if (!storage || sid->evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } From patchwork Thu Feb 8 13:10:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gainey X-Patchwork-Id: 198415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp177300dyd; Thu, 8 Feb 2024 05:49:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUgLc89yDeBkvtJAXsHs1J7mqgtNY7BzFSoQKCuFqNt7HgTOG/FhHaSXdvsoIShlPux+Ba5RnOQWc+uT9oiqKEzzk3aKQ== X-Google-Smtp-Source: AGHT+IHimREVM0mzYFbQIUVV4ca2VZADucx81pkXIc1Ax/uZ6Q54Eh01f109P0dl53dh3RYlPoRl X-Received: by 2002:a05:6870:ad0a:b0:215:48c2:b801 with SMTP id nt10-20020a056870ad0a00b0021548c2b801mr10102918oab.14.1707400169462; Thu, 08 Feb 2024 05:49:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707400169; cv=pass; d=google.com; s=arc-20160816; b=TugfosrXTzT+Hk/v8Cmg2vlqG+R0UqCrMo3nUxV5wwHWY0XBeeM2EH0HMzV+K+/X8R vNtEjiVHzqns/NDuh6y4C2iS56g8DkH9Fzm+Kl8TrjCk//smTHY/Mw69K6IzuicLsBvc Kmap2JV4lQV/JxZ3a2G+oUi/NFYJQhzR0iu88aJReQG2nb/+hQbTml9xYr4ZJcHLfueB pfwIETxb06VwpGEat0f5sTfjJJpxjEFIQ5KNGE6vTLzUsFDqIhXaKUdmWyeOCW9yIy8h 9T3kF5m07b2jsKBe9+dxP5aLJT48uxESG5usRiVs6VtH4dfawQeDaLQknQsLoh5+DO/i 7J5g== 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=HdFcFRhojqbgWaYGhbFk7N9sDT7hHPEt8NkEavlN2MQ=; fh=c2rzY0qZRoukhCMHschNv6DmDvQU4pH0Wl2HyO1Ce1s=; b=JlLupa4gjANUUcjheut7vq1qRRYZUUOc0hf8A07eXWrmBlJZ+FWqLGJvHkhyQy/f/E mZOS0gbaNQtnTEAV75WiZmev0Zn3YwOO3ck4jh5Yg1Y2iCgUpvjpXJQv+9NfyawgmCFS AWnKpKUOXwPZ6+xwKw6Gsgz9KTZysW0K1n26uh9a/8saI5mFpllJYX9Aic9TYWNe6AMO NTKweVZoG76KucR6SDphIi/sYN0FwLKXUAwmslsbRY+SbKILXxwiQAy/ms35exkHho7q PLeQUyqKReZtVXRLQwpkLRX/ue4ecgwF7auwVE0VMn/ZeFuaKBZdSFwOZdGh8JwJ1Q44 Q/zQ==; 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-58133-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58133-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXGltqxnWSBBpKkrbgkL/azjR5y7ytLwEIZXt8tBFKpMpD8u2hLtWnV+R5hv1Pdnkx2GGj+p1TKajZN20q6vGnAMi4lhg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r9-20020a632b09000000b005dbec91be93si3736098pgr.595.2024.02.08.05.49.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 05:49:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58133-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-58133-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58133-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id ABFF6B29F9A for ; Thu, 8 Feb 2024 13:19:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72A3B1292F0; Thu, 8 Feb 2024 13:11:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB4D3128393; Thu, 8 Feb 2024 13:11:20 +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=1707397882; cv=none; b=TwNWeYPdgzRiwpOdZLUupZ6gVXOK3m2DIFerDhywVtlRBxL15tQGcTzmdTZdLmow/mm2xUas9KDl8HM+JiIKVJY4R2b3FE8ETVGc8r+ovSGh6qWNlcPFs6SUdn2woXSxiI9hNV5Y23dqGIlvyLI8iTN4ba40WYmG0wffEuf2Fes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707397882; c=relaxed/simple; bh=NXmmRDt9OvFlC34NViJ9HXJ7Z7vXKtF1o7U8eiErB4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OAygWMJih4Xq+spF9mKZkDxj4HG0VTWWyLA20M+pnIShjnyDTV32iNMq/USO88jhVn8CfJ5Akq/+eKHfDadGK94V0Epy/ThN5t57DrcgLNDBoOnmTafE5yAY4oqpSg9J4uZCgEofxWLCZhLCwwG5Krtswxar6HXsnqecWX0P/SM= 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 673201570; Thu, 8 Feb 2024 05:12:02 -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 741163F5A1; Thu, 8 Feb 2024 05:11:18 -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 4/4] tools/perf: Allow inherit + inherit_stat + PERF_SAMPLE_READ when opening events Date: Thu, 8 Feb 2024 13:10:50 +0000 Message-ID: <20240208131050.2406183-5-ben.gainey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240208131050.2406183-1-ben.gainey@arm.com> References: <20240208131050.2406183-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: 1790338839775907143 X-GMAIL-MSGID: 1790338839775907143 When PERF_SAMPLE_READ is used will enable inherit_stat when inherit is set. Provides a fallback path to disable inherit when this feature is not available, which is inline with the previous behaviour. Signed-off-by: Ben Gainey --- tools/perf/util/evsel.c | 15 +++++++++++++-- tools/perf/util/evsel.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6d7c9c58a9bc..dc74b39a2254 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1156,7 +1156,11 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts, */ if (leader->core.nr_members > 1) { attr->read_format |= PERF_FORMAT_GROUP; - attr->inherit = 0; + } + + /* Inherit + READ requires inherit_stat */ + if (attr->inherit) { + attr->inherit_stat = true; } } @@ -1832,6 +1836,8 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, static void evsel__disable_missing_features(struct evsel *evsel) { + if (perf_missing_features.inherit_sample_read) + evsel->core.attr.inherit = 0; if (perf_missing_features.branch_counters) evsel->core.attr.branch_sample_type &= ~PERF_SAMPLE_BRANCH_COUNTERS; if (perf_missing_features.read_lost) @@ -1887,7 +1893,12 @@ bool evsel__detect_missing_features(struct evsel *evsel) * Must probe features in the order they were added to the * perf_event_attr interface. */ - if (!perf_missing_features.branch_counters && + if (!perf_missing_features.inherit_sample_read && + evsel->core.attr.inherit && (evsel->core.attr.sample_type & PERF_SAMPLE_READ)) { + perf_missing_features.inherit_sample_read = true; + pr_debug2("Using PERF_SAMPLE_READ / :S modifier is not compatible with inherit, falling back to no-inherit.\n"); + return true; + } else if (!perf_missing_features.branch_counters && (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS)) { perf_missing_features.branch_counters = true; pr_debug2("switching off branch counters support\n"); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index efbb6e848287..11cc9b8bee27 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -192,6 +192,7 @@ struct perf_missing_features { bool weight_struct; bool read_lost; bool branch_counters; + bool inherit_sample_read; }; extern struct perf_missing_features perf_missing_features;