Pintos Hanyang University Embedded Software Systems Lab.
Contents 0. Introduction 1. Command Line Parsing 2. System Call 3. Hierarchical Process Structure 4. File Descriptor 5. Denying Write to Executable 6. Alarm System Call 7. Priority Scheduling 8. Priority Scheduling and Synchronization 9. Priority Inversion Problem 10. Multi-Level Feedback Queue Scheduler 11. Virtual Memory 12. Memory Mapped File 13. Swapping 14. Stack 15. Buffer Cache 16. Extensible File 17. Subdirectory 2
Project 상관관계 User Program Thread Virtual Memory Filesystem 1. Command Line Parsing 6. Alarm System Call 11. Virtual Memory 15. Buffer cache 2. System Call 7. Priority Scheduling 12. Memory Mapped File 16. Extensible File 3. Hierarchical Process Structure 8. Priority Scheduling and Synchronization 13. Swapping 17. Subdirectory 4. File Description 9. Priority Inversion Problem 14. Stack 5. Denying Write to Executable 10. Multi-Level Feedback Queue Scheduler 3
Introduction 4
PintOS 핀토스가뭐지? x86 아키텍처를위한교육용운영체제 2004년스탠포드대학에 Ben Pfaff에의해만들어짐 kernel threads, loading and running user programs, file system등을지원 Bochs나 QEMU등 x86 시뮬레이터를사용 왜핀토스를사용할까? 운영체제에서실제로각종개념 ( 쓰레드, 프로세스, 메모리관리, 파일시스템 ) 을구현해보는것이매우중요 리눅스와같은상용운영체제는매우큼 (100만라인). 80% 이상이다양한하드웨어지원을위한디바이스드라이버코드 리눅스컴파일 : 최소한한시간이상걸림. 간단하고, 이해하기쉽고, 컴파일도쉬운운영체제핀토스 (PintOS) 5
Pintos 실습서버접속방법 SSH 설치 ($ sudo apt-get install ssh) 서버접속 ($ ssh -p 8022 사용자계정 @csedev.hanyang.ac.kr) 6
Pintos 설치및환경설정 해당명령어를통해핀토스소스코드다운로드 $ wget http://dmclab.hanyang.ac.kr/wikidata/download/pintos.tar.gz 압축해제 $ tar xvf pintos.tar.gz pintos/src/threads 디렉토리로이동후 make 명령어입력 7
Pintos 설치확인 pintos/src/threads/ 디렉토리로이동 $ make $ cd build $ pintos -- run alarm-multiple 프로그램동작확인 8
핀토스의실행 PintOS 수정 x86 Bochs/QEMU 설치 Ubuntu virtualbox/xen/ VMWare Windows 노트북 x86 9
개인 PC 에서 Pintos 사용하기 1: Virtual Box 설치 http://www.virtualbox.org 에서 Virtual Box 다운로드후설치 여기서다운로드 10
개인 PC 에서 Pintos 사용하기 2.1: 우분투설치 VirtualBox 상에리눅스가상머신을생성한다. 리눅스설치 (Ubuntu 12.04 LTS) ubuntu-12.04-desktop-i386.iso 다운로드 : http://www.ubuntu.com/download/desktop 가상머신만들기 11
개인 PC 에서 Pintos 사용하기 2.2: 우분투설치 다운받은우분투이미지파일을마운트하고, 설치 or 12
개인 PC 에서 Pintos 사용하기 2.3: 우분투설치완료 Ubuntu 설치완료및부팅 13
개인 PC 에서 Pintos 사용하기 3: Bochs 설치 http://bochs.sourceforge.net 사이트에서 Bochs 다운로드 여기서다운로드 14
개인 PC 에서 Pintos 사용하기 3: Bochs 설치 파일압축해제 $ tar xvf bochs-2.6.2.tar.gz bochs 폴더로이동 $./configure --enable-gdb-stub --with-nogui $ make $ sudo make install 15
개인 PC 에서 Pintos 사용하기 3: Bochs 설치 오류 1: C compiler cannot create executables gcc, g++ 및라이브러리패키지설치 $ sudo apt-get install libc6-dev g++ gcc 오류 2: X windows libraries were not found X windows 라이브러리설치 $ sudo apt-get install xorg-dev 16
개인 PC 에서 Pintos 사용하기 3: QEMU 설치 $ sudo apt-get install qemu $ sudo ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu 17
개인 PC 에서 Pintos 사용하기 4: Pintos 설치및환경설정 해당명령어를통해핀토스소스코드다운로드 $ wget http://dmclab.hanyang.ac.kr/wikidata/download/pintos.tar.gz 압축해제 $ tar xvf pintos.tar.gz pintos/src/threads 디렉토리로이동후 make 명령어입력 18
개인 PC 에서 Pintos 사용하기 4: Pintos 설치및환경설정 ~/.bashrc 파일에환경변수설정 pintos 를설치한디렉토리경로를추가 export PATH="$PATH:/home/user/pintos/src/utils 추가 $source ~/.bashrc 수정사항적용 19
개인 PC 에서 Pintos 사용하기 5: GCC 다운그레이드 gcc 버전을 pintos 권장인 4.5 버전으로다운그레이드 $ sudo apt-get install gcc-4.5 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50 20
How User Program Work Pintos Simulated File system disk Hardware Emulator (bochs or QEMU) Host OS (linux, ) Hardware (ex. cspro) PUT File System (Disk) Regular ELF executable 21
Pintos File System 사용방법 Pintos 에서 User program 실행하기 $ cd ~/pintos/src/userprog/ $ make $ cd bulid 1. 파일시스템디스크를생성 $pintos-mkdisk filesys.dsk --filesys-size=2 pintos-mkdisk : pintos에서제공하는가상디스크생성도구. 파일시스템디스크의이름은무조건 filesys.dsk로해야한다. --filesys-size 옵션 : 가상디스크의용량을지정하기위한옵션. 2. 파일시스템디스크초기화 $pintos f -q -f 옵션 : filesys.dsk 를포맷. pintos 의자체파일시스템구조사용. -q 옵션 : 모든작업이끝나면 pintos 를종료하게하는옵션. 22
Pintos File System 사용방법 (Cont.) Pintos 에서 User program 실행하기 (cont.) $ cd ~/pintos/src/examples/ $ make $ cd../userprog/bulid 3. 파일시스템디스크에실행할응용프로그램복사 (ex: echo 프로그램 ) $pintos p../../examples/echo a echo -- -q -p 옵션 : 시스템디스크로복사, -a 옵션 : 프로그램이름설정 -- : Pintos 프로그램에전달할인자와 Pintos 에서동작하는가상 OS 에전달할인자를구분하기위해사용 실행프로그램은 Regular ELF executable 파일형식으로만들어져야함 4. 프로그램실행 (ex: echo 프로그램을 x 라는인자를넣어서실행 ) $pintos q run echo x run 옵션 : 응용프로그램을실행 pintos 의현재상태로는응용프로그램이실행되지않음 23
Pintos File System 사용방법 (Cont.) Pintos 에서 User program 실행하기 (cont.) 결합된명령어 $pintos --filesys-size=2 p../../examples/echo a echo -- -f q run echo x 앞의모든옵션을한번에넣어서프로그램을실행할수있음. 옵션은반드시 -p, -a, --, -f, -q, -run 순서로실행되어야함. 24
Patch 파일만들기 Patch 파일생성은 'diff' 명령을사용 $ diff [ 옵션 ] [ 원본파일 ] [ 수정된파일 ] > 출력파일.patch $ diff [ 옵션 ] [ 원본디렉토리 ] [ 수정된디렉토리 ] > 출력파일.patch 주요옵션 ( urn ) -u : 수정된부분의앞뒤동일한내용을 3 줄만표시 --unified=2 을사용하면동일한라인을 2 줄만표시 -r : recursive. 재귀적검색, 하위디렉토리를모두검색하여비교 -N : new file. 두디렉토리중어느한디렉토리에만파일이있는경우, 두디렉토리모두에같은파일이존재한다고가정하고비교를진행 자세한옵션은 $ diff --help' 로확인 25
Patch 파일만들기 예제 파일 vs 파일비교하여 patch 파일생성예시 $ diff -u process.c process_new.c > process.c.patch 디렉토리 vs 디렉토리비교하여 patch 파일생성예시 ( -r 옵션사용 ) $ diff -urn pintos/ pintos_new/ > pintos.patch 26
Patch 파일적용하기 Patch 파일적용은 'patch' 명령을사용 $ patch [ 옵션 ] < 결과파일.patch 주요옵션 -p : -pnum 형식으로사용 (NUM= 숫자 ) NUM은 patch에명시된파일경로에서 NUM 만큼하위디렉터리로이동하여 patch 를적용하라는의미 Ex) patch 파일안에 '--- driver/src/display.c' 라는경로가있는경우, -p1 을사용하면 'src/display.c' 경로에위치한파일에해당 patch를적용 패치파일적용예시 $ patch -p0 < pintos.patch 27