-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv3_config_v3vee.pl
executable file
·362 lines (280 loc) · 9.03 KB
/
v3_config_v3vee.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/usr/bin/perl -w
print <<END
Welcome. The purpose of this tool is to simplify configuration
of the V3VEE environment on a Linux system. It assumes you
have already built Palacios, the Linux embedding, and the Linux
user-sapce tools. If you haven't, hit CTRL-C now and do the
at least the following:
make menuconfig
[choose your options]
make
cd linux_usr
make
cd ..
./v3_config_v3vee.pl
This tool will create (or overwrite) the following for you:
./ENV An environment file that you can source
./v3_init A script that will insert Palacios with
relevant options and with appropriate memory
allocations.
./v3_deinit A script that will free memory and remove
Palacios.
After these are created, you can insert Palacio in the following way:
source ./ENV
./v3_init
Then create and run VMs:
v3_create image_file name
v3_launch /dev/v3-vmN
v3_stop /dev/v3-vmN
v3_free /dev/v3-vmN
And you can remove Palacios and free memory it is using.
./v3_deinit
We begin with a set of questions.
END
;
$pdir = `pwd`; chomp($pdir);
print "What is your Palacios directory? [$pdir] : ";
$pdir = get_user($pdir);
$kdir = "/boot";
print "Where are your Linux kernel config files? [$kdir] : ";
$kdir = get_user($kdir);
$hotremove = get_kernel_feature($kdir, "CONFIG_MEMORY_HOTREMOVE");
if (!defined($hotremove)) {
$hotremove="n";
}
$canhotremove=$hotremove;
$memblocksize = get_palacios_core_feature($pdir,"V3_CONFIG_MEM_BLOCK_SIZE");
if (!defined($memblocksize)) {
print "Cannot determine your memory block size from your Palacios configuration.\n";
exit -1;
}
if (!powerof2($memblocksize)) {
print "Cannot handle a memory block size that is not a power of two ($memblocksize)...\n";
exit -1;
}
$compmemblocksize = $memblocksize;
$maxalloc = 4194304;
print "What is your kernel's maximum contiguous page allocation size in bytes (typically 2^(MAX_ORDER-1)*4096) [$maxalloc] : ";
$maxalloc = get_user($maxalloc);
$gb4 = 'n';
print "Do you need to use features that require 4GB enforcement of page allocation? [$gb4] : ";
$gb4 = get_user($gb4);
if ($hotremove eq "y") {
print "Your kernel supports hot remove. Do you want to use it? [$hotremove] : ";
$hotremove = get_user($hotremove);
}
$override_memblocksize = 'n';
if ($hotremove eq "n") {
do {
$override_memblocksize = 'y';
print "You are not using hot-remove, so we will adjust memory block size\n";
print "Desired memory block size? [$maxalloc or less, power of 2] : ";
$memblocksize = get_user($maxalloc);
} while ($memblocksize>$maxalloc && !powerof2($memblocksize));
do {
print "You are not using hot-remove, so we can adjust the allocation size\n";
print "Typically, you want this as large as possible (up to what your\n";
print "kernel allows, but for special purposes, for example cache\n";
print "partitioning, you want this to be as small as possible (just\n";
print "larger than the largest contiguous allocation your guests will need.)\n";
print "Desired allocation size? [$maxalloc or less, power of 2] : ";
$allocsize = get_user($maxalloc);
} while ($allocsize>$maxalloc && !powerof2($allocsize));
} else {
$allocsize=$memblocksize;
}
$mem = 1024;
print "How much memory (in MB) do you want to initially allocate for Palacios? [$mem] : ";
$mem = get_user($mem);
$devmem='y';
print "Do you need userspace access to your VMs' physical memory? [$devmem] : ";
$devmem = get_user($devmem);
$qemu='n';
$qemudir=$pdir."/linux_usr/qemu";
$hostdev = get_palacios_core_feature($pdir,"V3_CONFIG_HOST_DEVICE");
if ($hostdev eq "y") {
print "Your Palacios configuration includes the host device interface.\n";
print "You can use it to interface with QEMU devices if you have a\n";
print "patched version of QEMU (see linux_usr/qemu for more info)\n\n";
print "Do you plan to use QEMU devices? [n] : ";
$qemu = get_user($qemu);
if ($qemu eq "y") {
while (1) {
print "What is the path to your patched version of QEMU ? [$qemudir] : ";
$qemudir = get_user($qemudir);
last if -e "$qemudir/bin/qemu-system-x86_64";
print "$qemudir/bin/qemu-system-x86_64 cannot be found\n";
}
}
}
print <<END2
Parameters
Palacios Direcotry: $pdir
Kernel Configs Directory: $kdir
Initial Palacios Memory (MB) $mem
Can Hot Remove: $canhotremove
Will Hot Remove: $hotremove
Enforce 4 GB Limit: $gb4
Compiled Memory Block Size: $compmemblocksize
Override Memory Block Size: $override_memblocksize
Actual Memory Block Size: $memblocksize
Allocation Block Size: $allocsize
Allow Devmem: $devmem
Support QEMU devices: $qemu
QEMU directory: $qemudir
END2
;
#
#
#
#
print "Writing ./ENV\n";
open(ENV,">ENV");
print ENV "export PALACIOS_DIR=$pdir\n";
if ($qemu eq "y") {
print ENV "export PALACIOS_QEMU_DIR=$qemudir\n";
}
print ENV "export PATH=$pdir/linux_usr:\$PATH\n";
close(ENV);
`chmod 644 ENV`;
print "Writing ./v3_init\n";
open(INIT,">v3_init");
print INIT "#!/bin/sh\n";
print INIT "source $pdir/ENV\n"; # just in case
# this file will track memory allocations
# made at user level so that they can be recovered later
# v3_mem will append to it
print INIT "rm -f $pdir/.v3offlinedmem\n";
print INIT "\n\n# insert the module\n";
$cmd = "insmod $pdir/v3vee.ko";
$cmd.= " allow_devmem=1 " if $devmem eq 'y';
$cmd.= " options=\"mem_block_size=$memblocksize\" " if $override_memblocksize eq 'y';
print INIT $cmd, "\n";
%numa = get_numa_data();
if (defined($numa{numnodes})) {
$numnodes=$numa{numnodes};
} else {
$numnodes=1;
}
if (defined($numa{numcores})) {
$numcores=$numa{numcores};
$numcorespalacios = get_palacios_core_feature($pdir,"V3_CONFIG_MAX_CPUS");
if (defined($numcorespalacios) && $numcores>$numcorespalacios) {
print "WARNING: Your Palacios configuration is configured to support\n";
print " a maximum of $numcorespalacios cores, but this machine has $numcores cores.\n";
print " Your Palacios will work on this machine, but will not be able to use\n";
print " the additional cores.\n";
if ($numnodes>1) {
print " This is also a NUMA machine, so this will also affect the initial\n";
print " allocation of memory in the NUMA nodes produced by this script.\n";
print " We highly recommend you reconfigure Palacios with at least $numcores cores and rebuild it.\n";
}
}
}
$chunk = $allocsize / (1024 * 1024) ;
$numchunks = $mem / $chunk;
$chunkspernode = $numchunks / $numnodes;
print "The initial memory allocation will be:\n\n";
print " Total memory: $mem MB\n";
print " Memory block size: $chunk MB\n";
print " Number of blocks: $numchunks\n";
print " Number of nodes: $numnodes\n";
print " Blocks/node: $chunkspernode\n";
print " 32 bit limit? $gb4\n";
print " Hot-removed? $hotremove\n";
if ($numnodes*$chunkspernode*$chunk != $mem) {
print "\nWARNING: The memory is not evenly divided among nodes or blocks.\n";
print " This means that LESS memory is allocated than requested.\n\n";
}
$cmd = "v3_mem -a";
$cmd.= " -k " if $hotremove eq 'n';
$cmd.= " -l " if $gb4 eq 'y';
for ($i=0;$i<$numnodes;$i++) {
for ($j=0;$j<$chunkspernode;$j++) {
if ($numnodes>1) {
print INIT "$cmd -n $i $chunk\n";
} else {
print INIT "$cmd $chunk\n";
}
}
}
close(INIT);
`chmod 755 v3_init`;
print "Writing ./v3_deinit\n";
open(DEINIT,">v3_deinit");
print DEINIT "#!/bin/sh\n";
# bring any offlined memory back to the kernel
print DEINIT "v3_mem -r offline\n";
# a side effect here is that the offline file will be empty
# the rmmod will free any in-kernel allocated memory
print DEINIT "rmmod v3vee\n";
close(DEINIT);
`chmod 755 v3_deinit`;
print "Done.\n";
sub get_user {
my $def = shift;
my $inp = <STDIN>; chomp($inp);
if ($inp eq "") {
return $def;
} else {
return $inp;
}
}
sub get_kernel_feature {
my $dir=shift;
my $feature=shift;
my $x;
$x=`grep $feature $dir/config-\`uname -r\``;
if ($x=~/^\s*\#/) {
return undef;
} else {
if ($x=~/\s*$feature\s*=\s*(\S*)\s*$/) {
return $1;
} else {
return undef;
}
}
}
sub get_palacios_core_feature {
my $dir=shift;
my $feature=shift;
my $x;
$x=`grep $feature= $dir/.config`;
if ($x=~/^\s*\#/) {
return undef;
} else {
if ($x=~/\s*$feature=\s*(\S*)\s*$/) {
return $1;
} else {
return undef;
}
}
}
sub powerof2 {
my $x = shift;
my $exp;
$exp = log($x) /log(2);
return $exp==int($exp);
}
sub get_numa_data() {
my $line;
my $maxnode=0;
my $maxcpu=0;
my %numa;
open (N, "numactl --hardware |");
while ($line=<N>) {
if ($line=~/^node\s+(\d+)\s+cpus:\s+(.*)$/) {
my $node=$1;
my @cpus = split(/\s+/,$2);
my $cpu;
if ($node>$maxnode) { $maxnode=$node; }
foreach $cpu (@cpus) {
if ($cpu>$maxcpu) { $maxcpu=$cpu; }
}
$numa{"node$node"}{cores}=\@cpus;
}
}
$numa{numnodes}=$maxnode+1;
$numa{numcores}=$maxcpu+1;
return %numa;
}