Message ID | 20230112214015.1014857-1-namhyung@kernel.org |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4121990wrt; Thu, 12 Jan 2023 13:51:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXtrD234WCS3Gy3J9vJp4cBjkDrZbaYWuxyoy7rAiP/kB8/FkzS6sqhvFceHNuDwR2eGf4bl X-Received: by 2002:a05:6a20:ce07:b0:af:ee05:fd0b with SMTP id ic7-20020a056a20ce0700b000afee05fd0bmr72617664pzb.3.1673560269900; Thu, 12 Jan 2023 13:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673560269; cv=none; d=google.com; s=arc-20160816; b=ji+q9ANVe44zouuFc4BlEA3YV7RpcsDdEMWhvhdZ/kJ8Io8vw78FC40Bcr0FD8j4VE sASiPDQueyrV46+YhIMghkzZIGrlwXmT/MT821+jpEuxDNomgfdvXl0Yra8P3ZfV/Lwn Pgn34Ik9r+taw9h3ATPh8a/31yieoPhxYmMMlCFenxYoVvVsXYm51oVkOxCyYo0sP7Sj Lgo92h0QYOdgp1R9thqLCXbHi44amXYY+XJBcKKIvpZMrrKEvKl352B0IIJkNg9imm7i DciilzS/64s/oCtBcFQe9xbQYDo+QM3BIlzfOMeHHvc9vg1gWMg8lwZ5YelVqNMRixah MAvQ== 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=sjVq4tOXJZ8sec8ReYRUdXeaFGuoHuExrBPraEOekVg=; b=hOx3UUZM2zveDaixyNjC+SCDjjnKWYn5bbkb7Y+fV0OCso9WXwYo0BC2UM7pXs7NAu q1vHNsVKdQyHv8U+8iKF8maXnc7Y3u7LkYPGnO4djpHHKpZ/VOzYK0RvrL6rIoeJ8b8P YE87tcRaSW49vbnqwVDsalg1gDXS1RvwZBkMvL5EQCd4wX+C2ib334zB8++Kopo/6Izk EOtKRSRp6K2O29jkG2orMYgSPMhB+70QTTvNqQ1H/R3xDLkO8JrB8RHxdvnzqVg/F57Z TORbReD4A9RZ5iBS88uhQfMUoyLHUT9LzTi6Iqxo4ZmKkPZ19PB2hswZWvD8aQ9koXCa 38SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSU2EKc6; 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 24-20020a631258000000b004b397afc343si6728960pgs.174.2023.01.12.13.50.53; Thu, 12 Jan 2023 13:51:09 -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=bSU2EKc6; 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 S239485AbjALVsM (ORCPT <rfc822;zhuangel570@gmail.com> + 99 others); Thu, 12 Jan 2023 16:48:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbjALVrd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 12 Jan 2023 16:47:33 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200706DBAE; Thu, 12 Jan 2023 13:40:20 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id a184so14781334pfa.9; Thu, 12 Jan 2023 13:40:20 -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=sjVq4tOXJZ8sec8ReYRUdXeaFGuoHuExrBPraEOekVg=; b=bSU2EKc6Nr9oWX+e8xzlaIbJFz7XQWYkYddZ7psGxBUWPGc2nEQB9Hai+qcGJgRmBB UWQK0lpVpEbFsXZpoTJLtyP6ZQw5JIqI+d0gEnVVcY0a7Ibot7u0EwvzCxXKRZ/Jxfhj 1sVAsOsoQ4U9wdOEKZXYhk2Y/SYDyq4v2TvGUQy83+w5uUK67GAqNXEF3wi5YV3Pl0bN liUo6YCIwDhqk79JFb0mFNsQ4taDMFDg2og1Qwn/tC7u65ve6bimsjwZQW62tRZOg4X5 8T5iYpXOgnE+dytf2wxLDwVOylvER+HGxUFeLISeWNAurtK+ydvtDTamWoitAyjdy3Br 5urg== 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=sjVq4tOXJZ8sec8ReYRUdXeaFGuoHuExrBPraEOekVg=; b=j/zxvH2QyNzSQNBuv6oFs6Uy9s6U6KnXFRe+DnI5xZ52ka9OYxi/+LxG5lbMdmEugi oBC2p+0bX9LkvFu2UC7U2oSY3fd/t0u3TKmm+uS4rll6eUCFaxOi30NYfR+z0erLUn4h vP95N65hPVH3wByouZ6KNoJkaKf4a3Z65Izdb5INggZXfVWvJlQSFRHaTcmzkaKmLxWK POU5w1UjUSfwpc6/WburYgW7SyjfaYoFBUZdrU1dzAcnYpFpiXDJjq/yOQ81JYa4OP9L J0qMwz3NObigHCuGlyUVcdldPeAgGW/8KSHhq+uIdIYKOtFny5eSRix79kP+ui6TUWXr 2gYg== X-Gm-Message-State: AFqh2kqZbIUxKdJd1ZrIT9fnUgcRVzCXKbXkPEAv1wktsAAFsQ7gAE+8 ZYvwIqFGSiBKQbaiss52u2fRaENHPTo= X-Received: by 2002:a05:6a00:f92:b0:582:a224:e740 with SMTP id ct18-20020a056a000f9200b00582a224e740mr37411596pfb.27.1673559619300; Thu, 12 Jan 2023 13:40:19 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:b71e:23d4:aa6a:47c0]) by smtp.gmail.com with ESMTPSA id q20-20020aa79834000000b0058134d2df41sm11344605pfl.146.2023.01.12.13.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 13:40:18 -0800 (PST) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@kernel.org>, 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 Date: Thu, 12 Jan 2023 13:40:07 -0800 Message-Id: <20230112214015.1014857-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.7 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?1754855133495333140?= X-GMAIL-MSGID: =?utf-8?q?1754855133495333140?= |
Series |
perf/core: Prepare sample data for BPF
|
|
Message
Namhyung Kim
Jan. 12, 2023, 9:40 p.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 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-v2' 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 Thu, Jan 12, 2023 at 01:40:07PM -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 Aside from a few small niggles, this looks really good, Thanks!
On Thu, Jan 12, 2023 at 01:40:07PM -0800, Namhyung Kim wrote: > 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 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-v2' 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 lgtm, I ran the bpf selftests on top of that and it's ok jirka > > 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 > -- > 2.39.0.314.g84b9a713c41-goog >
Hi Jiri, On Fri, Jan 13, 2023 at 5:26 AM Jiri Olsa <olsajiri@gmail.com> wrote: > > On Thu, Jan 12, 2023 at 01:40:07PM -0800, Namhyung Kim wrote: > > 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 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-v2' 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 > > lgtm, I ran the bpf selftests on top of that and it's ok Thanks for your review. I'll add your Acked-by and Tested-by in the v3. :) Thanks, Namhyung