[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <54190846.9060601@martingkelly.com>
Date: Tue, 16 Sep 2014 21:04:22 -0700
From: Martin Kelly <martin@...tingkelly.com>
To: "Li, Aubrey" <aubrey.li@...ux.intel.com>, x86@...nel.org,
mingo@...hat.com
CC: vishwesh.m.rudramuni@...el.com, joe@...ches.com,
hpa@...ux.intel.com, linux-kernel@...r.kernel.org,
Martin Kelly <martkell@...zon.com>
Subject: Re: [PATCH v2] x86/pmc_atom: Fix warning when CONFIG_DEBUG_FS=n
On 09/16/2014 08:44 PM, Li, Aubrey wrote:
>
> Why do you want to call pmc_dbgfs_register() anyway even if
> CONFIG_DEBUG_FS=n?
>
> Thanks,
> -Aubrey
>
The compiler will optimize away the call when CONFIG_DEBUG_FS=n, as the function body is just "return 0". Since the line following the call is "if (ret)" and since ret will always be 0, the compiler will likely optimize away the branch as well.
The reasoning for doing it this way is that it gives you a uniform code flow, which is easier to follow and reason about than having to think about branching #ifdefs sprinkled throughout the functions. The link I pasted gives full detail, but here's a snippet from Linus:
"Code cluttered with ifdefs is difficult to read and maintain. Don't do
it. Instead, put your ifdefs in a header, and conditionally define
'static inline' functions, or macros, which are used in the code.
Let the compiler optimize away the "no-op" case."
https://www.kernel.org/doc/Documentation/SubmittingPatches
(section 2.2, "#ifdefs are ugly")
In addition, Ingo Molnar suggested that I revise the patch in this way.
Thanks,
Martin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists