Thursday, July 30, 2009

Multithreading Models

  • Many-to-one

In this model, the library maps all threads to a single lightweight process Advantages: totally portable easy to do with few systems dependencies Disadvantages: cannot take advantage of parallelism may have to block for synchronous I/O there is a clever technique for avoiding it Mainly used in language systems, portable libraries

  • One-to-one

In this model, the library maps each thread to a different lightweight process Advantages: can exploit parallelism, blocking system calls Disadvantages: thread creation involves LWP creation each thread takes up kernel resources limiting the number of total threads Used in LinuxThreads and other systems where LWP creation is not too expensive.

  • Many-to-many

n this model, the library has two kinds of threads: bound and unbound bound threads are mapped each to a single lightweight process unbound threads may be mapped to the same LWP Probably the best of both worlds Used in the Solaris implementation of Pthreads (and several other Unix implementations) .

Thead Library

  • The Thread Library (TL) is a software feature that enables the computer to run programs written to use POSIX Threads fairly efficiently and conscies.

Kernel mode

  • kernel directly supports multiple threads of control in a process

  • Benefits:scheduling/synchronization coordination, less overheadthan process, suitable for parallel application

  • Drawbacks:more expensive than user-level threads, generalityleads to greater overhead

User Thread

  • user libraries implementation

  • Benefits:no kernel modifications, flexible and low cost

  • Drawbacks:thread may block entire process, no parallelism

Benifits of Multi-threaded Programming

Responsiveness

Resource Sharing

Economy

Utilization of MP Architectures

Theard

  • Single-threaded process

- Single threaded process have one path of execution, and multi-threaded programs have two or more paths of execution. Single threaded programs can perform only one task at a time, and have to finish each task in sequence before they can start another. For most programs, one thread of execution is all you need, but sometimes it makes sense to use multiple threads in a program to accomplish multiple simultaneous tasks.

  • Multi-threaded process

Each process can include many threads.

All threads of a process share:

–memory (program code and global data)


–open file/socket descriptors


–signal handlers and signal dispositions


–working environment (current directory, user ID, etc.)

Producer

*Producer :
»get a message block from mayproduce

»put data item in block

»send message to mayconsume

*consumer :

»get a message from mayconsume

»consume data in block

»return empty message block to mayproduce mailbox

Buffering

•Buffering - the number of messages that can reside in a link temporarily

–Zero capacity - queue length 0

»sender must wait until receiver ready to take the message

–Bounded capacity - finite length queue
»messages can be queued as long as queue not full

»otherwise sender will have to wait

–Unbounded capacity

»any number of messages can be queued - in virtual space?

»sender never delayed

Interprocess Communication

  • Direct Communication


–each process wanting to communicate must explicitly name the recipient or sender of the communication

–send and receive primitives defined:
send ( P, message ) : send a message to process P
receive ( Q, message ) : receive a message from process Q


–a link established automatically between every pair of processes that want to communicate
»processes only need to know each other’s identity

–link is associated with exactly two processes

–link is usually bidirectional but can be unidirectional

– Process A Process Bwhile (TRUE) { while (TRUE) { produce an item receive ( A, item ) send ( B, item ) consume item} }

  • Indirect Communication


•messages sent to and received from mailboxes (or ports)

–mailboxes can be viewed as objects into which messages placed by processes and from which messages can be removed by other processes

–each mailbox has a unique ID

–two processes can communicate only if they have a shared mailbox


send ( A, message ) : send a message to mailbox Areceive ( A, message ) :

receive a message from mailbox A

  • Synchronization

- Message passing may be either blocking or non-blocking.

• Blocking is considered synchronous

• Non-blocking is considered asynchronous

- Send and receive primitives may be either blocking or non-blocking.

Thursday, July 16, 2009

Inter-process communication

Inter-process communication (IPC) is a set of techniques for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC).

The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated.

There are several reasons for providing an environment that allows process cooperation:
Information sharing Computation speedup Modularity Convenience IPC may also be referred to as inter-thread communication and inter-application communication.
IPC, on par with the address space concept, is the foundation for address space independence/isolation.[1]

Cooperating processes

Once we have multiple processes or threads, it islikely that two or more of them will want tocommunicate with each other

• Process cooperation (i.e., interprocesscommunication) deals with three main issues

– Passing information between processes/threads

– Making sure that processes/threads do not interfere witheach other

– Ensuring proper sequencing of dependent operations

• These issues apply to both processes and theads– Initially we concentrate on shared memory mechanismswe have multilple

Operating in Process

  • Process Creation
Parent process creates children processes, which, in turn create other processes, forming a tree
of processes.Resource sharing:

>Parent and children share all resources.

>Children share subset of parent’s resources.

>Parent and child share no resources.

Execution:

>Parent and children execute concurrently.

>Parent waits until children terminate.

  • Process termination

>Process executes last statement and asks the operating system to delete it (exit).

>Output data from child to parent (via wait).

>Process’ resources are deallocated by operating system.>Parent may terminate execution of children processes (abort).

>Child has exceeded allocated resources.

>Task assigned to child is no longer required.

>Parent is exiting.

>Operating system does not allow child to continue if its parent terminates.

>Cascading termination.

Process Scheduling

  • Scheduling Queues

>Job queue – set of all processes in the system.

>Ready queue – set of all processes residing in main memory, ready and waiting to execute

device

>Device queues – set of processes waiting for an I/O device.

>Processes migrate between the various queues.

  • Schedules

>Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.

>Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.

  • Control Switch

>When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

>Context-switch time is overhead; the system does no useful work while switching.

>Time dependent on hardware support.

Process

  • Process State

In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of processes.

  • Process Control Block

-Information associated with each process.

>Process ID

>Process state

>Program countern CPU registers

>CPU scheduling information

>Memory-management information

>Accounting information

>I/O status information

  • Threads

In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.


On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Support for threads in programming languages varies: a number of languages simply do not support having more than one execution context inside the same program executing at the same time.

Examples of such languages include Python, and OCaml, because the parallel support of their runtime support is limited by the use of a central lock, called "Global Interpreter Lock" in Python, "master lock" in Ocaml. Other languages may be limited because they use threads that are user threads, which are not visible to the kernel, and thus cannot be scheduled to run concurrently. On the other hand, kernel threads, which are visible to the kernel, can run concurrently.

Tuesday, July 7, 2009

System Boot

  • Operating system must be made available to hardware so hardware can start it

-Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it

-Sometimes two-step process where boot block at fixed location loads bootstrap loader


-When power initialized on system, execution starts at a fixed memory location


Firmware used to hold initial boot code

System Generation

- Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site

- SYSGEN program obtains information concerning the specific configuration of the hardware system- Booting

– starting a computer by loading the kernel- Bootstrap program

– code stored in ROM that is able to locate the kernel, load it into memory, and start its execution

Virtual Machine

  • A virtual machine was originally defined by Popek and Goldberg as "an efficient, isolated duplicate of a real machine". Current use includes virtual machines which have no direct correspondence to any real hardware.[1]
    Virtual machines are separated into two major categories, based on their use and degree of correspondence to any real machine. A system virtual machine provides a complete system platform which supports the execution of a complete operating system (OS). In contrast, a process virtual machine is designed to run a single program, which means that it supports a single process. An essential characteristic of a virtual machine is that the software running inside is limited to the resources and abstractions provided by the virtual machine -- it cannot break out of its virtual world.
    Example: A program written in Java receives services from the Java Runtime Environment (JRE) software by issuing commands to, and receiving the expected results from, the Java software. By providing these services to the program, the Java software is acting as a "virtual machine", taking the place of the operating system or hardware for which the program would ordinarily be tailored.

  • System virtual machines
    See also: Virtualization and Comparison of virtual machinesSystem virtual machines (sometimes called hardware virtual machines) allow the sharing of the underlying physical machine resources between different virtual machines, each running its own operating system. The software layer providing the virtualization is called a virtual machine monitor or hypervisor. A hypervisor can run on bare hardware (Type 1 or native VM) or on top of an operating system (Type 2 or hosted VM).
    The main advantages of system VMs are:
    multiple OS environments can co-exist on the same computer, in strong isolation from each other the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine application provisioning, maintenance, high availability and disaster recovery[2] Multiple VMs each running their own operating system (called guest operating system) are frequently used in server consolidation, where different services that used to run on individual machines in order to avoid interference are instead run in separate VMs on the same physical machine. This use is frequently called quality-of-service isolation (QoS isolation).
    The desire to run multiple operating systems was the original motivation for virtual machines, as it allowed time-sharing a single computer between several single-tasking OSes. This technique requires a process to share the CPU resources between guest operating systems and memory virtualization to share the memory on the host.
    The guest OSes do not have to be all the same, making it possible to run different OSes on the same computer (e.g., Microsoft Windows and Linux, or older versions of an OS in order to support software that has not yet been ported to the latest version). The use of virtual machines to support different guest OSes is becoming popular in embedded systems; a typical use is to support a real-time operating system at the same time as a high-level OS such as Linux or Windows.


Thursday, July 2, 2009

System Structure

  • Simple Structure

-->View the OS as a series of levels

-->Each level performs a related subset of functions

-->Each level relies on the next lower level to perform more primitive functions

-->This decomposes a problem into a number of more manageable subproblems

  • Layred Approach

The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers.
A process is a program in execution. A process needs certain resources: CPU time, memory (address space), files, and I/O devices, to accomplish its task.

