Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


manual update
[palacios.git] / manual / manual.tex
1
2 \documentclass[11pt]{article}
3
4 \usepackage{calc}
5 \usepackage{graphics}
6 %\usepackage{latex8}
7 \usepackage{times}
8 \usepackage{epsf}
9 \usepackage{epsfig}
10 \usepackage{graphicx}
11 \usepackage{changebar}
12 \usepackage{portland}
13 \usepackage{lscape}
14
15 \setlength{\textheight}{8.50in}
16 \setlength{\textwidth}{6.5in}
17 \setlength{\topmargin}{-0.3in}
18 %\setlength{\leftmargin}{2.9in}
19 %\setlength{\rightmargin}{-2.9in}
20 \setlength{\oddsidemargin}{0in}
21 \setlength{\parindent}{0.5in}
22 \setlength\parindent{0in}
23 \setlength\parskip{0.1in} 
24
25 \begin{document}
26
27 \title{
28 \includegraphics[height=1.5in]{v3vee.pdf}
29 \includegraphics[height=1.5in]{logo6.png} \\
30 \vspace{0.5in} 
31 Palacios Internal Developer Manual
32 }
33
34
35 \maketitle
36
37
38 This manual is written for Internal Palacios developers. It contains
39 information on how to obtain the palacios code base, how to go about
40 the development process, and how to commit those changes to the
41 mainline source tree.  This assumes that the reader has read {\em An
42 Introduction to the Palacios Virtual Machine Monitor -- Release 1.0}
43 and also has a slight working knowledge of {\em git}.
44
45
46 \section{Overview}
47
48
49 Both Palacios and Kitten follow a hybrid development process that
50 uses both the centralized repository and distributed development
51 models. A central repository exists that holds the master version of
52 the code base. This central repository is cloned by multiple people
53 and in multiple places to support various development efforts. A
54 feature of git is that every developer actually has a fully copy of
55 the entire repository, and so can function independently until such
56 time as they need to resync with the master version. 
57
58 There are typically multiple levels of access to the central
59 repository, that are granted based on the type of developer being
60 granted access. The three basic developer types and their access
61 privileges are:
62
63 \begin{itemize}
64 \item Core Developers: These are the lead developers and are in
65 charge of managing the master repository. They have full read/write
66 access permissions to the central repository.
67
68 \item Internal Developers: Formal members of the development
69 team. These people are capable of pulling directly from the central
70 repository, but lack the ability to write directly to it. 
71
72 \item External Developers: People who are not actual members of the
73 development team. These people can only access the public repository
74 which is only updated to contain the release versions. 
75 \end{itemize}
76
77 Because internal and external developers cannot write directly to the
78 master repository, they need to first submit their changes to a core
79 developer before they can be added to the mainline. We will discuss
80 that process in Section~\ref{sec:submission}.
81
82
83 \section{Checking out Palacios}
84 The central palacios repository is located on {\em
85 newskysaw.cs.northwestern.edu} in {\em /home/palacios/palacios}. All
86 internal developers have read access to the directory. Each developer
87 must create their own local version of the repository, this is done
88 with {\em git clone}.
89
90 \begin{verbatim}
91 git clone /home/palacios/palacios
92 \end{verbatim}
93
94 This creates a local copy of the repository at {\em ./palacios/}.
95
96
97 All development work is done in the {\em devel} branch of the
98 repository. The developer can access this branch via:
99
100 \begin{verbatim}
101 git checkout --track -b devel origin/devel
102 \end{verbatim}
103
104 or 
105
106 \begin{verbatim}
107 /opt/vmm-tools/bin/checkout_branch devel
108 \end{verbatim}
109
110 {\em Important:}
111 Note that palacios is very actively developed so the contents of the
112 {\em devel} branch are frequently changing. In order to keep up to
113 date with the latest version, it is necessary to periodically pull the
114 latest changes from the master repository by running \verb.git pull..
115
116
117
118 \section{Checking out Kitten}
119
120 Kitten is available from Sandia National Labs, and is the main host OS
121 we are targetting with Palacios. Loosely speaking core Palacios
122 developers are internal Kitten developers, and internal Palacios
123 developers are external Kitten developers. Because we have limited
124 access to the Kitten repository, we are maintaining a local mirror
125 copy in {\em /home/palacios/kitten}. 
126
127 Kitten uses Mercurial for their source management, so you will have to
128 make sure the local mercurial version is configured correctly.
129 Specifically you should add the following python path to your shell environment.
130
131 \begin{verbatim}
132 export PYTHONPATH=/usr/local/lib64/python2.4/site-packages/
133 \end{verbatim}
134
135 You can then clone Kitten from the local mirror:
136 \begin{verbatim}
137 hg clone /home/palacios/kitten
138 \end{verbatim}
139
140 Both the Kitten and Palacios clone commands should be run from the
141 same direcotyr. This means that both repositories should be located at
142 the same directory level. The Kitten build process depends on this.
143
144 {\em Important:} Like Palacios, Kitten is very actively developed so
145 source tree is frequently changing. In order to keep up to date with
146 the latest version, it is necessary to periodically pull the latest
147 changes from the mirror repository by running \verb.hg pull. followed
148 by \verb.hg update..
149
150 \section{Compiling Palacios}
151 Palacios is capable of targeting 32 and 64 bit operating systems, and
152 includes a build process that supports both these
153 architectures. Furthermore, Palacios has multiple build locations,
154 with multiple makefiles: a top level build directory and a Palacios
155 specific build directory. The Palacios build process first generates a
156 static library that includes the Palacios VMM. This static library is
157 then linked into a host operating system. Palacios internally supports
158 GeekOS and can generate a complete OS image via a unified build
159 process. To combine Palacios with Kitten, it is necessary to first
160 compile Palacios and then to compile Kitten externally link it with
161 Palacios. The output of the compilation process is a bit more complex
162 and generates multiple binaries, and the specifics can be found in the
163 Makefiles.
164
165 The top level build directory provides a number of high level make
166 targets, and is located in {\em palacios/build/}. It supports building
167 32 and 64 bit versions of the Palacios library independently as well
168 as building an integrated version of GeekOS.   The basic targets are:
169 \begin{itemize}
170 \item \verb.make palacios-full32. -- Generates a 32 bit version of the Palacios static library 
171 \item \verb.make palacios-full64. -- Generates a 64 bit version of the
172 Palacios static library
173 \item \verb.make geekos. -- Compiles the GeekOS kernel, and link it with the
174 Palacios static library 
175 \item \verb.make geekos-iso. -- Generate an ISO boot disk image from the
176 GeekOS kernel that has been compiled
177 \end{itemize}
178
179 The second build directory is located at {\em palacios/palacios/build}
180 and handles only the Palacios compilation process. It supports a
181 differnt set of targets and arguments:
182 \begin{itemize}
183 \item \verb.make ARCH=32. -- iteratively compiles a 32 bit version of Palacios
184 \item \verb.make ARCH=64. -- iteratively compiles a 64 bit version of
185 Palacios
186 \item \verb.make ARCH=32 world. -- fully recompiles a 32 bit version of
187 Palacios
188 \item \verb.make ARCH=64 world. -- fully recompiles a 64 bit version of
189 Palacios
190 \end{itemize}
191
192 Both build levels support compilation directives that control the
193 debugging messages that are generated by Palacios. These are specified
194 by appending a \verb.DEBUG_<COMPONENT>=1. to the end of the
195 \verb.make. command. The components that are currently supported are:
196 \begin{itemize}
197 \item \verb.DEBUG_ALL=1. -- enables debugging for all the VMM components
198 ({\em Warning:} this generates a {\em lot} of debug information.
199 \item \verb.DEBUG_SHADOW_PAGING=1.
200 \item \verb.DEBUG_CTRL_REGS=1.
201 \item \verb.DEBUG_INTERRUPTS=1.
202 \item \verb.DEBUG_IO=1.
203 \item \verb.DEBUG_KEYBOARD=1.
204 \item \verb.DEBUG_PIC=1.
205 \item \verb.DEBUG_PIT=1.
206 \item \verb.DEBUG_NVRAM=1.
207 \item \verb.DEBUG_GENERIC=1.
208 \item \verb.DEBUG_EMULATOR=1.
209 \item \verb.DEBUG_RAMDISK=1.
210 \item \verb.DEBUG_XED=1.
211 \item \verb.DEBUG_HALT=1.
212 \item \verb.DEBUG_DEV_MGR=1.
213 \item \verb.DEBUG_APIC=1.
214 \end{itemize}
215
216
217
218 \section{Compiling Kitten}
219 Kitten requires a 64 bit version of Palacios, so make sure that
220 Palacios has been correctly compiled before compiling Kitten.
221
222 \subsection{Configuration}
223 Kitten borrows a lot of concepts from Linux, including the Linux build
224 process. As such it must be configured before it is actually compiled.
225 The Kitten configuration process is the same as Linux, and can be
226 accessed via any of these make targets.
227 \begin{itemize}
228 \item \verb.make xconfig.
229 \item \verb.make config.
230 \item \verb.make menuconfig.
231 \end{itemize}
232
233 There are some specific configuration options that should be disabled
234 to work with Palacios. Because Palacios is configured by default to
235 provide a guest with direct access to the VGA console, the {\em VGA
236 console} device driver should be disbabled in the Kitten
237 configuration. Similarly the {\em VM console} driver should be
238 disabled as well.
239
240 Furthermore, because the VGA console is not being used the {\em Kernel
241 Command Line Arguments} must be modified to remove the {\em VGA}
242 device from the console list.
243
244 The guest OS that is booted as a VM is included as an ISO image in raw
245 binary format inside Kitten's {\em init\_task}. To change the guest
246 ISO, you must change the makefile for the init\_task. This is located
247 in {\em user/hello\_world/Makefile} and the syntax is well commented.
248 On {\em newskysaw} a collection of guest ISO images are located in
249 {\em /opt/vmm-tools/isos/}. 
250
251
252 \subsection{Compilation}
253 After Kitten has been configured the compilation can be done. The
254 general process is to compile a reference build of Kitten, followed by
255 compiling Palacios support as a kernel module, and then doing a new
256 full recompilation of Kitten.
257
258 The specific compilation steps are run from the top level Kitten directory:
259 \begin{verbatim}
260 make
261 cd palacios
262 make -C .. M=`pwd`
263 cp built-in.o ../modules/palacios-mod.o
264 cd ..
265 make
266 make isoimage
267 \end{verbatim}
268
269 This generates an ISO boot image containing Kitten, Palacios, and the
270 guest that will be run as a VM. The ISO image is located at {\em
271 ./arch/x86\_64/boot/image.iso}.
272
273
274 \section{Running Palacios/Kitten}
275 Kitten and Palacios are capable of running under Qemu, which makes
276 debugging much simpler.
277
278 The basic form of the command to start the Qemu emulator is:
279 \begin{verbatim}
280 /usr/local/qemu/bin/qemu-system-x86_64 -smp 1 -m 1024 \
281         -serial file:./serial.out \
282         -cdrom ./arch/x86_64/boot/image.iso  \
283         < /dev/null
284 \end{verbatim}
285
286 The command starts up a single processor emulated machine, with 1gig
287 of RAM and a cdrom drive loaded with the Kitten ISO image. Furthermore
288 all output to the serial port is written directly to a file called
289 {\em serial.out}. This command can be copied into a shell script for easy access.
290
291 \section{Development Guidelines}
292
293 There are standard requirements we have for code entering the mainline. 
294
295 First and foremost, Palacios is designed to be OS indenpendent and
296 support 32 and 64 bit architectures. This means that developers should
297 not include any external OS specific dependencies in any Palacios
298 component. Also all changes need to be tested on both 32 and 64 bit
299 architectures to make sure that they compile as well as run corrrectly.
300
301 \paragraph*{Coding Style}
302
303 "The use of equal negative space, as a balance to positive space, in a
304 composition is considered by many as good design. This basic and often
305 overlooked principle of design gives the eye a "place to rest,"
306 increasing the appeal of a composition through subtle means."
307 \newline\newline
308 Translation: Use the spacebar, newlines, and parentheses. 
309 \newline\newline
310 {\em Bad}
311 \begin{verbatim}
312 if(a&&b==5||c!=0){return;}
313 \end{verbatim}
314
315
316 {\em Good}
317
318 \begin{verbatim}
319 if (((a) && (b == 5)) || 
320     (c != 0)) {
321        return;
322 }
323 \end{verbatim}
324
325 \paragraph*{Fail Stop}
326 Because booting a basic linux kernel results in over 1 million VM exits
327 catching silent errors is next to impossible. For this reason
328 ANY time your code has an error it should return -1, and expect the
329 execution to halt. 
330
331 This includes unimplemented features and unhandled cases. These cases
332 should ALWAYS return -1. 
333
334
335 \paragraph*{Function names}
336 Externally visible function names should be used rarely and have
337 unique names. Currently we have several techniques for achieving this:
338
339 \begin{enumerate}
340 \item \verb.#ifdefs. in the header file
341 \newline
342 When the V3 Hypervisor is compiled it defines the symbol
343 \verb.__V3VEE__. Any function that is not needed outside the Hypervisor
344 context should be inside an \verb.#ifdef __V3VEE__. block, this will make it
345 invisible to the host environment.
346
347 \item Static Functions
348 \newline
349 Any utility functions that are only needed in the .c file where they
350 are defined should be declared as static and not included in the
351 header file. You should make an effort to use static functions
352 whenever possible. 
353
354 \item \verb.v3_. prefix
355 \newline
356 Major interface functions should be named with the prefix \verb.v3_. This
357 allows easy understanding of how to interact with the subsystems. And
358 in the case that they need to be externally visible to the host os,
359 make them unlikely to collide with other functions. 
360 \end{enumerate}
361
362 \paragraph*{Debugging Output}
363 Debugging output is sent through the host os via functions in the
364 \verb.os_hooks. structure. These functions have various wrappers of the form
365 \verb.Print*., with printf style semantics. 
366
367 Two functions of note are \verb.PrintDebug. and \verb.PrintError..
368
369 \begin{itemize}
370
371 \item PrintDebug:
372 \newline
373 Should be used for debugging output that will often be
374 turned off selectively by the VMM configuration. 
375
376 \item PrintError
377 \newline
378 Should be used when an error occurs, this will never be optimized out
379 and will always print. 
380 \end{itemize}
381
382
383 \section{Code Submission}
384 \label{sec:submission}
385
386 To commit changes to the central repository they need to be exported
387 as a patch set that can be applied directly to a mainline. Both Git
388 and Mercurial contain functionality to allow developers to maintain
389 changes as a patch set. There are also a few options that make dealing
390 with patches easier.
391
392 \subsection{Palacios}
393
394 Git includes support for directly exporting local repository commits
395 as a patch set. The basic operation is for a developer to commit a
396 change to a local repository, and then export that change as a patch
397 that can be applied to another git repository. While this is
398 functionally possible, there are a number of issues. The main problem
399 is that it is difficult to fully encapsulate a new feature in a single
400 commit, and dealing with multiple patches that often overwrite each
401 other is not a viable option either. Furthermore, once a patch is
402 applied to the mainline, it will generate a conflicting commit that
403 will become present when the developer next pulls from the central
404 repository. This can result in both repositories getting out of
405 sync. It is possible to deal with this by manually rebasing the local
406 repository, but it is difficult and error-prone. 
407
408 This approach also does not map well when patches are being revised. A
409 normal patch will go through multiple revisions as it is reviewed and
410 modified by others. This often leads to synchronization issues as well
411 as errors with patch revisions. Ultimately it is the responsibility of
412 the developer to generate a patch that will apply cleanly to the
413 mainline.
414
415 For this reason most internal developers should seriously consider
416 {\em stacked git}. Stacked git is designed to make patch development
417 easier and less of a headache. The basic mode of operation is for a
418 developer to intialize a patch for a new feature and then continuously
419 apply changes to the patch. Stacked Git allows a developer to layer a
420 series of patches on top of a local git repository, without causing
421 the repository to unsync due to local commits. Basically, the
422 developer never commits changes to the repository itself but instead
423 commits the changes to a specific patch. The local patches are managed
424 using stack operations (push/pop) which allows a developer to apply
425 and unapply patches as needed. Stacked git also manages new changes to
426 the underlying git repository as a result of a pull operation and
427 prevents collisions as changes are propagated upstream. For instance
428 if you have a local patch that is applied to the mainline as a commit,
429 when the commit is pulled down the patch becomes empty because it is
430 effectively identical to the mainline. It also makes incorporating
431 external revisions to a patch easier. Stacked git is installed on {\em
432 newskysaw} in \verb./opt/vmm-tools/bin/. 
433
434 Brief command overview:
435 \begin{itemize}
436 \item \verb.stg init. -- Initialize stacked git in a given branch
437 \item \verb.stg new. -- create a new patch set, an editor will open
438 asking for a commit message that will be used when the patch is
439 ultimately committed.
440 \item \verb.stg pop. -- pops a patch off of the source tree.
441 \item \verb.stg push. -- pushes a patch back on to a source tree.
442 \item \verb.stg export. -- exports a patch to a directory as a file
443 that can then be emailed.
444 \item \verb.stg refresh. -- commits local changes to the patch set at
445 the top of the applied stack.
446 \item \verb.stg fold. -- Apply a patch file to the current
447 patch. (This is how you can manage revisions that are made by other developers).
448 \end{itemize}
449
450 You should definately look at the online documentation to better
451 understand how stacked git works. It is not required of course, but if
452 you want your changes to be applied its up to you to generate a patch
453 that is acceptable to a core developer. Ultimately using Stacked git
454 should be easier than going it alone.
455
456
457 All patches should be emailed to Jack for inclusion in the
458 mainline. An overview of the organization is given in
459 Figure~\ref{fig:process}. You should assume that the first revision of
460 a patch will not be accepted, and that you will have to make
461 changes. Furthermore, the final form of the patch most likely will not
462 be exactly what you submitted. 
463
464  
465 \begin{figure}[t]
466 \begin{center}
467 \includegraphics[height=3.5in]{dev_chart.pdf}
468 \end{center}
469 \caption{Development organization}
470 \label{fig:process}
471 \end{figure}
472
473
474 \subsection{Kitten}
475
476 Writing code for Kitten follows essentially the same process as
477 Palacios. The difference is that the patches need to be emailed to the
478 Kitten developers. To send in a patch, you can just email it to the
479 V3Vee development list.
480
481
482 Also, instead of Stacked git you should use Mercurial patch
483 queues. This feature is enabled in your .hgrc file.
484 \begin{verbatim}
485 [extensions]
486 hgext.mq=
487 \end{verbatim}
488
489 Mercurial queues use the same stack operations as stacked git, however
490 does not automatically handle the synchronization with pull
491 operations. Before you update from the central version of Kitten you
492 need to pop all of the patches, and then push them once the update is
493 complete.
494
495 Basically:
496 \begin{verbatim}
497 hg qpop -a
498 hg pull
499 hg update
500 hg qupush -a
501 \end{verbatim}
502
503
504 %Also, remember that Kitten is not a Northwestern project and is being
505 %developed by professional developers at Sandia National Labs. So keep
506 %in mind that you are representing Northwestern and the rest of the
507 %Palacios development group. We are collaborating with them because
508 %Kitten and the resources they have are very important for our research
509 %efforts. They are collaborating with us because they believe that
510 %Palacios might be able to help them. Therefore it is important that we
511 %continue to ensure that they see value in our collaboration. In plain
512 %terms, we need to make sure they think we're smart and know what we're
513 %doing. So please keep that in mind when dealing with the Kitten group.
514
515
516 \section{Networking}
517
518 \section{Configuring the development host's Qemu network}
519 Set up Tap interfaces:
520
521 /root/util/tap\_create tapX
522
523 Bridging tapX with eth1 will only work (work = send packet and also
524 make packet visible on localhost) if the IP address is set correctly
525 (correctly = match network it is connected to e.g., network of eth1)
526 so bring up the network inside of the VM / QEMU as 10-net, and it
527 should route through the eth1 rule and be visible both on the host and
528 in the physical network
529
530
531 \subsection{Configuring Kitten}
532
533 To enable networking in Qemu, networking needs to be enabled in the configuration.
534
535 Make sure turn on the network device driver, networking, and input
536 kernel command 'console=serial net=rtl8139'
537
538 How to set ip address in kitten:
539
540 Kitten ip address setting is in file drivers/net/ne2k/rtl8139.c, in the code below which is located in function rtl8139\_init.
541
542   struct ip\_addr ipaddr = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 16 << 0) }; 
543   struct ip\_addr netmask = { htonl(0xffffff00) }; 
544   struct ip\_addr gw = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 2 << 0) };
545
546 This sets the ip address as 10.0.2.16, netmask 255.255.255.0 and gateway address 10.0.2.2, change it as you need.
547
548
549
550 \subsection{Running with networking}
551
552 \paragraph*{Tap Interface}
553 In which, the command line: 
554
555 -net tap, ifname=tap2
556
557 specifies Qemu to use the host's tap0 as its network interface, then Qemu can access the host's physical network.
558
559 \paragraph*{Redirection}
560
561 Also you can use the following command instead to redirect host's 9555 port to Qemu's 80 port.
562
563 -net user -net nic,model=rtl8139  -redir tcp:9555::80
564
565 In this case, you can access Qemu's 80 port in the host like:
566
567 telnet localhost 9555
568
569 Qemu has many options to build up a virtual or real networking. See http://www.h7.dion.ne.jp/~qemu-win/HowToNetwork-en.html for more information.
570
571
572
573
574
575
576 For more questions, talk to Jack or Lei.
577
578 \end{document}