Skip to contentSkip to conversation

Real-Time Preemption, -RT-2.6.10-rc1-mm2-V0.7.1

PATCH [email protected] 6 participants 12 messages Nov 4, 2004 – Nov 8, 2004

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines

what priority does events/0 and events/1 have? keventd handles part of the mouse/keyboard workload.

The default priorities and not RT.

ps -eo pid,pri,rtprio,cmd
...

  6  34    -  [events/0]
  7  34    -  [events/1]

...
I can set those as well but then I'd probably have to follow with the X server and everything else in the chain. The starvation problem ripples across the system.

Will try the patch shortly and get back on the results later today.

--Mark H Johnson
<mailto:[email protected]>

#1 lore raw
Quoted 4 lines · * [email protected] <[email protected]> wrote:
Quoted 2 lines

what priority does events/0 and events/1 have? keventd handles part of the mouse/keyboard workload.

The default priorities and not RT.

Quoted 8 lines

ps -eo pid,pri,rtprio,cmd
...

  6  34    -  [events/0]
  7  34    -  [events/1]

...
I can set those as well but then I'd probably have to follow with the X server and everything else in the chain. The starvation problem ripples across the system.

X should be scheduled on the other CPU just fine. Only per-CPU kernel threads (which are affine to their particular CPU) are affected by this problem - ordinary tasks not. I.e. the system threads that have /0 and /1 in their name. In theory you should not even need to chrt the hardirq threads, those should schedule fine too.

Ingo

#2 lore raw
Quoted 5 lines · Ingo Molnar

X should be scheduled on the other CPU just fine. Only per-CPU kernel threads (which are affine to their particular CPU) are affected by this problem - ordinary tasks not. I.e. the system threads that have /0 and /1 in their name. In theory you should not even need to chrt the hardirq threads, those should schedule fine too.

plus there's the 'priority inheritance dependency-chain closure' bug noticed by John Cooper - that should only affect the latency of RT tasks though.

Ingo

#3 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 5 lines · Ingo Molnar

X should be scheduled on the other CPU just fine. Only per-CPU kernel threads (which are affine to their particular CPU) are affected by this problem - ordinary tasks not. I.e. the system threads that have /0 and /1 in their name. In theory you should not even need to chrt the hardirq threads, those should schedule fine too.

Quoted 3 lines

plus there's the 'priority inheritance dependency-chain closure' bug noticed by John Cooper - that should only affect the latency of RT tasks though.

This is a fairly gnarly problem to address. The obvious solution is to hold spinlocks in the mutexes as the dependency tree is atomically traversed. However this will deadlock under MP due to the unpredictable order of mutexes traversed. If the dependency chain is not traversed (and semantics applied) atomically, races exist which cause promotion decisions to be made on [now] stale data.

The simple solution is a global spinlock which doesn't scale well under MP. Another possible solution would be conditional traversal of the chain where contention within the chain under foot (from another chain walker) causes the traversal to abort and retry. Though this has the down side of being nondeterministic.

Signature · 1 line
[email protected]
#4 lore raw
Quoted 10 lines · john cooper
Quoted 3 lines

plus there's the 'priority inheritance dependency-chain closure' bug noticed by John Cooper - that should only affect the latency of RT tasks though.

This is a fairly gnarly problem to address. The obvious solution is to hold spinlocks in the mutexes as the dependency tree is atomically traversed. However this will deadlock under MP due to the unpredictable order of mutexes traversed. If the dependency chain is not traversed (and semantics applied) atomically, races exist which cause promotion decisions to be made on [now] stale data.

is the order of locks in the dependency chain really unpredictable? If two chain walkers get two locks in opposite order, doesnt that mean that the lock ordering (as attempted by the blocked tasks) is deadlock-prone already? I.e. this scenario should not happen.

Ingo

#5 lore raw
Quoted 14 lines · Ingo Molnar
Quoted 9 lines · john cooper
Quoted 2 lines

plus there's the 'priority inheritance dependency-chain closure' bug noticed by John Cooper - that should only affect the latency of RT tasks though.

This is a fairly gnarly problem to address. The obvious solution is to hold spinlocks in the mutexes as the dependency tree is atomically traversed. However this will deadlock under MP due to the unpredictable order of mutexes traversed. If the dependency chain is not traversed (and semantics applied) atomically, races exist which cause promotion decisions to be made on [now] stale data.

