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.


Clean up debugging output
[palacios.git] / v3_config.pl
1 #!/usr/bin/perl -w
2
3
4 print <<END
5
6 Welcome.  The purpose of this tool is to simplify configuration
7 of the V3VEE environment on a Linux system.   It assumes you
8 have already built Palacios, the Linux embedding, and the Linux
9 user-sapce tools.   If you haven't, hit CTRL-C now and do the
10 at least the following:
11
12   make menuconfig 
13      [choose your options]
14   make
15   cd linux_usr
16   make
17   cd ..
18   ./v3_config.pl
19
20
21 This tool will create (or overwrite) the following for you:
22
23   ./ENV       An environment file that you can source
24   ./v3_init   A script that will insert Palacios with
25               relevant options and with appropriate memory
26               allocations.
27   ./v3_deinit A script that will free memory and remove 
28               Palacios.
29
30 After these are created, you can insert Palacio in the following way:
31
32   source ./ENV
33   ./v3_init
34
35 Then create and run VMs:
36
37   v3_create image_file name
38   v3_launch /dev/v3-vmN
39   v3_stop /dev/v3-vmN
40   v3_free /dev/v3-vmN
41
42 And you can remove Palacios and free memory it is using.
43
44   ./v3_deinit
45
46
47 We begin with a set of questions.
48
49 END
50 ;
51
52 $pdir = `pwd`; chomp($pdir);
53
54 print "What is your Palacios directory? [$pdir] : ";
55
56 $pdir = get_user($pdir);
57
58 $kdir = "/boot";
59
60 print "Where are your Linux kernel config files? [$kdir] : ";
61
62 $kdir = get_user($kdir);
63
64 $hotremove = get_kernel_feature($kdir, "CONFIG_MEMORY_HOTREMOVE");
65
66 if (!defined($hotremove)) { 
67   $hotremove="n";
68 }
69
70 $canhotremove=$hotremove;
71
72 $memblocksize = get_palacios_core_feature($pdir,"V3_CONFIG_MEM_BLOCK_SIZE");
73
74 if (!defined($memblocksize)) { 
75   print "Cannot determine your memory block size from your Palacios configuration.\n";
76   exit -1;
77 }
78
79 if (!powerof2($memblocksize)) { 
80   print "Cannot handle a memory block size that is not a power of two ($memblocksize)...\n";
81   exit -1;
82 }
83
84 $compmemblocksize = $memblocksize;
85
86 $maxalloc = 4194304;
87
88 print "What is your kernel's maximum contiguous page allocation size in bytes (typicaly (MAX_ORDER-1)*4096) [$maxalloc] : ";
89
90 $maxalloc = get_user($maxalloc);
91
92 $shadow = 'y';
93
94 print "Do you need to run guests with shadow paging or for other reasons that require 4GB enforcement of page allocation? [$shadow] : ";
95
96 $shadow = get_user($shadow);
97
98 if ($hotremove eq "y") {
99   print "Your kernel supports hot remove.  Do you want to use it? [$hotremove] : ";
100   $hotremove = get_user($hotremove);
101 }
102
103
104 $override_memblocksize = 'n';
105
106 if ($hotremove eq "n") {
107   do  { 
108      $override_memblocksize = 'y';
109      print "You are not using hot-remove, so we will adjust memory block size\n";
110      print "Desired memory block size? [$maxalloc or less, power of 2] : ";
111      $memblocksize = get_user($maxalloc);
112   } while ($memblocksize>$maxalloc && !powerof2($memblocksize));
113 }
114
115 $mem = 1024;
116
117 print "How much memory (in MB) do you want to initially allocate for Palacios? [$mem] : ";
118 $mem = get_user($mem);
119
120 $devmem='y';
121
122 print "Do you need userspace access to your VMs' physical memory? [$devmem] : ";
123 $devmem = get_user($devmem);
124
125 print <<END2
126
127 Parameters
128    Palacios Direcotry:          $pdir
129    Kernel Configs Directory:    $kdir
130    Initial Palacios Memory (MB) $mem
131    Can Hot Remove:              $canhotremove
132    Will Hot Remove:             $hotremove
133    Enforce 4 GB Limit:          $shadow
134    Compiled Memory Block Size:  $compmemblocksize
135    Override Memory Block Size:  $override_memblocksize
136    Actual Memory Block Size:    $memblocksize
137    Allow Devmem:                $devmem
138
139 END2
140 ;
141
142
143 #
144 #
145 #
146 #
147 print "Writing ./ENV\n";
148 open(ENV,">ENV");
149 print ENV "export PALACIOS_DIR=$pdir\n";
150 print ENV "export PATH=$pdir/linux_usr:\$PATH\n";
151 close(ENV);
152 `chmod 644 ENV`;
153
154 print "Writing ./v3_init\n";
155 open(INIT,">v3_init");
156 print INIT "#!/bin/sh\n";
157 print INIT "source $pdir/ENV\n";  # just in case
158
159 # this file will track memory allocations
160 # made at user level so that they can be recovered later
161 # v3_mem will append to it
162 print INIT "rm -f $pdir/.v3offlinedmem\n";
163
164 print INIT "\n\n# insert the module\n";
165 $cmd = "insmod $pdir/v3vee.ko";
166 $cmd.= " allow_devmem=1 " if $devmem eq 'y';
167 $cmd.= " options=\"mem_block_size=$memblocksize\" " if $override_memblocksize eq 'y';
168 print INIT $cmd, "\n";
169
170 $cmd = "v3_mem -a";
171 $cmd.= " -k " if $hotremove eq 'n';
172 $cmd.= " -l " if $shadow eq 'y';
173
174 $chunk = $memblocksize / (1024 * 1024) ;
175 $numchunks = $mem / $chunk;
176 for ($i=0;$i<$numchunks;$i++) {
177   print INIT "$cmd $chunk\n";
178 }
179 close(INIT);
180 `chmod 755 v3_init`;
181
182 print "Writing ./v3_deinit\n";
183 open(DEINIT,">v3_deinit");
184 print DEINIT "#!/bin/sh\n";
185 # bring any offlined memory back to the kernel
186 print DEINIT "v3_mem -r offline\n";
187 # a side effect here is that the offline file will be empty
188 # the rmmod will free any in-kernel allocated memory
189 print DEINIT "rmmod v3vee\n";
190 close(DEINIT);
191 `chmod 755 v3_deinit`;
192 print "Done.\n";
193
194
195
196 sub get_user {
197   my $def = shift;
198   
199   my $inp = <STDIN>; chomp($inp);
200   
201   if ($inp eq "") { 
202     return $def;
203   } else {
204     return $inp;
205   }
206 }
207
208 sub get_kernel_feature {
209   my $dir=shift;
210   my $feature=shift;
211   my $x;
212
213   $x=`grep $feature $dir/config-\`uname -r\``;
214
215   if ($x=~/^\s*\#/) {
216     return undef;
217   } else {
218     if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
219       return $1;
220     } else {
221       return undef;
222     }
223   }
224 }
225   
226 sub get_palacios_core_feature {
227   my $dir=shift;
228   my $feature=shift;
229   my $x;
230
231   $x=`grep $feature $dir/.config`;
232
233   if ($x=~/^\s*\#/) {
234     return undef;
235   } else {
236     if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
237       return $1;
238     } else {
239       return undef;
240     }
241   }
242 }
243
244
245 sub powerof2  {
246   my $x = shift;
247   my $exp;
248   
249   $exp = log($x) /log(2);
250
251   return $exp==int($exp);
252 }