1 Chapter 1 Introduction to System Programming September

1 Chapter 1. Introduction to System Programming September, 2015 Seungjae Baek Dept. of software Dankook University http: //embedded. dankook. ac. kr/~baeksj Seungjae Baek

강의 목표 2 Understand the definition of system program Describe the types of system program ü ü Compilation system Operating system Runtime system Hardware consideration Realize the concept of abstraction Seungjae Baek

Definition of System Program (1/6) 3 컴퓨터 구성 Computer CPU H/W S/W I/O Device System software Memory Application software Seungjae Baek

Definition of System Program (2/6) 4 Hardware components: PC Input device Main memory Output Device Secondary storage CPU Communication device Seungjae Baek

Definition of System Program (3/6) 5 Hardware components: Smart Phone ü ü ü CPU : Coretex-A 15, A 7, A 9… Storage : NAND flash memory Communication Devices § GSM, HSDPA, LTE, Bluetooth, . . ü Peripherals § Accelerometer, gyro, compass, GPS, . . source : http: //mobilemonitorsoftware. wordpress. com/2013/ 07/25/smartphones-spy/ Seungjae Baek


Definition of System Program (5/6) 7 Software component: System program ü 이 프로그램이 CPU에서 어떻게 수행되는가? § compiler, assembler, loader, . . . ü printf()란 무엇인가? § library, linker, . . . ü 문자열이 어떻게 터미널에 출력되는가? § driver, file system, . . . ü 이 프로그램이 다른 프로그램과 어떻게 동시에 수행되는가? § scheduler, context switch, IPC (Inter process communication), . . . ü 지역 변수와 전역 변수는 메모리에서 어떻게 관리되는가? § virtual memory, buddy system, stack, heap, . . . ü 프로그램의 성능을 향상시키는 방법은? § compiler optimization (loop unrolling, reordering), CPU optimization (pipeline, superscalar, out-of-order execution), … Seungjae Baek

Definition of System Program (6/6) 8 Software component: System program ü Hardware와 긴밀하게 연관 (Hardware 관리) 응용이 쉽게 수행될 수 있는 환경 제공 (Interface 제공) ü 시스템 추상화 (abstraction) ü § § § § Machine level language and High level language CPU and Multitasking Physical and Virtual memory Disk and File Device and Driver Untrusted and Trusted Domain. . . Seungjae Baek

시스템 프로그램 종류 (1/19) 9 분류 Compilation system Runtime system compiler linker debugger editor assembler library command shell utility loader file system window system scheduler IPC Operating system driver CPU buddy system Memory protocol stack Devices Hardware Consideration Seungjae Baek

시스템 프로그램 종류 (2/19) 10 Compilation system: Concept C Language - High Level Language Assembly Language Binary Code - Machine Level Language Seungjae Baek

시스템 프로그램 종류 (3/19) 11 Compilation system: Overall Editor Other Object & Library C file ASM file Compiler Error Msg Linker Assembler Input Data Object file Executable File Loader Results Debugger Seungjae Baek

시스템 프로그램 종류 (4/19) 12 Compilation system: in Linux Seungjae Baek

GCC compiler? GCC source file. c file cpp 0 Preprocessor . i file cc 1 compiler . s file executable file ld or collect 2 linker . o file as compiler Seungjae Baek

시스템 프로그램 종류 (5/19) 14 Compilation system: details hello. c와 hello. s의 차이는? hello. o와 a. out의 차이는? Seungjae Baek

시스템 프로그램 종류 (6/19) 15 Operating system: structure process 1 process 2 process 3 process n User Space System Call Interface Filesystem Manager Ext 2 fs proc xiafs minix nfs msdos Process Manager Memory Management Task Management Scheduler Signaling Kernel Space Buffer Cache Device Manager block Network Manager character socket Ir. DA Console KBD SCSI CD-ROM PCI ethernet Ipv 6 Hardware Interface dev 1 dev 2 dev 3 dev 4 devn (Source: Linux Kernel Internals) Seungjae Baek

