From: Michael Schnell <mschnell@lumino.de>
To: Pavel Machek <pavel@ucw.cz>,
linux-kernel <linux-kernel@vger.kernel.org>,
nios2-dev <nios2-dev@sopc.et.ntust.edu.tw>
Subject: Re: atomic RAM ?
Date: Wed, 14 Apr 2010 10:42:38 +0200 [thread overview]
Message-ID: <4BC57FFE.5050703@lumino.de> (raw)
In-Reply-To: <20100412125402.GA22773@ucw.cz>
On 04/12/2010 02:54 PM, Pavel Machek wrote:
>
> You could create unpriviledged 'disable interrupts for 10
> instructions' and 'test if interrupts are still disabled'
> instructions, and base your mutex implementation on that.
>
That would be great, but AFAIK, it's not decently possible with NIOS.
The interrupt enable flag of the CPU can't be accessed by custom
instructions. The CPU has up to 32 interrupt lines that it exposes to
the custom FPGA "hardware". of course it _would_ be possible to gate all
of them and manage this additional flag by a custom instruction. We
would need to investigate how big the min/max delay between setting the
interrupt and the CPU acknowledging it is. According to this, the count
of NOPs between the "custom interrupt disable" and the load of the
atomic value needs to be chosen and how many clock cycles the interrupt
lock needs to be held.
Unfortunately, AFAIK, the CPU-external FPGA "hardware" (that implements
the custom instructions) can't see the shifting of the CPU's instruction
queue. So the lock duration only can be counted in clock cycles, but not
in instructions. The CPU might need to wait for a very large count of
clocks for accessing (instructions or data) words e.g. in external
dynamic RAM.
That is why (when considering how to implement the atomic user land
macros necessary for FUTEX) I did consider your idea to reduce the
average overhead imposed by the necessity of having the Kernel ISR code
finish a would be atomic operation. But as the delay is very uncertain,
I feel that the ISR-trick can't be dropped completely.
It might be a good idea to ask Altera to implement such a
userland-enabled instruction (disable interrupt for the next n
instructions). That would be really easy within the NIOS CPU iP-Core,
but with custom instructions we are out of luck :(.
Moreover, of course any interrupt logic only helps with the nos-SMP-case.
> But you'll have to stop calling it futex at that point...
>
FUTEX (e.g. the userland part of same) is just one paradigm (and IMHO
the most important one, as pthread_mutex_..() uses it for fast POSIX
compatible thread synchronization) that requires atomic user land
operations. So any implementation of the appropriate atomic userland
operations can be used to do FUTEX on top of it.
> Or you could just optimize syscalls to be really fast...
I trust that the Kernel developers already did that :).
My test showed that with a x86 PC, the system calls really are
astonishingly fast. But same supposedly features sophisticated hardware
to support syscalls. Nonetheless using Futex did provide a considerable
speed gain, even with SMP hardware where atomic operations are
expensive, due to cache synchronization done by hardware.
But the little old NIOS hardware of course is done using as few gates as
possible ;)
Thanks !
-Michael
next prev parent reply other threads:[~2010-04-14 8:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-08 7:32 atomic RAM ? Michael Schnell
[not found] ` <4BBDA1CB.3070204@davidnewall.com>
2010-04-08 9:52 ` Michael Schnell
2010-04-12 12:54 ` Pavel Machek
2010-04-14 8:42 ` Michael Schnell [this message]
[not found] ` <k2gbca41b4c1004080243nc45a10aereaae18557808c943@mail.gmail.com>
2010-04-08 10:12 ` Michael Schnell
2010-04-08 10:45 ` Alan Cox
2010-04-08 12:11 ` Michael Schnell
2010-04-08 12:14 ` David Miller
2010-04-08 12:30 ` Michael Schnell
2010-04-08 14:15 ` Arnd Bergmann
2010-04-09 10:54 ` Michael Schnell
[not found] ` <4BBEECC8.10005@lumino.de>
[not found] ` <201004091714.04990.arnd@arndb.de>
2010-04-12 9:58 ` Michael Schnell
2010-04-12 15:02 ` Arnd Bergmann
2010-04-13 10:11 ` Michael Schnell
[not found] ` <u2j42b5547a1004120845x87d7f2f7wd4acea1144153dd6@mail.gmail.com>
2010-04-13 8:39 ` [Nios2-dev] " Michael Schnell
2010-04-08 13:37 ` Alan Cox
2010-04-09 10:55 ` Michael Schnell
2010-04-09 11:54 ` Alan Cox
2010-04-09 12:53 ` Michael Schnell
2010-04-09 13:15 ` Alan Cox
2010-04-09 13:14 ` Michael Schnell
2010-04-09 13:32 ` Michael Schnell
2010-04-14 12:46 ` Michael Schnell
2010-04-14 12:57 ` Alan Cox
2010-04-14 14:38 ` Michael Schnell
2010-04-09 1:36 ` Mike Frysinger
2010-04-09 9:23 ` Michael Schnell
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=4BC57FFE.5050703@lumino.de \
--to=mschnell@lumino.de \
--cc=linux-kernel@vger.kernel.org \
--cc=nios2-dev@sopc.et.ntust.edu.tw \
--cc=pavel@ucw.cz \
/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