public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: FUSYN and RT
@ 2005-04-12 20:35 Perez-Gonzalez, Inaky
  2005-04-12 23:11 ` Esben Nielsen
  0 siblings, 1 reply; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 20:35 UTC (permalink / raw)
  To: Esben Nielsen, Daniel Walker; +Cc: linux-kernel, mingo

>From: Esben Nielsen [mailto:simlo@phys.au.dk]
>On 12 Apr 2005, Daniel Walker wrote:
>
>>
>>
>> At least, both mutexes will need to use the same API to raise and
lower
>> priorities.
>
>You basicly need 3 priorities:
>1) Actual: task->prio
>2) Base prio with no RT locks taken: task->static_prio
>3) Base prio with no Fusyn locks taken: task->??
>
>So no, you will not need the same API, at all :-) Fusyn manipulates
>task->static_prio and only task->prio when no RT lock is taken. When
the
>first RT-lock is taken/released it manipulates task->prio only. A
release
>of a Fusyn will manipulate task->static_prio as well as task->prio.

Yes you do. You took care of the simple case. Things get funnier
when you own more than one PI lock, or you need to promote a
task that is blocked on other PI locks whose owners are blocked
on PI locks (transitivity), or when you mix PI and PP (priority
protection/ priority ceiling).

In that case not having a sim{pl,g}e API for doing it is nuts.

>> The next question is deadlocks. Because one mutex is only in the
kernel,
>> and the other is only in user space, it seems that deadlocks will
only
>> occur when a process holds locks that are all the same type.
>
>Yes.
>All these things assumes a clear lock nesting: Fusyns are on the outer
>level, RT locks on the inner level. What happens if there is a bug in
RT
>locking code will be unclear. On the other hand errors in Fusyn locking
>(user space) should not give problems in the kernel.

Wrong. Fusyns are kernel locks that are exposed to user space (much as
a file descriptor is a kernel object exposed to user space through
a system call). Of course if the user does something mean with them
they will cause an error, but should not have undesired consequences
in the kernel. But BUGS in the code will be as unclear as in RT mutexes.

>it is is bad maintainance to have to maintain two seperate systems. The
>best way ought to be to try to only have one PI system. The kernel is
big
>and confusing enough as it is!

Ayeh for the big...it is not that confusing :)

-- Inaky

^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: FUSYN and RT
@ 2005-04-12 23:36 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 23:36 UTC (permalink / raw)
  To: Esben Nielsen; +Cc: Daniel Walker, linux-kernel, mingo

>From: Esben Nielsen [mailto:simlo@phys.au.dk]
>
>I think we (at least) got a bit confused here. What (I think) the
thread
>started out with was a clear layering of the mutexes. I.e. the code
obeys
>the grammar
>
> VALID_LOCK_CODE   = LOCK_FUSYN VALID_LOCK_CODE UNLOCK_FUSYN
>                   | VALID_LOCK_CODE VALID_LOCK_CODE
>                   | VALID_RTLOCK_CODE
> VALID_RTLOCK      = LOCK_RTLOCK VALID_RTLOCK_CODE UNLOCK_RTLOCK
>                   | VALID_RTLOCK_CODE VALID_RTLOCK_CODE
>                   | VALID_SPINLOCK_CODE
>                   | (code with no locks at all)
> VALID_SPINLOCK_CODE = ... :-)

Errrr...sorry, /me no comprende but I get the idea :)

Going back to the API problem I guess it'd be possible to code 
an equivalent of __prio_boost [your fusyn_setprio()], 
but it still does not answer another underlying problem. 

mutex_setprio() won't take into account the case where a task
(1) takes a mutex, (2) it is boosted for that, (3) it (or somebody 
else) changes its priority and then (4) it is deboosted. 

[4] will deboost it to the prio (static or RT) it had before 
boosting (at [1]), not the new one set at [3] (am I right, Ingo? I
didn't see any hooks in sched_setscheduler() and friends).

Now, this would be easy to solve: do a hook up in any function that
is going to touch the priority, and then for every owned mutex,
go updating the mutex->owner_prio. 

And now the underlying problem: this is where it gets plenty of 
complex when you have to implement PI transitivity--suddenly whenever
I boost an owner I have to walk all the mutexes that it potentially
owns. This becomes O(fugly) the minute you have an ownership chain
deeper than two or three levels with each owner owning more than a
couple of mutexes.

So that's why I chose to put it in the task struct, it becomes O(1)
at the expense (granted) of having to calc a min each time we compute
the dynamic priority.

But these are implementation details

> ...
>will never hit the RT-level. So assuming the RT-lock based code is
>debugged the error must be in Fusyn based code.

Naaah :)

-- Inaky


^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: FUSYN and RT
@ 2005-04-12 23:09 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 23:09 UTC (permalink / raw)
  To: dwalker; +Cc: Esben Nielsen, linux-kernel, mingo

>From: Daniel Walker [mailto:dwalker@mvista.com]
>On Tue, 2005-04-12 at 15:26, Perez-Gonzalez, Inaky wrote:
>
>> You should not need any of this if your user space mutexes are a
>> wrapper over the kernel space ones. The kernel handles everything
>> the same and there is no need to take care of any special cases or
>> variations [other than the ones imposed by the wrapping].
>
>The problem situation that I'm thinking of is when a task gets priority
>boosted by Fusyn , then gets priority boosted by an RT Mutex. In that
>situation, when the RT mutex demotes back to task->static_prio it will
>be lower than the priority that Fusyn has given the task (potentially).
>I don't think that's handled in the kernel anyplace, is it?

There would be conflicts, for sure [I haven't been able
to grok all the details of rt-mutex, so if I say something
really gross, please speak up]:

- rt saves the new owner's original prio in the mutex
- fusyn uses the mutex owned list and recalculates
  everytime the dyn prio changes based on that (so
  if we change the prio of the owner while owning
  there are no side effects).

- rt saves the pi-waiters in a per-task list, the rest
  in another list
- fusyn associates all the waiters in a per-mutex list, 
  and the PI or not is not a per-waiter attribute, is 
  is a per-mutex attribute--this simplifies the bubbling
  up of the boosting priority

In general the methods are similar, but the implementations
are too different. Yielding to the fact that I haven't looked
too deep at rt-mutex [to be far, I get lost :)], I think we'd
have a hard time getting them to interoperate with regards
to PI and PP.

Are you *really* considering to have them coexisting? I lack
the braveness :) It'd be easier to zap one in favour of the
other and crosspolinate.

<biased opinion>
if we take out all the user space crap from fusyn (vlocator.c,
ufu* and merge in or remove the hooks it requires), it seems 
to me to be simpler than rt-mutex in the PI handling section.
However, that is possibly because I wrote it.
</biased opinion>

<long explanation copied from somewhere else> 

fusyn uses (for transitivity and stacking purposes) the
priority of the 'fulock_olist' ownership list in the task 
struct as the priority the task needs to be boosted to
and calls __prio_boost() [which sets task->boost_prio] with
that prio.

Thus, whenever you acquire a mutex, it is added to that list
in the right position:

 - non PI or PP mutexes have priority BOTTOM_PRIO, so they 
   are always lower than any possible priority you can get
   and won't affect your dynamic prio.

- PI mutexes inherit their prio from the highest prio 
  (task->prio) of the tasks waiting in its waiters list.

- PP mutexes get a prio assigned by a sort of ioctl

</long explanation copied from somewhere else>

-- Inaky

^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: FUSYN and RT
@ 2005-04-12 22:26 Perez-Gonzalez, Inaky
  2005-04-12 22:33 ` Daniel Walker
  0 siblings, 1 reply; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 22:26 UTC (permalink / raw)
  To: dwalker, Esben Nielsen; +Cc: linux-kernel, mingo

