Re: [PATCH v4 07/18] static_call: Add inline static call infrastructure
From: Josh Poimboeuf
Date: Tue May 05 2020 - 18:11:07 EST
On Fri, May 01, 2020 at 10:28:56PM +0200, Peter Zijlstra wrote:
> +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
> +
> +struct static_call_mod {
> + struct static_call_mod *next;
> + struct module *mod; /* for vmlinux, mod == NULL */
> + struct static_call_site *sites;
> +};
> +
> +struct static_call_key {
> + void *func;
> + struct static_call_mod *next;
> +};
"next" implies it links to another key. How about "mods" or
"site_mods"?
> +++ b/include/linux/static_call_types.h
> @@ -2,14 +2,27 @@
> #ifndef _STATIC_CALL_TYPES_H
> #define _STATIC_CALL_TYPES_H
>
> +#include <linux/types.h>
> #include <linux/stringify.h>
>
> #define STATIC_CALL_PREFIX __SC__
> +#define STATIC_CALL_PREFIX_STR __stringify(STATIC_CALL_PREFIX)
> +#define STATIC_CALL_PREFIX_LEN (sizeof(STATIC_CALL_PREFIX_STR) - 1)
STATIC_CALL_KEY_PREFIX_STR
STATIC_CALL_KEY_PREFIX_LEN
> +void __static_call_update(struct static_call_key *key, void *tramp, void *func)
> +{
> + struct static_call_site *site, *stop;
> + struct static_call_mod *site_mod;
> +
> + cpus_read_lock();
> + static_call_lock();
> +
> + if (key->func == func)
> + goto done;
> +
> + key->func = func;
> +
> + arch_static_call_transform(NULL, tramp, func);
> +
> + /*
> + * If uninitialized, we'll not update the callsites, but they still
> + * point to the trampoline and we just patched that.
> + */
> + if (WARN_ON_ONCE(!static_call_initialized))
> + goto done;
> +
> + for (site_mod = key->next; site_mod; site_mod = site_mod->next) {
> + if (!site_mod->sites) {
> + /*
> + * This can happen if the static call key is defined in
> + * a module which doesn't use it.
> + */
> + continue;
> + }
> +
> + stop = __stop_static_call_sites;
> +
> +#ifdef CONFIG_MODULES
> + if (site_mod->mod) {
> + stop = site_mod->mod->static_call_sites +
> + site_mod->mod->num_static_call_sites;
> + }
> +#endif
Instead of defining 'mod' in the inner loop below, it can be set at the
top of the outer loop above. Then the above 'stop' calculation can
be a little less verbose.
--
Josh