From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Jason Baron <jbaron@akamai.com>,
Nathan Chancellor <natechancellor@gmail.com>,
Nick Desaulniers <ndesaulniers@google.com>,
linux-kernel@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH v6 5/8] dynamic_debug: drop use of bitfields in struct _ddebug
Date: Tue, 18 Jun 2019 00:20:31 +0200 [thread overview]
Message-ID: <20190617222034.10799-6-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <20190617222034.10799-1-linux@rasmusvillemoes.dk>
Properly initializing a struct containing bitfields in assembly is
hard. Instead, merge lineno and flags to a single unsigned int, which we
mask manually. This should not cause any worse code than what gcc would
need to generate for accessing the bitfields anyway.
Actually, on 64 bit, there is a four byte hole after these fields, so we
could just give flags and lineno each their own u32. But I don't think
that's worth the ifdeffery.
Acked-by: Jason Baron <jbaron@akamai.com>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/dynamic_debug.h | 12 ++++------
lib/dynamic_debug.c | 44 +++++++++++++++++++++++------------
2 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 6c809440f319..7d6d0153096e 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -20,7 +20,6 @@ struct _ddebug {
const char *function;
const char *filename;
const char *format;
- unsigned int lineno:18;
/*
* The flags field controls the behaviour at the callsite.
* The bits here are changed dynamically when the user
@@ -37,7 +36,7 @@ struct _ddebug {
#else
#define _DPRINTK_FLAGS_DEFAULT 0
#endif
- unsigned int flags:8;
+ unsigned int flags_lineno; /* flags in lower 8 bits, lineno in upper 24 */
#ifdef CONFIG_JUMP_LABEL
union {
struct static_key_true dd_key_true;
@@ -46,7 +45,7 @@ struct _ddebug {
#endif
} __attribute__((aligned(8)));
-
+#define _DPRINTK_FLAGS_LINENO_INIT (((unsigned)__LINE__ << 8) | _DPRINTK_FLAGS_DEFAULT)
#if defined(CONFIG_DYNAMIC_DEBUG)
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
@@ -85,8 +84,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
.function = __func__, \
.filename = __FILE__, \
.format = (fmt), \
- .lineno = __LINE__, \
- .flags = _DPRINTK_FLAGS_DEFAULT, \
+ .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \
_DPRINTK_KEY_INIT \
}
@@ -111,10 +109,10 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
#ifdef DEBUG
#define DYNAMIC_DEBUG_BRANCH(descriptor) \
- likely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
+ likely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)
#else
#define DYNAMIC_DEBUG_BRANCH(descriptor) \
- unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
+ unlikely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)
#endif
#endif
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 3599c4c0361a..3a1a80041cd6 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -55,6 +55,18 @@ static inline const char *dd_format(const struct _ddebug *dd)
{
return dd->format;
}
+static inline unsigned dd_lineno(const struct _ddebug *dd)
+{
+ return dd->flags_lineno >> 8;
+}
+static inline unsigned dd_flags(const struct _ddebug *dd)
+{
+ return dd->flags_lineno & 0xff;
+}
+static inline void dd_set_flags(struct _ddebug *dd, unsigned newflags)
+{
+ dd->flags_lineno = (dd_lineno(dd) << 8) | newflags;
+}
extern struct _ddebug __start___verbose[];
extern struct _ddebug __stop___verbose[];
@@ -113,7 +125,7 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
BUG_ON(maxlen < 6);
for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
- if (dp->flags & opt_array[i].flag)
+ if (dd_flags(dp) & opt_array[i].flag)
*p++ = opt_array[i].opt_char;
if (p == buf)
*p++ = '_';
@@ -159,7 +171,7 @@ static int ddebug_change(const struct ddebug_query *query,
{
int i;
struct ddebug_table *dt;
- unsigned int newflags;
+ unsigned int newflags, oldflags;
unsigned int nfound = 0;
char flagbuf[10];
@@ -196,27 +208,28 @@ static int ddebug_change(const struct ddebug_query *query,
/* match against the line number range */
if (query->first_lineno &&
- dp->lineno < query->first_lineno)
+ dd_lineno(dp) < query->first_lineno)
continue;
if (query->last_lineno &&
- dp->lineno > query->last_lineno)
+ dd_lineno(dp) > query->last_lineno)
continue;
nfound++;
- newflags = (dp->flags & mask) | flags;
- if (newflags == dp->flags)
+ oldflags = dd_flags(dp);
+ newflags = (oldflags & mask) | flags;
+ if (newflags == oldflags)
continue;
#ifdef CONFIG_JUMP_LABEL
- if (dp->flags & _DPRINTK_FLAGS_PRINT) {
+ if (oldflags & _DPRINTK_FLAGS_PRINT) {
if (!(flags & _DPRINTK_FLAGS_PRINT))
static_branch_disable(&dp->key.dd_key_true);
} else if (flags & _DPRINTK_FLAGS_PRINT)
static_branch_enable(&dp->key.dd_key_true);
#endif
- dp->flags = newflags;
+ dd_set_flags(dp, newflags);
vpr_info("changed %s:%d [%s]%s =%s\n",
- trim_prefix(dd_filename(dp)), dp->lineno,
+ trim_prefix(dd_filename(dp)), dd_lineno(dp),
dt->mod_name, dd_function(dp),
ddebug_describe_flags(dp, flagbuf,
sizeof(flagbuf)));
@@ -539,10 +552,11 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
{
int pos_after_tid;
int pos = 0;
+ unsigned flags = dd_flags(desc);
*buf = '\0';
- if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
+ if (flags & _DPRINTK_FLAGS_INCL_TID) {
if (in_interrupt())
pos += snprintf(buf + pos, remaining(pos), "<intr> ");
else
@@ -550,15 +564,15 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
task_pid_vnr(current));
}
pos_after_tid = pos;
- if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
+ if (flags & _DPRINTK_FLAGS_INCL_MODNAME)
pos += snprintf(buf + pos, remaining(pos), "%s:",
dd_modname(desc));
- if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
+ if (flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
pos += snprintf(buf + pos, remaining(pos), "%s:",
dd_function(desc));
- if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
+ if (flags & _DPRINTK_FLAGS_INCL_LINENO)
pos += snprintf(buf + pos, remaining(pos), "%d:",
- desc->lineno);
+ dd_lineno(desc));
if (pos - pos_after_tid)
pos += snprintf(buf + pos, remaining(pos), " ");
if (pos >= PREFIX_SIZE)
@@ -844,7 +858,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
}
seq_printf(m, "%s:%u [%s]%s =%s \"",
- trim_prefix(dd_filename(dp)), dp->lineno,
+ trim_prefix(dd_filename(dp)), dd_lineno(dp),
iter->table->mod_name, dd_function(dp),
ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
seq_escape(m, dd_format(dp), "\t\r\n\"");
--
2.20.1
next prev parent reply other threads:[~2019-06-17 22:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 22:20 [PATCH v6 0/8] implement DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2019-06-17 22:20 ` [PATCH v6 1/8] linux/device.h: use unique identifier for each struct _ddebug Rasmus Villemoes
2019-06-17 22:20 ` [PATCH v6 2/8] linux/net.h: " Rasmus Villemoes
2019-06-17 23:08 ` David Miller
2019-06-17 22:20 ` [PATCH v6 3/8] linux/printk.h: " Rasmus Villemoes
2019-06-17 22:20 ` [PATCH v6 4/8] dynamic_debug: introduce accessors for string members of " Rasmus Villemoes
2019-06-17 22:20 ` Rasmus Villemoes [this message]
2019-06-17 22:20 ` [PATCH v6 6/8] dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2019-06-17 22:20 ` [PATCH v6 7/8] dynamic_debug: add asm-generic implementation for DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
2019-06-17 22:35 ` Nick Desaulniers
2019-06-20 20:46 ` Rasmus Villemoes
2019-06-24 21:53 ` Nick Desaulniers
2019-06-25 6:35 ` Rasmus Villemoes
2019-06-25 22:18 ` Nick Desaulniers
2019-06-26 23:16 ` Nick Desaulniers
2019-06-26 23:52 ` Rasmus Villemoes
2019-06-27 18:03 ` Nick Desaulniers
2019-06-17 22:20 ` [PATCH v6 8/8] x86-64: select HAVE_DYNAMIC_DEBUG_RELATIVE_POINTERS Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190617222034.10799-6-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=jbaron@akamai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®