From: Tejun Heo <htejun@gmail.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: saeed bishara <saeed.bishara@gmail.com>,
linux-ide@vger.kernel.org, Saeed Bishara <saeed@marvell.com>,
Mark Lord <liml@rtr.ca>
Subject: Re: [PATCH 1/2] [libata] sata_mv: Remove PCI dependency
Date: Wed, 23 Jan 2008 13:15:33 +0900 [thread overview]
Message-ID: <4796BF65.6040005@gmail.com> (raw)
In-Reply-To: <4796BCEB.1090207@garzik.org>
Jeff Garzik wrote:
> Tejun Heo wrote:
>> Jeff Garzik wrote:
>>> saeed bishara wrote:
>>>> - if (unlikely(irq_stat & PCI_ERR)) {
>>>> + if (unlikely(irq_stat & PCI_ERR) && HAS_PCI(host)) {
>>>> mv_pci_error(host, mmio);
>>>> handled = 1;
>>>> goto out_unlock; /* skip all other HC irq handling */
>>> the unlikely() should cover the entire expression.
>>
>> Hmm... I also sometimes hesitate about these things. I think when the
>> first condition is unlikely but the latter isn't so, it's better to tell
>> the compiler that the first part is unlikely and let it figure out the
>> rest. Another thing is using unlikely on the return value of helper
>> function like the following.
>>
>> static bool test_some_condition(arg)
>> {
>> return unlikely(unlikely_test_on_arg(arg));
>> }
>>
>> I haven't looked at the generated code yet but hope the compiler can
>> DTRT if the function body is visible when compiling. Has anyone played
>> with these?
>
> Think about the question being answered -- this is branch prediction.
> After all tests in an 'if' are complete, the question is: do we take
> this branch or not? (yes/no)
Well, if (a && b) is not a single branch. It's two (or more) branches.
Let's say a is unlikely but b is; then with unlikely(a && b), the
compiler do something like the following.
jmp L0 if !a
jmp L0 if !b
jmp L1
.L0 continue excution after if block
---------
cold unlikely block
.L1 body of if
Or some other form. With (unlikely(a) && b), the compiler knows the
optimal form is...
jmp L1 if a
.L0 continue excution after if block
---------
cold unlikely block
.L1 jmp L0 if !b
body of if
> And while it is valid to note unlikely() as done above, it doesn't
> necessarily give the compiler the best idea about how to predict the
> ultimate end result of all the tests, which is the decision on whether
> or not to take the branch.
It actually gives the compiler better information to optimize with and
test conditions in if() can get quite involved and it also gives better
idea of what the writer was thinking when writing the likely/unlikely
when the code is read later.
--
tejun
next prev parent reply other threads:[~2008-01-23 4:15 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-02 15:43 [PATCH 0/2] [libata] sata_mv: Add support for Marvell's integrated SATA controller saeed.bishara
2007-12-02 15:43 ` [PATCH 1/2] [libata] sata_mv: Remove PCI dependency saeed.bishara
2007-12-02 15:43 ` [PATCH 2/2] [libata] sata_mv: Support integrated controllers saeed.bishara
2007-12-18 22:02 ` Jeff Garzik
2007-12-18 21:57 ` [PATCH 1/2] [libata] sata_mv: Remove PCI dependency Jeff Garzik
2007-12-18 21:58 ` Jeff Garzik
2007-12-25 16:42 ` saeed bishara
2008-01-09 11:59 ` saeed bishara
2008-01-10 4:35 ` Jeff Garzik
2008-01-16 10:01 ` Jeff Garzik
2008-01-16 16:17 ` saeed bishara
2008-01-16 19:01 ` Mark Lord
2008-01-17 14:24 ` saeed bishara
2008-01-29 17:12 ` Jeff Garzik
2008-01-29 17:17 ` saeed bishara
2008-01-21 7:31 ` Tejun Heo
2008-01-23 4:04 ` Jeff Garzik
2008-01-23 4:15 ` Tejun Heo [this message]
2008-01-29 8:51 ` saeed bishara
2008-01-29 16:20 ` Mark Lord
2008-01-29 16:28 ` Jeff Garzik
2008-01-29 16:26 ` Jeff Garzik
-- strict thread matches above, loose matches on Subject: below --
2007-12-02 15:26 [PATCH 0/2] [libata] sata_mv: Add support for Marvell's integrated SATA controller saeed.bishara
2007-12-02 15:26 ` [PATCH 1/2] [libata] sata_mv: Remove PCI dependency saeed.bishara
2007-12-04 9:07 ` saeed bishara
2007-12-05 12:11 ` saeed bishara
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=4796BF65.6040005@gmail.com \
--to=htejun@gmail.com \
--cc=jeff@garzik.org \
--cc=liml@rtr.ca \
--cc=linux-ide@vger.kernel.org \
--cc=saeed.bishara@gmail.com \
--cc=saeed@marvell.com \
/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;
as well as URLs for NNTP newsgroup(s).