From: Roland Dreier <roland@digitalvampire.org>
To: linux-kernel@vger.kernel.org
Subject: Fast 64-bit atomic writes (SSE?)
Date: 19 Mar 2004 16:39:17 -0800 [thread overview]
Message-ID: <874qskl5ca.fsf@love-shack.home.digitalvampire.org> (raw)
Hi, I'm trying to find the best (fastest) way to write a 64-bit
quantity atomically to a device (on i386). Taking a spinlock around
two 32-bit accesses seems to be rather expensive. I'm mostly
concerned about newish CPUs, so I'm willing to use SSE or SSE2
instructions (of course falling back to a slower locked path if the
kernel is built for an old CPU).
I guess I have two questions, a general one and a specific one.
General question:
What's the best way to do this?
Specific question:
I've come up with the below function. However, you may notice that
I'm forced to use movdqu (instead of movdqa, which is presumably
faster). This is because even with the __attribute__((aligned(16))),
my xmmsave array is not guaranteed to be aligned to 16 bytes. I could
just allocate 31 bytes for xmmsave and align it to 16 bytes by hand,
but that seems a little ugly. Is there some magic I'm missing?
Thanks,
Roland
static inline void mywrite64(u32 *val, void *dest)
{
u8 xmmsave[16] __attribute__((aligned(16)));
/* The #ifs are a hack to deal with 2.4 kernels without preempt. */
#if CONFIG_PREEMPT
preempt_disable();
#endif
/* We use movdqu for the moment, because even
__attribute__((aligned(16))) doesn't seem to guarantee
xmmsave is aligned to a 16 byte boundary. */
__asm__ __volatile__ (
"movdqu %%xmm0,(%0); \n\t"
"movq (%1),%%xmm0; \n\t"
"movq %%xmm0,(%2); \n\t"
"movdqu (%0),%%xmm0; \n\t"
:
: "r" (xmmsave), "r" (val), "r" (dest)
: "memory" );
#if CONFIG_PREEMPT
preempt_enable();
#endif
}
next reply other threads:[~2004-03-20 0:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-20 0:39 Roland Dreier [this message]
[not found] <874qskl5ca.fsf@love-shack.home.digitalvampire.org.suse.lists.linux.kernel>
2004-03-20 7:37 ` Andi Kleen
2004-03-20 14:43 ` Roland Dreier
2004-03-20 14:48 ` Roland Dreier
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=874qskl5ca.fsf@love-shack.home.digitalvampire.org \
--to=roland@digitalvampire.org \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®