dynamic_debug: Remove __used attribute from metadata
RFC PATCH 1/1 dynamic_debug: Remove __used attribute from metadata
The __used attribute in the declaration of the dynamic_debug metadata stops the compiler from optimizing and eliminating constant tests and the metadata declaration used in things like:
#define DEBUG_LEVEL 0
if (DEBUG_LEVEL > 1)
pr_debug("foo...");This is a common construct for debugging macros with a constant "level" test.
When dynamic_debug is not configured, this is pr_debug and format string is eliminated unless DEBUG_LEVEL is greater than 1.
Remove the unnecessary __used attribute so the even the dynamic_debug use of pr_debug can be appropriately optimized away completely.
--- include/linux/dynamic_debug.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/dynamic_debug.h +1 -1
@@ -58,7 +58,7 @@ int __dynamic_netdev_dbg(struct _ddebug *descriptor, const char *fmt, ...);#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - static struct _ddebug __used __aligned(8) \ + static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \ .modname = KBUILD_MODNAME, \ .function = __func__, \
Jim Cromie
maintainerQuoted 12 lines · Joe Perches
The
__usedattribute in the declaration of thedynamic_debugmetadata stops the compiler from optimizing and eliminating constant tests and the metadata declaration used in things like:#define
DEBUG_LEVEL0
if (DEBUG_LEVEL> 1)
pr_debug("foo...");This is a common construct for debugging macros with a constant "level" test.
Quoted 8 lines
When
dynamic_debugis not configured, this ispr_debugand format string is eliminated unlessDEBUG_LEVELis greater than 1.Remove the unnecessary
__usedattribute so the even thedynamic_debuguse ofpr_debugcan be appropriately optimized away completely.
Im a bit puzzled - the __used attr is in the #if defined(CONFIG_DYNAMIC_DEBUG) branch.
If its not config'd, the METADATA is not compiled, and this should have no effect.
Did you mean enabled instead of configured ?
FWIW, removing __used causes no harm here, ie it doesnt break dynamic-debug facility.
Still, Id like to hear from Jason, he wrote it.
Quoted 17 lines · Jim Cromie
Quoted 16 lines · Joe Perches
The
__usedattribute in the declaration of thedynamic_debugmetadata stops the compiler from optimizing and eliminating constant tests and the metadata declaration used in things like:#define DEBUG_LEVEL 0 if (DEBUG_LEVEL > 1) pr_debug("foo...");This is a common construct for debugging macros with a constant "level" test.
When
dynamic_debugis not configured, this ispr_debugand format string is eliminated unlessDEBUG_LEVELis greater than 1.
Quoted 8 lines
Quoted 4 lines
Remove the unnecessary
__usedattribute so the even thedynamic_debuguse ofpr_debugcan be appropriately optimized away completely.Im a bit puzzled - the
__usedattr is in the
#ifdefined(CONFIG_DYNAMIC_DEBUG)branch.
Correct, the optimization is for CONFIG_DYNAMIC_DEBUG enabled.
Quoted 3 lines
If its not config'd, the METADATA is not compiled, and this should have no effect.
Did you mean enabled instead of configured ?
Nope.
if (0)
dynamic_pr_debug("foo %u\n", bar);will not be optimized away completely becausedynamic_pr_debug uses
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);
and that DEFINE includes __used
so even though the compiler knows that the branch
can not be taken, it still declares the known
unnecessary metadata.
Jason Baron
Acked-byQuoted 26 lines · Jim Cromie
Quoted 12 lines · Joe Perches
The
__usedattribute in the declaration of thedynamic_debugmetadata stops the compiler from optimizing and eliminating constant tests and the metadata declaration used in things like:#define
DEBUG_LEVEL0
if (DEBUG_LEVEL> 1)
pr_debug("foo...");This is a common construct for debugging macros with a constant "level" test.
Quoted 8 lines
When
dynamic_debugis not configured, this ispr_debugand format string is eliminated unlessDEBUG_LEVELis greater than 1.Remove the unnecessary
__usedattribute so the even thedynamic_debuguse ofpr_debugcan be appropriately optimized away completely.Im a bit puzzled - the
__usedattr is in the #ifdefined(CONFIG_DYNAMIC_DEBUG)branch.
Quoted 8 lines
If its not config'd, the METADATA is not compiled, and this should have no effect.
Did you mean enabled instead of configured ?FWIW, removing
__usedcauses no harm here, ie it doesnt break dynamic-debug facility.Still, Id like to hear from Jason, he wrote it.
Yeah, can't recall atm why its there. I agree that since the call sites reference the '_ddebug' structure it should be unecessary. So feel free to add:
Thanks,
-Jason