Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1318232lqo; Fri, 17 May 2024 20:30:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOnq/LTiJ0kHZeMCOW4Vk5ztUjQE20jLrmGWMgpt1Vv4ojZMkJux8oHWobWOnWJYCA0Y3aEhigHBMS6briLesy+SNWxy6BJV5+n8WRdQ== X-Google-Smtp-Source: AGHT+IGZKyEiqEcGxP/EGzaK3LHjxw9GH2Ie0nyyN7etWw70kkHLXVkL9ycxsZWEGMNEpUwhhwWH X-Received: by 2002:a50:c082:0:b0:575:9a8:be1a with SMTP id 4fb4d7f45d1cf-57509a8be78mr4493638a12.16.1716003033098; Fri, 17 May 2024 20:30:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716003033; cv=pass; d=google.com; s=arc-20160816; b=dLwDedppsPNBhYAyaPbCRBpaLuD1ijKaUqZvDfE8teISO+QfFbmSZLws70QFKLJqAv BkpWvQzu4ZYMDfxAMSdanUFwovdHunyoxsfzzgXZLBnGMvIdu5bidwXadRx+3vlanjE1 9waVcdT/9XUJjcHDZK9/PMP3MbbtsaSAR3IoAdTNnRoorFaFZXYml948aIcDbbPrQz3q o80Thg0g+vas0lLvxotV+Xkw5oQzdm9q1j4AWUc8P09JJSfjFmTPVlahX1MnVEYKOV4s MJ6n2XTvG/Bu/J0b0heBDwmqXrYc/c8gsEEsKwDGr6eHovzvHoKwvU/Q2UNZsH9ELrkW XigQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=1nWYYKjaR/jDGFeRF8uaCxl0MPSOP0KopiQrG5iiGtI=; fh=weKHEuJNYsVmjux6PzEFNPxV6VYWKgTo6oa7oA1Uqqw=; b=qf5WDllSNvf79g7syYnSjC8iIot+FijsFxQzToMTxiqIxuHmmpo+SdNs2ohb9ADnsO sGkSQ4m26one0vKNilis1jyqLOCrKlHuZNi2A/fef+E3J9+0S3vXlM5bmrziihadIQ8D lsFYAI4WkpiQ2+BhGK97ZapIqrt6JOrgRPL5SgNZHu8WG7uzv92H7sEyEAeHnhJoReNL KGI8pxfqnFIC8t4RPxXRICXbhCxOHIDJpxBT6PLAxbEJOzH5FFWqzYlFZ6RMn5b7OU4I 4z5AoJ/avK3WwcQEBgKR4Hd7TfDrvZDyT/HnnWlWJlo8+WKrw1S2RIURD1yA/ekPuXso hXiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MnfKwSv3; 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-182765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-574fdbc258fsi3145536a12.147.2024.05.17.20.30.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 20:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MnfKwSv3; 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-182765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182765-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A10D81F2215A for ; Sat, 18 May 2024 03:30:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 629088F44; Sat, 18 May 2024 03:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MnfKwSv3" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 2A6933D64 for ; Sat, 18 May 2024 03:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716003021; cv=none; b=FMHcSDjB0ldnE3RGXMZY6LV0CUEAUiPouqpj6oPXgDVx/GtBwHOaE0nzCXG2pCc/pUMk22nePyJ9WLyURdbZOy/9vILgc6y7Jl922MtIDGbR1UHiIlKmOrOVvA2/1myJiXp++qXFvSYVbqHpfBgs9ANuFLPOz7gbRYa+3SAJQHM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716003021; c=relaxed/simple; bh=i2aLlf3CCtikkEtAK0ntXxBrsOx2ayXvknDbt5qFetw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QRMneDfp5WjBISGL6sIDJbh+prKmweRKnxrvlr/PwUY8hObpTWQOANaY70zXraWpdJ6QBgBKBnvyRQgbN6kSpUzWBznZZNksG5RjklYjX3OTU5eH0dJqROhTMZBQjsDEivnOHvjt7Oo94bnGBwgCvYRbiXXTSPa0gpqxhWSOrs4= 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=MnfKwSv3; arc=none smtp.client-ip=209.85.214.182 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-pl1-f182.google.com with SMTP id d9443c01a7336-1ee5f3123d8so11535ad.1 for ; Fri, 17 May 2024 20:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716003018; x=1716607818; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1nWYYKjaR/jDGFeRF8uaCxl0MPSOP0KopiQrG5iiGtI=; b=MnfKwSv3agOSvJqwuxCwLKPkUOuTka2RxjV5dJZAzjDKNni2b2U4X2WkAay/0Hwg9c aMbBHeTDY9dYj8JePiYNYiZkv7gn2OO1uCA29eT9cIvo+VCRiJrfMg9WRMBrz/iIt+lB AMgXpzrbZIysQMZqEl+gS6u3xYRNx+1y1Z3IEwN7J+ufQvHUGz7ucI6NFkIG/M4DeYDN NHnuRTgRZr4jNoInD3rWI/AeHUo85AW1/h+g66Ie33D9O7QxvMkQZAtlhKdMpG17j5Ao z4zFCDPzRToVpFLj2r9asZmxIUwy9p+hyor8HGakspvY74oTB6UZnWU8gwEJItD6fTcl hbsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716003018; x=1716607818; h=content-transfer-encoding:cc: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=1nWYYKjaR/jDGFeRF8uaCxl0MPSOP0KopiQrG5iiGtI=; b=IyJzuIVMyIIP5EPRKIKOd9q18E7zO/dnz/arRIiUvNCC9WpgjcL0voMS8N72CyWAnE 2eGibD4+DbjKxcgA2ZIrVlbiv+LWfZU/4t4Y/SgBXdzZvr0MvEyxPOmVdMtmnRnMke3n Uetp+aV/B+bnsLWySTG8R2+MsBUOfmWkGsaMnNQn2jGpmZKx0jLjYeUxqIINrcydwrmr b6EHicI4RxcBkGijAE7NOhWAxjz1cnaRmAPJ/yt1eadc1eSenXArptH/cDs6Ro36QHRQ 6ZjfzypXnpwtDlIYtM+ByJOqw0Bj54vfC1S3NLy6wcLum+GQC4jgtnRxlqN8+DWvA5af Xu2w== X-Forwarded-Encrypted: i=1; AJvYcCUs2hbBeK+HDh0gJt74gNp8uQQTGJAMe53feBJ21fpkTOgA4fwpRwVNLpmTMa7pxMnAhRomS4lEgt9O10vmKeZ9fLGOcOPjGNyNLFy8 X-Gm-Message-State: AOJu0YwLCGQP7lwA5F729BE/6/ojj1aUCiKXAr6RM17udD0ixWEGHIVx 3Sa29S8kU62oUhCcZ6F+yHozCyf9DPd3zyf0TC0VcLspunV3dU5zler3nQljMGV0GD8HVoLMjRt ED7u/VuoBAb0+iSyfDVsck52O0iJEmYzOAEEq X-Received: by 2002:a17:902:6549:b0:1e5:62:7a89 with SMTP id d9443c01a7336-1f2ecbc4160mr1086035ad.18.1716003018134; Fri, 17 May 2024 20:30:18 -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> <20240516041948.3546553-2-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Fri, 17 May 2024 20:29:59 -0700 Message-ID: Subject: Re: [PATCH v1 1/3] perf bpf filter: Give terms their own enum To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , 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 Fri, May 17, 2024 at 6:36=E2=80=AFPM Namhyung Kim = wrote: > > On Wed, May 15, 2024 at 9:20=E2=80=AFPM Ian Rogers w= rote: > > > > Give the term types their own enum so that additional terms can be > > added that don't correspond to a PERF_SAMPLE_xx flag. The term values > > are numerically ascending rather than bit field positions, this means > > they need translating to a PERF_SAMPLE_xx bit field in certain places > > and they are more densely encoded. > > > > Signed-off-by: Ian Rogers > > --- > [SNIP] > > diff --git a/tools/perf/util/bpf_skel/sample-filter.h b/tools/perf/util= /bpf_skel/sample-filter.h > > index 2e96e1ab084a..161d5ff49cb6 100644 > > --- a/tools/perf/util/bpf_skel/sample-filter.h > > +++ b/tools/perf/util/bpf_skel/sample-filter.h > > @@ -16,12 +16,32 @@ enum perf_bpf_filter_op { > > PBF_OP_GROUP_END, > > }; > > > > +enum perf_bpf_filter_term { > > + /* No term is in use. */ > > + PBF_TERM_NONE, > > + /* Terms that correspond to PERF_SAMPLE_xx values. */ > > + PBF_TERM_IP, > > + PBF_TERM_ID, > > + PBF_TERM_TID, > > + PBF_TERM_CPU, > > + PBF_TERM_TIME, > > + PBF_TERM_ADDR, > > + PBF_TERM_PERIOD, > > + PBF_TERM_TRANSACTION, > > + PBF_TERM_WEIGHT, > > + PBF_TERM_PHYS_ADDR, > > + PBF_TERM_CODE_PAGE_SIZE, > > + PBF_TERM_DATA_PAGE_SIZE, > > + PBF_TERM_WEIGHT_STRUCT, > > + PBF_TERM_DATA_SRC, > > +}; > > + > > /* BPF map entry for filtering */ > > struct perf_bpf_filter_entry { > > enum perf_bpf_filter_op op; > > __u32 part; /* sub-sample type info when it has multiple values= */ > > - __u64 flags; /* perf sample type flags */ > > + enum perf_bpf_filter_term term; > > __u64 value; > > }; > > > > -#endif /* PERF_UTIL_BPF_SKEL_SAMPLE_FILTER_H */ > > \ No newline at end of file > > +#endif /* PERF_UTIL_BPF_SKEL_SAMPLE_FILTER_H */ > > diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/= util/bpf_skel/sample_filter.bpf.c > > index fb94f5280626..8666c85e9333 100644 > > --- a/tools/perf/util/bpf_skel/sample_filter.bpf.c > > +++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c > > @@ -48,31 +48,50 @@ static inline __u64 perf_get_sample(struct bpf_perf= _event_data_kern *kctx, > > { > > struct perf_sample_data___new *data =3D (void *)kctx->data; > > > > - if (!bpf_core_field_exists(data->sample_flags) || > > - (data->sample_flags & entry->flags) =3D=3D 0) > > + if (!bpf_core_field_exists(data->sample_flags)) > > return 0; > > > > - switch (entry->flags) { > > - case PERF_SAMPLE_IP: > > + switch (entry->term) { > > + case PBF_TERM_NONE: > > + return 0; > > + case PBF_TERM_IP: > > + if ((data->sample_flags & PERF_SAMPLE_IP) =3D=3D 0) > > + return 0; > > Can we check this in a single place like in the original code > instead of doing it in every case? I think we can keep the > entry->flags and check it only if it's non zero. Then uid and > gid will have 0 to skip. I found the old way confusing. As the flags are a bitmap it looks like more than one can be set, if that were the case then the switch statement would be broken as the case wouldn't exist. Using an enum like this allows warnings to occur when a term is missing in the switch statement - which is good when you are adding new terms. I think it more obviously matches the man page. We could arrange for the enum values to encode the shift position of the flag. Something like: if ((entry->term > PBF_TERM_NONE && entry->term <=3D PBF_TERM_DATA_SRC) && (data->sample_flags & (1 << entry->term)) =3D=3D 0) return 0; But the problem there is that not every sample type has an enum value, and I'm not sure it makes sense for things like STREAM_ID. We could do some macro magic to reduce the verbosity like: #define SAMPLE_CASE(x) \ case PBF_TERM_##x: \ if ((data->sample_flags & PERF_SAMPLE_x) =3D=3D 0) \ return 0 But I thought that made the code harder to read given the relatively small number of sample cases. Thanks, Ian > Thanks, > Namhyung > > > > return kctx->data->ip; > > - case PERF_SAMPLE_ID: > > + case PBF_TERM_ID: > > + if ((data->sample_flags & PERF_SAMPLE_ID) =3D=3D 0) > > + return 0; > > return kctx->data->id; > > - case PERF_SAMPLE_TID: > > + case PBF_TERM_TID: > > + if ((data->sample_flags & PERF_SAMPLE_TID) =3D=3D 0) > > + return 0; > > if (entry->part) > > return kctx->data->tid_entry.pid; > > else > > return kctx->data->tid_entry.tid; > > - case PERF_SAMPLE_CPU: > > + case PBF_TERM_CPU: > > + if ((data->sample_flags & PERF_SAMPLE_CPU) =3D=3D 0) > > + return 0; > > return kctx->data->cpu_entry.cpu; > > - case PERF_SAMPLE_TIME: > > + case PBF_TERM_TIME: > > + if ((data->sample_flags & PERF_SAMPLE_TIME) =3D=3D 0) > > + return 0; > > return kctx->data->time; > > - case PERF_SAMPLE_ADDR: > > + case PBF_TERM_ADDR: > > + if ((data->sample_flags & PERF_SAMPLE_ADDR) =3D=3D 0) > > + return 0; > > return kctx->data->addr; > > - case PERF_SAMPLE_PERIOD: > > + case PBF_TERM_PERIOD: > > + if ((data->sample_flags & PERF_SAMPLE_PERIOD) =3D=3D 0) > > + return 0; > > return kctx->data->period; > > - case PERF_SAMPLE_TRANSACTION: > > + case PBF_TERM_TRANSACTION: > > + if ((data->sample_flags & PERF_SAMPLE_TRANSACTION) =3D= =3D 0) > > + return 0; > > return kctx->data->txn; > > - case PERF_SAMPLE_WEIGHT_STRUCT: > > + case PBF_TERM_WEIGHT_STRUCT: > > + if ((data->sample_flags & PERF_SAMPLE_WEIGHT_STRUCT) = =3D=3D 0) > > + return 0; > > if (entry->part =3D=3D 1) > > return kctx->data->weight.var1_dw; > > if (entry->part =3D=3D 2) > > @@ -80,15 +99,25 @@ static inline __u64 perf_get_sample(struct bpf_perf= _event_data_kern *kctx, > > if (entry->part =3D=3D 3) > > return kctx->data->weight.var3_w; > > /* fall through */ > > - case PERF_SAMPLE_WEIGHT: > > + case PBF_TERM_WEIGHT: > > + if ((data->sample_flags & PERF_SAMPLE_WEIGHT) =3D=3D 0) > > + return 0; > > return kctx->data->weight.full; > > - case PERF_SAMPLE_PHYS_ADDR: > > + case PBF_TERM_PHYS_ADDR: > > + if ((data->sample_flags & PERF_SAMPLE_PHYS_ADDR) =3D=3D= 0) > > + return 0; > > return kctx->data->phys_addr; > > - case PERF_SAMPLE_CODE_PAGE_SIZE: > > + case PBF_TERM_CODE_PAGE_SIZE: > > + if ((data->sample_flags & PERF_SAMPLE_CODE_PAGE_SIZE) = =3D=3D 0) > > + return 0; > > return kctx->data->code_page_size; > > - case PERF_SAMPLE_DATA_PAGE_SIZE: > > + case PBF_TERM_DATA_PAGE_SIZE: > > + if ((data->sample_flags & PERF_SAMPLE_DATA_PAGE_SIZE) = =3D=3D 0) > > + return 0; > > return kctx->data->data_page_size; > > - case PERF_SAMPLE_DATA_SRC: > > + case PBF_TERM_DATA_SRC: > > + if ((data->sample_flags & PERF_SAMPLE_DATA_SRC) =3D=3D = 0) > > + return 0; > > if (entry->part =3D=3D 1) > > return kctx->data->data_src.mem_op; > > if (entry->part =3D=3D 2) > > -- > > 2.45.0.rc1.225.g2a3ae87e7f-goog > >