public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin Kelly <martin@martingkelly.com>
To: "Li, Aubrey" <aubrey.li@linux.intel.com>,
	x86@kernel.org, mingo@redhat.com
Cc: vishwesh.m.rudramuni@intel.com, joe@perches.com,
	hpa@linux.intel.com, linux-kernel@vger.kernel.org,
	Martin Kelly <martkell@amazon.com>
Subject: Re: [PATCH v2] x86/pmc_atom: Fix warning when CONFIG_DEBUG_FS=n
Date: Tue, 16 Sep 2014 21:04:22 -0700	[thread overview]
Message-ID: <54190846.9060601@martingkelly.com> (raw)
In-Reply-To: <541903A9.7090301@linux.intel.com>

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

  reply	other threads:[~2014-09-17  4:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-17  0:49 [PATCH v2] x86/pmc_atom: Fix warning when CONFIG_DEBUG_FS=n Martin Kelly
2014-09-17  2:09 ` Li, Aubrey
2014-09-17  3:20   ` Martin Kelly
2014-09-17  3:44     ` Li, Aubrey
2014-09-17  4:04       ` Martin Kelly [this message]
2014-09-17 12:24 ` Ingo Molnar
2014-09-17 14:19   ` Martin Kelly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54190846.9060601@martingkelly.com \
    --to=martin@martingkelly.com \
    --cc=aubrey.li@linux.intel.com \
    --cc=hpa@linux.intel.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martkell@amazon.com \
    --cc=mingo@redhat.com \
    --cc=vishwesh.m.rudramuni@intel.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox