linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [ANNOUNCE] Native POSIX Thread Library 0.1
@ 2002-09-20  0:41 Ulrich Drepper
  2002-09-20  0:51 ` William Lee Irwin III
                   ` (8 more replies)
  0 siblings, 9 replies; 114+ messages in thread
From: Ulrich Drepper @ 2002-09-20  0:41 UTC (permalink / raw)
  To: linux-kernel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

We are pleased to announce the first publically available source
release of a new POSIX thread library for Linux.  As part of the
continuous effort to improve Linux's capabilities as a client, server,
and computing platform Red Hat sponsored the development of this
completely new implementation of a POSIX thread library, called Native
POSIX Thread Library, NPTL.

Unless major flaws in the design are found this code is intended to
become the standard POSIX thread library on Linux system and it will
be included in the GNU C library distribution.

The work visible here is the result of close collaboration of kernel
and runtime developers.  The collaboration proceeded by developing the
kernel changes while writing the appropriate parts of the thread
library.  Whenever something couldn't be implemented optimally some
interface was changed to eliminate the issue.  The result is this
thread library which is, unlike previous attempts, a very thin layer
on top of the kernel.  This helps to achieve a maximum of performance
for a minimal price.


A white paper (still in its draft stage, though) describing the design
is available at

   http://people.redhat.com/drepper/nptl-design.pdf

It provides a larger number of details on the design and insight into
the design process.  At this point we want to repeat only a few
important points:

- - the new library is based on an 1-on-1 model.  Earlier design
   documents stated that an M-on-N implementation was necessary to
   support a scalable thread library.  This was especially true for
   the IA-32 and x86-64 platforms since the ABI with respect to threads
   forces the use of segment registers and the only way to use those
   registers was with the Local Descriptor Table (LDT) data structure
   of the processor.

   The kernel limitations the earlier designs were based on have been
   eliminated as part of this project, opening the road to a 1-on-1
   implementation which has many advantages such as

   + less complex implementation;
   + avoidance of two-level scheduling, enabling the kernel to make all
     scheduling decisions;
   + direct interaction between kernel and user-level code (e.g., when
     delivering signals);
   + and more and more.

   It is not generally accepted that a 1-on-1 model is superior but our
   tests showed the viability of this approach and by comparing it with
   the overhead added by existing M-on-N implementations we became
   convinced that 1-on-1 is the right approach.

   Initial confirmations were test runs with huge numbers of threads.
   Even on IA-32 with its limited address space and memory handling
   running 100,000 concurrent threads was no problem at all, creating
   and destroying the threads did not take more than two seconds.  This
   all was made possible by the kernel work performed as part of this
   project.

   The only limiting factors on the number of threads today are
   resource availability (RAM and processor resources) and architecture
   limitations.  Since every thread needs at least a stack and data
   structures describing the thread the number is capped.  On 64-bit
   machines the architecture does not add any limitations anymore (at
   least for the moment) and with enough resources the number of
   threads can be grown arbitrarily.

   This does not mean that using hundreds of thousands of threads is a
   desirable design for the majority of applications.  At least not
   unless the number of processors matches the number of threads.  But
   it is important to note that the design on the library does not have
   a fixed limit.

   The kernel work to optimize for a high thread count is still
   ongoing.  Some places in which the kernel iterates over process and
   threads remain and other places need to be cleaned up.  But it has
   already been shown that given sufficient resources and a reasonable
   architecture an order of magnitude more threads can be created than
   in our tests on IA-32.


- - The futex system call is used extensively in all synchronization
   primitives and other places which need some kind of
   synchronization.  The futex mechanism is generic enough to support
   the standard POSIX synchronization mechanisms with very little
   effort.

   The fact that this is possible is also essential for the selection
   of the 1-on-1 model since only with the kernel seeing all the
   waiters and knowing that they are blocked for synchronization
   purposes will allow the scheduler to make decisions as good as a
   thread library would be able to in an M-on-N model implementation.

   Futexes also allow the implementation of inter-process
   synchronization primitives, a sorely missed feature in the old
   LinuxThreads implementation (Hi jbj!).


- - Substantial effort went into making the thread creation and
   destruction as fast as possible.  Extensions to the clone(2) system
   call were introduced to eliminate the need for a helper thread in
   either creation or destruction.  The exit process in the kernel was
   optimized (previously not a high priority).  The library itself
   optimizes the memory allocation so that in many cases the creation
   of a new thread can be achieved with one single system call.

   On an old IA-32 dual 450MHz PII Xeon system 100,000 threads can be
   created and destroyed in 2.3 secs (with up to 50 threads running at
   any one time).


- - Programs indirectly linked against the thread library had problems
   with the old implementation because of the way symbols are looked
   up. This should not be a problem anymore.


The thread library is designed to be binary compatible with the old
LinuxThreads implementation.  This compatibility obviously has some
limitations.  In places where the LinuxThreads implementation diverged
from the POSIX standard incompatibilities exist.  Users of the old
library have been warned from day one that this day will come and code
which added work-arounds for the POSIX non-compliance better be
prepared to remove that code.  The visible changes of the library
include:


- - The signal handling changes from per-thread signal handling to the
   POSIX process signal handling.  This change will require changes in
   programs which exploit the non-conformance of the old implementation.

   One consequence of this is that SIGSTOP works on the process.  Job 
control
   in the shell and stopping the whole process in a debugger work now.

- - getpid() now returns the same value in all threads

- - the exec functions are implemented correctly: the exec'ed process gets
   the PID of the process.  The parent of the multi-threaded application
   is only notified when the exec'ed process terminates.

- - thread handlers registered with pthread_atfork are not anymore run
   if vfork is used.  This isn't required by the standard (which does
   not define vfork) and all which is allowed in the child is calling
   exit() or an exec function.  A user of vfork better knows what s/he
   does.

- - libpthread should now be much more resistant to linking problems: even
   if the application doesn't list libpthread as a direct dependency
   functions which are extended by libpthread should work correctly.

- - no manager thread

- - inter-process mutex, read-write lock, conditional variable, and barrier
   implementations are available

- - the pthread_kill_other_threads_np function is not available.  It was
   needed to work around the broken signal handling.  If somebody shows
   some existing code which makes legitimate use of this function we
   might add it back.

- - requires a kernel with the threading capabilities of Linux 2.5.36.



The sources for the new library are for the time being available at

   ftp://people.redhat.com/drepper/nptl/

The current sources contain support only for IA-32 but this will
change very quickly.  The thread library is built as part of glibc so
the complete set of glibc sources is available as well.  The current
snapshot for glibc 2.3 (or glibc 2.3 when released) is necessary.  You
can find it at

   ftp://sources.redhat.com/pub/glibc/snapshots

Final releases will be available on ftp.gnu.org and its mirrors.


Building glibc with the new thread library is demanding on the
compilation environment.

- - The 2.5.36 kernel or above must be installed and used.  To compile
   glibc it is necessary to create the symbolic link

      /lib/modules/$(uname -r)/build

   to point to the build directory.

- - The general compiler requirement for glibc is at least gcc 3.2.  For
   the new thread code it is even necessary to have working support for
   the __thread keyword.

   Similarly, binutils with functioning TLS support are needed.

   The (Null) beta release of the upcoming Red Hat Linux product is
   known to have the necessary tools available after updating from the
   latest binaries on the FTP site.  This is no ploy to force everybody
   to use Red Hat Linux, it's just the only environment known to date
   which works.  If alternatives are known they can be announced on the
   mailing list.

- - To configure glibc it is necessary to run in the build directory
   (which always should be separate from the source directory):

    /path/to/glibc/configure --prefix=/usr --enable-add-ons=linuxthreads2 \
       --enable-kernel=current --with-tls

   The --enable-kernel parameter requires that the 2.5.36+ kernel is
   running.  It is not strictly necessary but helps to avoid mistakes.
   It might also be a good idea to add --disable-profile, just to speed
   up the compilation.

   When configured as above the library must not be installed since it
   would overwrite the system's library.  If you want to install the
   resulting library choose a different --prefix parameter value.
   Otherwise the new code can be used without installation.  Running
   existing binaries is possible with

    elf/ld.so --library-path .:linuxthreads2:dlfcn:math <binary> <args>...

   Alternatively the binary could be build to find the dynamic linker
   and DSO by itself.  This is a much easier way to debug the code
   since gdb can start the binary.  Compiling is a bit more complicated
   in this case:

    gcc -nostdlib -nostartfiles -o <OUTPUT> csu/crt1.o csu/crti.o \
      $(gcc --print-file-name=crtbegin.o) <INPUTS> \
      -Wl,-rpath,$PWD,-dynamic-linker,$PWD/ld-linux.so.2 \
      linuxthreads2/libpthread.so.0 ./libc.so.6 ./libc_nonshared.a \
      elf/ld-linux.so.2 $(gcc --print-file-name=crtend.o) csu/crtn.o

   This command assumes that it is run in the build directory.  Correct
   the paths if necessary.  The compilation will use the system's
   headers which is a good test but might lead to strange effects if
   there are compatibility bugs left.


