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:
21 This tool will create (or overwrite) the following for you:
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
27 ./v3_deinit A script that will free memory and remove
30 After these are created, you can insert Palacio in the following way:
35 Then create and run VMs:
37 v3_create image_file name
42 And you can remove Palacios and free memory it is using.
47 We begin with a set of questions.
52 $pdir = `pwd`; chomp($pdir);
54 print "What is your Palacios directory? [$pdir] : ";
56 $pdir = get_user($pdir);
60 print "Where are your Linux kernel config files? [$kdir] : ";
62 $kdir = get_user($kdir);
64 $hotremove = get_kernel_feature($kdir, "CONFIG_MEMORY_HOTREMOVE");
66 if (!defined($hotremove)) {
70 $canhotremove=$hotremove;
72 $memblocksize = get_palacios_core_feature($pdir,"V3_CONFIG_MEM_BLOCK_SIZE");
74 if (!defined($memblocksize)) {
75 print "Cannot determine your memory block size from your Palacios configuration.\n";
79 if (!powerof2($memblocksize)) {
80 print "Cannot handle a memory block size that is not a power of two ($memblocksize)...\n";
84 $compmemblocksize = $memblocksize;
88 print "What is your kernel's maximum contiguous page allocation size in bytes (typicaly (MAX_ORDER-1)*4096) [$maxalloc] : ";
90 $maxalloc = get_user($maxalloc);
94 print "Do you need to run guests with shadow paging or for other reasons that require 4GB enforcement of page allocation? [$shadow] : ";
96 $shadow = get_user($shadow);
98 if ($hotremove eq "y") {
99 print "Your kernel supports hot remove. Do you want to use it? [$hotremove] : ";
100 $hotremove = get_user($hotremove);
104 $override_memblocksize = 'n';
106 if ($hotremove eq "n") {
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));
117 print "How much memory (in MB) do you want to initially allocate for Palacios? [$mem] : ";
118 $mem = get_user($mem);
122 print "Do you need userspace access to your VMs' physical memory? [$devmem] : ";
123 $devmem = get_user($devmem);
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
147 print "Writing ./ENV\n";
149 print ENV "export PALACIOS_DIR=$pdir\n";
150 print ENV "export PATH=$pdir/linux_usr:\$PATH\n";
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
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";
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";
170 %numa = get_numa_data();
172 if (defined($numa{numnodes})) {
173 $numnodes=$numa{numnodes};
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";
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";
196 $chunk = $memblocksize / (1024 * 1024) ;
197 $numchunks = $mem / $chunk;
198 $chunkspernode = $numchunks / $numnodes;
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";
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";
215 $cmd.= " -k " if $hotremove eq 'n';
216 $cmd.= " -l " if $shadow eq 'y';
218 for ($i=0;$i<$numnodes;$i++) {
219 for ($j=0;$j<$chunkspernode;$j++) {
221 print INIT "$cmd -n $i $chunk\n";
223 print INIT "$cmd $chunk\n";
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";
239 `chmod 755 v3_deinit`;
247 my $inp = <STDIN>; chomp($inp);
256 sub get_kernel_feature {
261 $x=`grep $feature $dir/config-\`uname -r\``;
266 if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
274 sub get_palacios_core_feature {
279 $x=`grep $feature= $dir/.config`;
284 if ($x=~/\s*$feature=\s*(\S*)\s*$/) {
297 $exp = log($x) /log(2);
299 return $exp==int($exp);
302 sub get_numa_data() {
308 open (N, "numactl --hardware |");
310 if ($line=~/^node\s+(\d+)\s+cpus:\s+(.*)$/) {
312 my @cpus = split(/\s+/,$2);
314 if ($node>$maxnode) { $maxnode=$node; }
315 foreach $cpu (@cpus) {
316 if ($cpu>$maxcpu) { $maxcpu=$cpu; }
318 $numa{"node$node"}{cores}=\@cpus;
321 $numa{numnodes}=$maxnode+1;
322 $numa{numcores}=$maxcpu+1;