Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation




* Linus Torvalds <torvalds@xxxxxxxx> wrote:

> I really can't think of any blocking kernel lock where priority
> inheritance would make _any_ sense at all. Please give me an example.

you are completely right, most of the blocking kernel locks we have in
Linux are an extremely poor candidate for priority inheritance. Most of
them are totally noncritical, or cover so long codepaths that 'latency
guarantees' and 'priority inheritance' make little sense for them.

the reason why we still have transformed most of the stock semaphore
users to generic mutexes in the -rt kernel is mostly because i wanted to
have _one_ central lock implementation. Firstly, it makes alot of sense
to consolidate code on embedded platforms anyway. Secondly, it was much
easier to implement (and validate) one robust locking primitive, than to
implement 5 separate primitives. The fact that this also made semaphores
PI-able is just a side-effect, with little to no practical relevance.

maybe ->i_sem is one notable exception: it is often held in critical
codepaths, and it's really hard for even the most-well-controlled RT app
to achieve _total_ isolation from the 'unprivileged' filesystem space.
So occasional 'resource sharing' in form of hitting an i_sem of another
task may still occur, and PI can at least reduce the worst-case cost
somehow. (even though i_sem codepaths are by no means deterministic!)

so in the -rt kernel, every semaphore, rw-semaphore, spinlock, rwlock
and seqlock [and in the latest -rt patches, every futex too] is
abstracted off a central generic mutex type, which mutex is blocking and
supports priority queueing and priority inheritance. It also has an
extensive debugging framework, which we didnt want to duplicate for
every separate lock object.

we also have a facility in the -rt kernel that traces the worst-case
latency path of critical applications (the 'latency tracer'), when mixed
with non-critical workloads, so we have quite good experience about what
kind of locks make a difference and what kind of locks make no
difference.

we also definitely know that priority inheritance done over _all_ these
lock objects makes a very real quality difference in practice, resulting
in real-time apps experiencing much lower worst-case latencies than
under the stock kernel. It is true that you could live without priority
inheritance, in cases were the RT app can be rewritten to have totally
separated resources, but in practice that is only possible for the
simplest applications.

Ingo
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [patch 00/10] PI-futex: -V1
    ... We are pleased to announce "lightweight userspace priority inheritance" ... No registration, no extra kernel ... only a single owner may own a lock (i.e. no ... Priority Inheritance - why, oh why??? ...
    (Linux-Kernel)
  • [PATCH 4/8] adaptive real-time lock support
    ... The Real Time patches to the Linux kernel converts the architecture ... compromising the integrity of critical sections protected by the lock. ... while retaining both the priority inheritance protocol as well as the ... the RT Mutex has been ...
    (Linux-Kernel)
  • Role of process priority in locking mechanism
    ... Role of process priority in locking mechanism ... They are used throughout the UNIX kernel, ... >out interrupts and some other activities while manipulating certain ... a primitive lock would be something like a spinlock. ...
    (comp.unix.programmer)
  • Priority inheritance
    ... I would like to now if there is a library that implements priority ... A little about priority inheritance: ... manages to run and obtains a lock for one of those resources. ... the low-priority process has trumped the ...
    (comp.lang.ruby)
  • Re: Why cant I set the priority of softirq-hrt? (Re: 2.6.17-rt1)
    ... High prio task is blocked on lock and boosts 3 other tasks. ... I'll try to see what I can do though, but I am afraid the patch might get too big. ... A boosts B whichs is blocked interruptible on a lock a boosts C, ... A wakes up first a decrease the priority of B but not C, because the B runs on another CPU, but with lower priority and fixes C. ...
    (Linux-Kernel)