Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp447500lqo; Thu, 16 May 2024 10:34:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV7RbjeJzQHMpFn9IO8tyGcyOgzKZyo6JNI0Zxtj1tdF7Vg49C4zb6BW93GIZ3nL57ILRoWJTQk8oa70/J9Z+f6eJE0ePs4dfbNASl5Og== X-Google-Smtp-Source: AGHT+IFqhqi+1ZaDNJ1yNdS7uG9tQqU3QPPEzPF6g2oHtIgu/g0Fv4GDm45IAqNfwk8N2Kbav+dz X-Received: by 2002:a17:90a:c02:b0:2b9:ae40:1098 with SMTP id 98e67ed59e1d1-2b9ae40122fmr7769943a91.40.1715880871144; Thu, 16 May 2024 10:34:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715880871; cv=pass; d=google.com; s=arc-20160816; b=i2V1xl1tz75JvNMPVhamz5P42fED7/m1ULuKGzu6pnOr1kWQwdV7So52crxep8Kiop U0uqSI0+f6pIO5SvoizrXa0xnoFI9AeGkXR4w429jqmVcJmgsc45tZhUq29SC4ZhQcya gsW6Tj891psYDduILULqlKtDauAvjJlnk0zD3/H29zzDkc8rtqKx8ChgpFIwJQk0BmEM XGWeL5ZJOVC1sHrJFW0RHXnQ891UjLVf123JOcTKwBErAXBiyOa2t6cCKFx8WLEvWVxF 5cvbfanaoGqiUBu3O0dB7vvxLRly7SXzHPyR2wwg1XKtbegeCHCOvCcVh1VtoVgID1IV uhxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=W5xOVdSKQxj3bC4Jw56jvdbDAorrHCwMBywGdman4qs=; fh=NIrSd0THhi97F/Elw/eMaVWxBY7C8wua5n65PZeWxrs=; b=W+IqlAYmuS8XNHwpTSgb1hQe0hXzn7n9gjCNIdmlbL0465bmUMnVbh0HIuxZ7DAvd7 vG3NZ/yU7yWfjfbHdeLtQ4i7UtUaZMvrbAudmctUxggrtZntI3sK4h/xm/9Qa7vRhLp2 JpXbwd9qBZY+WmoOy+OjmwWnntySp9rg+yY8OdhI5/dUgwdWuFgfPxkcPruQhglTjY4H /jFBZVqVuN/bTGgD3BqO28L4dC0eZsMtXVaDQiuw/lkHl7AM0as6EXyjAwjH/W+M8L2u bOgDvEVfPj9QsG77gHmsfwtAacDAzt1ZGudj84qAeIyKdrWmbLNGOpY3kLEp7Qbv/Mk2 eY0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="iOZ+7PC/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-181373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b6c51b362bsi14892357a91.14.2024.05.16.10.34.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 10:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181373-linux.lists.archive=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; dkim=pass header.i=@google.com header.s=20230601 header.b="iOZ+7PC/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-181373-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 B0E28281B0A for ; Thu, 16 May 2024 17:34:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3691E15696F; Thu, 16 May 2024 17:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iOZ+7PC/" Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 394871553BD for ; Thu, 16 May 2024 17:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715880861; cv=none; b=NH9UUtlN1wo8iEBtyOP2wAXcsrcB4V3DGzmP+0XUNGL0AHQSxE61U9g7e8VaQ47jpk7vn1bK67JMCaPKwCgbayRpmo76JdhqxjyOBv08q+z7vEdXdl3QphK6qvvlTCc3d2OnK4WtqptC9sfR7pKRfXT63lAfE8d9MNeCAoeXWvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715880861; c=relaxed/simple; bh=DQzUrR+dgEZ4KhK9ztnpAP2CVSJ041lYtvQDEgYT9OM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=qIhKerUt5/csUYCRzaJSQc5hx+/glkMnRVz+e0GYzNtZG7jP9MhF3rIKd0d+rMj58bqzx57t4Xg2rGpxnhHW49qb9OxaqMRTQ3IRVphQPab64SABoC7S+qgnJFuH1ZYA4wxbnUpH6MyLnVzEy8tGcU1KZK4rlv9jtSUyDGfVeU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iOZ+7PC/; arc=none smtp.client-ip=209.85.166.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-36db863679bso6715ab.1 for ; Thu, 16 May 2024 10:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715880858; x=1716485658; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=W5xOVdSKQxj3bC4Jw56jvdbDAorrHCwMBywGdman4qs=; b=iOZ+7PC/CpK9o+u00tUzrosnQbm/sm4DhuNKyk+8AUqz0k6gvAs9GslvPpMsJB+2RB RGT42GZixX6E5GN2yQRi6bCVjk+q0tMk6elqjjRPZDijZGV42pCBY4OkwvjTTlYGwS63 4pEpK21zGvrJCPOguFFMNxz5fDfnlt4ssx3muFIxBDCjXwxjJyUcpbrJAhUla+6In2Kc FyUBu9Nw+tuRD2LezG8vUQajNWfToMms3hv9yGZqbaxRySlsXCFf0nRzk2nXRd78Z2wX NI0siX0P4XWtZZEsjWJlS9gH+R0Zh8n5guzAWspzSzGDVpbTbtziJWVsZYAt52qhq3EO WwVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715880858; x=1716485658; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W5xOVdSKQxj3bC4Jw56jvdbDAorrHCwMBywGdman4qs=; b=QcRJup/UVoWR1UgRUR2Gz+t2VTI4UO9puYeucNFveMTkUwvkfnCoHdU3vnfP5+wHmK ugDWvs8225z4pB6kIc5r6BkZPaspWXElXpxpMLLXySvtXSdwaWiU9c+vV88XJI0tBRHT TSNQacp9CMjrr76Zgj1KUns+wyd/y+nB2d4guxrNmL9HpIo4Y3dOywLAXlXynHziNbDU 1N0ktjWKDdMWG5BOOIqV4GR9/gncwnXbXV+yE6Aal8ispl8J5REnP8obFXsbxJXLirCY DhiyJOmsnA1kDxRfxHnDTE0lth/WE658UCwnF4ZXyQhs/1zgw0szxOCtDGr8vl6+hK91 ht4Q== X-Forwarded-Encrypted: i=1; AJvYcCW3Cxf6YE5gvTNWp0ASNAh0DlmBgf4shfAQgjHAu9FSc+UHT63G2J83o1J/zsG7CLSeGyE0fkGwqNDzPTxSPA9hucfH68fm3mahVzV/ X-Gm-Message-State: AOJu0Yxy2kXIaehIpsywFP6pqZnHNEtTOPzxFc78fzIe9kdKyb6JkBql 4t+9KS9ROWtsLDBwXRdpKYtytDH6QX9PVgUdI3WGByX8psjhkLcL3PRXo3Xmq+U41DIuF4vkktb HF1Oq/K5S5P6h8XpSx3gxyjF99ozCeU6T4H9Z X-Received: by 2002:a92:c264:0:b0:36d:959b:fb5e with SMTP id e9e14a558f8ab-36d959bfc0bmr11900255ab.21.1715880857923; Thu, 16 May 2024 10:34:17 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240516041948.3546553-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Thu, 16 May 2024 10:34:06 -0700 Message-ID: Subject: Re: [PATCH v1 0/3] Use BPF filters for a "perf top -u" workaround To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Changbin Du , John Fastabend , Andrii Nakryiko , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 15, 2024 at 10:04=E2=80=AFPM Ian Rogers wr= ote: > > On Wed, May 15, 2024 at 9:20=E2=80=AFPM Ian Rogers w= rote: > > > > Allow uid and gid to be terms in BPF filters by first breaking the > > connection between filter terms and PERF_SAMPLE_xx values. Calculate > > the uid and gid using the bpf_get_current_uid_gid helper, rather than > > from a value in the sample. Allow filters to be passed to perf top, thi= s allows: > > > > $ perf top -e cycles:P --filter "uid =3D=3D $(id -u)" > > > > to work as a "perf top -u" workaround, as "perf top -u" usually fails > > due to processes/threads terminating between the /proc scan and the > > perf_event_open. > > Fwiw, something I noticed playing around with this (my workload was > `perf test -w noploop 100000` as different users) is that old samples > appeared to linger around making terminated processes still appear in > the top list. My guess is that there aren't other samples showing up > and pushing the old sample events out of the ring buffers due to the > filter. This can look quite odd and I don't know if we have a way to > improve upon it, flush the ring buffers, histograms, etc. It appears > to be a latent `perf top` issue that you could encounter on other low > frequency events, but I thought I'd mention it anyway. Some other thoughts: - It is kind of annoying with the --filter option (either on top or record) that there first needs to be an event to filter on. It'd be nice if we could just filter the default event. - Should "perf top --uid=3D1234" be removed or turned into an alias for '--filter "uid =3D=3D $(id -u)"' given the --uid option generally doesn't work? - What should happen to the perf top --pid and --tid options, should they be filters? Should they fallback on /proc scanning if there aren't sufficient BPF permissions? The plumbing for that is going to be messy. - There should probably be a way to filter on cgroups. - Does the user care that there are 3 kinds of filter that will work differently? Could we break them apart to make it more explicit, I may want tracepoint events with a BPF filter. How can we ensure 1 syntax for the 3 kinds of filter. - Filtering on register values could be potentially interesting, for example, sampling on memcpy-s where the length is over a threshold. We have a register capture test: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tr= ee/tools/perf/tests/shell/record.sh#n81 Perhaps the filter could look something like 'perf record -g -e mem:$ADDRESS_OF_MEMCPY:x --filter "reg:rdx > 1024"' - this makes me think we need to make a more convenient way to specify memory addresses as symbols. Thanks, Ian > > > Ian Rogers (3): > > perf bpf filter: Give terms their own enum > > perf bpf filter: Add uid and gid terms > > perf top: Allow filters on events > > > > tools/perf/Documentation/perf-record.txt | 2 +- > > tools/perf/Documentation/perf-top.txt | 4 ++ > > tools/perf/builtin-top.c | 9 +++ > > tools/perf/util/bpf-filter.c | 55 ++++++++++++---- > > tools/perf/util/bpf-filter.h | 5 +- > > tools/perf/util/bpf-filter.l | 66 +++++++++---------- > > tools/perf/util/bpf-filter.y | 7 +- > > tools/perf/util/bpf_skel/sample-filter.h | 27 +++++++- > > tools/perf/util/bpf_skel/sample_filter.bpf.c | 67 +++++++++++++++----- > > 9 files changed, 172 insertions(+), 70 deletions(-) > > > > -- > > 2.45.0.rc1.225.g2a3ae87e7f-goog > >