System Programming Chapter 1 What is System Programming

  • Slides: 40
Download presentation
System Programming Chapter 1. What is System Programming September 1, 2015 Jongmoo Choi Dept.

System Programming Chapter 1. What is System Programming September 1, 2015 Jongmoo Choi Dept. of Software Dankook University choijm@dankook. ac. kr http: //embedded. dankook. ac. kr/~choijm

Chapter Objectives Understand the definition of system program Describe the types of system program

Chapter Objectives 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 2

Definition of System Program (1/6) Computer organization Computer Software Hardware I/O Devices CPU System

Definition of System Program (1/6) Computer organization Computer Software Hardware I/O Devices CPU System program Memory 3 Application program

Definition of System Program (2/6) Hardware components: PC Secondary storage Main memory Output device

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

Definition of System Program (3/6) Hardware components: Smart Phone ü ü ü CPU: Multicore

Definition of System Program (3/6) Hardware components: Smart Phone ü ü ü CPU: Multicore (ARM based), GPU, DSP, Accelerator, … Memory: NOR flash, SRAM, DRAM Storage: NAND flash Input: Key pad, Touch Screen, Sensors Output: LCD, LED, Sound, Buzzer Communication § § § WLAN LTE, CDMA, GSM Ir. DA, Bluetooth, NFC UART, USB … 5

Definition of System Program (4/6) Software components ü Application program vs. System program #include

Definition of System Program (4/6) Software components ü Application program vs. System program #include <stdio. h> int main() { printf(“hello, worldn”); } How to run this program on CPU? What is the role of printf()? How the string is displayed on Monitor? How this program can be executed with other programs concurrently? What are the differences between local and global variables? What kinds of techniques can be applied to enhance the performance of this program? 6

Definition of System Program (5/6) Software components: System program ü How to run a

Definition of System Program (5/6) Software components: System program ü How to run a program on CPU? § object, binary, compiler, assembler, loader, . . . ü What is the role of printf()? § library, linker, . . . ü How the string is displayed on Monitor? § device driver, file system, . . . ü How a program can be executed with other programs concurrently? § scheduler, context switch, IPC (Inter process communication), . . . ü What are the differences between local and global memory? § data, stack, heap, virtual memory, buddy system, . . . ü What kind of techniques can be applied to enhance the performance of a program? § compiler optimization (loop unrolling, reordering), CPU optimization (pipeline, superscalar, out-of-order execution), … 7

Definition of System Program (6/6) Software components: System program ü ü ü Strongly related

Definition of System Program (6/6) Software components: System program ü ü ü Strongly related to hardware (hardware management) Supporting computing environments for application programs (Support Interfaces such as commands, library functions and system calls) Abstraction (Supports conceptual objects) § CPU and Multitasking § Physical and Virtual memory § Disk and File § Device and Driver § Machine level language and High level language § Untrusted and Trusted Domain §. . . 8

Types of System Program (1/19) Classification Compilation system Runtime system compiler assembler linker library

Types of System Program (1/19) Classification Compilation system Runtime system compiler assembler linker library debugger editor command shell utility loader file system window system scheduler IPC Operating system driver CPU buddy system Memory protocol stack Devices Hardware Consideration 9

Types of System Program (2/19) Compilation system: Concept C = A + B; High

Types of System Program (2/19) Compilation system: Concept C = A + B; High level Language movl 0 x 8049388, %eax addl 0 x 8049384, %eax movl %eax, 0 x 804946 c Assembly Language … 00 a 1 8893 0408 0305 8493 0408 00 a 3 6 c 94 0408 … Machine Language (Binary code) 10

Types of System Program (3/19) Compilation system: Overall Editor Other Object File & library

Types of System Program (3/19) Compilation system: Overall Editor Other Object File & library C File Compiler ASM File Linker Error Msg Assembler Object File Input Data Debugger 11 Executable File (binary) Loader Results

Types of System Program (4/19) Compilation system: in Linux 12

Types of System Program (4/19) Compilation system: in Linux 12

Types of System Program (5/19) Compilation system: details What are the differences btw hello.

Types of System Program (5/19) Compilation system: details What are the differences btw hello. c and hello. s? What are the differences btw hello. o and a. out?

Types of System Program (6/19) Operating system: structure process 1 process 2 process 3

Types of System Program (6/19) Operating system: structure process 1 process 2 process 3 process n User Space System Call Interface File system Process Manager Ext 4 proc v. FAT LFS NTFS nfs Memory 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) 14

Types of System Program (7/19) Operating system: resource manager OS CPU Disk 15 Memory

Types of System Program (7/19) Operating system: resource manager OS CPU Disk 15 Memory

Types of System Program (8/19) Operating system: file creation (file system) vi test. c

Types of System Program (8/19) 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 CPU Disk 69 6 e 74 20. . . 16 Memory

Types of System Program (9/19) Operating system: compile vi test. c a. out int

