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 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));
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);
126 $qemudir=$pdir."/linux_usr/qemu";
128 $hostdev = get_palacios_core_feature($pdir,"V3_CONFIG_HOST_DEVICE");
130 if ($hostdev eq "y") {
131 print "Your Palacios configuration includes the host device interface.\n";
132 print "You can use it to interface with QEMU devices if you have a\n";
133 print "patched version of QEMU (see linux_usr/qemu for more info)\n\n";
134 print "Do you plan to use QEMU devices? [n] : ";
135 $qemu = get_user($qemu);
138 print "What is the path to your patched version of QEMU ? [$qemudir] : ";
139 $qemudir = get_user($qemudir);
140 last if -e "$qemudir/bin/qemu-system-x86_64";
141 print "$qemudir/bin/qemu-system-x86_64 cannot be found\n";
149 Palacios Direcotry: $pdir
150 Kernel Configs Directory: $kdir
151 Initial Palacios Memory (MB) $mem
152 Can Hot Remove: $canhotremove
153 Will Hot Remove: $hotremove
154 Enforce 4 GB Limit: $gb4
155 Compiled Memory Block Size: $compmemblocksize
156 Override Memory Block Size: $override_memblocksize
157 Actual Memory Block Size: $memblocksize
158 Allow Devmem: $devmem
159 Support QEMU devices: $qemu
160 QEMU directory: $qemudir
170 print "Writing ./ENV\n";
172 print ENV "export PALACIOS_DIR=$pdir\n";
174 print ENV "export PALACIOS_QEMU_DIR=$qemudir\n";
176 print ENV "export PATH=$pdir/linux_usr:\$PATH\n";
180 print "Writing ./v3_init\n";
181 open(INIT,">v3_init");
182 print INIT "#!/bin/sh\n";
183 print INIT "source $pdir/ENV\n"; # just in case
185 # this file will track memory allocations
186 # made at user level so that they can be recovered later
187 # v3_mem will append to it
188 print INIT "rm -f $pdir/.v3offlinedmem\n";
190 print INIT "\n\n# insert the module\n";
191 $cmd = "insmod $pdir/v3vee.ko";
192 $cmd.= " allow_devmem=1 " if $devmem eq 'y';
193 $cmd.= " options=\"mem_block_size=$memblocksize\" " if $override_memblocksize eq 'y';
194 print INIT $cmd, "\n";
196 %numa = get_numa_data();
198 if (defined($numa{numnodes})) {
199 $numnodes=$numa{numnodes};
204 if (defined($numa{numcores})) {
205 $numcores=$numa{numcores};
206 $numcorespalacios = get_palacios_core_feature($pdir,"V3_CONFIG_MAX_CPUS");
207 if (defined($numcorespalacios) && $numcores>$numcorespalacios) {
208 print "WARNING: Your Palacios configuration is configured to support\n";
209 print " a maximum of $numcorespalacios cores, but this machine has $numcores cores.\n";
210 print " Your Palacios will work on this machine, but will not be able to use\n";
211 print " the additional cores.\n";
213 print " This is also a NUMA machine, so this will also affect the initial\n";
214 print " allocation of memory in the NUMA nodes produced by this script.\n";
215 print " We highly recommend you reconfigure Palacios with at least $numcores cores and rebuild it.\n";
222 $chunk = $memblocksize / (1024 * 1024) ;
223 $numchunks = $mem / $chunk;
224 $chunkspernode = $numchunks / $numnodes;
226 print "The initial memory allocation will be:\n\n";
227 print " Total memory: $mem MB\n";
228 print " Memory block size: $chunk MB\n";
229 print " Number of blocks: $numchunks\n";
230 print " Number of nodes: $numnodes\n";
231 print " Blocks/node: $chunkspernode\n";
232 print " 32 bit limit? $gb4\n";
233 print " Hot-removed? $hotremove\n";
235 if ($numnodes*$chunkspernode*$chunk != $mem) {
236 print "\nWARNING: The memory is not evenly divided among nodes or blocks.\n";
237 print " This means that LESS memory is allocated than requested.\n\n";
241 $cmd.= " -k " if $hotremove eq 'n';
242 $cmd.= " -l " if $gb4 eq 'y';
244 for ($i=0;$i<$numnodes;$i++) {
245 for ($j=0;$j<$chunkspernode;$j++) {
247 print INIT "$cmd -n $i $chunk\n";
249 print INIT "$cmd $chunk\n";
256 print "Writing ./v3_deinit\n";
257 open(DEINIT,">v3_deinit");
258 print DEINIT "#!/bin/sh\n";
259 # bring any offlined memory back to the kernel
260 print DEINIT "v3_mem -r offline\n";
261 # a side effect here is that the offline file will be empty
262 # the rmmod will free any in-kernel allocated memory
263 print DEINIT "rmmod v3vee\n";
265 `chmod 755 v3_deinit`;
273 my $inp = <STDIN>; chomp($inp);
282 sub get_kernel_feature {
287 $x=`grep $feature $dir/config-\`uname -r\``;
292 if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
300 sub get_palacios_core_feature {
305 $x=`grep $feature= $dir/.config`;
310 if ($x=~/\s*$feature=\s*(\S*)\s*$/) {
323 $exp = log($x) /log(2);
325 return $exp==int($exp);
328 sub get_numa_data() {
334 open (N, "numactl --hardware |");
336 if ($line=~/^node\s+(\d+)\s+cpus:\s+(.*)$/) {
338 my @cpus = split(/\s+/,$2);
340 if ($node>$maxnode) { $maxnode=$node; }
341 foreach $cpu (@cpus) {
342 if ($cpu>$maxcpu) { $maxcpu=$cpu; }
344 $numa{"node$node"}{cores}=\@cpus;
347 $numa{numnodes}=$maxnode+1;
348 $numa{numcores}=$maxcpu+1;