Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4340316imj; Tue, 12 Feb 2019 14:13:00 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib22A2FoxPs57S/eROCLN7wW73Warmg677/Ty61JCwUB5rX7LcFTNE3PA1he/M9z6Vj1+j0 X-Received: by 2002:a62:8d46:: with SMTP id z67mr6034606pfd.249.1550009580345; Tue, 12 Feb 2019 14:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550009580; cv=none; d=google.com; s=arc-20160816; b=ac/J2Gav2/4ZjTV/oSfMp++T2ts2Zh3NZ6aZir7+pal/xRL6CywKqD3RM3tPJR+KyB 95vrWEuZ32ZtdE+uq6PV2nTfUcPViW4p+wTwsQG4UdK0LGveqqVbXz5/WKllxk7PZO+b lKXf5xJOrNiaCbjKw/bAYMHw8i+TX4m4t+hqU2zjSpcODdVC3p/pgpxVVh4WlQ+Ifh27 mYSL58S/bLgKGUpQGtXkhb5UEvlTgXsYSG5xRi21+a+stppPAGlriJ9fGuA3ImrYYTB/ aADDrzBU9iUzE7l/4eXaWqVMN6IiVaxze9dUPskfTA6I/HtMux3uuEk5OYJy4FmU9Nzz u+pA== 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=85vvFN2kaHL03HAGXK2CD9rX/wTyoy7q0CdAo1TKtSM=; b=c62lXX/sutg+K9Y9o56fV6q0H6PJfOxaD6OQi/8mwADD+hut0I2e+PhOmvCwGDi0Lb 9/q7tKQUKgti39cXl/b4KEC/OXdHE5nz1XoKh0rinIAqDQFnJWtBcmnkvN2TJef5RXt8 vtP1d2nIv/CYDiNC7V7FJfgA1eu+O7UL2NJqvgIKrkZKLCGHgZo/C1TZkcVjFID7D4Aa 7UCytN1rMhXVKeECQbkjC1wn0DLrz4xSwLS50nRk/VnxG5VmkP+zS/hAZp8InqqbhU1/ G6tGJ//0shBEwL9oRyKqGkuGIFU2d7EJLewfXiHye8i4VPmskbhtADkM/d+ccxOQu+fE n6tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=P5juK3zS; 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 z6si14063462plk.133.2019.02.12.14.12.44; Tue, 12 Feb 2019 14:13:00 -0800 (PST) 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=P5juK3zS; 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 S1732001AbfBLVmL (ORCPT + 99 others); Tue, 12 Feb 2019 16:42:11 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42439 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731676AbfBLVmJ (ORCPT ); Tue, 12 Feb 2019 16:42:09 -0500 Received: by mail-ed1-f66.google.com with SMTP id r15so152810eds.9 for ; Tue, 12 Feb 2019 13:42:08 -0800 (PST) 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=85vvFN2kaHL03HAGXK2CD9rX/wTyoy7q0CdAo1TKtSM=; b=P5juK3zSsaANB2V0jcvndYD2I2w84L+gKAdgX5lGHLKhllxN1OklLBKRz/q2KuLvrd Z/k9WXx0LJsMqBfLBOtCDuIqRXvwoZBC7DSaKAYe/QolDI1/Ypnl16OH5eRxPja//+tM 1NwcvNETe2i3xSDNPoDL85+HHxmOtfA+xMapA= 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=85vvFN2kaHL03HAGXK2CD9rX/wTyoy7q0CdAo1TKtSM=; b=ovRZBd8+P0ZIHjkrC7T6pOrM+rr/VCxUeEZpOQnE5O6IEpEtyzMUx12Tq4IqrcgRMs CSp1eNYmPLKek2ZDMujxLZf0B1Xz+LFed0tSRyOoGzKIFkVNZwMY1KlTlt5+/I+h5Eue s39iIbgpO3eOxhcfo3K2EEkcVEdiLL9RK3VtGh+3pMhg9gsVrN/lx6khelsnyvnf3IAj s66TvScAmD1X9pbsAty5uWkzP9wo5ls07uBpd9M6DmpItyqp5QQnWdd+LP9yezUlvkaX 7optJZvVfrjJAt6jOsk9B4jLPtU6Y32bk2WAX9/0G6GRkYMQA7GITjiXq9ErEKA/kpKf XMEw== X-Gm-Message-State: AHQUAualQJr+aenWOVtDWpZaXU/aiMyPtQMRjZfJJaEtcB02r+Sp30F9 l2eYFgpSYCouHBGUCMBqDU25uQ== X-Received: by 2002:a17:906:b7c3:: with SMTP id fy3mr4260766ejb.5.1550007727289; Tue, 12 Feb 2019 13:42:07 -0800 (PST) Received: from prevas-ravi.waoo.dk (ip-5-186-119-174.cgn.fibianet.dk. [5.186.119.174]) by smtp.gmail.com with ESMTPSA id v1sm3697607eds.47.2019.02.12.13.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 13:42:06 -0800 (PST) From: Rasmus Villemoes To: Andrew Morton , Jason Baron Cc: linux-kernel@vger.kernel.org, Rasmus Villemoes Subject: [PATCH v4 10/14] dynamic_debug: refactor dynamic_pr_debug and friends Date: Tue, 12 Feb 2019 22:41:46 +0100 Message-Id: <20190212214150.4807-11-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212214150.4807-1-linux@rasmusvillemoes.dk> References: <20190212214150.4807-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 For the upcoming 'define the _ddebug descriptor in assembly', we need all the descriptors in a translation unit to have distinct names (because asm does not understand C scope). The easiest way to achieve that is as usual with an extra level of macros, passing the identifier to use to the innermost macro, generating it via __UNIQUE_ID or something. However, instead of repeating that exercise for dynamic_pr_debug, dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we can use the similarity between their bodies to implement them via a common macro, _dynamic_func_call - though the hex_dump case requires a slight variant, since print_hex_dump does not take the _ddebug descriptor. We'll also get to use that variant elsewhere (btrfs). Acked-by: Jason Baron Signed-off-by: Rasmus Villemoes --- include/linux/dynamic_debug.h | 72 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 3f8977cfa479..c2be029b9b53 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, #endif -#define dynamic_pr_debug(fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ - ##__VA_ARGS__); \ +#define __dynamic_func_call(id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(&id, ##__VA_ARGS__); \ } while (0) -#define dynamic_dev_dbg(dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_dev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ +#define __dynamic_func_call_no_desc(id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(__VA_ARGS__); \ } while (0) -#define dynamic_netdev_dbg(dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ -} while (0) +/* + * "Factory macro" for generating a call to func, guarded by a + * DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be + * initialized using the fmt argument. The function will be called with + * the address of the descriptor as first argument, followed by all + * the varargs. Note that fmt is repeated in invocations of this + * macro. + */ +#define _dynamic_func_call(fmt, func, ...) \ + __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) +/* + * A variant that does the same, except that the descriptor is not + * passed as the first argument to the function; it is only called + * with precisely the macro's varargs. + */ +#define _dynamic_func_call_no_desc(fmt, func, ...) \ + __dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) -#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - print_hex_dump(KERN_DEBUG, prefix_str, \ - prefix_type, rowsize, groupsize, \ - buf, len, ascii); \ -} while (0) +#define dynamic_pr_debug(fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_pr_debug, \ + pr_fmt(fmt), ##__VA_ARGS__) + +#define dynamic_dev_dbg(dev, fmt, ...) \ + _dynamic_func_call(fmt,__dynamic_dev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_netdev_dbg(dev, fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii) #else -- 2.20.1