From: Ralf Baechle <ralf@linux-mips.org>
To: David Daney <ddaney@caviumnetworks.com>
Cc: linux-mips <linux-mips@linux-mips.org>,
Adam Nemet <anemet@caviumnetworks.com>
Subject: Re: .subsection madness
Date: Fri, 14 Aug 2009 22:57:59 +0100 [thread overview]
Message-ID: <20090814215759.GA8282@linux-mips.org> (raw)
In-Reply-To: <4A85ABD3.5040801@caviumnetworks.com>
On Fri, Aug 14, 2009 at 11:24:19AM -0700, David Daney wrote:
> In atomic.h for atomic_add we have this gem:
>
> __asm__ __volatile__(
> " .set mips3 \n"
> "1: ll %0, %1 # atomic_add \n"
> " addu %0, %2 \n"
> " sc %0, %1 \n"
> " beqz %0, 2f \n"
> " .subsection 2 \n"
> "2: b 1b \n"
> " .previous \n"
> " .set mips0 \n"
>
>
> What is the purpose of the .subsection here?
>
> It will not affect branch prediction in the beqz as nothing happens in
> .subsection 2.
I'm not following. Most simple branch predictors will assume a backward
branch to be a loop completion branch and thus predict it as taken while
we assume that the SC instruction rarely fails no matter if spinlock,
bit or atomic operation.
It can even help on a CPU without branch prediction like the R4000 which
kills the two instruction following the delay slot for a taken branch.
> For spin locks it is clear that this technique can help, but for
> atomic_add I don't think so. To make matters worse for some code the
> subsection is going out of branch range.
That problem should have be solved by building the kernel with
-ffunction-sections. Other architectures needed -ffunction-sections for
the same reason.
Ralf
prev parent reply other threads:[~2009-08-14 21:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-14 18:24 .subsection madness David Daney
2009-08-14 21:57 ` Ralf Baechle [this message]
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=20090814215759.GA8282@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=anemet@caviumnetworks.com \
--cc=ddaney@caviumnetworks.com \
--cc=linux-mips@linux-mips.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;
as well as URLs for NNTP newsgroup(s).