3 Processes: 3.1 Threads
3 Processes: 3.1 Threads
3 Processes: 3.1 Threads
3
3.1
Processes
Threads
Introduction to Threads
Basic idea We build virtual processors in software, on top of physical processors: Processor: Provides a set of instructions along with the capability of automatically executing a series of those instructions. Thread: A minimal software processor in whose context a series of instructions can be executed. Saving a thread context implies stopping the current execution and saving all the data needed to continue the execution at a later stage. Process: A software processor in whose context one or more threads may be executed. Executing a thread, means executing a series of instructions in the context of that thread.
Context Switching Contexts Processor context: The minimal collection of values stored in the registers of a processor used for the execution of a series of instructions (e.g., stack pointer, addressing registers, program counter). Thread context: The minimal collection of values stored in registers and memory, used for the execution of a series of instructions (i.e., processor context, state). Process context: The minimal collection of values stored in registers and memory, used for the execution of a thread (i.e., thread context, but now also at least MMU register values).
Context Switching Observations 1. Threads share the same address space. Thread context switching can be done entirely independent of the operating system. 2. Process switching is generally more expensive as it involves getting the OS in the loop, i.e., trapping to the kernel. 3. Creating and destroying threads is much cheaper than doing so for processes.
Geoff Hamilton
Solaris Threads Basic idea Introduce a two-level threading approach: lightweight processes that can execute user-level threads.
Thread state User space Thread
Geoff Hamilton
Solaris Threads
Principal operation User-level thread does system call the LWP that is executing that thread, blocks. The thread remains bound to the LWP. The kernel can schedule another LWP having a runnable thread bound to it. Note: this thread can switch to any other runnable thread currently in user space. A thread calls a blocking user-level operation do context switch to a runnable thread, (then bound to the same LWP). When there are no threads to schedule, an LWP may remain idle, and may even be removed (destroyed) by the kernel. Note This concept has been virtually abandoned its just either user-level or kernel-level threads.
Geoff Hamilton
3.2
Virtualizaton
Virtualization Observation Virtualization is becoming increasingly important: Hardware changes faster than software Ease of portability and code migration Isolation of failing or attacked components
Program Interface A Program Interface A Hardware/software system A (a) Implementation of mimicking A on B Interface B Hardware/software system B (b)
Architecture of VMs Observation Virtualization can take place at very different levels, strongly depending on the interfaces as offered by various systems components:
General instructions
Geoff Hamilton
Application Runtime system Runtime system Runtime system Operating system Hardware (a)
Applications Operating system Operating system Operating system Virtual machine monitor Hardware (b)
Process VM: A program is compiled to intermediate (portable) code, which is then executed by a runtime system (Example: Java VM). VM Monitor: A separate software layer mimics the instruction set of hardware a complete operating system and its applications can be supported (Example: VMware, VirtualBox). VM Monitors on operating systems Practice Were seeing VMMs run on top of existing operating systems. Perform binary translation: while executing an application or operating system, translate instructions to that of the underlying machine. Distinguish sensitive instructions: traps to the orginal kernel (think of system calls, or privileged instructions). Sensitive instructions are replaced with calls to the VMM.
3.3
Clients
Clients: User Interfaces Essence A major part of client-side software is focused on (graphical) user interfaces.
Application server Window manager Xlib Local OS Application server Application Xlib interface User's terminal
Xlib Local OS X protocol X kernel Device drivers Terminal (includes display keyboard, mouse, etc.)
Geoff Hamilton
Clients: User Interfaces Compound documents User interface is application-aware interapplication communication: drag-and-drop: move objects across the screen to invoke interaction with other applications in-place editing: integrate several applications at user-interface level (word processing + drawing facilities)
Client-Side Software
Generally tailored for distribution transparency access transparency: client-side stubs for RPCs location/migration transparency: let client-side software keep track of actual location replication transparency: multiple invocations handled by client stub:
Client machine Client appl. Server 1 Server appl Server 2 Server appl Server 3 Server appl
Replicated request
failure transparency: can often be placed only at client (were trying to mask server and communication failures).
3.4
Servers
Servers: General organization Basic model A server is a process that waits for incoming service requests at a specic transport address. In practice, there is a one-to-one mapping between a port and a service.
ftp-data ftp telnet smtp login sunrpc courier 20 21 23 24 25 49 111 530 File Transfer [Default Data] File Transfer [Control] Telnet any private mail system Simple Mail Transfer Login Host Protocol SUN RPC (portmapper) Xerox RPC
Geoff Hamilton
Servers: General organization Type of servers Superservers: Servers that listen to several ports, i.e., provide several independent services. In practice, when a service request comes in, they start a subprocess to handle the request (UNIX inetd) Iterative vs. concurrent servers: Iterative servers can handle only one client at a time, in contrast to concurrent servers
Out-of-band communication
Issue Is it possible to interrupt a server once it has accepted (or is in the process of accepting) a service request? Solution 1 Use a separate port for urgent data: Server has a separate thread/process for urgent messages Urgent message comes in associated request is put on hold Note: we require OS supports priority-based scheduling Solution 2 Use out-of-band communication facilities of the transport layer: Example: TCP allows for urgent messages in same connection Urgent messages can be caught using OS signaling techniques
Servers and state Question Does connection-oriented communication t into a stateless design? Geoff Hamilton
Servers and state Stateful servers Keeps track of the status of its clients: Record that a le has been opened, so that prefetching can be done Knows which data a client has cached, and allows clients to keep local copies of shared data Observation The performance of stateful servers can be extremely high, provided clients are allowed to keep local copies. As it turns out, reliability is not a major problem. Server clusters: three different tiers
Logical switch (possibly multiple) Application/compute servers Distributed file/database system
Client requests
Dispatched request
First tier
Second tier
Third tier
Crucial element The rst tier is generally responsible for passing requests to an appropriate server. Request Handling Observation Having the rst tier handle all communication from/to the cluster may lead to a bottleneck. Solution Various, but one popular one is TCP-handoff
Logically a single TCP connection
Response
Server
Client
Request
Switch
Server
Geoff Hamilton
Example: PlanetLab Essence Different organizations contribute machines, which they subsequently share for various experiments. Problem We need to ensure that different distributed applications do not get into each others way virtualization Example: PlanetLab
User-assigned virtual machines Priviliged management virtual machines
Vserver: Independent and protected environment with its own libraries, server versions, and so on. Distributed applications are assigned a collection of vservers distributed across multiple machines (slice).
Process
Process
Process
Process
Process
Process
Process
Process
Process
Process
...
...
...
...
...
Vserver
Vserver
Vserver
Vserver
Vserver
3.5
Code Migration
Code Migration Approaches to code migration Migration and local resources Migration in heterogeneous systems Code Migration: Some Context
Geoff Hamilton
10
Client
Strong and weak mobility Object components Code segment: contains the actual code Data segment: contains the state Execution state: contains context of thread executing the objects code Strong and weak mobility Weak mobility Move only code and data segment (and reboot execution): Relatively simple, especially if code is portable Distinguish code shipping (push) from code fetching (pull) Strong mobility Move component, including execution state Migration: move entire object from one machine to the other Cloning: start a clone, and set it in the same execution state. Managing local resources Problem An object uses local resources that may or may not be available at the target site. Resource types Geoff Hamilton
11
Fixed: the resource cannot be migrated, such as local hardware Fastened: the resource can, in principle, be migrated but only at high cost Unattached: the resource can easily be moved along with the object (e.g. a cache)
Managing local resources Object-to-resource binding By identier: the object requires a specic instance of a resource (e.g. a specic database) By value: the object requires the value of a resource (e.g. the set of cache entries) By type: the object requires that only a type of resource is available (e.g. a color monitor)
GR = Establish global systemwide reference MV = Move the resource CP = Copy the value of the resource RB = Re-bind to a locally available resource
Migration in heterogenous systems Main problem The target machine may not be suitable to execute the migrated code The denition of process/thread/processor context is highly dependent on local hardware, operating system and runtime system Only solution Make use of an abstract machine that is implemented on different platforms: Interpreted languages, effectively having their own VM Virtual VM (as discussed previously)
Geoff Hamilton