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.


updated indentation rules in the manual
[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
310 Curly-brackets are not optional, even for single line conditionals. 
311
312 Tabs should be 4 characters in width.
313
314 {\em Special:} If you are using XEmacs add the following to your \verb.init\.el. file:
315 \begin{verbatim}
316 (setq c-basic-offset 4)
317 (c-set-offset 'case-label 4)
318 \end{verbatim}
319
320 {\em Bad}
321 \begin{verbatim}
322 if(a&&b==5||c!=0) return;
323 \end{verbatim}
324
325
326 {\em Good}
327
328 \begin{verbatim}
329 if (((a) && (b == 5)) || 
330     (c != 0)) {
331         return;
332 }
333 \end{verbatim}
334
335
336
337 \paragraph*{Fail Stop}
338 Because booting a basic linux kernel results in over 1 million VM exits
339 catching silent errors is next to impossible. For this reason
340 ANY time your code has an error it should return -1, and expect the
341 execution to halt. 
342
343 This includes unimplemented features and unhandled cases. These cases
344 should ALWAYS return -1. 
345
346
347 \paragraph*{Function names}
348 Externally visible function names should be used rarely and have
349 unique names. Currently we have several techniques for achieving this:
350
351 \begin{enumerate}
352 \item \verb.#ifdefs. in the header file
353 \newline
354 When the V3 Hypervisor is compiled it defines the symbol
355 \verb.__V3VEE__. Any function that is not needed outside the Hypervisor
356 context should be inside an \verb.#ifdef __V3VEE__. block, this will make it
357 invisible to the host environment.
358
359 \item Static Functions
360 \newline
361 Any utility functions that are only needed in the .c file where they
362 are defined should be declared as static and not included in the
363 header file. You should make an effort to use static functions
364 whenever possible. 
365
366 \item \verb.v3_. prefix
367 \newline
368 Major interface functions should be named with the prefix \verb.v3_. This
369 xallows easy understanding of how to interact with the subsystems. And
370 in the case that they need to be externally visible to the host os,
371 make them unlikely to collide with other functions. 
372 \end{enumerate}
373
374 \paragraph*{Debugging Output}
375 Debugging output is sent through the host os via functions in the
376 \verb.os_hooks. structure. These functions have various wrappers of the form
377 \verb.Print*., with printf style semantics. 
378
379 Two functions of note are \verb.PrintDebug. and \verb.PrintError..
380
381 \begin{itemize}
382
383 \item PrintDebug:
384 \newline
385 Should be used for debugging output that will often be turned off
386 selectively by the VMM configuration.
387
388 \item PrintError
389 \newline
390 Should be used when an error occurs, this will never be optimized out
391 and will always print. 
392 \end{itemize}
393
394
395 \section{Code Submission}
396 \label{sec:submission}
397
398 To commit changes to the central repository they need to be exported
399 as a patch set that can be applied directly to a mainline. Both Git
400 and Mercurial contain functionality to allow developers to maintain
401 changes as a patch set. There are also a few options that make dealing
402 with patches easier.
403
404 \subsection{Palacios}
405
406 Git includes support for directly exporting local repository commits
407 as a patch set. The basic operation is for a developer to commit a
408 change to a local repository, and then export that change as a patch
409 that can be applied to another git repository. While this is
410 functionally possible, there are a number of issues. The main problem
411 is that it is difficult to fully encapsulate a new feature in a single
412 commit, and dealing with multiple patches that often overwrite each
413 other is not a viable option either. Furthermore, once a patch is
414 applied to the mainline, it will generate a conflicting commit that
415 will become present when the developer next pulls from the central
416 repository. This can result in both repositories getting out of
417 sync. It is possible to deal with this by manually rebasing the local
418 repository, but it is difficult and error-prone. 
419
420 This approach also does not map well when patches are being revised. A
421 normal patch will go through multiple revisions as it is reviewed and
422 modified by others. This often leads to synchronization issues as well
423 as errors with patch revisions. Ultimately it is the responsibility of
424 the developer to generate a patch that will apply cleanly to the
425 mainline.
426
427 For this reason most internal developers should seriously consider
428 {\em stacked git}. Stacked git is designed to make patch development
429 easier and less of a headache. The basic mode of operation is for a
430 developer to intialize a patch for a new feature and then continuously
431 apply changes to the patch. Stacked Git allows a developer to layer a
432 series of patches on top of a local git repository, without causing
433 the repository to unsync due to local commits. Basically, the
434 developer never commits changes to the repository itself but instead
435 commits the changes to a specific patch. The local patches are managed
436 using stack operations (push/pop) which allows a developer to apply
437 and unapply patches as needed. Stacked git also manages new changes to
438 the underlying git repository as a result of a pull operation and
439 prevents collisions as changes are propagated upstream. For instance
440 if you have a local patch that is applied to the mainline as a commit,
441 when the commit is pulled down the patch becomes empty because it is
442 effectively identical to the mainline. It also makes incorporating
443 external revisions to a patch easier. Stacked git is installed on {\em
444 newskysaw} in \verb./opt/vmm-tools/bin/. 
445
446 Brief command overview:
447 \begin{itemize}
448 \item \verb.stg init. -- Initialize stacked git in a given branch
449 \item \verb.stg new. -- create a new patch set, an editor will open
450 asking for a commit message that will be used when the patch is
451 ultimately committed.
452 \item \verb.stg pop. -- pops a patch off of the source tree.
453 \item \verb.stg push. -- pushes a patch back on to a source tree.
454 \item \verb.stg export. -- exports a patch to a directory as a file
455 that can then be emailed.
456 \item \verb.stg refresh. -- commits local changes to the patch set at
457 the top of the applied stack.
458 \item \verb.stg fold. -- Apply a patch file to the current
459 patch. (This is how you can manage revisions that are made by other developers).
460 \end{itemize}
461
462 You should definately look at the online documentation to better
463 understand how stacked git works. It is not required of course, but if
464 you want your changes to be applied its up to you to generate a patch
465 that is acceptable to a core developer. Ultimately using Stacked git
466 should be easier than going it alone.
467
468
469 All patches should be emailed to Jack for inclusion in the
470 mainline. An overview of the organization is given in
471 Figure~\ref{fig:process}. You should assume that the first revision of
472 a patch will not be accepted, and that you will have to make
473 changes. Furthermore, the final form of the patch most likely will not
474 be exactly what you submitted. 
475
476  
477 \begin{figure}[t]
478 \begin{center}
479 \includegraphics[height=3.5in]{dev_chart.pdf}
480 \end{center}
481 \caption{Development organization}
482 \label{fig:process}
483 \end{figure}
484
485
486 \subsection{Kitten}
487
488 Writing code for Kitten follows essentially the same process as
489 Palacios. The difference is that the patches need to be emailed to the
490 Kitten developers. To send in a patch, you can just email it to the
491 V3Vee development list.
492
493
494 Also, instead of Stacked git you should use Mercurial patch
495 queues. This feature is enabled in your .hgrc file.
496 \begin{verbatim}
497 [extensions]
498 hgext.mq=
499 \end{verbatim}
500
501 Mercurial queues use the same stack operations as stacked git, however
502 it does not automatically handle the synchronization with pull
503 operations. Before you update from the central version of Kitten you
504 need to pop all of the patches, and then push them once the update is
505 complete.
506
507 Basically:
508 \begin{verbatim}
509 hg qpop -a
510 hg pull
511 hg update
512 hg qpush -a
513 \end{verbatim}
514
515
516 %Also, remember that Kitten is not a Northwestern project and is being
517 %developed by professional developers at Sandia National Labs. So keep
518 %in mind that you are representing Northwestern and the rest of the
519 %Palacios development group. We are collaborating with them because
520 %Kitten and the resources they have are very important for our research
521 %efforts. They are collaborating with us because they believe that
522 %Palacios might be able to help them. Therefore it is important that we
523 %continue to ensure that they see value in our collaboration. In plain
524 %terms, we need to make sure they think we're smart and know what we're
525 %doing. So please keep that in mind when dealing with the Kitten group.
526
527
528 \section{Networking}
529
530 \section{Configuring the development host's Qemu network}
531 Set up Tap interfaces:
532
533 /root/util/tap\_create tapX
534
535 Bridging tapX with eth1 will only work (work = send packet and also
536 make packet visible on localhost) if the IP address is set correctly
537 (correctly = match network it is connected to e.g., network of eth1)
538 so bring up the network inside of the VM / QEMU as 10-net, and it
539 should route through the eth1 rule and be visible both on the host and
540 in the physical network
541
542
543 \subsection{Configuring Kitten}
544
545 To enable networking in Qemu, networking needs to be enabled in the configuration.
546
547 Make sure turn on the network device driver, networking, and input
548 kernel command 'console=serial net=rtl8139'
549
550 How to set ip address in kitten:
551
552 Kitten ip address setting is in file drivers/net/ne2k/rtl8139.c, in the code below which is located in function rtl8139\_init.
553
554   struct ip\_addr ipaddr = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 16 << 0) }; 
555   struct ip\_addr netmask = { htonl(0xffffff00) }; 
556   struct ip\_addr gw = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 2 << 0) };
557
558 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.
559
560
561
562 \subsection{Running with networking}
563
564 \paragraph*{Tap Interface}
565 In which, the command line: 
566
567 -net tap, ifname=tap2
568
569 specifies Qemu to use the host's tap0 as its network interface, then Qemu can access the host's physical network.
570
571 \paragraph*{Redirection}
572
573 Also you can use the following command instead to redirect host's 9555 port to Qemu's 80 port.
574
575 -net user -net nic,model=rtl8139  -redir tcp:9555::80
576
577 In this case, you can access Qemu's 80 port in the host like:
578
579 telnet localhost 9555
580
581 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.
582
583
584
585
586
587
588 For more questions, talk to Jack or Lei.
589
590 \end{document}