시스템 프로그램 종류 (7/19) 16 Operating system: resource manager OS Disk CPU Memory Seungjae Baek

시스템 프로그램 종류 (8/19) 17 Operating system: file creation (file system) vi test. c int sum = 0; int main() { int i; for (i=0; i<10; i++) sum += i; printf(“%d”, sum); } OS inode Disk CPU Memory 69 6 e 74 20. . . Seungjae Baek

시스템 프로그램 종류 (9/19) 18 Operating system: compile vi test. c a. out int sum = 0; int main() { int i; for (i=0; i<10; i++) sum += i; 컴파일 printf(“%d”, sum); } . data. align 4. type sum, @object. size sum, 4. text. global main. type main, @func main: pushl %ebp … movl -4(%ebp), %eax addl %eax, sum … OS inode Disk CPU Memory 69 6 e 74 20. . . Seungjae Baek

시스템 프로그램 종류 (10/19) 19 Operating system: running (scheduler) vi test. c a. out int sum = 0; int main() { int i; for (i=0; i<10; i++) sum += i; 컴파일 printf(“%d”, sum); } . data. align 4. type sum, @object. size sum, 4. text. global main. type main, @func main: pushl %ebp … movl -4(%ebp), %eax addl %eax, sum … 수행 OS inode Disk CPU a. out이 더 이상 passive가 아닌 active한 객체로 변화 prev task CPU new task CPU Memory 69 6 e 74 20. . . Seungjae Baek

시스템 프로그램 종류 (11/19) 20 Operating system: loading (virtual memory) vi test. c a. out int sum = 0; int main() { int i; for (i=0; i<10; i++) sum += i; 컴파일 printf(“%d”, sum); } . data. align 4. type sum, @object. size sum, 4. text. global main. type main, @func main: pushl %ebp … movl -4(%ebp), %eax addl %eax, sum … 수행 a. out이 더 이상 passive가 아닌 active한 객체로 변화 prev task OS new task inode Disk 69 6 e 74 20. . . CPU Memory segment/page table a. out이 수행 되려면 디스크에서 메모리로 이동되어야 함 메모리 관리 필요 (언제, 어디에 올릴 것인가? ) Seungjae Baek

시스템 프로그램 종류 (12/19) 21 Operating system: summary ü Task manager § CPU: task manipulation, schedule, IPC, signal, context switch § fork, exec, wait, getpid, (pthread_create) , … ü Virtual Memory § Main memory: page, segment, address translation, buddy, LRU § brk, (malloc, free), … ü File system § Storage: file, directory, disk scheduling, FAT § open, read, write, mknod, pipe, (fopen, fwrite, printf), … ü Device driver § Device: interrupt, DMA, IO port management § open, read, write, ioctl, module, … ü Network protocol § Network: socket, fragmentation, routing § socket, bind, listen, send, receive, … Seungjae Baek

시스템 프로그램 종류 (13/19) 22 Runtime system ü command § § § ü file related: ls, more, cp, mkdir, cd, … task related: ps, kill, jobs, … utility: make, tar, patch, ddd, . . management: adduser, passwd, ifconfig, mount, fsck, shutdown, . . others: man, file, readelf, grep, wc, … command interpreter: shell § pipe, redirection, background processing, . . § shell script programming command user shell command processing Seungjae Baek

시스템 프로그램 종류 (14/19) 23 Runtime system ü library § A collection of functions, invoked frequently by a lot of users § Most languages have a standard library (also programmers can make their own custom libraries using ar, ranlib and libtool. ) § Relocatable objects Seungjae Baek

시스템 프로그램 종류 (15/19) 24 Runtime system ü ü Windows system, Database, RPC, Middleware, Framework, . . . ukernel (RTOS) and Servers Seungjae Baek

