Ch6. Flow of Time Ch7. Getting Hold of Memory 2003. 1. 24 홍원의.

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

Real-Time Library: RTX
The Linux Kernel: Memory Management
Allocating Memory Ted Baker  Andy Wang CIS 4930 / COP 5641.
Memory management.
CS 6560 Operating System Design Lecture 7: Kernel Synchronization Kernel Time Management.
The Process Control Block From: A Process Control Block (PCB, also called Task Control Block or Task Struct) is.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Multiprocessing Memory Management
CS 104 Introduction to Computer Science and Graphics Problems
COMS W6998 Spring 2010 Erich Nahum
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Chapter 13 Embedded Systems
Chapter 11 Operating Systems
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Computer Organization and Architecture
Process Description and Control A process is sometimes called a task, it is a program in execution.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Computer Organization and Architecture Operating System Support Chapter 8.
Chapter 3 Operating Systems Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Real-Time Concepts for Embedded Systems
Data Types in the Kernel Ted Baker  Andy Wang CIS 4930 / COP 5641.
CS591 (Spring 2001) The Linux Kernel: Debugging. CS591 (Spring 2001) Accessing the “Black Box” n Kernel code: n Not always executed in context of a process.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Time, Delays, and Deferred Work
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Computers Operating System Essentials. Operating Systems PROGRAM HARDWARE OPERATING SYSTEM.
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 Chapter 4 Processes R. C. Chang. 2 Linux Processes n Each process is represented by a task_struct data structure (task and process are terms that Linux.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Chapter 12. Memory Management. Overview Memory allocation inside the kernel is not as easy as memory allocation outside the kernel  The kernel simply.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Lecture 12 Page 1 CS 111 Online Using Devices and Their Drivers Practical use issues Achieving good performance in driver use.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
Time Sources and Timing David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
UDI Technology Benefits Slide 1 Uniform Driver Interface UDI Technology Benefits.
Linux Kernel Development Memory Management Pavel Sorokin Gyeongsang National University
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Where Testing Fails …. Problem Areas Stack Overflow Race Conditions Deadlock Timing Reentrancy.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Timers and Time Management Ok-Kyun Ha
REAL-TIME OPERATING SYSTEMS
Linux Kernel Development - Robert Love
CS501 Advanced Computer Architecture
Process Management Process Concept Why only the global variables?
Time Sources and Timing
William Stallings Computer Organization and Architecture
Time Sources and Timing
Real-time Software Design
Applied Operating System Concepts
Intro. To Operating Systems
Process Description and Control
Process Description and Control
Time Sources and Timing
Processes David Ferry CSCI 3500 – Operating Systems
CSE 451 Autumn 2003 November 13 Section.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
Presentation transcript:

Ch6. Flow of Time Ch7. Getting Hold of Memory 홍원의

Contents Flow of Time Time Intervals in the Kernel Knowing the Current Time Delaying Execution Task Queue Kernel Timers Getting Hold of Memory The Real Story of kmalloc get_free_page and Friends vmalloc and Friends Boot-Time Allocation

Time Intervals in the Kernel timer interrupt the kernel uses to keep track of time intervals HZ : an architecture-dependent value jiffies initialized to 0 when the system boots timer interrupt  jiffies increase change the HZ value  different clock interupt frequency to use Linux for hard real-time tasks : known to raise the value of HZ to get better response times

Knowing the Current Time measure time interval : looking at the jiffies measure short time lapse sharply : processor-specific register wall-clock time void do_gettimeofday(struct timeval *tv) : near ㎲ resolution for many architecture xtime value : can not automatically access both fields void get_fast_time(struct timeval *tv) : quick but less precise

Delaying Execution to allow the hardware to accomplish some task Long Delays (longer than on clock tick) : use the system clock Short Delays : implemented with software loops

Delaying Execution Long Delays busy waiting unsigned long j = jiffies + jit_delay * HZ; while (jiffies < j) / * nothing */; locks the processor If interrupts is disabled,jiffies won’t be updated should be avoided

Delaying Execution a better solution while (jiffies < j) schedule(); allows other processes to run If it is the only process, idle task will never run If system is very busy, could ends up waiting rather longer

Delaying Execution asking the kernel to do waiting for some events within a certain period of time (bounded sleep) sleep_on_timeout (wait_queue_head_t *q, unsigned long timeout); interruptible_sleep_on_timeout (wait_queue_head_t *q, unsigned long timeout); no other events expected schedule_timeout (unsigned long timeout);

Delaying Execution Short Delays often used to synchronize with h/w kernel function: void udelay (unsigned long usec); void mdelay (unsigned long msec); udelay is based on the value loops_per_second, which is the result of BogoMips at boot-time software loop, busy waiting

Task Queue provides a flexible utility for scheduling execution at a “later” time examples to manage hardware that cannot generate interrupts but still allows block read (periodically waking a process requires two context switching each time) giving timely input to a simple hardware device (example: stepper motor)

Task Queue a list of tasks, each task being represented by a function pointer and an argument struct tq_struct { struct tq_struct *next; /* linked list of active bh’s */ int sync; /* must be initialized to zero */ void (*routine)(void *); /* function to call */ void *data; /* argument to function */ } task_queue : pointer to struct tq_struct operations DECLARE_TASK_QUEUE(name); int queue_task(struct tq_struct *task, task_queue *list); void run_task_queue(task_queue *list);

Task Queue How it works Each of queued tasks do its task independently They are always run when the kernel has no other pressing work to do Different queues are run at different times They are not run when the process that queued the task is executing

Task Queue predefined queue the scheduler queue the timer queue the immediate queue custom queue use DECLARE_TASK_QUEUE(), queue_task(), run_task_queue(); Tasklet may be run in parallel with other tasklets on SMP systems

Kernel Timer can specify “when” in the future your function will be called register a function once, and the kernel calls it one when the timer expires struct timer_list { struct timer_list *next; struct timer_list *prev; unsigned long expires; unsigned long data; void (*function)(unsigned long); volatile int running; }

Kernel Timer functions void init_timer(struct timer_list *timer); void add_timer(struct timer_list *timer); int mod_timer(struct timer_list *timer, unsigned long expires); int del_timer(struct timer_list *timer);

The Real Story of kmalloc powerful and easily learned prototype void *kmalloc(size_t size, int flags); void kfree(void *obj); most-used flags GFP_KERNEL, GFP_ATOMIC additional flags GFP_BUFFER, GFP_USER, GFP_HIGHUSER, __GFP_DMA, __GFP_HIGHMEM

The Real Story of kmalloc the size argument kernel allocate only certain predefined fixed-size of byte array minimum size depends on the page size of the architecture data size : power of 2 asking 2000 bytes  allocate 2048 bytes 2048 bytes  allocate 4096 bytes (due to the control flags; worst possible case)

get_free_page and Friends allocate big chunks of memory unsigned long get_zeroed_page (int flags); unsigned long __get_free_page (int flags); unsigned long __get_free_pages (int flags, unsigned long order); unsigned long __get_dma_pages (int flag, unsigned long order); void free_page (unsigned long addr); void free_pages (unsigned long addr, unsigned long order); arguments flags : same in kmalloc() order : page size of log 2 N better memory usage, speed

vmalloc and Friends allocate a contiguous memory region in the virtual address space void vmalloc (unsigned long size); void vfree (void *addr); void * ioremap (unsigned long offset, unsigned long size); void iounmap (void *addr); vmalloc must both retreive the memory and build the page table  has more overhead than __get_free_pages ioremap does not actually allocate any memory

Boot-Time Allocation allocate a huge buffer of physically contiguous memory at boot time bypassing the limit of get_free_pages void *alloc_bootmem (unsigned long size); void *alloc_bootmem_low (unsigned long size); void *alloc_bootmem_pages (unsigned long size); void *alloc_bootmem_low_page (unsigned long size); a device driver can only be installed or replaced by “rebuilding the kernel and rebooting the computer”