Presentation is loading. Please wait.

Presentation is loading. Please wait.

Home: www.cse.dmu.ac.uk/~pkang Phones OFF Please Unix Kernel Parminder Singh Kang Home: www.cse.dmu.ac.uk/~pkang Email: pkang@dmu.ac.uk.

Similar presentations


Presentation on theme: "Home: www.cse.dmu.ac.uk/~pkang Phones OFF Please Unix Kernel Parminder Singh Kang Home: www.cse.dmu.ac.uk/~pkang Email: pkang@dmu.ac.uk."— Presentation transcript:

1 Home: www.cse.dmu.ac.uk/~pkang
Phones OFF Please Unix Kernel Parminder Singh Kang Home:

2 Kernel: kernel is the central component of operating system.
As a basic component of an operating system, kernel can provide the lowest-level abstraction layer for the resources. Applications and processes use these resources through IPC mechanisms and System calls. Kernel Shell Hardware; CPU, I/O, Memory and Storage Devices

3 2. Unix Kernel The Unix Kernel is monolithic in design.
When it was first written it was fairly small - about 16K bytes. It has grown in size as more and more functions have been added. Berkeley 4.2 was about one megabytes long. BSD 4.3 kernel was about lines of C and lines of assembler. The Kernel can be split into two sections :- machine dependent and machine independent

4 User Program Libraries trap User level Kernel level System call Interface File Subsystem Process Control subsystem IPC Scheduler Memory Management Buffer cache Character/block device drivers Hardware control Hardware level Hardware

5 Machine dependent part
main function is hardware control. incorporating low-level I/O, device drivers, interrupt handlers, context switching and some memory management. Machine Independent Part The machine independent is the rest. Processes communicate with the system via system calls; implemented with a trap or software interrupt instruction. Every process has a user part and a system part. The system part is activated when a system call is made. The Kernel has its own stack and registers. The user stack contains arguments, local variables etc - a fairly standard stack frame in fact.

6 Each process has unique process ID.
Processes are organised into process groups. A process inherits its group from its parent, although it can change its group. swapper process zero schedules transfers of processes between memory and backing store. init process 1 fires off login processes and shells for each terminal. page daemon process 2 deals with creating free pages in a virtual memory system.

7 3. Kernel Structure Key structure for the kernel is the process table; contains an entry for every process. It is of fixed size - an array (Most kernel structures were initially designed to be simple and are fixed size tables. To make it manageable it has pointers to other tables. The process table contains information which must be accessible to the kernel. The user area contains fields relating to the current process which can be swapped to disk.

8 user area | >| | | P1 | | | | | | | | | |--| | | | P2 | | | | | | | >| > | | | | | | | | | Pn | | | | | process table per process memory region table

9 Process table entries:-
Scheduling details process priority, amount of CPU time used, recently used, sleeping etc. Identifiers unique process id, parent's process id, user id. Memory usage how much space process is using and where it is - memory or disk. This will be pointers to processes page tables, size of process page tables, location of user area page tables etc. Signals signals sent to the process but not yet dealt with. Masks showing which signals are being caught, ignored etc. Sync event process is awaiting Resource accounting pointer to usage, pointer to disk usage. Timer management amount of real-time until timer expires.

10 The user area :- machine registers in user state;
system call state - parameters and results; file descriptor table - files process has open; i/o parameters - amount of data to transfer etc; current directory; permission modes for creating files; accounting information - user time, system time; kernel stack.

11 4. Variables Global variables - the process table, data buffers etc - hence are NOT re-entrant. I.e. process switches can only take place at certain points. Kernel itself is not preemptable. I.e. kernel processes run to completion, or until they block. For re-entrant it must not have any global variables. Local variables must be located on a stack frame local to that invocation of the procedure. User processes - pre-emptive scheduling. I.e. CPU can be forcibly taken away from process and new process set running. Runs on user stack in user space. Unprivileged. Kernel - hardware independent - runs until completed or blocked. Can block to wait for resources. Runs on kernel stack in kernel mode. Privileged. Kernel - hardware dependent - Never scheduled. Cannot block. Deals with interrupts. Runs on kernel stack, in kernel address space.

12 5. Interrupts: - High priority Machine errors Clock Disk Network
High priority Machine errors Clock Disk Network Terminals Low priority Software Interrupt Care has to be taken. If an interrupt occurs while top half of kernel running race conditions can arise. E.g. kernel accessing a buffer cache and interrupt occurs with i/o device. Device could modify cache. Some data structures are shared between top and bottom half of kernel. In this case the top half has to disable interrupts when it is running critical code.

13 6. Sleep And Wakeup When process is executing in the kernel it may need to wait for some event. To do this it executes the sleep routine. Process state changed to blocked and scheduler selects other process. When the event occurs the interrupt routine executes the wakeup routine. I.e. process state changed from blocked to runnable. Several processes may be waiting for the same event - all are made runnable. Interrupts are disabled while sleep and wakeup are executing. Kernel sets the priority of the sleeping process according to the reason for sleeping.

14 process A process B process C
| : : v : : buffer locked | : sleeps | : v : buffer locked | sleeps | v buffer locked, sleeps - buffer unlocked. A, B, C woken ready to run ready to run ready to run Runs - locks : buffer : : : : : sleeps for : : some reason : Runs - buffer : locked - sleeps Runs - buffer locked - sleeps

15 7. Context Switching Can be done :- when process puts itself to sleep.
when process exits. when it is about to return from a system call when interrupt occurs in user mode. Kernel makes sure the state of its data structures is consistent before doing switch.


Download ppt "Home: www.cse.dmu.ac.uk/~pkang Phones OFF Please Unix Kernel Parminder Singh Kang Home: www.cse.dmu.ac.uk/~pkang Email: pkang@dmu.ac.uk."

Similar presentations


Ads by Google