Kernel Programming Task Management 2005. 5. 30( 월 ) 이 병 희

Slides:



Advertisements
Similar presentations
Chapter 3 Process Description and Control
Advertisements

CS591 (Spring 2001) The Linux Kernel: Process Management.
Context Switch Animation Another one by Anastasia.
Project 2 Roadmap. Background – Context Switching One processor and multiple threads running concurrently – How?!! Give each thread a small time quantum.
Context switch in Linux
Operating Systems Processes (Ch 4.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
Operating Systems Processes (Ch 3.1). Processes “A program in execution” Modern computers allow several at once –“pseudoparallelism” A B C Program Counter.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Linux Operating System
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Chapter 3 Process Description and Control
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
Linux Kernel introduction COSC 513 Xiaoping Yang.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
Linux Processes. Process Descriptor Process – dynamic, program in motion –Kernel data structures to maintain "state" –Descriptor, PCB (control block),
Linux Disk Structure Disk Structure Disk Scheduling Disk Scheduling Disk Management Disk Management Swap-Space Management Swap-Space Management RAID Structure.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
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.
3. System Mechanisms ■ Trap Dispatching - Trap : A Processor`s mechanism for capturing an executing thread an exception or an interrupt occurs and transferring.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Processes.
LINUX System : Lecture 7 Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Chapter 4 Process Abstraction Chien-Chung Shen CIS, UD
Processes and Process Control Anand Sivasubramaniam Dept. of Computer Science & Eng. Pennsylvania State University.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
MP2: RATE-MONOTONIC CPU SCHEDULING Based on slides by Gourav Khaneja, Raoul Rivas and Keun Yim University of Illinois at Urbana-Champaign Department of.
CSC 660: Advanced Operating Systems
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
2 장 프로세스 제 03 강 : 프로세스. Multi-user System OS boot 탐색기 hwp OS kernel a.out game.
What is a Process ? A program in execution.
Virtualizing the CPU: Processes 1. How to provide the illusion of many CPUs? CPU virtualizing – The OS can promote the illusion that many virtual CPUs.
Operating Systems Engineering
CS 6560: Operating Systems Design
Processes.
Linux Process (Task) Structure and Scheduling Overview
Structure of Processes
Processes in Unix, Linux, and Windows
CS 143A Quiz 1 Solution.
Processes in Unix, Linux, and Windows
Operating Systems Processes (Ch 4.1).
Tutorial No. 11 Module 10.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Low-Level Thread Dispatching on the x86
Linux Process State Scheduling information Identifiers
Process Description and Control in Unix
Process Description and Control in Unix
Implementing Processes, Threads, and Resources
Operating Systems Processes (Ch 2.1).
Presentation transcript:

Kernel Programming Task Management ( 월 ) 이 병 희

Contents  Introduction  Task state transition  Task structure  Scheduling

Introduction  What is the task ?  Running or runable program  Execution environment of a program  Scheduling entity  task management of kernel  task 의 생성 / 소멸 / 상태전이 / 문맥교환 등을 관리  task management 를 위해 task 가 사용하는 자원에 대한 정보 유지 (task_struct 사용 )  Creation of task  Use fork() function  fork : 자신의 프로세스와 똑같은 프로세스를 copy-on-write 형식으로 실행, 이때 생성된 프로세는 자신만의 PID 를 가짐  exec : 역시 fork 와 마찬가지로 새로운 프로세스를 생성, 하지만 fork 와 같이 copy-on-write 를 이용한 전혀 새로운 프로세스를 실행시키지 않고, 현재의 프로세스이미지를 새로운 프로세스 이미지가 덮어씀

Task state transition initial fork ready fork running dispatch timeout waiting zombie wakeup exit sleep wait ready state : 생성된 task 가 준비상태가 되어 ready_queue 에 연결됨 스케줄러는 자신의 스케줄링 정책에 따라 task 를 선택하여 running state 로 바꿈 zombie state : 자신의 모든 자원을 커널에 반납 task 의 exit status 상태와 PID 는 여전히 남아서 task_struct 에 유지 waiting state : sleep system call 이 불리거나 lock 이 걸려있는 자원을 기다릴 경우 waiting 상태로 전이. waiting state 로 전이되는 경우 sleep_queue 에 연결

Task state transition user program execution user level running return from system call Interrupt routine system call Interrupt Scheduler readywaiting Kernel level running kernel level running 상태로의 전이 : system call 과 interrupt running state

Task structure  Task 가 생성된 후 kernel 은 task 의 정보관리를 위해 여러 자료구조들 (context) 을 할당  Context 는 3 부분으로 구분가능  system context  memory context  hardware context sp eip … eflags file structure inode fd task_structsegment table page table thread structure (TSS) swap or a.out disk system context hardware context memory context

Task structure  task_struct  Include/linux/sched.h 에 정의  각 task 마다 하나씩 존재  task identification  state  task relationship  scheduling information  signal information  memory information  file information  thread structure  time information  resource limits  miscellaneous

Task structure  state

Task structure  task relationship  new processes are copied from previous process  task structure keeps pointers to its parent process and it siblings  all processes in the system are held in a doubly linked list prev_task init_task prev_task next_task prev_task next_task task next_task.... prev_task next_task task prev_run next_run run_queue prev_run next_run youngest child parent childoldest child task_struct p_ctpr p_pptr p_ysptr p_osptr p_ysptr [ Task family relationship]

Task structure  task relationship

Task structure  signal information  task 에게 비동기적인 사건의 발생을 알리는 매커니즘  signal 처리를 위한 3 가지 기능  다른 task 에게 signal 을 보낼 수 있어야 함 (sys_kill() system call)  signal 을 수신할 수 있어야 함 (sigpending, signal, blocked)  signal 이 오면 이를 처리할 수 있는 함수를 호출 (sys_signal(), sig)

Task structure count action[_NSIG] siglock sa_handler sa_flags sa_restorer sa_mask sys_signal(sig, handler) /* kernel/signal.c */ do_sigaction(sig, new_sa, old_sa) …. sig signal,blocked sigpending …. task_struct …. signal_struct sigaction sigset_t 63 0 …. sigset_t 63 0 sys_kill(pid,sig) /* kernel/signal.c */ kill_proc_info(sig, info, pid) send_sig_info(sig, info, *t) sigaddset(t->signal, sig); t->sigpending = 1;

Task structure  thread information  task 가 실행되다 중지할 때 현재 어디까지 실행하였는지 저장  처리기의 레지스터들의 내용을 저장 include/asm-i386/processor.h unsigned long esp0; unsigned short ss0; unsigned long esp1; unsigned short ss1; unsigned long esp2; unsigned short ss2; unsigned long cr3; unsigned long eip, eflags; unsigned long eax, ecx, edx, ebx; unsigned long esp; unsigned long ebp, esi, edi; unsigned short es, cs, ss, ds, fs, gs; unsigned short ldt; ……..... tss... task_struct

Task structure  time information  kernel keeps track of time information  start_time : task creation time  struct tms times : task start time at user and kernel level  resource limits  indicates limitation of resource task_struct … rlim[] … /*include/linux/resource.h */

Scheduling  Linux scheduling  clock interrupt 는 10msec 마다 발생  real-time task 지원  task_struct 스케줄링 관련 변수 (/*include/linux/sched.h */)  policy  태스크 유형 (task type)  SCHED_FIFO :real-time task, non-preemptive  SCHED_RR : real-time task, preemptive  SCHED_OTHER : normal task, preemptive  priority  태스크 우선순위  태스크가 생성될 때 기본 값인 20 (DEF_PRIORITY) 으로 설정  sys_nice() 나 sys_setpriority() 시스템 호출로 변경 가능

Scheduling  counter  태스크의 처리기 사용량  태스크가 생성될 때 priority 값으로 설정  태스크가 수행중일 때, clock interrupt 이 발생하면 1 씩 감소  모든 태스크의 counter 값이 0 이 되면, 모든 태스크의 counter 값을 priority 값으로 재 설정  normal task 의 경우, 스케줄러는 priority + counter 값이 가장 큰 태스크를 선택하여 수행  need_resched  스케줄링이 수행될 필요가 있으면 1 로 설정  커널 수준 실행 상태에서 사용자 수준 실행 상태로 전이될 때 ( 시스템 호출이나 인터럽트 처리를 마칠 때 ), 이 변수를 조사하여 1 이면 스케줄러 호출  rt_priority  실시간 태스크의 우선 순위, 보통 1000 이상  sched_setscheduler(pid, policy, sched_param) 시스템 호출로 설정  실시간 태스크의 경우, 스케줄러는 이 값이 가장 큰 태스크를 선택하여 수행

Scheduling  스케줄링 함수 : schedule() function /* kernel/sched.c */ schedule() need_resched sleep_on - schedule real time task first (rt_priority) - select a task which has highest values of counter + priority (using goodness function) give advantage to the task which run this_cpu give slight advantage to the task which has mm object - if (counter == 0) for all task counter = priority - context switch : switch_to (current, next) /* arch/i386/kernel/process.c */

Scheduling  Example of linux scheduling  3 normal tasks  단일 처리기 시스템  clock interrupt 는 10ms 마다 한 번씩 발생 T1 priority counter millisecond T2 priority counter T3 priority counter