Re: [PATCH bpf-next v2 01/11] btf: change BTF_KIND_* macros to enums

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/13/21 9:59 PM, Andrii Nakryiko wrote:
On Mon, Sep 13, 2021 at 8:51 AM Yonghong Song <yhs@xxxxxx> wrote:

Change BTF_KIND_* macros to enums so they are encoded in dwarf and
appear in vmlinux.h. This will make it easier for bpf programs
to use these constants without macro definitions.

Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
  include/uapi/linux/btf.h       | 36 ++++++++++++++++++----------------
  tools/include/uapi/linux/btf.h | 36 ++++++++++++++++++----------------
  2 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h
index d27b1708efe9..c32cd6697d63 100644
--- a/include/uapi/linux/btf.h
+++ b/include/uapi/linux/btf.h
@@ -56,23 +56,25 @@ struct btf_type {
  #define BTF_INFO_VLEN(info)    ((info) & 0xffff)
  #define BTF_INFO_KFLAG(info)   ((info) >> 31)

-#define BTF_KIND_UNKN          0       /* Unknown      */
-#define BTF_KIND_INT           1       /* Integer      */
-#define BTF_KIND_PTR           2       /* Pointer      */
-#define BTF_KIND_ARRAY         3       /* Array        */
-#define BTF_KIND_STRUCT                4       /* Struct       */
-#define BTF_KIND_UNION         5       /* Union        */
-#define BTF_KIND_ENUM          6       /* Enumeration  */
-#define BTF_KIND_FWD           7       /* Forward      */
-#define BTF_KIND_TYPEDEF       8       /* Typedef      */
-#define BTF_KIND_VOLATILE      9       /* Volatile     */
-#define BTF_KIND_CONST         10      /* Const        */
-#define BTF_KIND_RESTRICT      11      /* Restrict     */
-#define BTF_KIND_FUNC          12      /* Function     */
-#define BTF_KIND_FUNC_PROTO    13      /* Function Proto       */
-#define BTF_KIND_VAR           14      /* Variable     */
-#define BTF_KIND_DATASEC       15      /* Section      */
-#define BTF_KIND_FLOAT         16      /* Floating point       */
+enum {
+       BTF_KIND_UNKN = 0,      /* Unknown      */
+       BTF_KIND_INT,           /* Integer      */
+       BTF_KIND_PTR,           /* Pointer      */
+       BTF_KIND_ARRAY,         /* Array        */
+       BTF_KIND_STRUCT,        /* Struct       */
+       BTF_KIND_UNION,         /* Union        */
+       BTF_KIND_ENUM,          /* Enumeration  */
+       BTF_KIND_FWD,           /* Forward      */
+       BTF_KIND_TYPEDEF,       /* Typedef      */
+       BTF_KIND_VOLATILE,      /* Volatile     */
+       BTF_KIND_CONST,         /* Const        */
+       BTF_KIND_RESTRICT,      /* Restrict     */
+       BTF_KIND_FUNC,          /* Function     */
+       BTF_KIND_FUNC_PROTO,    /* Function Proto       */
+       BTF_KIND_VAR,           /* Variable     */
+       BTF_KIND_DATASEC,       /* Section      */
+       BTF_KIND_FLOAT,         /* Floating point       */

Can you please leave explicit integer values specified? It's extremely
helpful and much easier in practice, compared to having to count the
number of rows from BTF_KIND_UNKN. Had to do it multiple times with
other BPF constants and was happy I didn't have to do that for
BTF_KIND enums.

Sure. Will do.


+};
  #define BTF_KIND_MAX           BTF_KIND_FLOAT
  #define NR_BTF_KINDS           (BTF_KIND_MAX + 1)

these two can be just an enum values as well, and actually will be
"auto-updated", if done this way (I think, haven't really tested)

BTF_KIND_FLOAT = 16,
NR_BTF_KINDS,
BTF_KIND_MAX = NR_BTF_KINDS - 1,

This should work. Previously, I tried to give a name to
the enum. If that is case, e.g., put NR_BTF_KINDS and
BTF_KIND_MAX inside the enum will not be a good idea
since then you have some case not a real type or
you have duplicated case number (e.g, BTF_KIND_FLOAT 16
and default (which covers BTF_KIND_MAX) also contains 16)
and compiler may warn.

But eventually I did not put an enum name here since
a common name like btf_kind may have been used by
application.

So will make the change as we don't name the enum.


... won't it?

[...]




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux