Kernel Services CIS 657

Similar documents
Kernel Services. System Processes in Traditional Unix. Kernel Processes in FreeBSD 5.x CIS 657. swapper. Three processes created at startup time init

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CPS221 Lecture: Operating System Protection

CS 104 Computer Organization and Design

CS 111. Operating Systems Peter Reiher

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Process Scheduling Queues

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Chapter 9: Virtual Memory

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

The Kernel Abstraction. Chapter 2 OSPP Part I

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

What is an Operating System? A Whirlwind Tour of Operating Systems. How did OS evolve? How did OS evolve?

Midterm Exam CPS 210: Operating Systems Spring 2013

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

IT 540 Operating Systems ECE519 Advanced Operating Systems

PROCESS STATES AND TRANSITIONS:

Process Description and Control. Chapter 3

Linux System Administration

Design Overview of the FreeBSD Kernel CIS 657

Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

CS 111. Operating Systems Peter Reiher

ELEC 377 Operating Systems. Week 12 Class 2

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

Chapter 9: Virtual-Memory

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Processes. Dr. Yingwu Zhu

Hardware OS & OS- Application interface

Computer Systems II. First Two Major Computer System Evolution Steps

Reserves time on a paper sign-up sheet. Programmer runs his own program. Relays or vacuum tube hardware. Plug board or punch card input.

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

UNIX Memory Management Interview Questions and Answers

Operating System Review

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Announcement. Exercise #2 will be out today. Due date is next Monday

Chapter 8: Virtual Memory. Operating System Concepts

Computer System Overview. Chapter 1

19: I/O Devices: Clocks, Power Management

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

OPERATING SYSTEM. Chapter 9: Virtual Memory

Common Computer-System and OS Structures

CSCE Introduction to Computer Systems Spring 2019

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Sistemi in Tempo Reale

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

The different Unix contexts

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

CS 537 Lecture 2 - Processes

Instruction Cycle. Computer-System Architecture. Computer-System Operation. Common Functions of Interrupts. Chapter 2: Computer-System Structures

fork, exec and the shell (1) Classic Processes (CSE 422S) waitpid fork, exec and the shell (2) Ken Wong Washington University

Requirements, Partitioning, paging, and segmentation

Introduction Programmer Interface User Interface Process Management Memory Management File System I/O System Interprocess Communication

OPERATING SYSTEM OVERVIEW

CSE 153 Design of Operating Systems

Computer System Architecture. CMPT 300 Operating Systems I. Summer Segment 3: Computer System Architecture. Melissa O Neill

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Definition: An operating system is the software that manages resources

Process Description and Control. Chapter 3

Computer System Overview

Operating System Control Structures

Lecture 4: Process Management

Review: Hardware user/kernel boundary

Chapter 10: Case Studies. So what happens in a real operating system?

Chap 4, 5: Process. Dongkun Shin, SKKU

Most of the work is done in the context of the process rather than handled separately by the kernel

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

Virtual Memory COMPSCI 386

CS307: Operating Systems

Each terminal window has a process group associated with it this defines the current foreground process group. Keyboard-generated signals are sent to

Process Time. Steven M. Bellovin January 25,

Computer System Overview

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Computer-System Architecture

Computer-System Architecture. Common Functions of Interrupts. Computer-System Operation. Interrupt Handling. Chapter 2: Computer-System Structures

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

TCSS 422: OPERATING SYSTEMS

Virtual Memory Outline

Requirements, Partitioning, paging, and segmentation

-Device. -Physical or virtual thing that does something -Software + hardware to operate a device (Controller runs port, Bus, device)

Computer architecture. A simplified model

UNIX rewritten using C (Dennis Ritchie) UNIX (v7) released (ancestor of most UNIXs).

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

The Kernel Abstraction

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

I/O Systems (3): Clocks and Timers. CSE 2431: Introduction to Operating Systems

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

5/8/2012. Controlling User Processes Chapter 10

Address spaces and memory management

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Background: Operating Systems

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

5 Lecture: Intro. to Concurrency

CS450/550 Operating Systems

Transcription:

Kernel Services CIS 657

