2
|
1 title: Studying Operating System Using Docker Platform
|
0
|
2 author: Shivani Dubey
|
3
|
3 profile: Madan Mohan Malaviya University of Technology, Gorakhpur
|
2
|
4
|
3
|
5 ## Why do we study Operating System?
|
2
|
6
|
3
|
7 - Every computer system has an operating system, which manages the resources of the computer.
|
2
|
8
|
3
|
9 - IoT or IT Services can't work well without resource managements.
|
2
|
10
|
3
|
11 - To handle it, we have to understand the API of OS.
|
2
|
12
|
3
|
13 - To understand the API, it is better to see the implementations.
|
2
|
14
|
3
|
15 - For example, API for tuning priorities of the processes.
|
2
|
16
|
|
17 ## Xv6 Operating System as an educational tool
|
|
18
|
3
|
19 - A Unix-like operating system developed in MIT, based on V6 kernel
|
2
|
20
|
3
|
21 - xv6 is written in ANSI C ( not in C++ )
|
2
|
22
|
|
23 - xv6 is small and simple (9628 lines of codes)
|
|
24
|
3
|
25 - It can run on Raspberry Pi ( Small PC board )
|
2
|
26
|
|
27 - Or on ARM emulator such as QEMU
|
0
|
28
|
3
|
29 ## Xv6 development environment with QEMU
|
2
|
30
|
|
31 - QEMU emulates ARM CPU with virtual memory
|
|
32
|
|
33 - Xv6 operating sytem itself is running on QEMU
|
|
34
|
|
35 - gdb debugger can be attached to the emulated program (both in user space and system space)
|
|
36
|
3
|
37 - We can step and trace inside xv6 kernel
|
2
|
38
|
3
|
39 ... but it requires complex development environments setup
|
2
|
40 ... very time consuming
|
|
41
|
3
|
42 ## Our development environments
|
2
|
43
|
|
44
|
|
45 - homebrew (it simplifies installation of software in macOS)
|
|
46
|
|
47 - Mercurial repository of the lab where we saved everything using ssh
|
|
48
|
|
49 - Cross Compilers
|
|
50
|
|
51 - ARM libraries for C language
|
|
52
|
|
53 - QEMU (ARM Emulator)
|
0
|
54
|
2
|
55 ## Introducing Docker
|
0
|
56
|
2
|
57 - What is Docker? It is a container.
|
|
58
|
3
|
59 - What is Container? An isolated envirornment such as file system.
|
2
|
60
|
3
|
61 - It has DockerFile, which describes how to setup the envrionment in the container.
|
2
|
62
|
3
|
63 - Docker can run on any computer using an emulator such as QEMU.
|
2
|
64
|
3
|
65 - Complex development environment can be build using DockerFile and docker built command.
|
2
|
66
|
|
67 # The DockerFile
|
|
68
|
|
69 ```
|
|
70 FROM phitek/qemu-arm
|
|
71 RUN apt-get update -y
|
|
72 RUN apt-get remove gdb -y
|
|
73 RUN apt-get install gcc-arm-none-eabi gdb-arm-none-eabi qemu-system-arm -y
|
|
74 WORKDIR /code
|
|
75 COPY ["src", "."]
|
|
76 RUN make
|
|
77 CMD /bin/bash
|
|
78 ```
|
|
79
|
3
|
80 - FROM line specifies the shared image in Docker repository.
|
2
|
81
|
3
|
82 - apt-get installs Linux cross compiling tools.
|
0
|
83
|
3
|
84 - Then it creates working directory, copies our sources to it, and executes make.
|
2
|
85
|
3
|
86 ## Docker commands
|
2
|
87
|
3
|
88 - Create docker image and environment, and build xv6 kernel
|
2
|
89
|
3
|
90 docker build --tag xv6-docker
|
2
|
91
|
3
|
92 - Run xv6 kernel on QEMU in the container
|
2
|
93
|
|
94 docker run --rm --privileged -it xv6-docker ./run-debug.sh
|
|
95
|
3
|
96 - Run gdb to connect the xv6 kernel running in the QEMU
|
2
|
97
|
|
98 docker exec -it xv6-docker ./debug.sh
|
|
99
|
|
100
|
0
|
101
|
1
|
102
|
3
|
103
|
|
104 # Exercise : Adding priorities to the xv6 scheduler
|
1
|
105
|
2
|
106 - Added getpriority() and setpriority()
|
|
107
|
|
108 - get_highest_priority() functions in proc.c file of xv6
|
0
|
109
|
3
|
110 - Implemented it in schelduler()
|
0
|
111
|
2
|
112 - Added a test function testpriority() in usertests.c file of xv6 to implement our algorithm
|
0
|
113
|
3
|
114 ## Function used in our exercise to find highest priority process
|
1
|
115 ```c
|
|
116 int get_highest_priority_proc(void)
|
|
117 {
|
|
118 int highest_priority;
|
|
119 int pid = 0;
|
|
120 int hpid = -1;
|
|
121 int rpid = 0;
|
|
122 highest_priority=100;
|
3
|
123
|
|
124 struct proc *p;
|
1
|
125 for(p = ptable.proc; p < &ptable.proc[NPROC]; p++, pid++){
|
|
126 if(p->state != RUNNABLE) {
|
3
|
127 continue; }
|
1
|
128 rpid = pid;
|
|
129 if (highest_priority > p->priority) {
|
|
130 highest_priority=p->priority;
|
3
|
131 hpid = pid; } }
|
1
|
132 return hpid > 0?hpid:rpid;
|
|
133 }
|
|
134 ```
|
3
|
135 - It assumes at least one process to be RUNNABLE.
|
1
|
136
|
2
|
137 - It may allow no highest priority process.
|
|
138
|
|
139 - The correctness of the function is *important*.
|
|
140
|
|
141 ## Docker Limitation
|
|
142
|
|
143
|
3
|
144 - If repository breaks, Docker poses a problem (a cloud problem).
|
|
145
|
|
146 - Cloud may be used conveniently but we must not rely on it.
|
2
|
147
|
|
148 - We can use a direct environment without Docker, since we have a Linux server.
|
|
149
|
3
|
150 - Docker images can easily eat up our disk spaces.
|
1
|
151
|
2
|
152 in ~/.zsh_history
|
1
|
153
|
2
|
154 ```c
|
|
155 : 1561014922:0;docker system prune
|
|
156 : 1561014973:0;docker container prune
|
|
157 : 1561015350:0;docker image prune
|
|
158 : 1561015362:0;docker volume prune
|
|
159 ```
|
|
160 # Conclusion
|
|
161
|
3
|
162
|
|
163 - Docker environment poses some problems, some of which are difficult to comprehend.
|
2
|
164
|
3
|
165
|
2
|
166
|
3
|
167 - Yet, it gives a good insight of the underlying important concepts of operating system because it is well documented, fast and uses less resources.
|