Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- From: "james.walmsley" <james@xxxxxxxxxx>
- Date: Sun, 01 Feb 2009 14:53:33 -0600
It is not the business of the application layer to interfere with the
system activities. Disabling interrupts is the kernel level operation.
The whole point is that it gets implemented inside the OS level. Obviously
for standalone single-threaded applications there's no problem. FullFAT is
below the application level, and provides an application level interface.
You should not make any assumptions about the atomicity of any operation
unless you know the target hardware and software in the very detail.
There are the OS services which you should rely upon.
I'm not making assumptions about how to ensure an atomic operation on
another platform. (Because I cannot!) I provide 2 functions, and inside
them I ask the developer to do whatever is necessary to enter a critical
region, to ensure atomic operations. Then to leave that state when the
second function is called. By calling the appropriate OS services.
It's true that DMA and other peripherals on the core could be running.
Operating systems provide sync functions, to remove the cache problem. So
if a developer places sync functions inside my critical region functions,
then all should work.
VDK is junk. Being dissatisfied with VDK and ucLinux, I rolled my own OS
for BlackFin.
We also wrote an operating system for BlackFIN, (well the firm I work
for).
How can the FAT driver know when it is safe to disable the interrupts
and for how long it is safe to disable the interrupts? That is very
application and platform dependent, and it is not the business of the
driver to make any assumptions.
You cannot know it's safe for sure, but a single increment or decrement
instruction shouldn't take a dangerous amount of time. It's unlikely you'll
be using a FAT driver in a critical system.
I guess the best thing to do is protect critical memory attributes with an
OS provided semaphore.
I just need to find the best way to make a semaphore wrapper, that can be
easily ported to other operating systems.
Drop the project.
I won't take your advice, but thanks for helping me to think about the
problems from a different angle!
I've also decided that LFN support will be built dependent on the
configuration file. So LFN support will work like a module, either you use
it or you don't.
From VDK it provides a function to CreateSemaphore,PendSemaphore,ReleaseSemaphore. Do most OS's essentially expose the same interfaces? If
so what kind of objects do they return?
James
issues
james.walmsley wrote:
It's not a naive idea, its just challenging. Of course there are
makewhen porting anything. However you can design code to be portable, and
disablingany porting easier for the end developer.
Can you explain why on a single core system why you think that
interrupts
won't guarantee atomic operations,
Because there is cache, DMA, speculative execution and deferred
reads/writes.
and also explain why you think it is bad.
You should not make any assumptions about the atomicity of any operation
unless you know the target hardware and software in the very detail.scheduler
There are the OS services which you should rely upon.
Working on BlackFIN, disabling interrupts means that the VDK Os
simply cannot switch threads/processes because as with all OS's this
requires a timer interrupt.
VDK is junk. Being dissatisfied with VDK and ucLinux, I rolled my own OS
for BlackFin.when
Obviously disabling interrupts is bad if done over to long a period of
time. It is sometimes necessary I believe, and if you fully understand
ato do it and how then its ok. Essentially it should only be done over
taskvery short period of time.
How can the FAT driver know when it is safe to disable the interrupts
and for how long it is safe to disable the interrupts? That is very
application and platform dependent, and it is not the business of the
driver to make any assumptions.
On a single-core system, if disabling interrupts prevents the OS from
.switching, this should mean that all operations are atomic.
Disabling interrupts doesn't imply atomicity, because there is cache,
DMA, speculative execution and deferred reads/writes.
If that is the
case, a simple mutex lock system should implementable?
Only if it based on the services provided by target OS.
I don't know the answers, I just want your opinions, and your
explanations.
Drop the project.
Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
- References:
- Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- From: Vladimir Vassilevsky
- Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- From: james.walmsley
- Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- From: Vladimir Vassilevsky
- Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- Prev by Date: Re: Parallel Cable IV
- Next by Date: Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- Previous by thread: Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- Next by thread: Re: Guarantee Critical Regions in Portable code. Portable Semaphores?
- Index(es):
Relevant Pages
|