Threading Models and HP-UX

   

Several threading models are utilized in modern operating systems (see Figure 4-3).

M x 1 threading allows for a single kernel-level thread per process. In the user space, a user-level scheduler may be employed to approximate the actions of a multithreaded environment. Programmers use user-space library routines to accomplish pseudo-scheduling and resource coordination. The library routines must monitor the individual user threads and context-switch if the current active thread is about to make a system call that would result in a blocking action. Once any of a process's user threads blocks on a call, the entire process is placed in a wait state. Keep in mind that from the perspective of the kernel, this is a single-threaded model (ergo the 1 in the M x 1 label). All of the scheduling is done by the user code, which results in a fairly low cost because the pseudo-scheduler does not encounter the additional overhead of system calls. While this is a plus, a big negative is that this model does not allow a process to take advantage of multiple CPU configurations.

1 x 1 threading does allow for multiple threads per process. In this model, there is a one-to-one relationship between kernel and user threads, and no user-space scheduler is allowed. The kernel scheduler works only with kernel threads and has no knowledge of what goes on in the user space. A process's user threads are bound one-on-one to a kernel thread, which in turn is scheduled on a specific CPU. The scheduler runs in kernel space and requires heavyweight system calls to manage each processor's run-queue. Processor run-queues are built by creating a linked list of kernel threads, kthreads, that share the same priority queue and processor affinity. The thread at the head of the list of the strongest active priority queue will be the next one scheduled. Once a kernel thread is scheduled, it may pass control to its user thread. We return to a kernel thread only when the user thread makes a system call or to the kernel proper upon receipt of a system interruption. While this model makes extensive use of system calls it allows a process to take advantage of parallel execution on SMP systems.

M x N threading brings together both of the previous models. In this environment, the programmer may choose to employe a user-space scheduler or simply rely on the kernel scheduler, or use a combination of both. On SMP systems, user threads may be multiplexed to several kernel threads or simply bound in a one-to-one fashion at the discretion of the application programmer. This gives the programmer the greatest degree of control when trying to optimize process performance.

Hewlett Packard is using a phased introduction of threading to the HP-UX kernel.

Phase 1 occurred with the release of HP-UX 10.10. This involved modifying the kernel's scheduling system to work with the newly created kthread table entries. For this release, only one thread of execution could exist per proc table entry. One could argue that this was not truly a threaded kernel: in effect, we were at the time merely "prepping the kernel for threads." A limited form of threading known as user threads, or the M x 1 model (making use of the DCE libcmathreads library), was also available to programmers at this time.

Phase 2 came with HP-UX release 10.30/11.00, which adopted a threading model called 1 x 1 threading: for each thread spawned by a user process, there is a single unique kernel thread. This new capability allowed a process to spawn multiple sibling threads and, for the first time on an HP-UX system, allowed a process to take full advantage of SMP system parallelism. To facilitate this model, the POSIX kernel threads library, libpthread, was implemented.

The release of HP-UX 10.30 (an early developers' release for workstations) provided for compliance with the POSIX 1003.1b API for multithreaded application development. With the full HP-UX 11.00 release, more thread features were added to make it POSIX 1003.1c compliant.

Phase 3 will be implemented in a future release. This phase will adopt the M x N threading model. In this model a single kernel thread may be associated with one or more individual user threads. This is a very flexible model, but along with flexibility comes an added cost in the complexity of the programming. M x N threads should be available on HP-UX in the near future.

Figure 4-3. Threading Models

graphics/04fig03.gif




HP-UX 11i Internals
HP-UX 11i Internals
ISBN: 0130328618
EAN: 2147483647
Year: 2006
Pages: 167

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net