Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2792104lqo; Mon, 20 May 2024 18:05:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTvYjOPuL4h7XGvETM90+8S3bEE9MQA8cDUojfFSd22V2l142ZWMs21xn+tvuF+yZ9Bb3m25NPB1HX55nCdCT2hVJgi4myRrKN0xsDfA== X-Google-Smtp-Source: AGHT+IFcCLS8S5XGGgg+iiB00p0nrY7VaEXD+LWh8e4cc1QTJPafev0Vovsl7pJPnKoVNr+Rx3FT X-Received: by 2002:a05:6102:cc6:b0:485:ea9f:8a28 with SMTP id ada2fe7eead31-485ea9f8d9amr13745353137.15.1716253500485; Mon, 20 May 2024 18:05:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716253500; cv=pass; d=google.com; s=arc-20160816; b=Y3vr9nDUcKl9c7S0p2+EaI4UpmK6i0CPx1ruWm4Q3KGb3r1is3yN/AOp2IsMD4dSBf he2UvXB+vzBKxltoZGMvLSgY6DgevNg1Vy/syqe7djdT1/v7o+8byWJmEwzqNbSuVHFS Z9VjtW1o3jrckX01tVbtI4OzQTt+9Ilbgj2kZ0+1smysUbeFfSqhGdX2TIc7tSc9g8Xf RPaeUnuoaGAl00jJxOkXjQN9wJcpHapxbAdDxak4YzmESvSFAEDm/oglTFKxLdMr1HEB +skk00iXRk5vFvMKNPp+hrxOQZQynhikwKgAebFuKWiUSVx1t3vJaSFqW7OyXuoRnyyt T4Zw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=qpOLP0XnzrTQf20d05HSRvs4OM1Ncix8hyKknNTHteQ=; fh=xMYCzn6NYJqLUaRTbZFkePrLWuIvwmfaqQ94krTYT4Y=; b=L8bp4nQM1P38QmSYiYP0Gw97SpCutOxim3Nq0SWtvl0n2b2pT3a60zSWUR9BVKyED+ fqjtW8+qlx4TJunxOyo9hSo/wlG2S57n2a8KJQoyJiPohtDhtEjTC8VA8J5JoUCFzFEs FkiN3ohWShT0kf0tOPpW6+eQUp7PH6xHn5eQkDi5f9w2o2jJbDtFwiomaysauzoqhDA9 zS7RdzmOz3c+8ubviYnU+UHANcHDfYFJXeHhY5gKxo/YuaUm7OH6L7DTYBruBiQupojc NWtCTtcstJJLx57IO8xCeHW5fz0T5ZKhIZ8NJKvJOwZJsjB4MAupZqzGmygqR+lI0M3G 0gyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=clp322AP; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-184334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2b7168si9479676d6.392.2024.05.20.18.05.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 18:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=clp322AP; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-184334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184334-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2CA9A1C21692 for ; Tue, 21 May 2024 01:05:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B1D2A92F; Tue, 21 May 2024 01:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="clp322AP" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 132907F for ; Tue, 21 May 2024 01:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716253493; cv=none; b=V0zsbOtErTeMEYUbCCCE8Imj8trqxXOqS/ygq21fsyY7qFeloMmQ0ko7Soh9buk5G2UJpuLBR6rxCJxZ6zS1s1xTd7ToUsRqGQnWe8Y/iIOx3NBuuM9STIcXSXMhDx3FS5J6d6C/5inewuCxsBou/CIA/fh3Wm0VvAC86gT1/RE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716253493; c=relaxed/simple; bh=HnZOyTLA1z7HGjFiTaimfVCHoyCYiv6gxIK1l/WLd9c=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=bh/CUognetbl1yIF/N2PDqBxGIHj3IgQ37Ts+3VT0FC5yTUyidXphO+Qsh1l2ANwDdfLhMvooHUJ/6vWZLgk5COK0Y1BNaUlcZTQUMwvOwUYqs/kvDfH3fnWmzx68Jm3hWyVIinRXZGmKmTQaS+r7nCFOl/FZNPEJmPC5qW3bGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=clp322AP; arc=none smtp.client-ip=209.85.128.201 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=flex--irogers.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6202fd268c1so220343337b3.2 for ; Mon, 20 May 2024 18:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716253491; x=1716858291; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=qpOLP0XnzrTQf20d05HSRvs4OM1Ncix8hyKknNTHteQ=; b=clp322APGH01SehhXEomMqOXDsUBlV6LzkR909b/LG8TnlVmQEEo0d/q4XoQV/UcRd NI6q9shi93Gg4LvAfTMCTlGnZjdej2Y3WUbP6vEbJ0Twq7mnkfJs0c2MdMWqBiqwTMy0 YibS5OYcVH7V9qvruf7e5BmdjqNfTuytX9mDhfTNOo03vyiVcKDA6/ggKpJxzwAHpJhT 9J2ItzI2Om2OR+/NFgsuFoBWxeAvvOEKJcylOYBatDtFBWOZeXtAHKRBn8CzBbVVVu37 za0huhStK95cGnKTpVW5nYYK75uNLGswQOLfg0BjGDCoDE3tbwkhbZKcdBAamaxqLdiM y29g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716253491; x=1716858291; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qpOLP0XnzrTQf20d05HSRvs4OM1Ncix8hyKknNTHteQ=; b=c+czjIxb9ZyiJIYIbmccweUtlzEE7aunGzjLazX4vkO5oAm8XWAAxssGpQJQtv3yhh 0DPjw/H7awwc1Y9FeCszURBVJiljnoRQk+EGI6vFWaL+Pcwc520cin3S9+vf226xY1js Q6arrb/cpON9z5SPSf3BNOMIvO7b6cyqwaR8HszsgNIOj8kC16wwJ9X1BTl+rvgURa2v prlpd1wn5HsdhaW4+e//WVruGbmpq7Kk9fOxTGepBjmklxG6/pE4RebuykYiky1dV9f6 1k37t+5Smq2aTtBhboRlcJHS3qsw2hlCNpg7+SH5bsMeG19/qqbhJ0Gb9/fFwdiGZiXZ Bo0w== X-Forwarded-Encrypted: i=1; AJvYcCWqrx5r28OKyvMzr/V72wimqozhZwlDit/0D2cQBevZP+ELI4jBpSo68cBirzY8zw1MIwPVeER7vmBZGMphSVw4IeTLETwkIV9YgxQN X-Gm-Message-State: AOJu0YwSlupmUeWMW65l4WXzi9uysognxrDImAKHgFL0d32e3mKd97Q8 MLw0a6wM+nUmm2vuzV7N0nsNEeUXf8/NG3h/dHOf3hSBsykZVwhZrvrJ9Bq01OmcJMfao9ZQAYt lwrC4XQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8533:b29a:936d:651a]) (user=irogers job=sendgmr) by 2002:a05:6902:a8b:b0:dc7:7ce9:fb4d with SMTP id 3f1490d57ef6-dee4f322140mr7251230276.12.1716253491136; Mon, 20 May 2024 18:04:51 -0700 (PDT) Date: Mon, 20 May 2024 18:04:36 -0700 Message-Id: <20240521010439.321264-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v2 0/3] Use BPF filters for a "perf top -u" workaround From: Ian Rogers 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" 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 == $(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. v2. Allow PERF_SAMPLE_xx to be computed from the PBF_TERM_xx value using a shift as requested by Namhyung. 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 | 33 ++++++---- 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 | 61 +++++++++++++++++- tools/perf/util/bpf_skel/sample_filter.bpf.c | 54 +++++++++++----- 9 files changed, 171 insertions(+), 70 deletions(-) -- 2.45.0.rc1.225.g2a3ae87e7f-goog