>From: Daniel Walker [mailto:dwalker@mvista.com]
>
>On Tue, 2005-04-12 at 13:29, Esben Nielsen wrote:
>
>> So no, you will not need the same API, at all :-) Fusyn manipulates
>> task->static_prio and only task->prio when no RT lock is taken. When
the
>> first RT-lock is taken/released it manipulates task->prio only. A
release
>> of a Fusyn will manipulate task->static_prio as well as task->prio.
>
>mutex_setprio() , I don't know if you could call that an API but that's
>what I was talking about.. They should both use that. I think it would
>be better if the RT mutex (and fusyn) didn't depend on a field in the
>task_struct to retain the old priority. That would make it easier ..
>
>This goes back to the assumption that the locking isn't intermingled
>once you get into the kernel . The RT mutex can safely save the owner
>priority with out a Fusyn jumping in and changing it and the other way
>around..

You should not need any of this if your user space mutexes are a
wrapper over the kernel space ones. The kernel handles everything
the same and there is no need to take care of any special cases or
variations [other than the ones imposed by the wrapping].

-- Inaky

^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: FUSYN and RT
@ 2005-04-12 21:28 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 21:28 UTC (permalink / raw)
  To: dwalker, joe.korty; +Cc: linux-kernel, mingo

>From: Daniel Walker [mailto:dwalker@mvista.com]
>
>> Well yeah, but you could lock a fusyn, then invoke a system call
which
>> locks a kernel semaphore.
>
>Right .. For deadlock detection, I want to assume that the fusyn lock
is
>on the outer level. That way both deadlock detection system will work
>properly (in theory).

So that would mean to create a restriction (which is implicit
now, anyway): "a system call cannot return holding an rt-mutex"
right? 

-- Inaky 

^ permalink raw reply	[flat|nested] 33+ messages in thread
* RE: FUSYN and RT
@ 2005-04-12 19:35 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 33+ messages in thread
From: Perez-Gonzalez, Inaky @ 2005-04-12 19:35 UTC (permalink / raw)
  To: dwalker, linux-kernel; +Cc: mingo

