Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp69007lqo; Wed, 15 May 2024 22:05:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXleu76vDZvr+PV7bfSJYuI2jZH0dqBnW7Diuq6MZv55ZM2cTw6DF48xE65/HEjZ6rYu3dne3q522QHzKcJrE/fcV7VS2d7gnHHGhV3WA== X-Google-Smtp-Source: AGHT+IHVqbSZl+vlaFtqBUYNpJIMDvtYIBmSB7GObZj5Ctiy1TZx0LbHYbdpx+liNq9XNUalQegj X-Received: by 2002:a05:6a20:d493:b0:1af:f497:8230 with SMTP id adf61e73a8af0-1aff4978855mr12056467637.24.1715835912121; Wed, 15 May 2024 22:05:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715835912; cv=pass; d=google.com; s=arc-20160816; b=P8ykT5747vGDJFqC+nveFjRg9lquPWN68zGwjXrVyCrfO4Sz/3tt6zU+TfnIMd1/Yk dTEr4oJPPRhwdshdFdgIoi6qB+VX1LEl/potWd6lBOV38mjYNDNX3230BfF4JzVllZFD QKcQcKpLzY2VJ6hMcohMS4ih0A6iILOSotu+vE9faI/EYcOllWCi/3Svh+cNUvLCJHqI bbiBNbX5qv7BQR/k8NAsgk2WnD6vjuQKKqro9a9eFaFyV2k5ZwQdQ98jxyCCV8S/MeQp AD+0D55hC85R2zkHgEgBrz58ZxDB9niLye72qA44CzXL8Lr17Jnl4TRpfQTzavCJbBGY cCZQ== 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=TQ2BUrI4nA4aMqiJQpw6TRcFQ7FyURr1y+deeKNa2KE=; fh=rjm6qE0ULj5nv1rB3JiGonX4f6kBifcCk0N/QNQMD2U=; b=s5RLnzT9kkyt6pAKKzEc8wpdLNJP9eqgPbBgN6/EOUA/EOdmU9vDi+6FJTvoJ8ADop 6AlTPddgIQdzr9MjNxVjO+LJEmq/zB7yay0d1eYq5jlgfK+p5gcpoH8JaVYUuyHKqz3L NcJzRPgU2dydFomF7fAr8zos098cBTirxS/ICjTpy9p7JX5yY8u7XlkRzBhiHW6ARebm 6GcfOZAUaiRqZ0qdMWeREg5cmAisSJtxLC2nwx/v0VnAEOL2WfbqUB0Vwxq6z5xjgy7b v/odzKKW7nKp6LWXiPTeFvgCVb+sc0MJ+aH06PgkeoTV2SD0F+JAhHwgjLtFeIsMRZRd /Jog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0xJuJhfh; 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-180649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180649-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2aee5c1si15192034b3a.215.2024.05.15.22.05.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 22:05:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180649-linux.lists.archive=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; dkim=pass header.i=@google.com header.s=20230601 header.b=0xJuJhfh; 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-180649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180649-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C678AB220A5 for ; Thu, 16 May 2024 05:05:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E82151CAB4; Thu, 16 May 2024 05:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0xJuJhfh" Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.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 A44BBE57B for ; Thu, 16 May 2024 05:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715835898; cv=none; b=R/QmHJqKEMnXMOufisvzc+n6Y8khCJ0okCQZXgUfEFiC+NVyv7AmoeviI/zZChaXMRGUQ4p8nG9m1K2vZznqBstiVxPCtMPL5cxxBAL9+rzc+ojM12O7+TFliWyPw2k57rhQtZBZ1JAknJ1NJFRFNUQermoV89oArT6yYOrRLeQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715835898; c=relaxed/simple; bh=KsZqB9Nc++1f2JW88Ah8LooOEDUxTd/rxuTVQxTapyI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=UQGlEbmpJ8CETWVptiQZrhGsitr8WE+yJgQMNwrdb/azHzz81tUQiSCzQzMY9IMBiv6PnWg1s1Y7TQnUt1E9oSPRtqo1lnMGJeIj5kc5sAhGFPC5OqnZoBOSPVue7D4t+dnqq9du/dYAOYaCAhSVQoCorIvqdQQFu56GJaN7qlA= 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=0xJuJhfh; arc=none smtp.client-ip=209.85.160.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-qt1-f179.google.com with SMTP id d75a77b69052e-43df9ac3ebcso2405101cf.0 for ; Wed, 15 May 2024 22:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715835895; x=1716440695; 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=TQ2BUrI4nA4aMqiJQpw6TRcFQ7FyURr1y+deeKNa2KE=; b=0xJuJhfhO10M8YW1sfgMSZe9zjaPoYMLSCr0kyavNp9OxDnH55jRV8gq4OwVDTtzVV S7v5QKMTNqJetuu3g7WAFO459906V/VJ+6VTJQvtbH8GtJ1DstCu2voPddvpBk8iSA82 xRt/zIIVFL3QHF3fRzovud6m+OUiravriNRCswoAI/9JcphQC4PrMKjbmouBagUeBhoE yMKovw5KXj8iM+3tw6jTy83lx/wKbiRNhg5qs2T0zxYsRIvz11LLEwA3n8V7Rod8btZE g3IhAz7uo+WwBZaZ5eUi6kVnSCKX7N/Ed/sPAyx9qBhVhbFrQDK9kBxGFCJWiO8T/x7G z4Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715835895; x=1716440695; 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=TQ2BUrI4nA4aMqiJQpw6TRcFQ7FyURr1y+deeKNa2KE=; b=ePGIo6aAX4kGOa1kPmVZs2fbqXZJUk5ABokomzaNkkRWlEyg/ushh3xO8t9V/eM596 5OLYNxvQ8zjmtaOP3TdlipwGUTWlLl6diD94xVgfMmiUhWUwU9SS1zIiKNykh/fjVECz hze2YX1YNJmyGTXcgfQwlr2R9ga+3dzwlukFCFaU1oytqC2L15Rk6i/ZZtiN3EqhY94W 2PoDPxeTxZOQBV5xrsMzzvvfIxTi4uYb6GNkwYYi/MYPnsPmLj2p1FcIi8vMEcxrUUGG tj0m4ZX9mJ7ZMA6fpZce62Ythhqk3SsKZ2Gg8gCxwODITgqDIPQ7J4IZaBS/kydMOZvA qXFQ== X-Forwarded-Encrypted: i=1; AJvYcCUjNxUr8vN03YkLYOf3A4fS1Tkn9XL6A/z8ERPLPHbFltJWcZDP+G4S1QBr65aQs2Ee+pw7gu/hdxnEkOiD3McJYuDRYjYS3jrGKt4L X-Gm-Message-State: AOJu0Yxmca9lp5v51tPzdX1zKT4718nL129vTtwAq30pD31uOHD1QRrl PbRPcZJ3/mmPLTNF3wRjnGvWHXASuBodyNbZOPtWFHwIUAdJnpMthOyVZZ6KnI8w+oRD6p4AY8w KM439rLlVr0k6QIX3Q5waj24bNx20jmTQoGNg X-Received: by 2002:a05:622a:7e0a:b0:43e:a94:c1c9 with SMTP id d75a77b69052e-43e0a94c28dmr12178511cf.20.1715835895129; Wed, 15 May 2024 22:04:55 -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: <20240516041948.3546553-1-irogers@google.com> From: Ian Rogers Date: Wed, 15 May 2024 22:04:43 -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 9:20=E2=80=AFPM Ian Rogers wro= te: > > 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, this = 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. 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 >