diff mbox series

[dwarves,v3,1/5] btf_encoder: use bitfield to control var encoding

Message ID 20241002235253.487251-2-stephen.s.brennan@oracle.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series [dwarves,v3,1/5] btf_encoder: use bitfield to control var encoding | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Brennan Oct. 2, 2024, 11:52 p.m. UTC
We will need more granularity in the future, in order to add support for
encoding global variables as well. So replace the skip_encoding_vars
boolean with a flag variable named "encode_vars". There is currently
only one bit specified, and it is set when percpu variables should be
emitted.

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
 btf_encoder.c | 10 ++++++----
 btf_encoder.h |  6 ++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Alan Maguire Oct. 3, 2024, 1:41 p.m. UTC | #1
On 03/10/2024 00:52, Stephen Brennan wrote:
> We will need more granularity in the future, in order to add support for
> encoding global variables as well. So replace the skip_encoding_vars
> boolean with a flag variable named "encode_vars". There is currently
> only one bit specified, and it is set when percpu variables should be
> emitted.
> 
> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

> ---
>  btf_encoder.c | 10 ++++++----
>  btf_encoder.h |  6 ++++++
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/btf_encoder.c b/btf_encoder.c
> index 51cd7bf..652a945 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -119,7 +119,6 @@ struct btf_encoder {
>  	uint32_t	  type_id_off;
>  	bool		  has_index_type,
>  			  need_index_type,
> -			  skip_encoding_vars,
>  			  raw_output,
>  			  verbose,
>  			  force,
> @@ -137,6 +136,7 @@ struct btf_encoder {
>  		int		allocated;
>  		uint32_t	shndx;
>  	} percpu;
> +	int                encode_vars;
>  	struct {
>  		struct elf_function *entries;
>  		int		    allocated;
> @@ -2369,7 +2369,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
>  
>  		encoder->force		 = conf_load->btf_encode_force;
>  		encoder->gen_floats	 = conf_load->btf_gen_floats;
> -		encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars;
>  		encoder->skip_encoding_decl_tag	 = conf_load->skip_encoding_btf_decl_tag;
>  		encoder->tag_kfuncs	 = conf_load->btf_decl_tag_kfuncs;
>  		encoder->gen_distilled_base = conf_load->btf_gen_distilled_base;
> @@ -2377,6 +2376,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
>  		encoder->has_index_type  = false;
>  		encoder->need_index_type = false;
>  		encoder->array_index_id  = 0;
> +		encoder->encode_vars = 0;
> +		if (!conf_load->skip_encoding_btf_vars)
> +			encoder->encode_vars |= BTF_VAR_PERCPU;
>  
>  		GElf_Ehdr ehdr;
>  
> @@ -2436,7 +2438,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
>  		if (!encoder->percpu.shndx && encoder->verbose)
>  			printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION);
>  
> -		if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars))
> +		if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU))
>  			goto out_delete;
>  
>  		if (encoder->verbose)
> @@ -2633,7 +2635,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co
>  			goto out;
>  	}
>  
> -	if (!encoder->skip_encoding_vars)
> +	if (encoder->encode_vars)
>  		err = btf_encoder__encode_cu_variables(encoder);
>  
>  	if (!err)
> diff --git a/btf_encoder.h b/btf_encoder.h
> index f54c95a..91e7947 100644
> --- a/btf_encoder.h
> +++ b/btf_encoder.h
> @@ -16,6 +16,12 @@ struct btf;
>  struct cu;
>  struct list_head;
>  
> +/* Bit flags specifying which kinds of variables are emitted */
> +enum btf_var_option {
> +	BTF_VAR_NONE = 0,
> +	BTF_VAR_PERCPU = 1,
> +};
> +
>  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load);
>  void btf_encoder__delete(struct btf_encoder *encoder);
>
Arnaldo Carvalho de Melo Oct. 3, 2024, 2:41 p.m. UTC | #2
On Thu, Oct 03, 2024 at 02:41:17PM +0100, Alan Maguire wrote:
> On 03/10/2024 00:52, Stephen Brennan wrote:
> > We will need more granularity in the future, in order to add support for
> > encoding global variables as well. So replace the skip_encoding_vars
> > boolean with a flag variable named "encode_vars". There is currently
> > only one bit specified, and it is set when percpu variables should be
> > emitted.
> > 
> > Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
> 
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

Thanks, applying this first one.

- Arnaldo
 