Quoted 4 lines

is the order of locks in the dependency chain really unpredictable? If two chain walkers get two locks in opposite order, doesnt that mean that the lock ordering (as attempted by the blocked tasks) is deadlock-prone already? I.e. this scenario should not happen.

There does appear to be hope here. If the per-task mutex ownership list is maintained in strict order of acquisition sequence and reader-mutex acquisition sequence is policed this would seem to remove the possibly of chain traversal deadlock.

As an implementation note, single-owner hard spinlocks seem excessive for the chain walk. An approach allowing maximum concurrency during traversal would be a reader-reference acquired per node during the walk which would need to upgrade to an exclusive writer-reference to effect promotion (waiter list priority reorder), and then downgrade to a reader-reference to continue the traversal.

-john

Signature · 1 line
[email protected]
#6 lore raw
In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · john cooper

This is a fairly gnarly problem to address. The obvious solution is to hold spinlocks in the mutexes as the dependency tree is atomically traversed. However this will deadlock under MP due to the unpredictable order of mutexes traversed. If the dependency chain is not traversed (and semantics applied) atomically, races exist which cause promotion decisions to be made on [now] stale data.

Quoted 4 lines

is the order of locks in the dependency chain really unpredictable? If two chain walkers get two locks in opposite order, doesnt that mean that the lock ordering (as attempted by the blocked tasks) is deadlock-prone already? I.e. this scenario should not happen.

It *shouldn't*, but bugs do happen, and it'd be nice if a mutex deadlock didn't get promoted into a less debuggable spinlock deadlock. Plus, if there's any intention of ever exporting this priority inheritance mechanism to userspace locks, we don't want to promote a userspace deadlock into a kernel one.

Given how rarely contention should occur, I don't think that a single lock would be a bottleneck except for obscenely large SMP machines.

-Scott

#7 lore raw
Quoted 6 lines · Scott Wood
Quoted 4 lines · Ingo Molnar

is the order of locks in the dependency chain really unpredictable? If two chain walkers get two locks in opposite order, doesnt that mean that the lock ordering (as attempted by the blocked tasks) is deadlock-prone already? I.e. this scenario should not happen.

Quoted 8 lines

It *shouldn't*, but bugs do happen, and it'd be nice if a mutex deadlock didn't get promoted into a less debuggable spinlock deadlock. Plus, if there's any intention of ever exporting this priority inheritance mechanism to userspace locks, we don't want to promote a userspace deadlock into a kernel one.

Given how rarely contention should occur, I don't think that a single lock would be a bottleneck except for obscenely large SMP machines.

Places that are surround by rcu locks are possibilities that could hit the kind of contention. There's numerous places in the kernel that use it, but nothing can be said until there's stats on how these things content against each other, dcache_lock, I believe and others.

I think of an RT kernel with N threads in terms where it's an SMP machine with same N number of processors. If you have N threads pounding on the same critical sections, it's effectively N physical processors hitting as well.

Correct me if I'm wrong, vague, etc... but that's how I understand the problem and that's how I think it should be addressed. Ideally, the kernel should be so efficient that these collision should never happen and the use of priority propagation should be very shallow to prevent irregularities with scheduling resulting from priority boosting lock chains. Only a statically gathering of how this system behaves will show the technical direction that this project should direct itself.

BTW, we're working getting a single super-mutex that right now internally that can possibly be used for proper priority propagation, for all blocking type locks. Hopefully, with testing we'll see how well it and the rest of the kernel performs with it. Correctness is is the highest priority, but overall behavior of the system is very important and should be next in ranking IMO.

bill

#8 lore raw
Quoted 6 lines · Bill Huey

[...]
I think of an RT kernel with N threads in terms where it's an SMP machine with same N number of processors. If you have N threads pounding on the same critical sections, it's effectively N physical processors hitting as well.

Not quite. On a UP RT system you know that all lower priority tasks are not running when your task is running. This gives some nice properties. If you take care not to sleep your high priority task effectively blocks all preemption by the lower priority tasks.

On a SMB system you don't have these nice properties. You always have to take into account that N processes are really running at the same time.