Types of System Program (9/19) Operating system: compile vi test. c a. out int sum = 0; int main() { int i; for (i=0; i<10; i++) sum += i; compile 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 CPU Disk 69 6 e 74 20. . . 17 Memory

Types of System Program (10/19) Operating system: running (scheduler) vi test. c a. out

Types of System Program (10/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; compile 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 … execute OS inode CPU Disk 69 6 e 74 20. . . 18 Memory a. out converts from passive object to active object prev task CPU new task CPU

Types of System Program (11/19) Operating system: loading (virtual memory) vi test. c a.

Types of System Program (11/19) 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; compile 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 … execute a. out converts from passive object to active object prev task OS new task inode Disk 69 6 e 74 20. . . CPU Memory segment/page table To execute a. out, it needs to move from disk to memory Require memory management (When and where to load? ) 19

Types of System Program (12/19) Operating system: summary ü Task manager: CPU § task

Types of System Program (12/19) 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 § IO port management, interrupt, DMA § open, read, write, ioctl, module, … ü Network protocol: Network § connection, routing, fragmentation § socket, bind, listen, send, receive, … 20

Types of System Program (13/19) Runtime system ü command § § § ü file

Types of System Program (13/19) Runtime system ü command § § § ü file related: ls, more, cp, mkdir, cd, … task related: ps, kill, jobs, … utility: make, tar, patch, debugger, . . management: adduser, passwd, ifconfig, mount, fsck, shutdown, . . others: man, file, readelf, grep, wc, … shell § command interpreter § pipe, redirection, background processing, . . § shell script programming command user shell command processing 21

Types of System Program (14/19) Runtime system ü library § A collection of functions,

Types of System Program (14/19) 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 User program Library functions printf() write() agent write() system call 22 user space kernel space

Types of System Program (15/19) Runtime system ü ü Windows, Database, RPC, Graphics, Multimedia,

Types of System Program (15/19) Runtime system ü ü Windows, Database, RPC, Graphics, Multimedia, Framework, . . . Servers on u-kernel (RTOS) 23

Types of System Program (16/19) Hardware consideration: organization task (process) program (binary) (Source: computer

Types of System Program (16/19) Hardware consideration: organization task (process) program (binary) (Source: computer systems: a programmer perspective) execute hello program invoke printf() 24

Types of System Program (17/19) Hardware consideration: Memory ü array programming example int a[1000];

Types of System Program (17/19) 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] ++; 25

Types of System Program (18/19) Hardware consideration: CPU ü Loop unrolling example void combine

Types of System Program (18/19) 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) 26

Types of System Program (19/19) Hardware consideration: CPU ü assembly language example § a

Types of System Program (19/19) Hardware consideration: CPU ü assembly language example § a = b + c; load add store b, eax c, eax, a VS add b, c, a 27

Abstraction (1/9) Key of System Program: Abstraction ü ü Abstraction is the process of

Abstraction (1/9) Key of System Program: Abstraction ü ü 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 programmer. 28

Abstraction (2/9) CPU Human-Friendly High Level Language (ISA: Instruction Set Architecture) Compilation system 29

Abstraction (2/9) CPU Human-Friendly High Level Language (ISA: Instruction Set Architecture) Compilation system 29

Abstraction (3/9) Multitasking task (logical CPU) (logical CPU) Scheduler Physical CPUs (1, 2, 4,

Abstraction (3/9) Multitasking task (logical CPU) (logical CPU) Scheduler Physical CPUs (1, 2, 4, 8 MPs) 30 task . . .

Abstraction (4/9) Memory management Relocatable Unlimited Memory Space virtual memory Fixed Limited Memory Space

Abstraction (4/9) Memory management Relocatable Unlimited Memory Space virtual memory Fixed Limited Memory Space 31

Abstraction (5/9) File system file system 32

Abstraction (5/9) File system file system 32

Abstraction (6/9) Device driver Handle and I/O STREAM (open, read, write, close) device driver

Abstraction (6/9) Device driver Handle and I/O STREAM (open, read, write, close) device driver 33

Abstraction (7/9) Data representation char float integer pointer data manipulation bits 34 . .

Abstraction (7/9) Data representation char float integer pointer data manipulation bits 34 . . .

Abstraction (8/9) Security and reliability Secure and Trusted World security and fault-tolerant system Real

Abstraction (8/9) Security and reliability Secure and Trusted World security and fault-tolerant system Real World 35

Abstraction (9/9) Software layers (Layered architecture) application program library system call file system device

Abstraction (9/9) Software layers (Layered architecture) application program library system call file system device driver device itself 36

Importance of System Program (1/3) Extending the usage of computing (Ubiquitous computing, BYOD, …)

Importance of System Program (1/3) Extending the usage of computing (Ubiquitous computing, BYOD, …) 37

Importance of System Program (2/3) New Emerging H/W ü New HCI, Wearable computer, LBS

Importance of System Program (2/3) New Emerging H/W ü New HCI, Wearable computer, LBS New Emerging S/W ü Augmented reality, TUI 38

Importance of System Program (3/3) Compact Flash Storage Card Internals HOST PCMCIA-ATA Interface ARM

Importance of System Program (3/3) 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) Knowledge about how HW and SW are cooperated becomes indispensable in recent computing industry (HW/SW Co-design) 39

Summary Definition of System Program ü ü Managing hardware directly Supporting computing environments 3

Summary 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. ü Caution: Do not copy!! 40