Skip to content

Commit 52159d9

Browse files
jibaronrostedt
authored andcommitted
jump label: Convert dynamic debug to use jump labels
Convert the 'dynamic debug' infrastructure to use jump labels. Signed-off-by: Jason Baron <jbaron@redhat.com> LKML-Reference: <b77627358cea3e27d7be4386f45f66219afb8452.1284733808.git.jbaron@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 8f7b50c commit 52159d9

5 files changed

Lines changed: 26 additions & 132 deletions

File tree

include/linux/dynamic_debug.h

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _DYNAMIC_DEBUG_H
22
#define _DYNAMIC_DEBUG_H
33

4+
#include <linux/jump_label.h>
5+
46
/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
57
* bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
68
* use independent hash functions, to reduce the chance of false positives.
@@ -22,8 +24,6 @@ struct _ddebug {
2224
const char *function;
2325
const char *filename;
2426
const char *format;
25-
char primary_hash;
26-
char secondary_hash;
2727
unsigned int lineno:24;
2828
/*
2929
* The flags field controls the behaviour at the callsite.
@@ -33,6 +33,7 @@ struct _ddebug {
3333
#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
3434
#define _DPRINTK_FLAGS_DEFAULT 0
3535
unsigned int flags:8;
36+
char enabled;
3637
} __attribute__((aligned(8)));
3738

3839

@@ -42,33 +43,35 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
4243
#if defined(CONFIG_DYNAMIC_DEBUG)
4344
extern int ddebug_remove_module(const char *mod_name);
4445

45-
#define __dynamic_dbg_enabled(dd) ({ \
46-
int __ret = 0; \
47-
if (unlikely((dynamic_debug_enabled & (1LL << DEBUG_HASH)) && \
48-
(dynamic_debug_enabled2 & (1LL << DEBUG_HASH2)))) \
49-
if (unlikely(dd.flags)) \
50-
__ret = 1; \
51-
__ret; })
52-
5346
#define dynamic_pr_debug(fmt, ...) do { \
47+
__label__ do_printk; \
48+
__label__ out; \
5449
static struct _ddebug descriptor \
5550
__used \
5651
__attribute__((section("__verbose"), aligned(8))) = \
57-
{ KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
58-
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
59-
if (__dynamic_dbg_enabled(descriptor)) \
60-
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
52+
{ KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
53+
_DPRINTK_FLAGS_DEFAULT }; \
54+
JUMP_LABEL(&descriptor.enabled, do_printk); \
55+
goto out; \
56+
do_printk: \
57+
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
58+
out: ; \
6159
} while (0)
6260

6361

6462
#define dynamic_dev_dbg(dev, fmt, ...) do { \
63+
__label__ do_printk; \
64+
__label__ out; \
6565
static struct _ddebug descriptor \
6666
__used \
6767
__attribute__((section("__verbose"), aligned(8))) = \
68-
{ KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
69-
DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
70-
if (__dynamic_dbg_enabled(descriptor)) \
71-
dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
68+
{ KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
69+
_DPRINTK_FLAGS_DEFAULT }; \
70+
JUMP_LABEL(&descriptor.enabled, do_printk); \
71+
goto out; \
72+
do_printk: \
73+
dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
74+
out: ; \
7275
} while (0)
7376

7477
#else

lib/dynamic_debug.c

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,11 @@
2626
#include <linux/dynamic_debug.h>
2727
#include <linux/debugfs.h>
2828
#include <linux/slab.h>
29+
#include <linux/jump_label.h>
2930

3031
extern struct _ddebug __start___verbose[];
3132
extern struct _ddebug __stop___verbose[];
3233

33-
/* dynamic_debug_enabled, and dynamic_debug_enabled2 are bitmasks in which
34-
* bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
35-
* use independent hash functions, to reduce the chance of false positives.
36-
*/
37-
long long dynamic_debug_enabled;
38-
EXPORT_SYMBOL_GPL(dynamic_debug_enabled);
39-
long long dynamic_debug_enabled2;
40-
EXPORT_SYMBOL_GPL(dynamic_debug_enabled2);
41-
4234
struct ddebug_table {
4335
struct list_head link;
4436
char *mod_name;
@@ -87,26 +79,6 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
8779
return buf;
8880
}
8981

90-
/*
91-
* must be called with ddebug_lock held
92-
*/
93-
94-
static int disabled_hash(char hash, bool first_table)
95-
{
96-
struct ddebug_table *dt;
97-
char table_hash_value;
98-
99-
list_for_each_entry(dt, &ddebug_tables, link) {
100-
if (first_table)
101-
table_hash_value = dt->ddebugs->primary_hash;
102-
else
103-
table_hash_value = dt->ddebugs->secondary_hash;
104-
if (dt->num_enabled && (hash == table_hash_value))
105-
return 0;
106-
}
107-
return 1;
108-
}
109-
11082
/*
11183
* Search the tables for _ddebug's which match the given
11284
* `query' and apply the `flags' and `mask' to them. Tells
@@ -170,17 +142,9 @@ static void ddebug_change(const struct ddebug_query *query,
170142
dt->num_enabled++;
171143
dp->flags = newflags;
172144
if (newflags) {
173-
dynamic_debug_enabled |=
174-
(1LL << dp->primary_hash);
175-
dynamic_debug_enabled2 |=
176-
(1LL << dp->secondary_hash);
145+
enable_jump_label(&dp->enabled);
177146
} else {
178-
if (disabled_hash(dp->primary_hash, true))
179-
dynamic_debug_enabled &=
180-
~(1LL << dp->primary_hash);
181-
if (disabled_hash(dp->secondary_hash, false))
182-
dynamic_debug_enabled2 &=
183-
~(1LL << dp->secondary_hash);
147+
disable_jump_label(&dp->enabled);
184148
}
185149
if (verbose)
186150
printk(KERN_INFO

scripts/Makefile.lib

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
101101
modname_flags = $(if $(filter 1,$(words $(modname))),\
102102
-D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
103103

104-
#hash values
105-
ifdef CONFIG_DYNAMIC_DEBUG
106-
debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\
107-
-D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))"
108-
else
109-
debug_flags =
110-
endif
111-
112104
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
113105
$(ccflags-y) $(CFLAGS_$(basetarget).o)
114106
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
@@ -152,8 +144,7 @@ endif
152144

153145
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
154146
$(__c_flags) $(modkern_cflags) \
155-
-D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) \
156-
$(debug_flags)
147+
-D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
157148

158149
a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
159150
$(__a_flags) $(modkern_aflags)

scripts/basic/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# fixdep: Used to generate dependency information during build process
1010
# docproc: Used in Documentation/DocBook
1111

12-
hostprogs-y := fixdep docproc hash
12+
hostprogs-y := fixdep docproc
1313
always := $(hostprogs-y)
1414

1515
# fixdep is needed to compile other host programs

scripts/basic/hash.c

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)