Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3082981lqo; Tue, 21 May 2024 06:31:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1d5NiN0ySzS/P/G5hnmaIxG9QBQpCbKA4NDmMoUF/v0e2eT2r4qE3wXp04Hr5OQn2XbKuxs+E1pankp4W/po397ugtPS50e/hSwBOEw== X-Google-Smtp-Source: AGHT+IFaXjtM0D6xbEtMaaQ59ryT4JZOCVR11TDjAg/jOJBR9hi4LJqYWWQURKJ1OyQMQR15lBzt X-Received: by 2002:a17:906:7fd6:b0:a59:c7d7:8b18 with SMTP id a640c23a62f3a-a5a2d57a3a6mr1936582866b.30.1716298312820; Tue, 21 May 2024 06:31:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716298312; cv=pass; d=google.com; s=arc-20160816; b=voNVdlI8lvfXtB1IGTlwv5jIHte62xJg8UXjy1xYZIrfyp2c4c3z4LRUw1TP40vUnt vgJZumDfpCzIHPEkDzbScl6y0gwNLdkBcWOQh3++jGrF6kzdE4COLHR2Q+rmR3EUA839 NIzqiFE/TmouhLp8BeDNHaxk/xGDAQJMknC+DhFMq0NjOdFHWakLlhyPYy88Wr7JWrKL CBcFw+FQfFItBT+W5kr+ASibc3ky5YSwPckxeEX1S0IcFz3AHRC2cyXWtuddhs/66AWc dDHu6caf4QuUZ/RLzDSd0lZ9q2LuDxhVRJ05n/AjnpAY4VYArxkUDF96kKQft7duUxe3 5nrw== 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=lblShckVzrbx0cB6cacZRlnl1lXCgpN+tIwULfrgWmE=; fh=qmyFNe8t+IUXUkrxfdZt+VGwiwY4q6x1nzoI5t8Y/1U=; b=L8cWFOKrsIrVxu0DeBGBRrNeCsWrqM/v1ZIfOCUzC0NsK0FVrvIV4AYDB1p1plJ+c8 jbr2usy6+s0LsjOK4lI5EuZNJr+0L4IRW4HlBvRGN2lCUZ+7Do/dH+wydV9H/874IaZD YUvyMQ0WbuUfh2suxY9Mo8mPJHTUNDIzYvlIt7oszv+cCdV46Nnq8Kvszc7tZKvfGrAB F3qvLAAWJWOKysBkK30t661Q4QfhAs393eqxaqgVd6ek/T9nwgWFkQIPqgch1lKBPcHZ ITbV1nLy9i/MiMCeCr/6NCSDyUVQv7Wl8C6PtstcjBxDkmqqU5e85sWPr2yysomeCoF4 vHOQ==; 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-185017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185017-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17be63d2si1407306666b.717.2024.05.21.06.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 06:31:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-185017-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185017-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3F34D1F214B9 for ; Tue, 21 May 2024 13:31:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9AEEC8003F; Tue, 21 May 2024 13:30:47 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3291B7F7FC; Tue, 21 May 2024 13:30:45 +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=1716298246; cv=none; b=tek6jurWsLGq12pOb62eEDVrSRZtKSpCPa8lUfUfF88R0gHKGfhOZdihsCl8A16I3ZpMK9Y0Y/Y/wOWn0i4aT9WCBcNe0al8uZ067sMD6cAXOUxTnJj585TNOrOn8ClPGOxIsMqWqVOWst4wVX+qRoWrJVh72amZVJtxmgSwMiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716298246; c=relaxed/simple; bh=v13Dt602tJnaqyKpadsMo9w6iuh3ZNfEnTiEaz+kZIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H6s6xlrL7n9F4cS+ARJ4kX5dxV0Qz0eqSexhZ3mMeSY8PvjZovHClJ25WprQgcboC9Wwvzmjza2vvrUidr+aJzmDnCYmjz/sh4rJgDwhdYIEd0BskV5uOr11GBXbUnH93FTihuV8ONx15FwQU6DPCS4OnRwnSYo63xJBGkeMSJU= 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 DE0D6FEC; Tue, 21 May 2024 06:31:08 -0700 (PDT) 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 2C2AF3F641; Tue, 21 May 2024 06:30:43 -0700 (PDT) From: Ben Gainey To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org Cc: 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, Ben Gainey Subject: [PATCH v6 4/4] tools/perf: Allow inherit + PERF_SAMPLE_READ when opening events Date: Tue, 21 May 2024 14:30:29 +0100 Message-ID: <20240521133029.83654-5-ben.gainey@arm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240521133029.83654-1-ben.gainey@arm.com> References: <20240521133029.83654-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 Content-Transfer-Encoding: 8bit The tool will now default to this new mode if the user specifies a sampling group when not in system-wide mode, and when --no-inherit is not specified. This change updates evsel to allow the combination of inherit and PERF_SAMPLE_READ. A fallback is implemented for kernel versions where this feature is not supported. Signed-off-by: Ben Gainey --- tools/perf/tests/attr/README | 2 + .../tests/attr/test-record-group-sampling | 39 ------------ .../tests/attr/test-record-group-sampling1 | 50 ++++++++++++++++ .../tests/attr/test-record-group-sampling2 | 60 +++++++++++++++++++ tools/perf/tests/attr/test-record-group2 | 9 +-- tools/perf/util/evsel.c | 19 +++++- tools/perf/util/evsel.h | 1 + 7 files changed, 135 insertions(+), 45 deletions(-) delete mode 100644 tools/perf/tests/attr/test-record-group-sampling create mode 100644 tools/perf/tests/attr/test-record-group-sampling1 create mode 100644 tools/perf/tests/attr/test-record-group-sampling2 diff --git a/tools/perf/tests/attr/README b/tools/perf/tests/attr/README index 4066fec7180a8..67c4ca76b85d5 100644 --- a/tools/perf/tests/attr/README +++ b/tools/perf/tests/attr/README @@ -51,6 +51,8 @@ Following tests are defined (with perf commands): perf record --call-graph fp kill (test-record-graph-fp-aarch64) perf record -e '{cycles,instructions}' kill (test-record-group1) perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2) + perf record -e '{cycles,cache-misses}:S' kill (test-record-group-sampling1) + perf record -c 10000 -e '{cycles,cache-misses}:S' kill (test-record-group-sampling2) perf record -D kill (test-record-no-delay) perf record -i kill (test-record-no-inherit) perf record -n kill (test-record-no-samples) diff --git a/tools/perf/tests/attr/test-record-group-sampling b/tools/perf/tests/attr/test-record-group-sampling deleted file mode 100644 index 97e7e64a38f07..0000000000000 --- a/tools/perf/tests/attr/test-record-group-sampling +++ /dev/null @@ -1,39 +0,0 @@ -[config] -command = record -args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 -ret = 1 - -[event-1:base-record] -fd=1 -group_fd=-1 -sample_type=343 -read_format=12|28 -inherit=0 - -[event-2:base-record] -fd=2 -group_fd=1 - -# cache-misses -type=0 -config=3 - -# default | PERF_SAMPLE_READ -sample_type=343 - -# PERF_FORMAT_ID | PERF_FORMAT_GROUP | PERF_FORMAT_LOST -read_format=12|28 -task=0 -mmap=0 -comm=0 -enable_on_exec=0 -disabled=0 - -# inherit is disabled for group sampling -inherit=0 - -# sampling disabled -sample_freq=0 -sample_period=0 -freq=0 -write_backward=0 diff --git a/tools/perf/tests/attr/test-record-group-sampling1 b/tools/perf/tests/attr/test-record-group-sampling1 new file mode 100644 index 0000000000000..9b87306266329 --- /dev/null +++ b/tools/perf/tests/attr/test-record-group-sampling1 @@ -0,0 +1,50 @@ +[config] +command = record +args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 +ret = 1 + +[event-1:base-record] +fd=1 +group_fd=-1 + +# cycles +type=0 +config=0 + +# default | PERF_SAMPLE_READ +sample_type=343 + +# PERF_FORMAT_ID | PERF_FORMAT_GROUP | PERF_FORMAT_LOST | PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING +read_format=28|31 +task=1 +mmap=1 +comm=1 +enable_on_exec=1 +disabled=1 + +# inherit is enabled for group sampling +inherit=1 + +[event-2:base-record] +fd=2 +group_fd=1 + +# cache-misses +type=0 +config=3 + +# default | PERF_SAMPLE_READ +sample_type=343 + +# PERF_FORMAT_ID | PERF_FORMAT_GROUP | PERF_FORMAT_LOST | PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING +read_format=28|31 +task=0 +mmap=0 +comm=0 +enable_on_exec=0 +disabled=0 +freq=0 + +# inherit is enabled for group sampling +inherit=1 + diff --git a/tools/perf/tests/attr/test-record-group-sampling2 b/tools/perf/tests/attr/test-record-group-sampling2 new file mode 100644 index 0000000000000..8e29fc13f6668 --- /dev/null +++ b/tools/perf/tests/attr/test-record-group-sampling2 @@ -0,0 +1,60 @@ +[config] +command = record +args = --no-bpf-event -c 10000 -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 +ret = 1 + +[event-1:base-record] +fd=1 +group_fd=-1 + +# cycles +type=0 +config=0 + +# default | PERF_SAMPLE_READ +sample_type=87 + +# PERF_FORMAT_ID | PERF_FORMAT_GROUP | PERF_FORMAT_LOST | PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING +read_format=28|31 +task=1 +mmap=1 +comm=1 +enable_on_exec=1 +disabled=1 + +# inherit is enabled for group sampling +inherit=1 + +# sampling disabled +sample_freq=0 +sample_period=10000 +freq=0 +write_backward=0 + +[event-2:base-record] +fd=2 +group_fd=1 + +# cache-misses +type=0 +config=3 + +# default | PERF_SAMPLE_READ +sample_type=87 + +# PERF_FORMAT_ID | PERF_FORMAT_GROUP | PERF_FORMAT_LOST | PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING +read_format=28|31 +task=0 +mmap=0 +comm=0 +enable_on_exec=0 +disabled=0 + +# inherit is enabled for group sampling +inherit=1 + +# sampling disabled +sample_freq=0 +sample_period=0 +freq=0 +write_backward=0 diff --git a/tools/perf/tests/attr/test-record-group2 b/tools/perf/tests/attr/test-record-group2 index cebdaa8e64e47..785892a54d9e1 100644 --- a/tools/perf/tests/attr/test-record-group2 +++ b/tools/perf/tests/attr/test-record-group2 @@ -9,8 +9,9 @@ group_fd=-1 config=0|1 sample_period=1234000 sample_type=87 -read_format=12|28 -inherit=0 +read_format=28|31 +disabled=1 +inherit=1 freq=0 [event-2:base-record] @@ -19,9 +20,9 @@ group_fd=1 config=0|1 sample_period=6789000 sample_type=87 -read_format=12|28 +read_format=28|31 disabled=0 -inherit=0 +inherit=1 mmap=0 comm=0 freq=0 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3536404e9447b..557d409c53d6c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1156,7 +1156,15 @@ 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 + SAMPLE_READ requires SAMPLE_TID in the read_format + */ + if (attr->inherit) { + evsel__set_sample_bit(evsel, TID); + evsel->core.attr.read_format |= + PERF_FORMAT_ID; } } @@ -1832,6 +1840,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 +1897,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 517cff431de20..21b8b7e70e75e 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; -- 2.45.1