On UP RT systems it is legal to think like this: The processor can only do one thing. For the overall performance I can just as well lock the rest out with one big mutex and get my work done in a hurry. This gives simpler code and it is more efficient since locking/unlocking sections takes time. It doesn't destroy the latency of the subsystem as long as you can verify that the maximum locking time is less than the required latency for that subsystem. If I can even keep my locking time below the maximum allowed interrupt latency I can optimize it further by using interrupt disable/enable instead of a mutex!

On SMB systems, on the other hand, this gives bad performance to have such big locking sections. Especially if you use the equivalent of interrupt disable/enable (spinlocks) you are not only slowing down your own subsystem but the whole system.

In short: For SMB you have to think of parellization much more than on a UP RT system. Ofcourse to think of UP RT system as a SMB system doesn't make your system fail, but it might give you a suboptimal system. On the other hand a system running on a UP with full preemption might not be portable to a SMB system as you might be saved by "the nice properties". So if you want to be portable, think of it as a SMB system :-)

Quoted 4 lines

[...]

bill

Esben

#9 lore raw
Quoted 3 lines · Esben Nielsen

On a SMP system you don't have these nice properties. You always have to take into account that N processes are really running at the same time.

not necessarily. In theory we could introduce the notion of "hyper-high-priority tasks" (e.g. SCHED_HYPER_FIFO), which tasks not only get preempted on one CPU immediately, but cause the kernel to stop and loop on all other CPUs as well. That way the same 'nice' properties of UP kernels get carried over to the SMP system as well, at the cost of serializing all execution while the hyper-high-prio task is running. Once the task stops running, the other CPUs can continue as well.

Ingo

#10 lore raw
In reply to Esben Nielsen
Quoted 4 lines · Esben Nielsen

Not quite. On a UP RT system you know that all lower priority tasks are not running when your task is running. This gives some nice properties. If you take care not to sleep your high priority task effectively blocks all preemption by the lower priority tasks.

...

Quoted 6 lines

In short: For SMB you have to think of parellization much more than on a UP RT system. Ofcourse to think of UP RT system as a SMB system doesn't make your system fail, but it might give you a suboptimal system. On the other hand a system running on a UP with full preemption might not be portable to a SMB system as you might be saved by "the nice properties". So if you want to be portable, think of it as a SMB system :-)

Yeah, good points. I know, I'm being paranoid intentionally since much of the kernel is so SMP oriented. I'm thinking in terms of large scale concurrency since the structures of the kernel are fundamentally SMP and which is tightly related to RT performance. There's a lot of overlap between both world as it concerns locking structures, fine grainedness.

The really appealing aspect of this project that the same things that make Linux such a high performance SMP system out of the box is exactly what will also give it outstanding RT performance in both UP and SMP configurations. The fine grained locking issues seem to be largely done and this work is going to push those boundaries even more.

I know what you're saying about thread run subsets with relation to priority (again good points), but I'm looking at large picture issues and how this system is going to behave as all parts work together. We haven't done this just yet and it's too immature a system to do so until it becomes more stable and popular. It's a different point of view than what you're talking about. :)

bill

#11 lore raw
In reply to Scott Wood
Quoted 8 lines · Scott Wood
Quoted 4 lines

is the order of locks in the dependency chain really unpredictable? If two chain walkers get two locks in opposite order, doesnt that mean that the lock ordering (as attempted by the blocked tasks) is deadlock-prone already? I.e. this scenario should not happen.

It *shouldn't*, but bugs do happen, and it'd be nice if a mutex deadlock didn't get promoted into a less debuggable spinlock deadlock. [...]

well, deadlock detection happens at lock-acquire time, so the deadlock will be detected _first_, any PI spinlock-locking will happen on already blocked (== no deadlock detected) tasks. This would also serve as a nice secondary check for the deadlock detector.

Quoted 3 lines

[...] Plus, if there's any intention of ever exporting this priority inheritance mechanism to userspace locks, we don't want to promote a userspace deadlock into a kernel one.

agreed.

Quoted 2 lines

Given how rarely contention should occur, I don't think that a single lock would be a bottleneck except for obscenely large SMP machines.

well, blocking on a mutex happens quite frequently. But i dont have a problem with the big lock other than the usual "if we can do better then we should do better" attitude :-)

Ingo