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 (typically 2^(MAX_ORDER-1)*4096) [$maxalloc] : ";
90 $maxalloc = get_user($maxalloc);
94 print "Do you need to use features that require 4GB enforcement of page allocation? [$gb4] : ";
96 $gb4 = get_user($gb4);
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));
114 print "You are not using hot-remove, so we can adjust the allocation size\n";
115 print "Typically, you want this as large as possible (up to what your\n";
116 print "kernel allows, but for special purposes, for example cache\n";
117 print "partitioning, you want this to be as small as possible (just\n";
118 print "larger than the largest contiguous allocation your guests will need.)\n";
119 print "Desired allocation size? [$maxalloc or less, power of 2] : ";
120 $allocsize = get_user($maxalloc);
121 } while ($allocsize>$maxalloc && !powerof2($allocsize));
123 $allocsize=$memblocksize;
128 print "How much memory (in MB) do you want to initially allocate for Palacios? [$mem] : ";
129 $mem = get_user($mem);
133 print "Do you need userspace access to your VMs' physical memory? [$devmem] : ";
134 $devmem = get_user($devmem);
137 $qemudir=$pdir."/linux_usr/qemu";
139 $hostdev = get_palacios_core_feature($pdir,"V3_CONFIG_HOST_DEVICE");
141 if ($hostdev eq "y") {
142 print "Your Palacios configuration includes the host device interface.\n";
143 print "You can use it to interface with QEMU devices if you have a\n";
144 print "patched version of QEMU (see linux_usr/qemu for more info)\n\n";
145 print "Do you plan to use QEMU devices? [n] : ";
146 $qemu = get_user($qemu);
149 print "What is the path to your patched version of QEMU ? [$qemudir] : ";
150 $qemudir = get_user($qemudir);
151 last if -e "$qemudir/bin/qemu-system-x86_64";
152 print "$qemudir/bin/qemu-system-x86_64 cannot be found\n";
160 Palacios Direcotry: $pdir
161 Kernel Configs Directory: $kdir
162 Initial Palacios Memory (MB) $mem
163 Can Hot Remove: $canhotremove
164 Will Hot Remove: $hotremove
165 Enforce 4 GB Limit: $gb4
166 Compiled Memory Block Size: $compmemblocksize
167 Override Memory Block Size: $override_memblocksize
168 Actual Memory Block Size: $memblocksize
169 Allocation Block Size: $allocsize
170 Allow Devmem: $devmem
171 Support QEMU devices: $qemu
172 QEMU directory: $qemudir
182 print "Writing ./ENV\n";
184 print ENV "export PALACIOS_DIR=$pdir\n";
186 print ENV "export PALACIOS_QEMU_DIR=$qemudir\n";
188 print ENV "export PATH=$pdir/linux_usr:\$PATH\n";
192 print "Writing ./v3_init\n";
193 open(INIT,">v3_init");
194 print INIT "#!/bin/sh\n";
195 print INIT "source $pdir/ENV\n"; # just in case
197 # this file will track memory allocations
198 # made at user level so that they can be recovered later
199 # v3_mem will append to it
200 print INIT "rm -f $pdir/.v3offlinedmem\n";
202 print INIT "\n\n# insert the module\n";
203 $cmd = "insmod $pdir/v3vee.ko";
204 $cmd.= " allow_devmem=1 " if $devmem eq 'y';
205 $cmd.= " options=\"mem_block_size=$memblocksize\" " if $override_memblocksize eq 'y';
206 print INIT $cmd, "\n";
208 %numa = get_numa_data();
210 if (defined($numa{numnodes})) {
211 $numnodes=$numa{numnodes};
216 if (defined($numa{numcores})) {
217 $numcores=$numa{numcores};
218 $numcorespalacios = get_palacios_core_feature($pdir,"V3_CONFIG_MAX_CPUS");
219 if (defined($numcorespalacios) && $numcores>$numcorespalacios) {
220 print "WARNING: Your Palacios configuration is configured to support\n";
221 print " a maximum of $numcorespalacios cores, but this machine has $numcores cores.\n";
222 print " Your Palacios will work on this machine, but will not be able to use\n";
223 print " the additional cores.\n";
225 print " This is also a NUMA machine, so this will also affect the initial\n";
226 print " allocation of memory in the NUMA nodes produced by this script.\n";
227 print " We highly recommend you reconfigure Palacios with at least $numcores cores and rebuild it.\n";
234 $chunk = $allocsize / (1024 * 1024) ;
235 $numchunks = $mem / $chunk;
236 $chunkspernode = $numchunks / $numnodes;
238 print "The initial memory allocation will be:\n\n";
239 print " Total memory: $mem MB\n";
240 print " Memory block size: $chunk MB\n";
241 print " Number of blocks: $numchunks\n";
242 print " Number of nodes: $numnodes\n";
243 print " Blocks/node: $chunkspernode\n";
244 print " 32 bit limit? $gb4\n";
245 print " Hot-removed? $hotremove\n";
247 if ($numnodes*$chunkspernode*$chunk != $mem) {
248 print "\nWARNING: The memory is not evenly divided among nodes or blocks.\n";
249 print " This means that LESS memory is allocated than requested.\n\n";
253 $cmd.= " -k " if $hotremove eq 'n';
254 $cmd.= " -l " if $gb4 eq 'y';
256 for ($i=0;$i<$numnodes;$i++) {
257 for ($j=0;$j<$chunkspernode;$j++) {
259 print INIT "$cmd -n $i $chunk\n";
261 print INIT "$cmd $chunk\n";
268 print "Writing ./v3_deinit\n";
269 open(DEINIT,">v3_deinit");
270 print DEINIT "#!/bin/sh\n";
271 # bring any offlined memory back to the kernel
272 print DEINIT "v3_mem -r offline\n";
273 # a side effect here is that the offline file will be empty
274 # the rmmod will free any in-kernel allocated memory
275 print DEINIT "rmmod v3vee\n";
277 `chmod 755 v3_deinit`;
285 my $inp = <STDIN>; chomp($inp);
294 sub get_kernel_feature {
299 $x=`grep $feature $dir/config-\`uname -r\``;
304 if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
312 sub get_palacios_core_feature {
317 $x=`grep $feature= $dir/.config`;
322 if ($x=~/\s*$feature=\s*(\S*)\s*$/) {
335 $exp = log($x) /log(2);
337 return $exp==int($exp);
340 sub get_numa_data() {
346 open (N, "numactl --hardware |");
348 if ($line=~/^node\s+(\d+)\s+cpus:\s+(.*)$/) {
350 my @cpus = split(/\s+/,$2);
352 if ($node>$maxnode) { $maxnode=$node; }
353 foreach $cpu (@cpus) {
354 if ($cpu>$maxcpu) { $maxcpu=$cpu; }
356 $numa{"node$node"}{cores}=\@cpus;
359 $numa{numnodes}=$maxnode+1;
360 $numa{numcores}=$maxcpu+1;