Message ID | 20230118060559.615653-1-namhyung@kernel.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2171272wrn; Tue, 17 Jan 2023 22:22:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXtLR3nkObfxlqUPdw6qzlWupQ/Gjf1H3CG+Su5ChyXsoPqpaQrMRYbb842QfFbvlJJkQliv X-Received: by 2002:a05:6a20:c705:b0:b8:827c:42c0 with SMTP id hi5-20020a056a20c70500b000b8827c42c0mr5360839pzb.61.1674022969073; Tue, 17 Jan 2023 22:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674022969; cv=none; d=google.com; s=arc-20160816; b=AcKzkYs1Xx0DBDq35FJZmy4Q6PFMt+YVipG7IdlYGFek7P+EtxQul2XUNc8TF1sap2 zydBp1hVpGZWQvIBt8r5nMtG/m0qmoAqgFwCcPz3fc1FFBCabg0497E+4VbI57oae8N8 y1FTpMIKD3cbz9qyPQjXL7+WAN71hfvdE3eWZxsIiU+6x7NeGDNxq3KRVsvSQivEOc7p H9R/PGATDugP+C35czeA7f/3rRGYkKruM7cCsNR9TpEO/zPmrurnog8DIo/uU+IJz+ne FdEVLaYRtjrARDpEzo11FiqyU+4+uin9GMiM8u5KVZVxfUVSDTdKzQIP4ZJ8Sx0TQY14 muNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=AJM2l+mABefkfyEbBF+RzKX6IR1PByT45QHpW0h3qe4=; b=YeeRAN6zy7pjhCi4x2HbwcM6FlW5Py5xdVXF8ugfoztVLJVgFOziNjg/yc9tm6soiT y3L4H6HnjhJ2ksuY7gBmCaIchYgve4Au76bQ9FAnugsX1wdYL5pQJL3dsUwFrZeQFO67 xiv9kO39FIzDdBNFAkSPxcKxGZT6kEETuIhTsYDKUI0tivdMjS+XpO5AQ6fiz1FJj9am StZGlHCRdNi/KrJISukSIk7M3DBKB3Ftve7PedMeX4kV6JE5fzSK0GRG6rMux6vYDqTx SAv0A5IIM2Ar9r70uND/jxRbJ8zzEHP7hYIl+11UIV5X9fOWC9R37pL4/0s7d5GeCBdo 6AiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Uk9EEPHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a056a000cd300b0058dc5ec09d4si4970222pfv.350.2023.01.17.22.22.36; Tue, 17 Jan 2023 22:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Uk9EEPHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbjARGVu (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Wed, 18 Jan 2023 01:21:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjARGSR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 18 Jan 2023 01:18:17 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86DA9193DE; Tue, 17 Jan 2023 22:06:03 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id d10so23711138pgm.13; Tue, 17 Jan 2023 22:06:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=AJM2l+mABefkfyEbBF+RzKX6IR1PByT45QHpW0h3qe4=; b=Uk9EEPHa9abUvjhRIQIWoxZOrA4S++vJR7Iml2l67ItI4NgzfFUOz1vV9Q63tFOjUm +QDRMwrVP7wbKL/UfKcz0XLrcmk5e32iTNT/I5grbXwJRvkLJnjCkYa+PrzAHHaIocjd uUtNOfaBvIUfMoTHFl8A7zTRslSf2vZPGjD9ijvZhaiqU66TeOxuFwSDxa+rlMS1wewi V4d0JUaeSZU9li9O4KdejcCLA88DVAhh4Vrp06iPXC/A3UOgbKQXznTgqh+4Cnz3z4Am iFtYE6EqMhZVXjwXvbIkYL/14mJS/XVDjY1S4HOxTFH+WMiR6KemWXi6zvzOhN53dQSV 59+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AJM2l+mABefkfyEbBF+RzKX6IR1PByT45QHpW0h3qe4=; b=2BMNowzCbHzbQC4fZS2fhgVVmQnGKRy0lHmlcs1NGnksJMMIiXcCHU9F1iFwQg3M2Y 6ITpS0HDIx9s+q0r1J1v/hYr16zvr+QaCLnlUSPFxe0fgxhz92ixBI4tI1za5FtqrXzs Pm0lCphsi2+DOY/snZ4mhBbPwVEnH6Nx79BnBWOwIZHlCtidAUM3jqtu03dnR8YybIZF /B7vw9/eyYF1iGmyFIHK+vZJKcfNx8K9Qe1H6MzFhBr/UbWBI4dXbJo3rsXpWmNLKkGL YRjTEJMsXO0rkE42FSZj12aLPG57/RriHjctZz5qXSQm0rSASKXvp6tMNuEH07peOzRY 6aag== X-Gm-Message-State: AFqh2kpN9ez7JgRRVNLFLeGC2+V9HKB51HLfmd/Ymmx/ovPgJpBuyTKt mus8L1BOICciQJhrobWJJwU= X-Received: by 2002:a05:6a00:180d:b0:58d:c694:9a9e with SMTP id y13-20020a056a00180d00b0058dc6949a9emr7449718pfa.18.1674021960598; Tue, 17 Jan 2023 22:06:00 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:ff0:3749:9eb3:dfb5:f449]) by smtp.gmail.com with ESMTPSA id b126-20020a62cf84000000b00574e84ed847sm10990180pfg.24.2023.01.17.22.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 22:06:00 -0800 (PST) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>, Song Liu <song@kernel.org>, bpf@vger.kernel.org Subject: [PATCHSET 0/8] perf/core: Prepare sample data for BPF (v3) Date: Tue, 17 Jan 2023 22:05:51 -0800 Message-Id: <20230118060559.615653-1-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755340308843024852?= X-GMAIL-MSGID: =?utf-8?q?1755340308843024852?= |
Series |
perf/core: Prepare sample data for BPF (v3)
|
|
Message
Namhyung Kim
Jan. 18, 2023, 6:05 a.m. UTC
Hello, The perf_prepare_sample() is to fill the perf sample data and update the header info before sending it to the ring buffer. But we want to use it for BPF overflow handler so that it can access the sample data to filter relevant ones. Changes in v3) * update data->sample_flags in __perf_event_header__init_id() (PeterZ) * add Acked-by's from Jiri and Song Changes in v2) * the layout change is merged * reduce branches using __cond_set (PeterZ) * add helpers to set dynamic sample data (PeterZ) * introduce perf_prepare_header() (PeterZ) * call perf_prepare_sample() before bpf_overflow_handler unconditionally This means the perf_prepare_handler() can be called more than once. To avoid duplicate work, use the data->sample_flags and save the data size. I also added a few of helpers to set those information accordingly. But it looks some fields like REGS_USER, STACK_USER and AUX are saved in the perf_prepare_sample() so I didn't add the helpers for them. After than we can just check the filtered_sample_type flags begin zero to determine if it has more work. In that case, it needs to update the data->type since it's possible to miss when PMU driver sets all required sample flags before calling perf_prepare_sample(). The code is also available at 'perf/prepare-sample-v3' branch in git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git Thanks, Namhyung Cc: Song Liu <song@kernel.org> Cc: bpf@vger.kernel.org Namhyung Kim (8): perf/core: Save the dynamic parts of sample data size perf/core: Add perf_sample_save_callchain() helper perf/core: Add perf_sample_save_raw_data() helper perf/core: Add perf_sample_save_brstack() helper perf/core: Set data->sample_flags in perf_prepare_sample() perf/core: Do not pass header for sample id init perf/core: Introduce perf_prepare_header() perf/core: Call perf_prepare_sample() before running BPF arch/powerpc/perf/core-book3s.c | 3 +- arch/s390/kernel/perf_cpum_cf.c | 4 +- arch/s390/kernel/perf_cpum_sf.c | 3 +- arch/s390/kernel/perf_pai_crypto.c | 4 +- arch/s390/kernel/perf_pai_ext.c | 4 +- arch/x86/events/amd/core.c | 6 +- arch/x86/events/amd/ibs.c | 9 +- arch/x86/events/intel/core.c | 6 +- arch/x86/events/intel/ds.c | 24 ++-- include/linux/perf_event.h | 133 +++++++++++++----- kernel/events/core.c | 207 ++++++++++++++++------------- kernel/trace/bpf_trace.c | 6 +- 12 files changed, 236 insertions(+), 173 deletions(-) base-commit: 9fcad995c6c52cc9791f7ee9f1386a5684055f9c
Comments
On Tue, Jan 17, 2023 at 10:05:51PM -0800, Namhyung Kim wrote: > Namhyung Kim (8): > perf/core: Save the dynamic parts of sample data size > perf/core: Add perf_sample_save_callchain() helper > perf/core: Add perf_sample_save_raw_data() helper > perf/core: Add perf_sample_save_brstack() helper > perf/core: Set data->sample_flags in perf_prepare_sample() > perf/core: Do not pass header for sample id init > perf/core: Introduce perf_prepare_header() > perf/core: Call perf_prepare_sample() before running BPF Thanks!, Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
On Wed, Jan 18, 2023 at 11:50:37AM +0100, Peter Zijlstra wrote: > On Tue, Jan 17, 2023 at 10:05:51PM -0800, Namhyung Kim wrote: > > Namhyung Kim (8): > > perf/core: Save the dynamic parts of sample data size > > perf/core: Add perf_sample_save_callchain() helper > > perf/core: Add perf_sample_save_raw_data() helper > > perf/core: Add perf_sample_save_brstack() helper > > perf/core: Set data->sample_flags in perf_prepare_sample() > > perf/core: Do not pass header for sample id init > > perf/core: Introduce perf_prepare_header() > > perf/core: Call perf_prepare_sample() before running BPF > > Thanks!, > > Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Thanks Peter. The patches look good to me as well. How do you want to route them bpf-next or tip ? Namhyung, I'd also like to see a follow up patch with a selftest/bpf for this. BPF CI didn't have a chance to really test the set, since there is a build issue on s390 due to llvm upstream repo. We're aware and working on that.
Hi Alexei, On Wed, Jan 18, 2023 at 11:43 AM Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > On Wed, Jan 18, 2023 at 11:50:37AM +0100, Peter Zijlstra wrote: > > On Tue, Jan 17, 2023 at 10:05:51PM -0800, Namhyung Kim wrote: > > > Namhyung Kim (8): > > > perf/core: Save the dynamic parts of sample data size > > > perf/core: Add perf_sample_save_callchain() helper > > > perf/core: Add perf_sample_save_raw_data() helper > > > perf/core: Add perf_sample_save_brstack() helper > > > perf/core: Set data->sample_flags in perf_prepare_sample() > > > perf/core: Do not pass header for sample id init > > > perf/core: Introduce perf_prepare_header() > > > perf/core: Call perf_prepare_sample() before running BPF > > > > Thanks!, > > > > Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> > > Thanks Peter. > The patches look good to me as well. > How do you want to route them bpf-next or tip ? > > Namhyung, > I'd also like to see a follow up patch with a selftest/bpf for this. > > BPF CI didn't have a chance to really test the set, since > there is a build issue on s390 due to llvm upstream repo. > We're aware and working on that. Yep, I'll add a test case as soon as it gets the change. Thanks, Namhyung