Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3856245imu; Fri, 18 Jan 2019 19:47:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN6krTSol/7UOcFvs5uzF5qohvSVA6ulPeX27jNVDKKlQxx8PztoOtQKlJ8ccMghGQF93x6G X-Received: by 2002:a65:50c1:: with SMTP id s1mr19830015pgp.350.1547869630607; Fri, 18 Jan 2019 19:47:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547869630; cv=none; d=google.com; s=arc-20160816; b=RNXkaHB69vUHoj+XZRK1+I6DGietYkvyFZ0ze7KqdEuGjedsEuNeOTrfGY7N1m9Dqz uHFpKus/bqIpf5o1HdVmN2Z+rt5eA8AOjx47eZmcx3FBFV1yms2ZQuY5ndU2ph/q+5d2 ojfGKaduVZ4k6qge08zAel4g9ZnyUvpb9sF0xDoMQyhu4x3U3QoIrpczvxhTIRkTt8fb b9oL4Pvi8Sw7FwMp/1tqnN2xuMSoCdP3/IcEmTdY8FEO+NWufNsh8J7U+KucLr0Qp4zc tCJy4HiIo4xaCiNPF2ZNEBYcWUgWarrj1H9mCWwLVcGdHDenL+ZOOXVsm6LUe8I427qR iQSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=GmXcVg56/uy4EXsHvS3OpOX4Tq5rsuK7nLrJEUMmhfk=; b=eE0QBsgG2TG0dUpjGcqwjEEBZZWh7PPovzFry5u+zOnjF/rUECXAfo85RfbCXGviS8 nli3yTQmXShgcW9f0tfqy7LkFPSkvUsPprRwovehQtO3b21WaBNnN4IJK8Ef4jTFSTgv C1Ol+FDtbaLIGKbMTdAo+N+3Pn74Pa7rfmuk1RwhL3qQ7Y7wyEAbaO/GFXw83j9g7MNp sh1BH+2mcL9hQntrdmsUogTC303u6TXZMIOyH8vSG2D03HMecSaAdLuslT2iKgfIWMVq jt+2qDv71ew8D0T4AWfb1P4vSi0FTRh/+qYqlOqkfoIjv16ngPuKBs5zxCPLbMhbyCPw 5MvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=JXxhXQKe; 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 d125si6335578pgc.418.2019.01.18.19.46.51; Fri, 18 Jan 2019 19:47:10 -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=@nifty.com header.s=dec2015msa header.b=JXxhXQKe; 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 S1730437AbfASDpj (ORCPT + 99 others); Fri, 18 Jan 2019 22:45:39 -0500 Received: from conssluserg-03.nifty.com ([210.131.2.82]:49396 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730410AbfASDpj (ORCPT ); Fri, 18 Jan 2019 22:45:39 -0500 Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (authenticated) by conssluserg-03.nifty.com with ESMTP id x0J3jVnQ007493 for ; Sat, 19 Jan 2019 12:45:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com x0J3jVnQ007493 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1547869532; bh=GmXcVg56/uy4EXsHvS3OpOX4Tq5rsuK7nLrJEUMmhfk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=JXxhXQKeGiNqRdWKMs07D6XGBPh4t+kofoEtXFeA7qY+O9I8zFqtOEKRMwsqDX4Tc X1u5Vg/jtQ4kdXD2AD3rG1y30Q+Q2biiAyZdaujUtieeExEh/Ex3P3sEiz4JHaKv4E +1xqUAOcxo8xponw8EKhA89GaKZycLZv9K18SQYmua6PGJb4hvn//FCjRIcE+bFStK dQXoN/chaGYwCzasw4AawKEKynp/suf8q0ib39y1YkSw3P87VnexUllHqr7nQqFuNS MUPUAmqtaai++nX9IUmf3fGyZ5k7IKjMjkLS5f/aYaEvcvDS6qtCdVqH+6QbFAnDlp sheTH4anKRXgA== X-Nifty-SrcIP: [209.85.221.172] Received: by mail-vk1-f172.google.com with SMTP id h128so3514392vkg.11 for ; Fri, 18 Jan 2019 19:45:32 -0800 (PST) X-Gm-Message-State: AJcUukd9kpsoZ8MzeQ76DxfhjB3P/jGQCopfDFBD7KnbBTfsdt5Lhqx3 H+rgo5QxNPOFQxX8PDh8bIPUI1ZHZTLmvDwXtcQ= X-Received: by 2002:a1f:91cb:: with SMTP id t194mr8320663vkd.74.1547869531293; Fri, 18 Jan 2019 19:45:31 -0800 (PST) MIME-Version: 1.0 References: <1547827230-55132-1-git-send-email-andrew.murray@arm.com> In-Reply-To: <1547827230-55132-1-git-send-email-andrew.murray@arm.com> From: Masahiro Yamada Date: Sat, 19 Jan 2019 12:44:55 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Linux-eng] [RFC 0/3] Abstract empty functions with STUB_UNLESS macro To: Andrew Murray Cc: Arnd Bergmann , Kees Cook , Andrew Morton , Catalin Marinas , Will Deacon , linux-arm-kernel , Rafael Wysocki , Linux Kernel Mailing List , Grant Likely , Steven Price , Dave P Martin Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 19, 2019 at 1:02 AM Andrew Murray wrote: > > A common pattern found in header files is a function declaration dependent > on a CONFIG_ option being enabled, followed by an empty function for when > that option isn't enabled. This boilerplate code can often take up a lot > of space and impact code readability. > > This series introduces a STUB_UNLESS macro that simplifies header files as > follows: > > STUB_UNLESS(CONFIG_FOO, [body], prototype) > > This evaluates to 'prototype' prepended with 'extern' if CONFIG_FOO is set > to 'y'. Otherwise it will evaluate to 'prototype' prepended with 'static > inline' followed by an empty function body. Where optional argument 'body' > is present then 'body' will be used as the function body, intended to allow > simple return statements. Using the macro results in hunks such as this: > > -#ifdef CONFIG_HAVE_HW_BREAKPOINT > -extern void hw_breakpoint_thread_switch(struct task_struct *next); > -extern void ptrace_hw_copy_thread(struct task_struct *task); > -#else > -static inline void hw_breakpoint_thread_switch(struct task_struct *next) > -{ > -} > -static inline void ptrace_hw_copy_thread(struct task_struct *task) > -{ > -} > -#endif > +STUB_UNLESS(CONFIG_HAVE_HW_BREAKPOINT, > +void hw_breakpoint_thread_switch(struct task_struct *next)); > + > +STUB_UNLESS(CONFIG_HAVE_HW_BREAKPOINT, > +void ptrace_hw_copy_thread(struct task_struct *task)); > > This may or may not be considered as more desirable than the status quo. > > This series updates arm64 and perf to use the macro as an example. > > Andrew Murray (3): > kconfig.h: abstract empty functions with STUB_UNLESS macro > cpufreq: update headers to use STUB_UNLESS macro > arm64: update headers to use STUB_UNLESS macro > > arch/arm64/include/asm/acpi.h | 38 +++++++++------------- > arch/arm64/include/asm/alternative.h | 6 +--- > arch/arm64/include/asm/cpufeature.h | 6 +--- > arch/arm64/include/asm/cpuidle.h | 18 +++-------- > arch/arm64/include/asm/debug-monitors.h | 10 ++---- > arch/arm64/include/asm/fpsimd.h | 57 +++++++++++++-------------------- > arch/arm64/include/asm/hw_breakpoint.h | 16 +++------ > arch/arm64/include/asm/kasan.h | 9 ++---- > arch/arm64/include/asm/numa.h | 19 ++++------- > arch/arm64/include/asm/ptdump.h | 13 +++----- > arch/arm64/include/asm/signal32.h | 29 +++++------------ > include/linux/cpufreq.h | 21 ++++-------- > include/linux/kconfig.h | 31 ++++++++++++++++++ > 13 files changed, 110 insertions(+), 163 deletions(-) > > -- > 2.7.4 > Honestly, I am not a big fan of shorting the code for the purpose of shorting. This patch series is based on the assumption the first argument is "defined or undefined". In other words, it cannot handle tristate CONFIG option. But, if you go this way, could you make it work in a more generic manner? And, decouple this from For example, see the following cases: https://github.com/torvalds/linux/blob/v5.0-rc2/include/acpi/button.h#L7 https://github.com/torvalds/linux/blob/v5.0-rc2/include/linux/firmware.h#L42 The latter is a good example. In many cases, the kernel headers look like this: #ifdef CONFIG_FOO { large block of prototype declaration } #else { large block of nop stubs } #endif So, this approach shifts "duplication of prototype" into "duplication of conditional part". -- Best Regards Masahiro Yamada