시스템 프로그램 종류 (16/19) 25 Hardware consideration: organization (Source: computer systems: a programmer perspective) hello program 수행 printf()수행 Seungjae Baek
![시스템 프로그램 종류 (17/19) 26 Hardware consideration: Memory ü array programming example int a[1000]; 시스템 프로그램 종류 (17/19) 26 Hardware consideration: Memory ü array programming example int a[1000];](http://slidetodoc.com/presentation_image/fc5b0a6e428a6acc6817abd88b05f98f/image-26.jpg)
시스템 프로그램 종류 (17/19) 26 Hardware consideration: Memory ü array programming example int a[1000]; int i, j; . . for (i=0; i<1000; i++) for (j=0; j<1000; j++) a[i][j] ++; VS int a[1000]; int i, j; . . for (i=0; i<1000; i++) for (j=0; j<1000; j++) a[j][i] ++; Seungjae Baek

시스템 프로그램 종류 (18/19) 27 Hardware consideration: CPU ü Loop unrolling example void combine 4(vec_ptr v, data_t *dest) { int i; int length = vec_length(v); data_t *data = get_vec_start(v); data_t x = IDENT; } VS void combine 5(vec_ptr v, data_t *dest) { int i; int length = vec_length(v); data_t *data = get_vec_start(v); data_t x = IDENT; int limit = length – 2; for (i = 0; i < length; i++) { x = x OPER data[i]; } *dest = x; for (i = 0; i < limit; i += 3) { x = x OPER data[i] OPER data[i+1] OPER data[i+2]; } } for ( ; i < length; i++) { x = x OPER data[i]; } *dest = x; (Source: computer systems: a programmer perspective) Seungjae Baek

시스템 프로그램 종류 (19/19) 28 Hardware consideration: CPU ü assembly language example § a = b + c; load add store b, eax c, eax, a VS add b, c, a Seungjae Baek

추상화 (1/7) 29 시스템 프로그램의 핵심: 추상화 ü ü Abstraction is the process of generalization by reducing the information content of a concept or an observable phenomenon, typically in order to retain only information which is relevant for a particular purpose. In computer science, abstraction tries to reduce and factor out details so that the programmer can focus on a few concepts at a time. A system can have several abstraction layers whereby different meanings and amounts of detail are exposed to the (Source: en. wikipedia. org/wiki/Abstraction) programmer. Seungjae Baek

추상화 (2/7) 30 CPU Human-Friendly High Level Language (ISA: Instruction Set Architecture) Compilation system Seungjae Baek

추상화 (3/7) 31 Multitasking task (logical CPU) . . . Scheduler Physical CPUs (1, 2, 4, 8 MPs) Seungjae Baek

추상화 (4/7) 32 Memory management Relocatable Unlimited Memory Space virtual memory Fixed Limited Memory Space Seungjae Baek

추상화 (5/7) 33 File system file system Seungjae Baek

추상화 (6/7) 34 Device driver Handle and I/O STREAM device driver Seungjae Baek

추상화 (7/7) 35 Software layers application program library system call file system device driver device itself Seungjae Baek


시스템 소프트웨어 중요성 (2/3) 37 새로운 H/W 등장 ü New HCI, Wearable computer, LBS 새로운 S/W 등장 ü Augmented reality, TUI Seungjae Baek

시스템 소프트웨어 중요성 (3/3) 38 Compact Flash Storage Card Internals HOST PCMCIA-ATA Interface ARM SRAM NOR core 16 KB 48 KB DMA 0/1 Flash Controller Data IN/OUT Control NAND Flash Memory (32 Mb-256 Mb) 새로운 컴퓨팅 환경에서는 하드웨어와 소프트웨어의 통합 개발이 중요해 짐. 응용 프로그램 개발자들에게도 시스템에 대한 이해가 요구됨. Seungjae Baek

Summary 39 Definition of System Program ü ü Managing hardware directly Supporting computing environments 3 Types of System Program ü ü Compilation system, operating system, runtime system Hardware consideration Concept of Abstraction ü ü Information hiding Layered architecture Homework 1: Read the chapter 1, “A Tour of Computer Systems”, from the beginning to 1. 4 and 1. 7 ü Requirement : Summary (2 page), What is the purpose of studying System Programming? (1 page) ü Deadline: The same day in the next week. Seungjae Baek
- Slides: 39