From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752206AbbKPIyY (ORCPT ); Mon, 16 Nov 2015 03:54:24 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:54035 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751957AbbKPIyT (ORCPT ); Mon, 16 Nov 2015 03:54:19 -0500 From: Arnd Bergmann To: Vineet Gupta Cc: Geert Uytterhoeven , Rasmus Villemoes , Paul Gortmaker , Ingo Molnar , Andrew Morton , Thomas Gleixner , "H. Peter Anvin" , Michal Marek , "linux-arch@vger.kernel.org" , "linux-kernel@vger.kernel.org" , arcml Subject: Re: using IS_ENABLED(CONFIG_xyz) effectively Date: Mon, 16 Nov 2015 09:52:16 +0100 Message-ID: <4200245.e01Ct9ua6M@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <5613F3DE.4010406@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:JFEi1azqRPoGwUmlUMp7ar+uRMO2BGxRV0nzD1iihxu7F9gh2VL mumza1hlq99/UZ8q6J8MX83K4zCxfxmgYOl3lJfsixAOMXXvMpe9kq5n7HGzcmRqwTRuJu3 0XEa25JWpUU8jJJWNuTGXLzjSEOYt0omBzYksum9VKCNuBxc2+d8vcr9/vYG6NAbjzbDabB HMV0+uNSwcNX+gB9LesaA== X-UI-Out-Filterresults: notjunk:1;V01:K0:p1NSdZR+6eo=:E4VVSYW6nNgzRCKkd2hApa 0CdAaWI9MaL70J9L8sL3ZMXeZrD8HWEash2OenWX72L+9jM0iH9UOf1cCXHP5urcecqgSttUm sIPMXFFfKKu3aMTwXgJsoBvCBqcCKSG6/qF6xI/S2BUbX5b2vGGWmTkT9vweD+IsSUyyboXYN 75PcBQhdwUfy9gp8I15w56pibLIVlYQvJ/+dUrpejeK/PGT1P9OomlSkebtrLWi1rxDRi8DBB 5f82k9l3ioUhvotZPyjDtx8kJ5cmBze8JlacZ7QS/XPXmZMEa0DzbcTLZiSI3wJgVy6NEkKps hVxCcjTFOi5uE8/alDii7khIcWY2jpJlqvsVAk4E1QOlIX6UU5194cCrHykUwg9XGb7Gxu2Ps jXc2yLJJtaS7g2+zKZnA54HLQkmExJu006FWd3P6gbwuCkoOvsCzJvQCYPqCafBji3yigp2ib bbLsFXhQd+qfwlrMWUbY1zVxi4teoLN5NZrXYs4MSBqZ+/bOijLapBYn7pFZyx1qxdpu6qUg7 P904tqoEHOZqzgsArc+DMc3n//vOI2AKUFloAA9GsstgvkfSko0W+U1++eeJ3mDOmPkmqFPUa tUBKdvNYBRJ8tg1bn/1FjuVNpNrJz8h5TaU12Jz8v/NNeFvcVd5o5Zrdm87VwxRiZ8YRRznG0 EGAo8YdBLgieMIiF+YnehQ2lMdcS77az2dsOpdxWGrXFuF/gFdxsg9NHCItZ4SucNUNIbAwPj GJG2XqTwxT4pcIgU Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 16 November 2015 08:35:05 Vineet Gupta wrote: > Hi Geert, > > On Monday 16 November 2015 01:58 PM, Geert Uytterhoeven wrote: > > Hi Vineet, > > > > On Mon, Nov 16, 2015 at 9:00 AM, Vineet Gupta > > wrote: > >> I've been using IS_ENABLED for some time and once in a while run into an issue > >> which prevents seamless use. Hence posing this question to experts in the area. > >> > >> C macro processor evaluates the ensuing control block even if IS_ENABLED evaluates > >> to false. This requires dummy #defines or worse still removing usage of IS_ENABLED > >> altogether. > >> > >> e.g. In example below even for ARCOMPACT builds, we need the ARCV2 specific define > >> ARCV2_IRQ_DEF_PRIO. > >> > >> void arch_cpu_idle(void) > >> { > >> if (is_isa_arcompact()) { <---- IS_ENABLED(CONFIG_ISA_ARCOMPACT) > >> __asm__("sleep 0x3"); > >> } else { > >> const int arg = 0x10 | ARCV2_IRQ_DEF_PRIO; > >> __asm__("sleep 0x10"); > >> } > >> } > >> > >> One could argue that the interface needs to be cleanly defined to not have such > >> specific #defines in common code in first place. However sometime that becomes > >> just too tedious. > >> > >> Is there a way to get around by this ? > > Use #ifdef CONFIG_...? > > > > The advantage of IS_ENABLED() over #ifdef is that it allows compile-testing of > > the disabled code path. Of course it should only be compiled if it makes > > sense. And that's exactly what you're running into. > > And I thought it was to de-uglify the code with same semantics - which doesn't > seem to be the case ! I would still try to do this with if(IS_ENABLED()) or another macro like you have above. The problem you ran into with the macro definitions is that you have conflicting header files: #ifdef CONFIG_ISA_ARCOMPACT #include #else #include #endif This has other (small) problems too, because you get possibly conflicting symbols (e.g. arch_local_irq_enable but also the register names) that make it harder to follow what's going on when reading the code. If you prefix all the defines in the two headers with the respective name, you can just include both headers and avoid this: static inline void arch_local_irq_enable(void) { if (IS_ENABLED(CONFIG_ISA_ARCCOMPACT)) return arccompact_local_irq_enable(); else return arcv2_local_irq_enable(); } Arnd