> > ---
> >  btf_encoder.c | 10 ++++++----
> >  btf_encoder.h |  6 ++++++
> >  2 files changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/btf_encoder.c b/btf_encoder.c
> > index 51cd7bf..652a945 100644
> > --- a/btf_encoder.c
> > +++ b/btf_encoder.c
> > @@ -119,7 +119,6 @@ struct btf_encoder {
> >  	uint32_t	  type_id_off;
> >  	bool		  has_index_type,
> >  			  need_index_type,
> > -			  skip_encoding_vars,
> >  			  raw_output,
> >  			  verbose,
> >  			  force,
> > @@ -137,6 +136,7 @@ struct btf_encoder {
> >  		int		allocated;
> >  		uint32_t	shndx;
> >  	} percpu;
> > +	int                encode_vars;
> >  	struct {
> >  		struct elf_function *entries;
> >  		int		    allocated;
> > @@ -2369,7 +2369,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
> >  
> >  		encoder->force		 = conf_load->btf_encode_force;
> >  		encoder->gen_floats	 = conf_load->btf_gen_floats;
> > -		encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars;
> >  		encoder->skip_encoding_decl_tag	 = conf_load->skip_encoding_btf_decl_tag;
> >  		encoder->tag_kfuncs	 = conf_load->btf_decl_tag_kfuncs;
> >  		encoder->gen_distilled_base = conf_load->btf_gen_distilled_base;
> > @@ -2377,6 +2376,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
> >  		encoder->has_index_type  = false;
> >  		encoder->need_index_type = false;
> >  		encoder->array_index_id  = 0;
> > +		encoder->encode_vars = 0;
> > +		if (!conf_load->skip_encoding_btf_vars)
> > +			encoder->encode_vars |= BTF_VAR_PERCPU;
> >  
> >  		GElf_Ehdr ehdr;
> >  
> > @@ -2436,7 +2438,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
> >  		if (!encoder->percpu.shndx && encoder->verbose)
> >  			printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION);
> >  
> > -		if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars))
> > +		if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU))
> >  			goto out_delete;
> >  
> >  		if (encoder->verbose)
> > @@ -2633,7 +2635,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co
> >  			goto out;
> >  	}
> >  
> > -	if (!encoder->skip_encoding_vars)
> > +	if (encoder->encode_vars)
> >  		err = btf_encoder__encode_cu_variables(encoder);
> >  
> >  	if (!err)
> > diff --git a/btf_encoder.h b/btf_encoder.h
> > index f54c95a..91e7947 100644
> > --- a/btf_encoder.h
> > +++ b/btf_encoder.h
> > @@ -16,6 +16,12 @@ struct btf;
> >  struct cu;
> >  struct list_head;
> >  
> > +/* Bit flags specifying which kinds of variables are emitted */
> > +enum btf_var_option {
> > +	BTF_VAR_NONE = 0,
> > +	BTF_VAR_PERCPU = 1,
> > +};
> > +
> >  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load);
> >  void btf_encoder__delete(struct btf_encoder *encoder);
> >
diff mbox series

Patch

diff --git a/btf_encoder.c b/btf_encoder.c
index 51cd7bf..652a945 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -119,7 +119,6 @@  struct btf_encoder {
 	uint32_t	  type_id_off;
 	bool		  has_index_type,
 			  need_index_type,
-			  skip_encoding_vars,
 			  raw_output,
 			  verbose,
 			  force,
@@ -137,6 +136,7 @@  struct btf_encoder {
 		int		allocated;
 		uint32_t	shndx;
 	} percpu;
+	int                encode_vars;
 	struct {
 		struct elf_function *entries;
 		int		    allocated;
@@ -2369,7 +2369,6 @@  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 
 		encoder->force		 = conf_load->btf_encode_force;
 		encoder->gen_floats	 = conf_load->btf_gen_floats;
-		encoder->skip_encoding_vars = conf_load->skip_encoding_btf_vars;
 		encoder->skip_encoding_decl_tag	 = conf_load->skip_encoding_btf_decl_tag;
 		encoder->tag_kfuncs	 = conf_load->btf_decl_tag_kfuncs;
 		encoder->gen_distilled_base = conf_load->btf_gen_distilled_base;
@@ -2377,6 +2376,9 @@  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 		encoder->has_index_type  = false;
 		encoder->need_index_type = false;
 		encoder->array_index_id  = 0;
+		encoder->encode_vars = 0;
+		if (!conf_load->skip_encoding_btf_vars)
+			encoder->encode_vars |= BTF_VAR_PERCPU;
 
 		GElf_Ehdr ehdr;
 
@@ -2436,7 +2438,7 @@  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 		if (!encoder->percpu.shndx && encoder->verbose)
 			printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION);
 
-		if (btf_encoder__collect_symbols(encoder, !encoder->skip_encoding_vars))
+		if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU))
 			goto out_delete;
 
 		if (encoder->verbose)
@@ -2633,7 +2635,7 @@  int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, struct co
 			goto out;
 	}
 
-	if (!encoder->skip_encoding_vars)
+	if (encoder->encode_vars)
 		err = btf_encoder__encode_cu_variables(encoder);
 
 	if (!err)
diff --git a/btf_encoder.h b/btf_encoder.h
index f54c95a..91e7947 100644
--- a/btf_encoder.h
+++ b/btf_encoder.h
@@ -16,6 +16,12 @@  struct btf;
 struct cu;
 struct list_head;
 
+/* Bit flags specifying which kinds of variables are emitted */
+enum btf_var_option {
+	BTF_VAR_NONE = 0,
+	BTF_VAR_PERCPU = 1,
+};
+
 struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load);
 void btf_encoder__delete(struct btf_encoder *encoder);