netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC net-next] generate boilerplate impls such as devlink_resource_register()
@ 2024-07-03 10:13 Przemek Kitszel
  2024-07-04  0:51 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Przemek Kitszel @ 2024-07-03 10:13 UTC (permalink / raw)
  To: Jakub Kicinski, Jiri Pirko; +Cc: netdev@vger.kernel.org

Hi,

I have and idea that boilerplate devlink_ wrappers over devl_ functions
could be generated via short script, with the handcrafted .c code as the
only input. Take for example the following [one line] added to 
devlink/resource.c would replace the whole definition and kdoc, which 
would be placed in the generated file in about the same form as the
current code. This will be applied to all suitable functions of course.

The script will be short, but not so trivial to write it without prior
RFC. For those wondering if I don't have better things to do: yes, but
I have also some awk-time that will not be otherwise spend on more 
serious stuff anyway :)

[one line]
DEVLINK_GEN_SYMBOL_GPL(devlink_resource_register);

[removed part below]

/**
  *	devlink_resource_register - devlink resource register
  *
  *	@devlink: devlink
  *	@resource_name: resource's name
  *	@resource_size: resource's size
  *	@resource_id: resource's id
  *	@parent_resource_id: resource's parent id
  *	@size_params: size parameters
  *
  *	Generic resources should reuse the same names across drivers.
  *	Please see the generic resources list at:
  *	Documentation/networking/devlink/devlink-resource.rst
  *
  *	Context: Takes and release devlink->lock <mutex>.
  */
int devlink_resource_register(struct devlink *devlink,
			      const char *resource_name,
			      u64 resource_size,
			      u64 resource_id,
			      u64 parent_resource_id,
			      const struct devlink_resource_size_params *size_params)
{
	int err;

	devl_lock(devlink);
	err = devl_resource_register(devlink, resource_name, resource_size,
				     resource_id, parent_resource_id, size_params);
	devl_unlock(devlink);
	return err;
}
EXPORT_SYMBOL_GPL(devlink_resource_register);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC net-next] generate boilerplate impls such as devlink_resource_register()
  2024-07-03 10:13 [RFC net-next] generate boilerplate impls such as devlink_resource_register() Przemek Kitszel
@ 2024-07-04  0:51 ` Jakub Kicinski
  2024-07-04  7:23   ` Przemek Kitszel
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2024-07-04  0:51 UTC (permalink / raw)
  To: Przemek Kitszel; +Cc: Jiri Pirko, netdev@vger.kernel.org

On Wed, 3 Jul 2024 12:13:58 +0200 Przemek Kitszel wrote:
> I have and idea that boilerplate devlink_ wrappers over devl_ functions
> could be generated via short script, with the handcrafted .c code as the
> only input. Take for example the following [one line] added to 
> devlink/resource.c would replace the whole definition and kdoc, which 
> would be placed in the generated file in about the same form as the
> current code. This will be applied to all suitable functions of course.

How?

> The script will be short, but not so trivial to write it without prior
> RFC. For those wondering if I don't have better things to do: yes, but
> I have also some awk-time that will not be otherwise spend on more 
> serious stuff anyway :)

What's the exchange rate from awk-time to other types of time?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC net-next] generate boilerplate impls such as devlink_resource_register()
  2024-07-04  0:51 ` Jakub Kicinski
@ 2024-07-04  7:23   ` Przemek Kitszel
  0 siblings, 0 replies; 3+ messages in thread
From: Przemek Kitszel @ 2024-07-04  7:23 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Jiri Pirko, netdev@vger.kernel.org

On 7/4/24 02:51, Jakub Kicinski wrote:
> On Wed, 3 Jul 2024 12:13:58 +0200 Przemek Kitszel wrote:
>> I have and idea that boilerplate devlink_ wrappers over devl_ functions
>> could be generated via short script, with the handcrafted .c code as the
>> only input. Take for example the following [one line] added to
>> devlink/resource.c would replace the whole definition and kdoc, which
>> would be placed in the generated file in about the same form as the
>> current code. This will be applied to all suitable functions of course.
> 
> How?

there are two options:
1. function is declared in .h but there is no impl in .c; a little magic
2. there is a line requesting to generate implementation, typically put
    just below devl_ variant; makes more sense for me

if you rather ask "how applied" instead of "how decided":
a. a helper shell script finds functions to generate (the list could be
    saved as an intermediate to speed up (to don't go through the rest)
b. the main script generates gen_devlink_wrappers.c file

(instead of intermediate file in step a., the output from step b. could
be `cmp || mv`, aka "don't touch if the same", to avoid .o invalidation)

> 
>> The script will be short, but not so trivial to write it without prior
>> RFC. For those wondering if I don't have better things to do: yes, but
>> I have also some awk-time that will not be otherwise spend on more
>> serious stuff anyway :)
> 
> What's the exchange rate from awk-time to other types of time?

I spend there only between a few and several percent of my time, but it
yields returns counted in months of C/++ devel saved :P (not saying
about this thread of course ;))

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-04  7:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-03 10:13 [RFC net-next] generate boilerplate impls such as devlink_resource_register() Przemek Kitszel
2024-07-04  0:51 ` Jakub Kicinski
2024-07-04  7:23   ` Przemek Kitszel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).