>From: Daniel Walker [mailto:dwalker@mvista.com]
>
>I just wanted to discuss the problem a little more. From all the
>conversations that I've had it seem that everyone is worried about
>having PI in Fusyn, and PI in the RT mutex.

It sure is overlapping functionalities.

> ...
>The RT mutex will never lower a tasks priority lower than the priority
>given to it by locking a Fusyn lock.
>
>At least, both mutexes will need to use the same API to raise and lower
>priorities.

This would be step one. This would also mean they'd need to share
some data structures to protect transitivity (like when you own
more than one mutex that is PI or PP).

>The next question is deadlocks. Because one mutex is only in the
kernel,
>and the other is only in user space, it seems that deadlocks will only
>occur when a process holds locks that are all the same type.

Actually, I think it would occur in both cases. It all boils down 
at the end to locks in the kernel. Some of them are not visible to 
user space, some are (and with those we implement mutexes):

Task B owns FUSYN-MUTEX 2
Task A owns RT-MUTEX 1
Task B is waiting for RT-MUTEX 1
TASK A wants to wait for FUSYN-MUTEX 2
[deadlock]

[replace at will RT for FUSYN, FUSYN for RT, both, it doesn't
matter, the problem stays the same].

In any case, if let's say we have both implementations coexisting, 
then verifying deadlock becomes a daunting tasks, because there
are two lists of ownerships that we have to verify: the chain 
becomes a graph.

Whatever happens at the end: the kernel implementation needs to
be only one. Whichever (I particularly don't care, although I'd
like to see fusyns take it, I think they are able). The one that
exposes user space mutexes has to be built on top of that. And
exposing to user space is the toughest task (unless you don't
care about the fast-path).

-- Inaky

^ permalink raw reply	[flat|nested] 33+ messages in thread
* FUSYN and RT
@ 2005-04-12 18:15 Daniel Walker
  2005-04-12 20:29 ` Esben Nielsen
  2005-04-12 20:33 ` Joe Korty
  0 siblings, 2 replies; 33+ messages in thread
From: Daniel Walker @ 2005-04-12 18:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: inaky.perez-gonzalez, mingo


I just wanted to discuss the problem a little more. From all the
conversations that I've had it seem that everyone is worried about
having PI in Fusyn, and PI in the RT mutex. 

It seems like these two locks are going to interact on a very limited
basis. Fusyn will be the user space mutex, and the RT mutex is only in
the kernel. You can't lock an RT mutex and hold it, then lock a Fusyn
mutex (anyone disagree?). That is assuming Fusyn stays in user space.

The RT mutex will never lower a tasks priority lower than the priority
given to it by locking a Fusyn lock.

At least, both mutexes will need to use the same API to raise and lower
priorities.

The next question is deadlocks. Because one mutex is only in the kernel,
and the other is only in user space, it seems that deadlocks will only
occur when a process holds locks that are all the same type.


Daniel



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2005-04-18 11:34 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-12 20:35 FUSYN and RT Perez-Gonzalez, Inaky
2005-04-12 23:11 ` Esben Nielsen
2005-04-13  0:27   ` Daniel Walker
2005-04-13 15:46     ` Steven Rostedt
2005-04-13 17:33       ` Daniel Walker
2005-04-13 18:38         ` Steven Rostedt
2005-04-15 22:51       ` Bill Huey
2005-04-15 23:37         ` Inaky Perez-Gonzalez
2005-04-16  1:14           ` Steven Rostedt
2005-04-16  1:20             ` Inaky Perez-Gonzalez
2005-04-16  1:38               ` Steven Rostedt
2005-04-16  1:53                 ` Inaky Perez-Gonzalez
2005-04-16  2:31                   ` Steven Rostedt
2005-04-16  3:00                     ` Sven Dietrich
2005-04-16  3:31                       ` Steven Rostedt
2005-04-16 13:05                       ` john cooper
2005-04-16 14:23                         ` Steven Rostedt
2005-04-16 14:51                           ` john cooper
2005-04-16  4:05                     ` Inaky Perez-Gonzalez
2005-04-18  5:30           ` Bill Huey
2005-04-18  7:37             ` Sven-Thorsten Dietrich
2005-04-18 11:33               ` Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2005-04-12 23:36 Perez-Gonzalez, Inaky
2005-04-12 23:09 Perez-Gonzalez, Inaky
2005-04-12 22:26 Perez-Gonzalez, Inaky
2005-04-12 22:33 ` Daniel Walker
2005-04-12 21:28 Perez-Gonzalez, Inaky
2005-04-12 19:35 Perez-Gonzalez, Inaky
2005-04-12 18:15 Daniel Walker
2005-04-12 20:29 ` Esben Nielsen
2005-04-12 22:15   ` Daniel Walker
2005-04-12 20:33 ` Joe Korty
2005-04-12 21:25   ` Daniel Walker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox