Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4243388yba; Tue, 9 Apr 2019 14:26:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuLh7/KEQJ68is6h+vNL1B+XdKOoUPbeq1htM26ZiPVOqUBjAFaG5FzUflQ4hLrTLIxqUC X-Received: by 2002:a65:524a:: with SMTP id q10mr35655095pgp.224.1554845207884; Tue, 09 Apr 2019 14:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554845207; cv=none; d=google.com; s=arc-20160816; b=W8SwweQ83QDYUwTAWeBOe589NzSbi1qzT6IZzx/dVPREdfjIA9wC8EHc8WbemkxlGk 2WxCAq1IA1em38jMTvKiG11tKaxOXKtV5seEms54KcEp7DThlZTYhJ9TaEqv5NqXkXkT E/bcDMXOSIvwHDSfyglM2L30FzlOVCJygnJJumjVS0W+c6y3oWtwFrWxUUJ48zrr/Okl GzAjCnF0mp2yV3IcBbaWk8Tl4MXUeD5ZrtbZirfym+/vVoTpY/MIMO8uG8q0Lq0+VMRp 4z2zE3E+fbHbalPxof9sEIBWGd0qT9paSmxFUb5VX5Ojxj4T8JIXPQxr3h5h0aTK5tkT fT0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NMdfYCF2Y0BJ3MV+fDSR37wOUAxiXZPH6PiL1kw5XrE=; b=dCAw4WcfLxZ4fNR8FH5wmtpKCp029IQ6mZwnlGnSG0g6Eg8BI2tKRy7gbXF2d8S6rY SpongMmX8FbTygXR7UjBPqhSP8QvIgenHyAiwcrqlHTsGhcb8+kMZwDvuEVgJTw+YLHi xpSL3idxf3W1Bd5JlZLGYMD7knIr+Uf5qmShSgMHvjRYHo9RvnSY/UjBhxBRpYiNrTTo +TiUTANhxppkA3xXozY1ckzos7hiiZwH8A+Ue9RkruhuvkcPtLn+9OXqQk4iqjJl6OC+ bbCUxq+MqjfyIkd8126iiJvoVaqwbKDsSM1hwhiSmCY1q4geU8uHKfqO7yyi7cbFDSV0 aTxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="E/3soZ0f"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si17658585pgc.472.2019.04.09.14.26.31; Tue, 09 Apr 2019 14:26:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="E/3soZ0f"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726750AbfDIVZ7 (ORCPT + 99 others); Tue, 9 Apr 2019 17:25:59 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:44132 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfDIVZ5 (ORCPT ); Tue, 9 Apr 2019 17:25:57 -0400 Received: by mail-ed1-f66.google.com with SMTP id d11so101057edp.11 for ; Tue, 09 Apr 2019 14:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NMdfYCF2Y0BJ3MV+fDSR37wOUAxiXZPH6PiL1kw5XrE=; b=E/3soZ0fucmmT9O2o/PIpJ0FQzTwq0ZtXbcOdUX5awpfc9cAe/fsyEhoCmHzhQ2a6X 2w7VGffcchaQW2szQcVVVYfNGI3Y/QgUlXIvEED0vYQZaMTyKxkasn/gbN0Cv8nncP4W EI1lSGSCcGcLfqMAGHpL6aSEpxqxWax1gHTpg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NMdfYCF2Y0BJ3MV+fDSR37wOUAxiXZPH6PiL1kw5XrE=; b=oqbs3AjTjhp64+ahUnU4ekk8i+DCz0tVWTEbBQhMgErTUN6X70FNEQ4nUUvsH/p5U8 AeSLnytEe43FB5d4AjngkSSiCHqI9oifyXKTNjJUVl/IPpN/SJGFuv3oQQpf9wm8upSn PBAT+2Vcgdj8obA3Z/xua3nPt5MepJfEayylu1ASfbbL5QVczSqsRjREDNGHx6RdxEs1 eMtaNxt5tUIRrAncGEVLh2nLL9dtQk6L3WKhWIQ8/KLLMWQP9J7vHfnObY0QIYypDqA6 o7RnTam2nrwR6Cpiup3DmkGV1ue2zB2+2s9DExoDgVWGey5VfOTqTmywuO6lvGeI4zeo plnA== X-Gm-Message-State: APjAAAUGALbizMMs3ZEdtDSWL7ppaQBUOeUhhD5thW/pHR0OMvDU/PGv gFk5op25/S70cVKHrbqZAWHOjQ== X-Received: by 2002:a05:6402:895:: with SMTP id e21mr15154920edy.139.1554845155822; Tue, 09 Apr 2019 14:25:55 -0700 (PDT) Received: from prevas-ravi.prevas.se (ip-5-186-118-63.cgn.fibianet.dk. [5.186.118.63]) by smtp.gmail.com with ESMTPSA id i26sm3477986ejc.51.2019.04.09.14.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 14:25:55 -0700 (PDT) From: Rasmus Villemoes To: Andrew Morton Cc: Jason Baron , linux-kernel@vger.kernel.org, Rasmus Villemoes Subject: [PATCH 05/10] dynamic_debug: drop use of bitfields in struct _ddebug Date: Tue, 9 Apr 2019 23:25:12 +0200 Message-Id: <20190409212517.7321-6-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409212517.7321-1-linux@rasmusvillemoes.dk> References: <20190409212517.7321-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Rasmus Villemoes --- 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 c2be029b9b53..e2fa2737a485 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, @@ -78,8 +77,7 @@ void __dynamic_netdev_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 \ } @@ -104,10 +102,10 @@ void __dynamic_netdev_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 497b1c8ccc2a..482a35a68752 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -53,6 +53,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[]; @@ -111,7 +123,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++ = '_'; @@ -157,7 +169,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]; @@ -194,27 +206,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))); @@ -537,10 +550,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), " "); else @@ -548,15 +562,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) @@ -807,7 +821,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