Once all these prerequisites are met compiling glibc should be easy.
But there are some tests which will flunk.  For good reasons we aren't
officially releasing the code yet.  The bugs are either in the TLS
code which is not enabled in the standard glibc build, or obviously in
the thread library itself.  To run the tests for the thread library
run

   make subdirs=linuxthreads2 check

One word on the name 'linuxthreads2' of the directory.  This is only a
convenience thing so that the glibc configure scripts don't complain
about missing thread support.  It will we changed to reflect the real
name of the library ASAP.


What can you expect?

This is a very early version of the code so the obvious answer is:
some problems.  The test suite for the new thread code should pass but
beside that and some performance measurement tool we haven't run much
code.  Ideally we would get people to write many more of these small
test programs which are included in the sources.  Compiling big
programs would mean not being able to locate problems easy.  But I
certainly won't object to people running and debugging bigger
applications.  Please report successes and failures to the mailing
list.

People who are interested in contributing must be aware that for any
non-trivial change we need an assignment of the code to the FSF.  The
process is unfortunately necessary in today's world.

People who are contaminated by having worked on proprietary thread
library implementation should not participate in discussions on the
mailing list unless they willfully disclose the information.  Every
bit of information is publically available from the mailing list
archive.


Which brings us to the final point: the mailing list for *all*
discussions related to this thread library implementation is

   phil-list@redhat.com

Go to

   https://listman.redhat.com/mailman/listinfo/phil-list

to subscribe, unsubscribe, or review the archive.

- -- 
- ---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE9im7E2ijCOnn/RHQRApe9AKCN20A8A5ITi3DUq+3IRZ0gsSVHTQCeKqEu
fA5OFtNuzYqltxSMoL8Ambw=
=4pb4
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 114+ messages in thread
* Re: [ANNOUNCE] Native POSIX Thread Library 0.1
@ 2002-09-20  7:46 Joerg Pommnitz
  0 siblings, 0 replies; 114+ messages in thread
From: Joerg Pommnitz @ 2002-09-20  7:46 UTC (permalink / raw)
  To: linux-kernel

Linus Torvalds wrote:
 > They started and waited for 100,000 threads.
 > 
 > They did not have them all running at the same time. I think the
 > original post said something like "up to 50 at a time".

To quote Ulrich:

"Even on IA-32 with its limited address space and memory handling
 running 100,000 concurrent threads was no problem at all, creating
 and destroying the threads did not take more than two seconds."

It clearly states 100,000 CONCURRENT threads. So, it really seems to
work (not that I have the hardware to verify this claim).

Regards
  Jörg

=====
-- 
Regards
       Joerg


__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Möchten Sie mit einem Gruß antworten? http://grusskarten.yahoo.de

^ permalink raw reply	[flat|nested] 114+ messages in thread
* Re: [ANNOUNCE] Native POSIX Thread Library 0.1
@ 2002-09-22 18:55 Peter Waechtler
  2002-09-22 21:32 ` Larry McVoy
                   ` (2 more replies)
  0 siblings, 3 replies; 114+ messages in thread
From: Peter Waechtler @ 2002-09-22 18:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: ingo Molnar

 > The true cost of M:N shows up when threading is actually used
 > for what it's intended to be used :-)

 > M:N's big mistakes is that it concentrates on what
 > matters the least: useruser context switches.

Well, from the perspective of the kernel, userspace is a black box.
Is that also true for kernel developers?

If you, as an application engineer, decide to use a multithreaded
design, it could be a) you want to learn or b) have some good
reasons to choose that.

Having multiple threads doing real work including IO means more
blocking IO and therefore more context switches. One reason to
choose threading is to _not_ have to use select/poll in app code.
If you gather more IO requests and multiplex them with select/poll
the chances are higher that the syscall returns without context
switch. Therefore you _save_ some real context switches with
useruser context switches.

