In
order to ensure the proper execution of the operating system, we must be able
to distinguish between the execution of operating-system code and user defined code. The approach
taken by most computer systems is to provide hardware support that allows us to
differentiate among various modes of execution.
1. Dual mode
and multi mode operations:
We
need two separate modes of operation: user mode and kernel mode (also called
supervisor mode, system mode, or privileged mode). A bit, called the mode bit,
is added to the hardware of the computer to indicate the current mode: kernel
(0) or user (1). With the mode bit, we can distinguish between a task that is
executed on behalf of the operating system and one that is executed on behalf
of the user. When the computer system is executing on behalf of a user
application, the system is in user mode. However, when a user application
requests a service from the operating system (via a system call), the system
must transition from user to kernel mode to fulfill the request.
The
dual mode of operation provides with the means for protecting the operating system
from errant users—and errant users from one another. We accomplish this
protection by designating some of the machine instructions that may cause harm
as privileged instructions.
The
concept of modes can be extended beyond two modes(in which case the CPU uses
more than one bit to set and test the mode). CPUs that support virtualization
frequently have as separate mode to indicate when the virtual machine manager
(VMM)—and the virtualization management software—is in control of the system.
In this mode, the VMM has more privileges than user processes but fewer than
the kernel. It needs that level of privilege so it can create and manage
virtual machines, changing the CPU state to do so.
2.
Timer:
The
operating system maintains control over the CPU. We cannot allow a user program
to get stuck in an infinite loop or to fail to call system services
and never return control to the operating system. To accomplish this goal, we
can use a timer. A timer can be set to interrupt the computer after a specified period. The period may
be fixed
(for example, 1/ 60 second) or variable (for example, from 1 millisecond to 1
second). A variable timer is generally implemented by a fixed-rate clock and a
counter. The operating system sets the counter. Every time the clock ticks, the
counter is decremented. When the counter reaches 0,an interrupt occurs.
We
can use the timer to prevent a user program from running too long. A simple
technique is to initialize a counter with the amount of time that a program is
allowed to run. A program with a7-minutetimelimit, for example, would have its
counter initialized to 420. Every second, the timer interrupts, and the counter
is decremented by 1.Aslong as the counter is positive, control is returned to the user
program. When the counter becomes negative, the operating system terminates the
program for exceeding the assigned time limit.
No comments:
Post a Comment