System Processes in Traditional Unix Three processes created at startup time init process 1 user-mode administrative tasks (keeps getty running; shutdown) ancestor of all of your processes Still in FreeBSD swapper process 0 kernel process moves entire processes between main memory and secondary storage pagedaemon process 2 kernel process moves parts of processes in and out

Kernel Processes in FreeBSD 5.x idle Runs when there are no other ready procs swapper Moves processes from secondary storage -> main memory vmdaemon Moves processes from main memory -> secondary storage pagedaemon Writes portions of a process s s address space to storage pagezero Supplies zero-filled pages bufdaemon Supplies clean buffers (by writing out dirty buffers)

Kernel Processes in FreeBSD 5.x (II) syncer Ensures dirty file data written within 30 seconds ktrace Logs system call trace records to a log file vnlru Maintains supply of free vnodes (LRU) random Seeds kernel random numbers and /dev/random g_event Handles dynamic devices g_up Data from device drivers -> processes g_down Data from processes -> device drivers

Note on Init and Logging In init keeps a getty process running on each terminal port (tty( tty) getty initializes the port and waits for a login name (the login: login: prompt) getty reads a string and execs login login prompts for the password, performs one- way encryption, and compares values if successful, login sets the user id and execs a shell

Run-Time Organization Top Half per-process stack library of shared code maintains process structure (always resident) maintains user structure (can be swapped out) division between process/user dependent on memory never preempted for another process (but can yield the processor) can block interrupts by setting processor priority level (see discussion on bottom half)

Run-Time Organization II Bottom Half handles hardware interrupts asynchronous activities (wrt( Top Half) special kernel stack (might not be a process running) Top and bottom half coordinate around work queues using mutexes top half starts I/O requests, waits for bottom half to finish

Entry Into the Kernel Hardware interrupt I/O device (disks, network cards, etc.) clock (used for scheduling, time of day) Hardware trap divide by 0, illegal memory reference Software-initiated trap system call

Entry Into the Kernel II First, kernel must save machine state Why? Example sequence hardware switches to kernel mode hardware pushes onto per-process kernel stack the PC, PSW, trap info additional asm routine saves all other state that the hardware doesn t kernel calls a C routine--the handler.

Entry Into the Kernel III Handlers for each kind of entry: syscall() for a system call trap() for hardware traps interrupt handlers for devices Each kind of handler takes specific parameters (e.g., syscall number, exception frame; or the unit number for an interrupt).

Return From Kernel asm routine restores registers and user stack pointer (it undoes what the companion asm routine did) hardware restores the stored PC, PSW, etc. (undoes what it did on the way in) execution returns at the next instruction in the user process

Software Interrupts Used as low-priority processing mechanism in the kernel Hardware interrupts have high priority Can put work in work queues (cf. network) When high-priority work is done, low-priority software interrupt does the rest might be real interrupt, might be flag checked in kernel (architecture-dependent) can be preempted by another hardware interrupt

Priority Levels in FreeBSD 5.2 High-priority hardware interrupt creates work for lower-priority software interrupt Work queues Software interrupt routines lower priority than device drivers; higher than user processes Hardware interrupt > software interrupt > user

Example: Network Packets Device driver (hardware interrupt) takes packets from network, puts them in a work queue; controller re-enabled Software interrupt handler moves packets from work queues to destination processes Thus, delivery to processes doesn t block packets coming in from the network

What FreeBSD 4.4 Did for x86 The cpl variable holds the current priority level Various macros are defined to set the cpl to a new level (e.g. spl0(), splx(), spltty()) Interrupts at lower levels are masked (but not really--a pending bit is set and the majority of the work handling the interrupt is deferred) See /usr/src/sys/i386/isa/ipl_funcs.c Homework: find out (and submit) what FreeBSD 5.2.1 does (you may work with your lab partner).

Clock Interrupts The system clock interrupts, or ticks, at regular intervals (usually 100 Hz). Interrupt handler calls the hardclock() routine, which must run quickly running for more than one tick will miss the next interrupt, causing the time-of-day clock to skew lower-priority devices (network devices, disk controllers) cannot be serviced while hardclock() is running. Non-critical clock functions handled by softclock()

The Four Clocks Hardclock: hardware timer, 100 Hz. Softclock: : handles non-critical timing work Profclock: profiling clock (collect process performance information), 1024 Hz. Statclock: collects system statistics, 128 Hz.

Clock Interrupts: What hardclock() does check for an interval timer on the currently running process increment the time of day do the job of profclock() if there is no spparate profiling clock do the job of statclock() if there is no separate clock for statistics gathering call softclock() directly if the cpl is low (saves overhead of a software interrupt that would just do that when hardclock() returns)

Statistics Historically, hardclock() collected resource utilization statistics, and forced context switches Problems (see McCanne & Torek) potential for inaccurate measurement of CPU utilization inaccurate profiling Use semi-randomized sampling with a second clock (the stat clock, see statclock()) charge the current process with a tick; if it has four, recalculate priority record what the system was doing at time of tick

Softclock() Handles events in the callout queue, such as: timeouts (real-time timer) retransmits dropped network packets monitors some peripherals that require polling process scheduling Scheduler would/should be called every second in a perfect world; uses interval timer to run 1 second after it last finished Discussion: why not do scheduling in hardclock()?

Callout Queue A circular list of n queues; sorted by time of event (in ticks) Each queue sorted in time order (soonest first) Pointer to current queue (now( now) ) moves around circular list hardclock() advances pointer, and softclock runs when the lead item in the new queue has time 0.

Example Callout Queue (200 queues in example) now +199 now now + 1 now now+200 now f(x) g(y) f(z) now + 2 now + 3. now + 2 h(x) Question: does f(z) happen this cycle, or next?

Memory Management Two kinds of executable files in BSD Unix interpreted compiled (directly executed) First 16 bits in a file contain a magic number telling what kind of file it is. #! indicates an interpreted file; interpreter must be directly executable (#!/bin/sh is the most common) Other magic numbers indicate whether the file can be paged and whether the text is sharable.

FreeBSD Process Layout 0xfff00000 0x00000000 Special stuff... User stack shared libs heap bss initialized data text 0-filled bss,, stack most of process is demand paged into memory (Ch. 5) Symbol table Initialized data text elf header elf magic number

What Was That Special Stuff? Per-process kernel stack Red zone User area Ps_strings struct Signal code Env strings argv strings Env pointers argc argv pointers Argv, argc, envp contain arguments and environment signal code used by kernel to deliver signals ps_strings used by ps to located argv of process

Timing Services Real Time: gettimeofday() returns the time since 1 Jan 1970 in UTC (the Epoch) adjtime() allows one to tweak the clock keeps multiple machines close enough response to normal clock skew give a delta argument; speed up or slow down the counted microseconds per clock tick by 10% until delta is reached Time is reported in microseconds

Interval Timers Each process gets three interval timers real: decrements in real time; SIGALRM; run from timeout queue maintained by softclock() profiling: decrements only when process runs, but tracks both user and kernel-mode execution; SIGPROF; checked by profclock() process virtual: decrements only when the process is running; SIGVTALRM; checked by profclock()

User, Group, Other Identifiers User ID (uid( uid): 32-bit identifier for all processes of each user, set by administrator Group ID (gid( gid): 32-bit identifier. Many users in one group; many groups for each user Root: uid 0, gid 0. These bits are checked on file access

Permission Checks Checked in order If the UID F == UID P use owner permission bits If UID F!= UID P, but GID F GID P then use group permission bits If UID F!= UID P, and GID F GID P then use the other permission bits Recall discussion last time of how uid, gid set on login Can I own a file that I can t t read?

Rights Amplification Users may need temporary write access on files (e.g. passwd) setuid() does this changes effective user id real user id stays the same effective uid also saved seteuid() changes only the effective user id setgid() used to work like setuid() now just put effective gid into 0th element of array

Effects of Syscalls on UIDs Action Real Effective Saved Exec-normal R R R Exec-setuid R S S Seteuid(R) R R S Seteuid(S) R S S Seteuid(R) R R S Exec-normal R R R R = Real UID, S = Special-privilege UID