diff options
-rw-r--r-- | include/linux/dynamic_debug.h | 39 | ||||
-rw-r--r-- | lib/dynamic_debug.c | 42 | ||||
-rw-r--r-- | scripts/Makefile.lib | 11 | ||||
-rw-r--r-- | scripts/basic/Makefile | 2 | ||||
-rw-r--r-- | scripts/basic/hash.c | 64 |
5 files changed, 26 insertions, 132 deletions
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 52c0da4bdd18..bef3cda44c4c 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef _DYNAMIC_DEBUG_H | 1 | #ifndef _DYNAMIC_DEBUG_H |
2 | #define _DYNAMIC_DEBUG_H | 2 | #define _DYNAMIC_DEBUG_H |
3 | 3 | ||
4 | #include <linux/jump_label.h> | ||
5 | |||
4 | /* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which | 6 | /* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which |
5 | * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They | 7 | * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They |
6 | * use independent hash functions, to reduce the chance of false positives. | 8 | * use independent hash functions, to reduce the chance of false positives. |
@@ -22,8 +24,6 @@ struct _ddebug { | |||
22 | const char *function; | 24 | const char *function; |
23 | const char *filename; | 25 | const char *filename; |
24 | const char *format; | 26 | const char *format; |
25 | char primary_hash; | ||
26 | char secondary_hash; | ||
27 | unsigned int lineno:24; | 27 | unsigned int lineno:24; |
28 | /* | 28 | /* |
29 | * The flags field controls the behaviour at the callsite. | 29 | * The flags field controls the behaviour at the callsite. |
@@ -33,6 +33,7 @@ struct _ddebug { | |||
33 | #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ | 33 | #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ |
34 | #define _DPRINTK_FLAGS_DEFAULT 0 | 34 | #define _DPRINTK_FLAGS_DEFAULT 0 |
35 | unsigned int flags:8; | 35 | unsigned int flags:8; |
36 | char enabled; | ||
36 | } __attribute__((aligned(8))); | 37 | } __attribute__((aligned(8))); |
37 | 38 | ||
38 | 39 | ||
@@ -42,33 +43,35 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, | |||
42 | #if defined(CONFIG_DYNAMIC_DEBUG) | 43 | #if defined(CONFIG_DYNAMIC_DEBUG) |
43 | extern int ddebug_remove_module(const char *mod_name); | 44 | extern int ddebug_remove_module(const char *mod_name); |
44 | 45 | ||
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 | |||
53 | #define dynamic_pr_debug(fmt, ...) do { \ | 46 | #define dynamic_pr_debug(fmt, ...) do { \ |
47 | __label__ do_printk; \ | ||
48 | __label__ out; \ | ||
54 | static struct _ddebug descriptor \ | 49 | static struct _ddebug descriptor \ |
55 | __used \ | 50 | __used \ |
56 | __attribute__((section("__verbose"), aligned(8))) = \ | 51 | __attribute__((section("__verbose"), aligned(8))) = \ |
57 | { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \ | 52 | { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ |
58 | DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \ | 53 | _DPRINTK_FLAGS_DEFAULT }; \ |
59 | if (__dynamic_dbg_enabled(descriptor)) \ | 54 | JUMP_LABEL(&descriptor.enabled, do_printk); \ |
60 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ | 55 | goto out; \ |
56 | do_printk: \ | ||
57 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ | ||
58 | out: ; \ | ||
61 | } while (0) | 59 | } while (0) |
62 | 60 | ||
63 | 61 | ||
64 | #define dynamic_dev_dbg(dev, fmt, ...) do { \ | 62 | #define dynamic_dev_dbg(dev, fmt, ...) do { \ |
63 | __label__ do_printk; \ | ||
64 | __label__ out; \ | ||
65 | static struct _ddebug descriptor \ | 65 | static struct _ddebug descriptor \ |
66 | __used \ | 66 | __used \ |
67 | __attribute__((section("__verbose"), aligned(8))) = \ | 67 | __attribute__((section("__verbose"), aligned(8))) = \ |
68 | { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \ | 68 | { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ |
69 | DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \ | 69 | _DPRINTK_FLAGS_DEFAULT }; \ |
70 | if (__dynamic_dbg_enabled(descriptor)) \ | 70 | JUMP_LABEL(&descriptor.enabled, do_printk); \ |
71 | dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \ | 71 | goto out; \ |
72 | do_printk: \ | ||
73 | dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \ | ||
74 | out: ; \ | ||
72 | } while (0) | 75 | } while (0) |
73 | 76 | ||
74 | #else | 77 | #else |
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 02afc2533728..e925c7b960f1 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c | |||
@@ -26,19 +26,11 @@ | |||
26 | #include <linux/dynamic_debug.h> | 26 | #include <linux/dynamic_debug.h> |
27 | #include <linux/debugfs.h> | 27 | #include <linux/debugfs.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/jump_label.h> | ||
29 | 30 | ||
30 | extern struct _ddebug __start___verbose[]; | 31 | extern struct _ddebug __start___verbose[]; |
31 | extern struct _ddebug __stop___verbose[]; | 32 | extern struct _ddebug __stop___verbose[]; |
32 | 33 | ||
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 | |||
42 | struct ddebug_table { | 34 | struct ddebug_table { |
43 | struct list_head link; | 35 | struct list_head link; |
44 | char *mod_name; | 36 | char *mod_name; |
@@ -88,26 +80,6 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, | |||
88 | } | 80 | } |
89 | 81 | ||
90 | /* | 82 | /* |
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 | |||
110 | /* | ||
111 | * Search the tables for _ddebug's which match the given | 83 | * Search the tables for _ddebug's which match the given |
112 | * `query' and apply the `flags' and `mask' to them. Tells | 84 | * `query' and apply the `flags' and `mask' to them. Tells |
113 | * the user which ddebug's were changed, or whether none | 85 | * the user which ddebug's were changed, or whether none |
@@ -170,17 +142,9 @@ static void ddebug_change(const struct ddebug_query *query, | |||
170 | dt->num_enabled++; | 142 | dt->num_enabled++; |
171 | dp->flags = newflags; | 143 | dp->flags = newflags; |
172 | if (newflags) { | 144 | if (newflags) { |
173 | dynamic_debug_enabled |= | 145 | enable_jump_label(&dp->enabled); |
174 | (1LL << dp->primary_hash); | ||
175 | dynamic_debug_enabled2 |= | ||
176 | (1LL << dp->secondary_hash); | ||
177 | } else { | 146 | } else { |
178 | if (disabled_hash(dp->primary_hash, true)) | 147 | disable_jump_label(&dp->enabled); |
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); | ||
184 | } | 148 | } |
185 | if (verbose) | 149 | if (verbose) |
186 | printk(KERN_INFO | 150 | printk(KERN_INFO |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 54fd1b700131..7bfcf1a09ac5 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -101,14 +101,6 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" | |||
101 | modname_flags = $(if $(filter 1,$(words $(modname))),\ | 101 | modname_flags = $(if $(filter 1,$(words $(modname))),\ |
102 | -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") | 102 | -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") |
103 | 103 | ||
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 | |||
112 | orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ | 104 | orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ |
113 | $(ccflags-y) $(CFLAGS_$(basetarget).o) | 105 | $(ccflags-y) $(CFLAGS_$(basetarget).o) |
114 | _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) | 106 | _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) |
@@ -152,8 +144,7 @@ endif | |||
152 | 144 | ||
153 | c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ | 145 | c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ |
154 | $(__c_flags) $(modkern_cflags) \ | 146 | $(__c_flags) $(modkern_cflags) \ |
155 | -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) \ | 147 | -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) |
156 | $(debug_flags) | ||
157 | 148 | ||
158 | a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ | 149 | a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ |
159 | $(__a_flags) $(modkern_aflags) | 150 | $(__a_flags) $(modkern_aflags) |
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile index 09559951df12..4c324a1f1e0e 100644 --- a/scripts/basic/Makefile +++ b/scripts/basic/Makefile | |||
@@ -9,7 +9,7 @@ | |||
9 | # fixdep: Used to generate dependency information during build process | 9 | # fixdep: Used to generate dependency information during build process |
10 | # docproc: Used in Documentation/DocBook | 10 | # docproc: Used in Documentation/DocBook |
11 | 11 | ||
12 | hostprogs-y := fixdep docproc hash | 12 | hostprogs-y := fixdep docproc |
13 | always := $(hostprogs-y) | 13 | always := $(hostprogs-y) |
14 | 14 | ||
15 | # fixdep is needed to compile other host programs | 15 | # fixdep is needed to compile other host programs |
diff --git a/scripts/basic/hash.c b/scripts/basic/hash.c deleted file mode 100644 index 2ef5d3f666b8..000000000000 --- a/scripts/basic/hash.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com> | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | |||
10 | #define DYNAMIC_DEBUG_HASH_BITS 6 | ||
11 | |||
12 | static const char *program; | ||
13 | |||
14 | static void usage(void) | ||
15 | { | ||
16 | printf("Usage: %s <djb2|r5> <modname>\n", program); | ||
17 | exit(1); | ||
18 | } | ||
19 | |||
20 | /* djb2 hashing algorithm by Dan Bernstein. From: | ||
21 | * http://www.cse.yorku.ca/~oz/hash.html | ||
22 | */ | ||
23 | |||
24 | static unsigned int djb2_hash(char *str) | ||
25 | { | ||
26 | unsigned long hash = 5381; | ||
27 | int c; | ||
28 | |||
29 | c = *str; | ||
30 | while (c) { | ||
31 | hash = ((hash << 5) + hash) + c; | ||
32 | c = *++str; | ||
33 | } | ||
34 | return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1)); | ||
35 | } | ||
36 | |||
37 | static unsigned int r5_hash(char *str) | ||
38 | { | ||
39 | unsigned long hash = 0; | ||
40 | int c; | ||
41 | |||
42 | c = *str; | ||
43 | while (c) { | ||
44 | hash = (hash + (c << 4) + (c >> 4)) * 11; | ||
45 | c = *++str; | ||
46 | } | ||
47 | return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1)); | ||
48 | } | ||
49 | |||
50 | int main(int argc, char *argv[]) | ||
51 | { | ||
52 | program = argv[0]; | ||
53 | |||
54 | if (argc != 3) | ||
55 | usage(); | ||
56 | if (!strcmp(argv[1], "djb2")) | ||
57 | printf("%d\n", djb2_hash(argv[2])); | ||
58 | else if (!strcmp(argv[1], "r5")) | ||
59 | printf("%d\n", r5_hash(argv[2])); | ||
60 | else | ||
61 | usage(); | ||
62 | exit(0); | ||
63 | } | ||
64 | |||