* Rasmus Villemoes <li...@rasmusvillemoes.dk> wrote:

> Similar to how x86_64 uses bug_entry-relative pointers to reduce
> sizeof(struct bug_entry), the same thing can now be done for struct
> _ddebug, saving 16 bytes for each of those (i.e., each pr_debug, dev_dbg
> etc. in a CONFIG_DYNAMIC_DEBUG kernel).
> 
> Note the use of .ifndef/.endif in asm to avoid
> 
> fs/aio.c:1382: Error: symbol `__UNIQUE_ID_ddebug112' is already defined
> 
> This is due to uses of pr_debug et al in functions that get inlined. In
> such a case, __COUNTER__ is obviously only expanded once, but the asm()
> is repeated once for every inlined instance. Letting all instances share
> the same descriptor object is the right thing to do; that is also what
> happens when it is the compiler that defines a static object inside an
> inline(d) function.
> 
> Cc: x...@kernel.org
> Signed-off-by: Rasmus Villemoes <li...@rasmusvillemoes.dk>
> ---
>  arch/x86/Kconfig                     |  1 +
>  arch/x86/include/asm/dynamic_debug.h | 35 +++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
>  create mode 100644 arch/x86/include/asm/dynamic_debug.h
> 
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 1a0be022f91d..a44168930e52 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -90,6 +90,7 @@ config X86
>       select CLOCKSOURCE_WATCHDOG
>       select DCACHE_WORD_ACCESS
>       select DMA_DIRECT_OPS
> +     select DYNAMIC_DEBUG_RELATIVE_POINTERS  if X86_64
>       select EDAC_ATOMIC_SCRUB
>       select EDAC_SUPPORT
>       select GENERIC_CLOCKEVENTS
> diff --git a/arch/x86/include/asm/dynamic_debug.h 
> b/arch/x86/include/asm/dynamic_debug.h
> new file mode 100644
> index 000000000000..350ef6e2feff
> --- /dev/null
> +++ b/arch/x86/include/asm/dynamic_debug.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _ASM_X86_DYNAMIC_DEBUG_H
> +#define _ASM_X86_DYNAMIC_DEBUG_H
> +
> +#ifdef HAVE_JUMP_LABEL
> +# ifdef DEBUG
> +#  define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_TRUE
> +# else
> +#  define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_FALSE
> +# endif
> +#else
> +# define _DPRINTK_ASM_KEY_INIT ""
> +#endif
> +
> +#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt)                     \
> +     extern struct _ddebug name;                                     \
> +     asm volatile(".ifndef " __stringify(name) "\n"                  \
> +                  ".pushsection __verbose,\"aw\"\n"                  \
> +                  "1:\n"                                             \
> +                  __stringify(name) ":\n"                            \
> +                  "\t.long %c0 - 1b \t# _ddebug::modname_disp\n"     \
> +                  "\t.long %c1 - 1b \t# _ddebug::function_disp\n"    \
> +                  "\t.long %c2 - 1b \t# _ddebug::filename_disp\n"    \
> +                  "\t.long %c3 - 1b \t# _ddebug::format_disp\n"      \
> +                  "\t.long %c4      \t# _ddebug::flags_lineno\n"     \
> +                  "\t.long 0        \t# <padding>\n"                 \
> +                  _DPRINTK_ASM_KEY_INIT                              \
> +                  ".popsection\n"                                    \
> +                  ".endif\n"                                         \
> +                  : : "i" (KBUILD_MODNAME), "i" (__func__),          \
> +                    "i" (__FILE__), "i" (fmt),                       \
> +                    "i" (_DPRINTK_FLAGS_LINENO_INIT))
> +
> +#endif /* _ASM_X86_DYNAMIC_DEBUG_H */
> +

Reviewed-by: Ingo Molnar <mi...@kernel.org>

Thanks,

        Ingo

Reply via email to