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.


Configuration Generation tool for Linux Embedding
[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 PATH=\$PATH:$pdir/linux_usr\n";
150 close(ENV);
151 `chmod 644 ENV`;
152
153 print "Writing ./v3_init\n";
154 open(INIT,">v3_init");
155 print INIT "#!/bin/sh\n";
156 print INIT "source $pdir/ENV\n";  # just in case
157
158 print INIT "\n\n# insert the module\n";
159 $cmd = "insmod $pdir/v3vee.ko";
160 $cmd.= " allow_devmem=1 " if $devmem eq 'y';
161 $cmd.= " options=\"mem_block_size=$memblocksize\" " if $override_memblocksize eq 'y';
162 print INIT $cmd, "\n";
163
164 $cmd = "v3_mem";
165 $cmd.= " -k " if $hotremove eq 'n';
166 $cmd.= " -l " if $shadow eq 'y';
167
168 $chunk = $memblocksize / (1024 * 1024) ;
169 $numchunks = $mem / $chunk;
170 for ($i=0;$i<$numchunks;$i++) {
171   print INIT "$cmd $chunk\n";
172 }
173 close(INIT);
174 `chmod 755 v3_init`;
175
176 print "Writing ./v3_deinit\n";
177 open(DEINIT,">v3_deinit");
178 print DEINIT "#!/bin/sh\n";
179 print DEINIT "echo WARNING - THIS DOES NOT CURRENTLY ONLINE MEMORY\n";
180 print DEINIT "rmmod v3vee\n";
181 close(DEINIT);
182 `chmod 755 v3_deinit`;
183 print "Done.\n";
184
185
186
187 sub get_user {
188   my $def = shift;
189   
190   my $inp = <STDIN>; chomp($inp);
191   
192   if ($inp eq "") { 
193     return $def;
194   } else {
195     return $inp;
196   }
197 }
198
199 sub get_kernel_feature {
200   my $dir=shift;
201   my $feature=shift;
202   my $x;
203
204   $x=`grep $feature $dir/config-\`uname -r\``;
205
206   if ($x=~/^\s*\#/) {
207     return undef;
208   } else {
209     if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
210       return $1;
211     } else {
212       return undef;
213     }
214   }
215 }
216   
217 sub get_palacios_core_feature {
218   my $dir=shift;
219   my $feature=shift;
220   my $x;
221
222   $x=`grep $feature $dir/.config`;
223
224   if ($x=~/^\s*\#/) {
225     return undef;
226   } else {
227     if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
228       return $1;
229     } else {
230       return undef;
231     }
232   }
233 }
234
235
236 sub powerof2  {
237   my $x = shift;
238   my $exp;
239   
240   $exp = log($x) /log(2);
241
242   return $exp==int($exp);
243 }