Process and Threads Implementation and Scheduling 1
PROCESS AND THREADS IMPLEMENTATION AND SCHEDULING
CS 554 OPERATING SYSTEMS SU14 AH1 06/04/2014
ABSTRACT Process and Threads Implementation and Scheduling 2 A process, and its modern extension, the thread, are the active computational elements in a modern computer system. Processes and threads operate on passive resources such as primary memory and devices. An OSs process manager provides a spectrum of services to define, support, and administer the systems processes, threads, and resources. The natural place to begin a study of OS details is process management. This project provide a complete discussion of process management. This project describes the general framework for the process manager, then looks at how the framework can be implemented. Subsequent chapters elaborate on the specific aspects of processor scheduling, synchronization, and deadlock.
A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. A thread is the entity within a process that can be scheduled for execution .Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads. . All threads of a process share its virtual address space and system resources. Threads are scheduled to run based on their scheduling priority. Each thread is assigned a scheduling priority. The priority levels range from zero (lowest priority) to 31 (highest priority). Only the zero-page thread can have a priority of zero. (The zero-page thread is a system thread responsible for zeroing any free pages when there are no other threads that need to run.).The system treats all threads with the same priority as equal. The system assigns time slices in a round-robin fashion to all threads with the highest priority.
Keywords: 1. Thread: a thread of execution is the smallest sequence of programmed instructions that can be managed independently by an operating system scheduler 2. Primary thread: Each process is started with a single thread, called as primary thread. 3. Scheduling priority: Each thread is scheduled to run based on priority known as scheduling priority
Process and Threads Implementation and Scheduling 3 1. Introduction A computer system can be divided roughly into four components: the hardware, the operating system, the application programs, and the users. Operating systems are an essential part of any computer system. An operating system acts as an intermediary between the user of a computer and the computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs in a convenient and efficient manner. An operating system is a program that manages a computers hardware. It also provides a basis for application programs and acts as an intermediary between the computer user and the computer hardware. Because an operating system is large and complex, it must be created piece by piece. Each of these pieces should be a well-delineated portion of the system, with carefully defined inputs, outputs, and functions. The hardwarethe central processing unit (CPU), the memory, and the input/output (I/O) devicesprovides the basic computing resources for the system. The application programssuch as word processors, spreadsheets, compilers, and Web browsersdefine the ways in which these resources are used to solve users computing problems. The operating system controls the hardware and coordinates its use among the various application programs for the various users. The most important type of system software is the operating system. An operating system has three main responsibilities: 1. Basic tasks, such as recognizing input from the keyboard, sending output to the display screen, keeping track of files and directories on the disk, and controlling peripheral devices such as disk drives and printers. 2. Ensure that different programs and users running at the same time do not interfere with each other. 3. Provide a software platform on top of which other programs (i.e., application software) can run. The first two responsibilities address the need for managing the computer hardware and the application programs that use the hardware. The third responsibility focuses on providing an Process and Threads Implementation and Scheduling 4 interface between application software and hardware so that application software can be efficiently developed. Since the operating system is already responsible for managing the hardware, it should provide a programming interface for application developers. 1.1 Types of Operating Systems: Following are few of the important types of operating system which are most commonly used. a) Batch operating system: The users of batch operating system do not interact with the computer directly. Each user prepares his job on an off-line device like punch cards and submits it to the computer operator. To speed up processing, jobs with similar needs are batched together and run as a group. Thus, the programmers left their programs with the operator. The operator then sorts programs into batches with similar requirements. The problems with Batch Systems are following. Lack of interaction between the user and job. CPU is often idle, because the speeds of the mechanical I/O devices is slower than CPU. Difficult to provide the desired priority. b) Time-sharing operating systems: Time sharing is a technique which enables many people, located at various terminals, to use a particular computer system at the same time. Time-sharing or multitasking is a logical extension of multiprogramming. Processor's time which is shared among multiple users simultaneously is termed as time-sharing. The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems is that in case of multiprogrammed batch systems, objective is to maximize processor use, whereas in Time-Sharing Systems objective is to minimize response time. c) Distributed operating System: Process and Threads Implementation and Scheduling 5 Distributed systems use multiple central processors to serve multiple real time application and multiple users. Data processing jobs are distributed among the processors accordingly to which one can perform each job most efficiently. The processors communicate with one another through various communication lines (such as high-speed buses or telephone lines). These are referred as loosely coupled systems or distributed systems. Processors in a distributed system may vary in size and function. These processors are referred as sites, nodes, and computers and so on d) Network operating System: Network Operating System runs on a server and and provides server the capability to manage data, users, groups, security, applications, and other networking functions. The primary purpose of the network operating system is to allow shared file and printer access among multiple computers in a network, typically a local area network (LAN), a private network or to other networks. Examples of network operating systems are Microsoft Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD. e) Real Time operating System: Real time system is defines as a data processing system in which the time interval required to process and respond to inputs is so small that it controls the environment. Real time processing is always on line whereas on line system need not be real time. The time taken by the system to respond to an input and display of required updated information is termed as response time. So in this method response time is very less as compared to the online processing. There are two types of real-time operating systems. HARD REAL-TIME SYSTEMS Hard real-time systems guarantee that critical tasks complete on time. In hard real-time systems secondary storage is limited or missing with data stored in ROM. In these systems virtual memory is almost never found. Process and Threads Implementation and Scheduling 6 SOFT REAL-TIME SYSTEMS Soft real time systems are less restrictive. Critical real-time task gets priority over other tasks and retains the priority until it completes. Soft real-time systems have limited utility than hard real-time systems. For example, Multimedia, virtual reality, Advanced Scientific Projects like undersea exploration and planetary rovers etc. 2) FULL OPERATING SYSTEM IDENTIFICATION
The Operating System used is the Windows 8 which is developed by the Microsoft developers and the full identification for this operating system in which the PC must be running are: Processor: 1 gigahertz (GHz) or faster with support for PAE, NX, and SSE2 RAM: 1 gigabyte (GB) (32-bit) or 2 GB (64-bit) Hard disk space: 16 GB (32-bit) or 20 GB (64-bit) Graphics card: Microsoft DirectX 9 graphics device with WDDM driver 2.1 Additional requirements to use certain features: To use touch, you need a tablet or a monitor that supports multitouch. To access the Windows Store and to download, run, and snap apps, you need an active Internet connection and a screen resolution of at least 1024 x 768 Microsoft account required for some features Some games and programs might require a graphics card compatible with DirectX 10 or higher for optimal performance Watching DVDs requires separate playback software. Windows Media Centre license sold separately. Internet access (ISP fees might apply) Secure boot requires firmware that supports UEFI v2.3.1 Errata B and has the Microsoft Windows Certification Authority in the UEFI signature database BitLocker To Go requires a USB flash drive (Windows 8.1 Pro only) Process and Threads Implementation and Scheduling 7 BitLocker requires either Trusted Platform Module (TPM) 1.2 or a USB flash drive (Windows 8.1 Pro only) Client Hyper-V requires a 64-bit system with second level address translation (SLAT) capabilities and additional 2 GB of RAM (Windows 8.1 Pro only) A TV tuner is required to play and record live TV in Windows Media Centre (Windows 8.1 Pro Pack and Windows 8.1 Media Centre Pack only) Wi-Fi Direct Printing requires a Wi-Fi adapter that supports Wi-Fi Direct and a device that supports Wi-Fi Direct Printing Free internet TV content varies by geography, some content might require additional fees (Windows 8.1 Pro Pack and Windows 8.1 Media Centre Pack only) To install a 64-bit OS on a 64-bit PC, your processor needs to support CMPXCHG16b, Prefect, and LAHF/SAHF Instant Go works only with computers designed for Connected Standby 2.2 ARCHITECTURAL SUPPORT Operating system functionality fundamentally depends upon the architectural features of the computer.Windows supports uniform access to input devices that are based on the Human Interface Devices (sometimes called the Human Input Devices) or HID specification. Vendors can extend the functionality of devices by adding filter drivers to the Windows layered driver architecture. Vendor-written drivers for most devices can use UMDF. Mouse and keyboard filter drivers should use KMDF. While earlier versions of Windows supported USB as the primary HID transport; Microsoft provides native support for the following transports in Windows 8: USB Bluetooth Bluetooth LE Vendor specific transports are also allowed via 3rd party transport drivers. Keyboards with special buttons (to start a browser, to control volume, and so on) do not require special Process and Threads Implementation and Scheduling 8 drivers. In fact, custom drivers can lengthen boot time. We encourage vendors to implement HID-compatible scan codes, and use the built-in HID support in Windows. Windows 8.1 supports multi-process and also supports multi-core system. This will run in multiple cores with more gigahertz speed. 3. PROCESS SUPPORT A multiprocessing operating system is one through which one can run on computer systems that contain more than one processor. Windows 8 is a symmetric multiprocessing (SMP) system, meaning that it assumes that all of the processors are equal and that they all have access to the same physical memory. Therefore, Windows 8 can access any thread on any available processor regardless of what process, user or Executive, owns the thread. There are also asymmetric multiprocessing (ASMP) systems in which processors are different from each other--they may address different physical memory spaces, or they may have other differences. These operating systems only run certain processes on certain processors--for instance, the kernel might always execute on a particular processor. The design of Windows 8 supports processor affinity, whereby a process or thread can specify that it is to run on a particular set of processors, but this facility isn't supported in the first release. Windows 8 uses the same rules for scheduling on a multiprocessor system as it does on a single processor system, so at any given time the threads that are ready and have the highest priorities are actually running. 4. THREAD SUPPORT A thread is a flow of execution through the process code, with its own prog ram counter, system registers and stack. A thread is also called a light weight process. Threads provide a way to improve application performance through parallelism. Threads represent a software approach to improving performance of operating system by reducing the overhead thread is equivalent to a classical process. Threads are implemented in following two ways User Level Threads -- User managed threads Process and Threads Implementation and Scheduling 9 Kernel Level Threads -- Operating System managed threads acting on kernel, an operating system Core User Level Threads In this case, application manages thread management kernel is not aware of the existence of threads. The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread contexts. The application begins with a single thread and begins running in that thread. Kernel Level Threads In this case, thread manag ement done by the Kernel. There is no thread manag ement code in the application area. Kernel threads are supported directly by the operating system. Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process.
Windows 8 supports the multi-threading concept. And this can run & work items asynchronously using the Windows Runtime thread pool API. Windows 8 provide a combined user level thread and Kernel level thread facility. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models are three types Many to many relationship. Many to one relationship. One to one relationship. Many to Many Model Process and Threads Implementation and Scheduling 10 In this model, many user level threads multiplexes to the Kernel thread of smaller or equal numbers. The number of Kernel threads may be specific to either a particular application or a particular machine. In this model, developers can create as many user threads asnecessary and the corresponding Kernel threads can run in parallels on a multiprocessor. Many to One Model Many to one model maps many user level threads to one Kernel level thread. Thread manag ement is done in user space. When thread makes a blocking system call, the entire process will be blocks. Only one thread can access the Kernel at a time, so multiple threads are unable to run in parallel on multiprocessors. If the user level thread libraries are implemented in the operating system in such a way that system does not support them then Kernel threads use the many to one relationship modes. One to One Model There is one to one relationship of user level thread to the kernel level thread.This model provides more concurrency than the many to one model. It also another thread to run when a thread makes a blocking system call. It support multiple thread to execute in parallel on microprocessors. Disadvantag e of this model is that creating user thread requires the corresponding Kernel thread. OS/2,windows NT and windows 2000 use one to one relationship model. 5. PROCESS SCHEDULING Multiprogramming operating system allows more than one process to be loaded into the executable memory at a time and for the loaded process to share the CPU using time multiplexing. The scheduling mechanism is the part of the process manager that handles the removal of the running process from the CPU and the selection of another process on the basis of particular strategy.
Process and Threads Implementation and Scheduling 11 Consider a 2.4 GHz processor. It executes approximately 2,400 million instructions per second. It can run 24 billion instructions in the ten seconds it might take you to skim a web page before you click on a link or 1.2 billion instructions in the half second it might take you to hit the next key as youre typing. The big idea in increasing overall throughput was the realization that we could switch the processor to running another process when a process has to do I/O. This is multiprogramming. The next big idea was realizing that you could pre-empt a process and let another process run and do this quickly enough to give the illusion that many processes are running at the same time. This is multitasking. Schedulers Schedulers are special system softwares which handles process scheduling in various ways. Their main task is to select the jobs to be submitted into the system and to decide which process to run. Schedulers are of three types Long Term Scheduler Short Term Scheduler Medium Term Scheduler Long Term Scheduler It is also called job scheduler. Long term scheduler determines which programs are admitted to the system for processing. Job scheduler selects processes from the queue and loads them into memory for execution. Process loads into the memory for CPU scheduler. The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound and processor bound. It also controls the degree of multiprogramming. If the degree of multiprogramming is stable, then the average rate of process creation must be equal to the average departure rate of processes leaving the system. Short Term Scheduler It is also called CPU scheduler. Main objective is increasing system performance in accordance with the chosen set of criteria. It is the change of ready state to running state of the process. CPU scheduler selects process among the processes that are ready to execute and allocates CPU to one of them. Process and Threads Implementation and Scheduling 12 Short term scheduler also known as dispatcher, execute most frequently and makes the fine grained decision of which process to execute next. Short term scheduler is faster than long term scheduler.
Medium Term Scheduler Medium term scheduling is part of the swapping. It removes the processes from the memory. It reduces the degree of multiprogramming. The medium term scheduler is in-charge of handling the swapped out-processes. 6. THREAD SCHEDULING Thread is a basic unit of CPU utilization, consisting of a thread ID, a program counter and a stack. It shares with the other threads which belongs to the same process, data section and other operating system resources. Process having multiple threads of control it can perform more than one task at a time. When a thread is created, it inherits its priority from the thread that created it. In addition, by using the set priority method, you can modify a thread's priority at any time after its creation. Thread priorities are integers that range between MIN_PRIORITY and MAX_PRIORITY (constants defined in the Thread class). The higher the integer, the higher the priority. At any given time, when multiple threads are ready to be executed, the runtime system chooses the Runnable thread for execution that has the highest priority. Only when that thread stops, yields, or becomes Not Runnable will a lower-priority thread start executing. If two threads of the same priority are waiting for the CPU, the scheduler arbitrarily chooses one of them to run first. The chosen thread runs until one of the following conditions is true: Process and Threads Implementation and Scheduling 13 A higher-priority thread becomes runnable. The thread yields, or its run method exits.
On systems that support time-slicing, the thread's time allotment has expired. Then the second thread is allotted a chance to run, and so on, until the interpreter exits. Windows implements the Windows API, which is the primary API for the family of Microsoft operating systems. A Windows application runs as a separate process, and each process may contain one or more threads. Windows uses the one-to-one mapping, where each user-level thread maps to an associated kernel thread. The general components of a thread include: A thread ID uniquely identifying the thread A register set representing the status of the processor A user stack, employed when the thread is running in user mode, and a kernel stack, employed when the thread is running in kernel mode A private storage area used by various run-time libraries and dynamic link libraries (DLLs)
The threads are of two types user-level and kernel-level threads. To run on a CPU, user- level threads must be mapped to an associated kernel-level thread, although this mapping may be indirect and may use a lightweight process (LWP). On operating systems that support them, it is kernel-level threadsnot processesthat are being scheduled by the operating system. User- level threads are managed by a thread library, and the kernel is unaware of them. The Thread Scheduling has different states they are:- 1.) Ready 2.) Running 3.) Waiting 7 CONCLUSION Process and Threads Implementation and Scheduling 14 Windows 8.1 and Windows RT come at a time of great change in the industry and challenge for Microsoft. The growth of the IOS and Android OS user bases has created a shift, prompting Microsoft to respond with the radical UI changes in Windows 8.1 and Windows RT. While the changes to the UI may have been the right thing to do from a marketing point of view, it also introduced new risks, as people have to learn a new, right way to do things. Not all changes are bad. Things like the new picture password feature definitely represent a step forward. And Microsoft continues the solid, steady progress it is making with architectural improvements in features like ASLR for years now. Overall, Windows 8 and Windows RT definitely represent a mixed bag of good and bad. Intels release of a dual-core Atom processor provides similar battery life to that found in Microsofts RT Surface. Now, lower-priced systems with greater storage question the viability of Windows RT since it also lacks support for Active Directory and Cisco or Juniper VPN solutions. 8.REFERENCES
Process and Threads Implementation and Scheduling 15
Process and Threads Implementation and Scheduling 16