Don't make the mistake to think too much about the optimal case.
(as Linus told us: optimize for the _common_ case :)

You think that one should have an almost equal number of threads
and processors. This is unrealistic despite some server apps
running on +4(8?) way systems. With this assumption nobody would
write a multithreaded desktop app (>90% are UP).

The effect of M:N on UP systems should be even more clear. Your
multithreaded apps can't profit of parallelism but they do not
add load to the system scheduler. The drawback: more syscalls
(I think about removing the need for
flags=fcntl(GETFLAGS);fcntl(fd,NONBLOCK);write(fd);fcntl(fd,flags))

Until we have some numbers we can't say which approach is better.
I'm convinced that apps exist that run better on one and others
on the other.

AIX and Irix deploy M:N - I guess for a good reason: it's more
flexible and combine both approaches with easy runtime tuning if
the app happens to run on SMP (the uncommon case).

Your great work at the scheduler and tuning on exit are highly
appreciated. Both models profit - of course 1:1 much more.


^ permalink raw reply	[flat|nested] 114+ messages in thread
* Re: [ANNOUNCE] Native POSIX Thread Library 0.1
@ 2002-09-23 16:36 Matthias Urlichs
  0 siblings, 0 replies; 114+ messages in thread
From: Matthias Urlichs @ 2002-09-23 16:36 UTC (permalink / raw)
  To: linux-kernel

Peter Waechtler:
>  [ unattributed -- please don't discard attributions ]

>  Having multiple threads doing real work including IO means more
>  blocking IO and therefore more context switches.

On the other hand, having to multiplex in userspace requires calls to 
poll() et al, _and_ explicitly handling state which the kernel needs 
to handle anyway -- including locking and all that crap.

Given that an efficient and fairly-low-cost 1:1 implementation is 
demonstrably possible ;-) the necessity to do any kind of n:m work 
strikes me as extremely low.
-- 
Matthias Urlichs      http://smurf.noris.de     ICQ:20193661    AIM:smurfixx

^ permalink raw reply	[flat|nested] 114+ messages in thread
[parent not found: <987738530@toto.iv>]

end of thread, other threads:[~2002-09-30 14:49 UTC | newest]

Thread overview: 114+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-20  0:41 [ANNOUNCE] Native POSIX Thread Library 0.1 Ulrich Drepper
2002-09-20  0:51 ` William Lee Irwin III
2002-09-20  1:35   ` Ulrich Drepper
2002-09-20  1:42     ` William Lee Irwin III
2002-09-20  1:56 ` Larry McVoy
2002-09-20  2:01 ` Rik van Riel
2002-09-20  2:15   ` Benjamin LaHaise
2002-09-20  2:40     ` Dave Hansen
2002-09-20  2:47     ` William Lee Irwin III
2002-09-20  2:17   ` Larry McVoy
2002-09-20  2:24     ` Rik van Riel
2002-09-20  2:32       ` Ulrich Drepper
2002-09-20  6:01       ` Linus Torvalds
2002-09-20  8:02         ` Ingo Molnar
2002-09-20  2:23   ` Anton Blanchard
2002-09-20  7:52   ` 100,000 threads? [was: [ANNOUNCE] Native POSIX Thread Library 0.1] Ingo Molnar
2002-09-20 15:47     ` Bill Davidsen
2002-09-20  9:53 ` [ANNOUNCE] Native POSIX Thread Library 0.1 Padraig Brady
2002-09-20 13:28   ` Robert Love
2002-09-20 16:01     ` Bill Davidsen
2002-09-20  9:54 ` Adrian Bunk
2002-09-20 10:53   ` Ingo Molnar
2002-09-20 19:04   ` Ulrich Drepper
2002-09-20 23:06     ` J.A. Magallon
2002-09-20 23:33       ` Ulrich Drepper
2002-09-20 23:42         ` J.A. Magallon
2002-09-20 10:20 ` Bill Huey
2002-09-20 10:47   ` Ingo Molnar
2002-09-20 12:06     ` Bill Huey
2002-09-20 16:20       ` Ingo Molnar
2002-09-20 21:50         ` Bill Huey
2002-09-20 22:30           ` dean gaudet
2002-09-20 23:11             ` Bill Huey
2002-09-21  3:38               ` dean gaudet
2002-09-21  4:01                 ` Bill Huey
2002-09-21  5:06                   ` Ingo Molnar
2002-09-20 23:45           ` Bill Huey
2002-09-21  4:58             ` Ingo Molnar
2002-09-22  2:51               ` Bill Huey
2002-09-21  4:48           ` Ingo Molnar
2002-09-22  1:38             ` Bill Huey
2002-09-22 13:38           ` Bill Davidsen
2002-09-22 18:41             ` Eric W. Biederman
2002-09-22 22:13               ` dean gaudet
2002-09-26 17:21                 ` Alan Cox
2002-09-23  0:11               ` Bill Huey
2002-09-24 16:07                 ` Eric W. Biederman
2002-09-24 23:21                   ` Bill Huey
2002-09-25  3:06                     ` Eric W. Biederman
2002-09-23 21:12             ` Bill Huey
2002-09-20 10:35 ` Luca Barbieri
2002-09-20 11:19   ` Ingo Molnar
2002-09-20 18:40     ` Roland McGrath
2002-09-20 21:21       ` Luca Barbieri
2002-09-20 12:37 ` jlnance
2002-09-20 16:42   ` Ingo Molnar
2002-09-24  0:40     ` Rusty Russell
2002-09-24  5:47       ` Ingo Molnar
2002-09-24  6:15         ` Rusty Russell
2002-09-20 15:43 ` Bill Davidsen
2002-09-20 16:15   ` Jakub Jelinek
2002-09-20 17:16     ` Bill Davidsen
2002-09-20  7:46 Joerg Pommnitz
2002-09-22 18:55 Peter Waechtler
2002-09-22 21:32 ` Larry McVoy
2002-09-23 10:05   ` Bill Davidsen
2002-09-23 11:55     ` Peter Waechtler
2002-09-23 19:14       ` Bill Davidsen
2002-09-29 23:26         ` Buddy Lumpkin
2002-09-30 14:54           ` Corey Minyard
2002-09-23 15:30     ` Larry McVoy
2002-09-23 19:44       ` Olivier Galibert
2002-09-23 19:48       ` Bill Davidsen
2002-09-23 20:32         ` Ingo Molnar
2002-09-24  0:03           ` Andy Isaacson
2002-09-24  0:10             ` Jeff Garzik
2002-09-24  0:14               ` Andy Isaacson
2002-09-24  5:53             ` Ingo Molnar
2002-09-24 20:34             ` David Schwartz
2002-09-24  7:12           ` Thunder from the hill
2002-09-24  7:30             ` Ingo Molnar
2002-09-23 22:35         ` Mark Mielke
2002-09-23 19:59       ` Peter Waechtler
2002-09-23 20:36         ` Ingo Molnar
2002-09-23 21:08           ` Peter Wächtler
2002-09-23 22:44             ` Mark Mielke
2002-09-23 23:01               ` Bill Huey
2002-09-23 23:11                 ` Mark Mielke
2002-09-24  0:21                   ` Bill Huey
2002-09-24  3:20                     ` Mark Mielke
2002-09-23 23:57           ` Andy Isaacson
2002-09-24 18:10             ` Christoph Hellwig
2002-09-23 21:32       ` Bill Huey
2002-09-23 21:41       ` dean gaudet
2002-09-23 22:10         ` Bill Huey
2002-09-23 22:56         ` Mark Mielke
2002-09-24 10:02       ` Nikita Danilov
2002-09-23 21:22     ` Bill Huey
2002-09-23 21:03 ` Bill Huey
2002-09-24 12:03   ` Michael Sinz
2002-09-24 13:40     ` Peter Svensson
2002-09-24 14:20       ` Michael Sinz
2002-09-24 20:19 ` David Schwartz
2002-09-24 21:10   ` Chris Friesen
2002-09-24 21:22     ` Rik van Riel
2002-09-24 21:35       ` Roberto Peon
2002-09-24 21:35       ` Chris Friesen
2002-09-25 19:02     ` David Schwartz
2002-09-24 23:16   ` Peter Waechtler
2002-09-24 23:23     ` Rik van Riel
2002-09-25 19:05     ` David Schwartz
2002-09-23 16:36 Matthias Urlichs
     [not found] <987738530@toto.iv>
2002-09-24  2:48 ` Peter Chubb
2002-09-24  3:37   ` Mark Mielke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).