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.


doc fix for config_v3vee
[palacios.git] / v3_config_v3vee.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_v3vee.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 %numa = get_numa_data();
171
172 if (defined($numa{numnodes})) {
173   $numnodes=$numa{numnodes};
174 } else {
175   $numnodes=1;
176 }
177
178 if (defined($numa{numcores})) { 
179   $numcores=$numa{numcores};
180   $numcorespalacios = get_palacios_core_feature($pdir,"V3_CONFIG_MAX_CPUS");
181   if (defined($numcorespalacios) && $numcores>$numcorespalacios) { 
182     print "WARNING: Your Palacios configuration is configured to support\n";
183     print " a maximum of $numcorespalacios cores, but this machine has $numcores cores.\n";
184     print " Your Palacios will work on this machine, but will not be able to use\n";
185     print " the additional cores.\n";
186     if ($numnodes>1) {
187        print " This is also a NUMA machine, so this will also affect the initial\n";
188        print " allocation of memory in the NUMA nodes produced by this script.\n";
189        print " We highly recommend you reconfigure Palacios with at least $numcores cores and rebuild it.\n";
190      }
191   }
192
193
194
195
196 $chunk = $memblocksize / (1024 * 1024) ;
197 $numchunks = $mem / $chunk;
198 $chunkspernode  = $numchunks / $numnodes;
199
200 print "The initial memory allocation will be:\n\n";
201 print "  Total memory:       $mem MB\n";
202 print "  Memory block size:  $chunk MB\n";
203 print "  Number of blocks:   $numchunks\n";
204 print "  Number of nodes:    $numnodes\n";
205 print "  Blocks/node:        $chunkspernode\n";
206 print "  32 bit limit?       $shadow\n";
207 print "  Hot-removed?        $hotremove\n";
208
209 if ($numnodes*$chunkspernode*$chunk != $mem) { 
210   print "\nWARNING: The memory is not evenly divided among nodes or blocks.\n";
211   print " This means that LESS memory is allocated than requested.\n\n";
212 }
213
214 $cmd = "v3_mem -a";
215 $cmd.= " -k " if $hotremove eq 'n';
216 $cmd.= " -l " if $shadow eq 'y';
217
218 for ($i=0;$i<$numnodes;$i++) {
219   for ($j=0;$j<$chunkspernode;$j++) { 
220     if ($numnodes>1) { 
221       print INIT "$cmd -n $i $chunk\n";
222     } else {
223       print INIT "$cmd $chunk\n";
224     }
225   }
226 }
227 close(INIT);
228 `chmod 755 v3_init`;
229
230 print "Writing ./v3_deinit\n";
231 open(DEINIT,">v3_deinit");
232 print DEINIT "#!/bin/sh\n";
233 # bring any offlined memory back to the kernel
234 print DEINIT "v3_mem -r offline\n";
235 # a side effect here is that the offline file will be empty
236 # the rmmod will free any in-kernel allocated memory
237 print DEINIT "rmmod v3vee\n";
238 close(DEINIT);
239 `chmod 755 v3_deinit`;
240 print "Done.\n";
241
242
243
244 sub get_user {
245   my $def = shift;
246   
247   my $inp = <STDIN>; chomp($inp);
248   
249   if ($inp eq "") { 
250     return $def;
251   } else {
252     return $inp;
253   }
254 }
255
256 sub get_kernel_feature {
257   my $dir=shift;
258   my $feature=shift;
259   my $x;
260
261   $x=`grep $feature $dir/config-\`uname -r\``;
262
263   if ($x=~/^\s*\#/) {
264     return undef;
265   } else {
266     if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
267       return $1;
268     } else {
269       return undef;
270     }
271   }
272 }
273   
274 sub get_palacios_core_feature {
275   my $dir=shift;
276   my $feature=shift;
277   my $x;
278
279   $x=`grep $feature= $dir/.config`;
280
281   if ($x=~/^\s*\#/) {
282     return undef;
283   } else {
284     if ($x=~/\s*$feature=\s*(\S*)\s*$/) {
285       return $1;
286     } else {
287       return undef;
288     }
289   }
290 }
291
292
293 sub powerof2  {
294   my $x = shift;
295   my $exp;
296   
297   $exp = log($x) /log(2);
298
299   return $exp==int($exp);
300 }
301
302 sub get_numa_data() {
303   my $line;
304   my $maxnode=0;
305   my $maxcpu=0;
306   my %numa;
307
308   open (N, "numactl --hardware |");
309   while ($line=<N>) { 
310     if ($line=~/^node\s+(\d+)\s+cpus:\s+(.*)$/) { 
311       my $node=$1;
312       my @cpus = split(/\s+/,$2);
313       my $cpu;
314       if ($node>$maxnode) { $maxnode=$node; }
315       foreach $cpu (@cpus) { 
316         if ($cpu>$maxcpu) { $maxcpu=$cpu; }
317       }
318       $numa{"node$node"}{cores}=\@cpus;
319     }
320   }
321   $numa{numnodes}=$maxnode+1;
322   $numa{numcores}=$maxcpu+1;
323   return %numa;
324 }