System Calls

  • Process control

Process control is a statistics and engineering discipline that deals with architectures, mechanisms, and algorithms for controlling the output of a specific process. See also control theory.

For example, heating up the temperature in a room is a process that has the specific, desired outcome to reach and maintain a defined temperature (e.g. 20°C), kept constant over time. Here, the temperature is the controlled variable. At the same time, it is the input variable since it is measured by a thermometer and used to decide whether to heat or not to heat. The desired temperature (20°C) is the setpoint. The state of the heater (e.g. the setting of the valve allowing hot water to flow through it) is called the manipulated variable since it is subject to control actions.

  • File Management

Also referred to as simply a file system or filesystem. The system that an operating system or program uses to organize and keep track of files. For example, a hierarchical file system is one that uses directories to organize files into a tree structure. Although the operating system provides its own file management system, you can buy separate file management systems. These systems interact smoothly with the operating system but provide more features, such as improved backup procedures and stricter file protection.

  • Device management

Device Management is a set of technologies, protocols and standards used to allow the remote management of mobile devices, often involving updates of firmware over the air (FOTA). The network operator, handset OEM or in some cases even the end-user (usually via a web portal) can use Device Management, also known as Mobile Device Management, or MDM, to update the handset firmware/OS, install applications and fix bugs, all over the air. Thus, large numbers of devices can be managed with single commands and the end-user is freed from the requirement to take the phone to a shop or service center to refresh or update.

  • Information Maintainance

Information management (IM) is the collection and management of information from one or more sources and the distribution of that information to one or more audiences. This sometimes involves those who have a stake in, or a right to that information. Management means the organization of and control over the structure, processing and delivery of information.

Throughout the 1970s this was largely limited to files, file maintenance, and the life cycle management of paper-based files, other media and records. With the proliferation of information technology starting in the 1970s, the job of information management took on a new light, and also began to include the field of Data maintenance. No longer was information management a simple job that could be performed by almost anyone. An understanding of the technology involved, and the theory behind it became necessary. As information storage shifted to electronic means, this became more and more difficult. By the late 1990s when information was regularly disseminated across computer networks and by other electronic means, network managers, in a sense, became information managers. Those individuals found themselves tasked with increasingly complex tasks, hardware and software. With the latest tools available, information management has become a powerful resource and a large expense for many organizations.

Operating System Service

  • Operating systems are responsible for providing essential services within a computer system:
    * Initial loading of programs and transfer of programs between secondary storage and main memory
    *Supervision of the input/output devices
    *File management
    *Protection facilities

System Components


  • Operating systems Process Management

The operating system is responsible for the following activities in connection with process management.

-->Process creation and deletion.

-->Process suspension and resumption.

-->Provision of mechanisms for:

-->Process synchronization

->Process communication



  • Main memory management
    Memory management is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. The management of main memory is critical to the computer system.
    Virtual memory systems separate the memory addresses used by a process from actual physical addresses, allowing separation of processes and increasing the effectively available amount of RAM using disk swapping. The quality of the virtual memory manager can have a big impact on overall system performance.
    Garbage collection is the automated allocation, and deallocation of computer memory resources for a program. This is generally implemented at the programming language level and is in opposition to manual memory management, the explicit allocation and deallocation of computer memory resources.




  • File management Also referred to as simply a file system or filesystem. The system that an operating system or program uses to organize and keep track of files. For example, a hierarchical file system is one that uses directories to organize files into a tree structure. Although the operating system provides its own file management system, you can buy separate file management systems. These systems interact smoothly with the operating system but provide more features, such as improved backup procedures and stricter file protection.


  • I/O System management

The I/O system consists of:

-->A buffer-caching system

-->A general device-driver interface

-->Drivers for specific hardware devices



  • Secondary Storage System
    Secondary storage management is a classical feature of database management systems. It is usually supported through a set of mechanisms. These include index management, data clustering, data buffering, access path selection and query optimization.
    None of these is visible to the user: they are simply performance features. However, they are so critical in terms of performance that their absence will keep the system from performing some tasks (simply because they take too much time). The important point is that they be invisible. The application programmer should not have to write code to maintain indices, to allocate disk storage, or to move data between disk and main memory. Thus, there should be a clear independence between the logical and the physical level of the system.



  • Protection System

Protection refers to a mechanism for controlling access by programs, processes, or users to both system and user resources.
The protection mechanism must:

-->Distinguish between authorized and unauthorized usage.

-->Specify the controls to be imposed.

-->Provide a means of enforcement.



  • Command-Interpreter System
    A command-line interpreter (also command line shell, command language interpreter) is a computer program that reads lines of text entered by a user and interprets them in the context of a given operating system or programming language.