Skip to contentSkip to conversation

generate boilerplate impls such as devlink_resource_register()

RFC Przemek Kitszel 2 participants 3 messages Jul 3, 2024 – Jul 4, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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);

maintainer
#1 lore raw
Quoted 6 lines · 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?

Quoted 4 lines

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?

#2 lore raw
Quoted 9 lines · Jakub Kicinski
Quoted 6 lines · 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)

Quoted 7 lines
Quoted 5 lines

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 ;))