-
Notifications
You must be signed in to change notification settings - Fork 1
/
justfile
600 lines (540 loc) · 20.3 KB
/
justfile
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# vim: set ft=make et :
PROJECT_ROOT := justfile_directory()
BUILD_DIR := join(PROJECT_ROOT, "build")
QEMU_SNP := join(BUILD_DIR, "qemu-amd-sev-snp/bin/qemu-system-x86_64")
OVMF_SNP := join(BUILD_DIR, "ovmf-amd-sev-snp-fd/FV/OVMF.fd")
OVMF_SNP_CODE := join(BUILD_DIR, "ovmf-amd-sev-snp-fd/FV/OVMF_CODE.fd")
OVMF_SNP_VARS := join(BUILD_DIR, "ovmf-amd-sev-snp-fd/FV/OVMF_VARS.fd")
# qemu and ovmf for normal guest (use SNP version for now)
QEMU := QEMU_SNP
OVMF := OVMF_SNP
OVMF_CODE := OVMF_SNP_CODE
OVMF_VARS := OVMF_SNP_VARS
SNP_IMAGE := join(BUILD_DIR, "image/snp-guest-image.qcow2")
NORMAL_IMAGE := join(BUILD_DIR, "image/normal-guest-image.qcow2")
GUEST_FS := join(BUILD_DIR, "image/guest-fs.qcow2")
SSH_PORT := "2225"
smp := "4"
mem := "16G"
REV := `nix eval --raw .#lib.nixpkgsRev`
NIX_RESULTS := justfile_directory() + "/.git/nix-results/" + REV
KERNEL_SHELL := "$(nix build --out-link " + NIX_RESULTS + "/kernel-fhs --json " + justfile_directory() + "#kernel-deps | jq -r '.[] | .outputs | .out')/bin/linux-kernel-build"
# we use ../linux as linux kernel source directory for development
LINUX_DIR := join(PROJECT_ROOT, "../linux")
LINUX_REPO := "https://github.com/torvalds/linux"
# LINUX_COMMIT := "0dd3ee31125508cd67f7e7172247f05b7fd1753a" # v6.7
LINUX_COMMIT := "e8f897f4afef0031fe618a8e94127a0934896aba" # v6.8
BRIDGE_NAME := "virbr_cvm"
TAP_NAME := "tap_cvm"
MTAP_NAME := "mtap_cvm"
default:
@just --choose
# ------------------------------
# QEMU commands
# e.g., just smp=16 start-vm-disk
# note: setting values (`smp=16`) needs to come before the command
start-vm-disk:
sudo {{QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-machine q35 \
-enable-kvm \
-nographic \
-blockdev qcow2,node-name=q2,file.driver=file,file.filename={{NORMAL_IMAGE}} \
-device virtio-blk-pci,drive=q2,bootindex=0 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::{{SSH_PORT}}-:22 \
-virtfs local,path={{PROJECT_ROOT}},security_model=none,mount_tag=share \
-netdev bridge,id=en0,br={{BRIDGE_NAME}} \
-device virtio-net-pci,netdev=en0 \
-drive if=pflash,format=raw,unit=0,file={{OVMF}},readonly=on
start-vm-direct:
sudo {{QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-machine q35 \
-enable-kvm \
-nographic \
-kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
-append "root=/dev/vda console=hvc0" \
-blockdev qcow2,node-name=q2,file.driver=file,file.filename={{GUEST_FS}} \
-device virtio-blk-pci,drive=q2 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::{{SSH_PORT}}-:22 \
-virtfs local,path={{PROJECT_ROOT}},security_model=none,mount_tag=share \
-drive if=pflash,format=raw,unit=0,file={{OVMF}},readonly=on \
-serial null \
-device virtio-serial \
-chardev stdio,mux=on,id=char0,signal=off \
-mon chardev=char0,mode=readline \
-device virtconsole,chardev=char0,id=vc0,nr=0
start-vm-direct-vhost:
sudo {{QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-machine q35 \
-enable-kvm \
-nographic \
-kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
-append "root=/dev/vda console=hvc0" \
-blockdev qcow2,node-name=q2,file.driver=file,file.filename={{GUEST_FS}} \
-device virtio-blk-pci,drive=q2 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::{{SSH_PORT}}-:22 \
-virtfs local,path={{PROJECT_ROOT}},security_model=none,mount_tag=share \
-drive if=pflash,format=raw,unit=0,file={{OVMF}},readonly=on \
-netdev tap,id=en0,ifname={{TAP_NAME}},script=no,downscript=no,vhost=on,queues=2 \
-device virtio-net-pci,netdev=en0,mq=on,vectors=18 \
-serial null \
-device virtio-serial \
-chardev stdio,mux=on,id=char0,signal=off \
-mon chardev=char0,mode=readline \
-device virtconsole,chardev=char0,id=vc0,nr=0
start-snp-disk:
sudo {{QEMU_SNP}} \
-cpu EPYC-v4,host-phys-bits=true \
-smp {{smp}} \
-m {{mem}} \
-machine q35,memory-backend=ram1,memory-encryption=sev0,vmport=off \
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,policy=0x30000 \
-object memory-backend-memfd,id=ram1,size={{mem}},share=true,prealloc=false \
-enable-kvm \
-nographic \
-blockdev qcow2,node-name=q2,file.driver=file,file.filename={{SNP_IMAGE}} \
-device virtio-blk-pci,drive=q2 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::{{SSH_PORT}}-:22 \
-virtfs local,path={{PROJECT_ROOT}},security_model=none,mount_tag=share \
-bios {{OVMF_SNP}}
start-snp-direct:
sudo {{QEMU_SNP}} \
-cpu EPYC-v4,host-phys-bits=true \
-smp {{smp}} \
-m {{mem}} \
-machine q35,memory-backend=ram1,memory-encryption=sev0,vmport=off \
-enable-kvm \
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,policy=0x30000 \
-object memory-backend-memfd,id=ram1,size={{mem}},share=true,prealloc=false \
-nographic \
-kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
-append "root=/dev/vda console=hvc0" \
-blockdev qcow2,node-name=q2,file.driver=file,file.filename={{GUEST_FS}} \
-device virtio-blk-pci,drive=q2 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::{{SSH_PORT}}-:22 \
-virtfs local,path={{PROJECT_ROOT}},security_model=none,mount_tag=share \
-bios {{OVMF_SNP}} \
-serial null \
-device virtio-serial \
-chardev stdio,mux=on,id=char0,signal=off \
-mon chardev=char0,mode=readline \
-device virtconsole,chardev=char0,id=vc0,nr=0
# ------------------------------
# TDX machine
#
#TDX_QEMU := "qemu-system-x86_64"
TDX_QEMU := join(BUILD_DIR, "qemu-tdx/bin/qemu-system-x86_64")
#TDVF_FIRMWARE := "/usr/share/ovmf/OVMF.fd"
TDVF_FIRMWARE := join(BUILD_DIR, "ovmf-tdx-fd/FV/OVMF.fd")
TDSHIM := "../td-shim/target/release/final.bin"
CLOUD_HYPERVISOR := "../cloud-hypervisor/target/release/cloud-hypervisor"
TD_IMG := join(BUILD_DIR, "image/tdx-guest-ubuntu-24.04-generic.qcow2")
QUOTE_ARGS := "-device vhost-vsock-pci,guest-cid=3"
start-tdx-vm:
{{TDX_QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-machine q35,hpet=off,kernel_irqchip=split,memory-encryption=tdx,memory-backend=ram1 \
-enable-kvm \
-object tdx-guest,id=tdx \
-object memory-backend-ram,id=ram1,size={{mem}},private=on \
-bios {{TDVF_FIRMWARE}} \
-nographic \
-nodefaults \
-serial stdio \
-device virtio-net-pci,netdev=nic0_td \
-netdev user,id=nic0_td,hostfwd=tcp::{{SSH_PORT}}-:22 \
-drive file={{TD_IMG}},if=none,id=virtio-disk0 \
-device virtio-blk-pci,drive=virtio-disk0 \
{{QUOTE_ARGS}}
start-tdx-direct:
{{TDX_QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-machine q35,hpet=off,kernel_irqchip=split,memory-encryption=tdx,memory-backend=ram1 \
-enable-kvm \
-object tdx-guest,id=tdx \
-object memory-backend-ram,id=ram1,size={{mem}},private=on \
-kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
-append "root=/dev/vda console=hvc0" \
-bios {{TDVF_FIRMWARE}} \
-nographic \
-nodefaults \
-device virtio-net-pci,netdev=nic0_td \
-netdev user,id=nic0_td,hostfwd=tcp::{{SSH_PORT}}-:22 \
-drive file={{GUEST_FS}},if=none,id=virtio-disk0 \
-device virtio-blk-pci,drive=virtio-disk0 \
-serial null \
-device virtio-serial \
-chardev stdio,mux=on,id=char0,signal=off \
-mon chardev=char0,mode=readline \
-device virtconsole,chardev=char0,id=vc0,nr=0 \
{{QUOTE_ARGS}}
start-ch:
{{CLOUD_HYPERVISOR}} \
--kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
--cmdline "console=hvc0 root=/dev/vda rw" \
--cpus boot={{smp}} \
--memory size={{mem}} \
--disk path={{GUEST_FS}}
start-ch-tdvf:
{{CLOUD_HYPERVISOR}} \
--platform tdx=on \
--firmware {{TDVF_FIRMWARE}} \
--kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
--cmdline "console=hvc0 root=/dev/vda rw" \
--cpus boot={{smp}} \
--memory size={{mem}} \
--disk path={{GUEST_FS}}
start-ch-tdshim:
{{CLOUD_HYPERVISOR}} \
--platform tdx=on \
--firmware {{TDSHIM}} \
--kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
--cmdline "console=hvc0 root=/dev/vda rw" \
--cpus boot={{smp}} \
--memory size={{mem}} \
--disk path={{GUEST_FS}}
start-intel-direct:
{{TDX_QEMU}} \
-cpu host \
-smp {{smp}} \
-m {{mem}} \
-enable-kvm \
-kernel {{LINUX_DIR}}/arch/x86/boot/bzImage \
-append "root=/dev/vda console=hvc0" \
-bios {{TDVF_FIRMWARE}} \
-nographic \
-nodefaults \
-device virtio-net-pci,netdev=nic0_td \
-netdev user,id=nic0_td,hostfwd=tcp::{{SSH_PORT}}-:22 \
-drive file={{GUEST_FS}},if=none,id=virtio-disk0 \
-device virtio-blk-pci,drive=virtio-disk0 \
-serial null \
-device virtio-serial \
-chardev stdio,mux=on,id=char0,signal=off \
-mon chardev=char0,mode=readline \
-device virtconsole,chardev=char0,id=vc0,nr=0
# ------------------------------
# Utility commands
ssh command="":
chmod 600 ./nix/ssh_key
ssh -i nix/ssh_key \
-o StrictHostKeyChecking=no \
-o NoHostAuthenticationForLocalhost=yes \
-p {{ SSH_PORT }} root@localhost -- "{{ command }}"
# e.g.,
# vm to host: just scp root@localhost:/root/a .
# host to vm: just scp a root@localhost:/root
# NOTE: this assumes that the command is run from the project root
scp src="" dst="":
scp -i {{ PROJECT_ROOT }}/nix/ssh_key \
-o StrictHostKeyChecking=no \
-o NoHostAuthenticationForLocalhost=yes \
-o UserKnownHostsFile=/dev/null \
-P {{ SSH_PORT }} \
{{ src }} {{ dst }}
stop-qemu:
just ssh "poweroff"
# dangerous: kill all qemu processes!
kill-qemu-force:
sudo pkill .qemu-system-x8
# ------------------------------
# Clone and build guest linux kernel for development (the built vmilnux is used for direct boot)
# (based on VMSH)
build-linux-shell:
{{ KERNEL_SHELL }} bash
clone-linux:
#!/usr/bin/env bash
set -euo pipefail
if [[ -d {{ LINUX_DIR }} ]]; then
echo " {{ LINUX_DIR }} already exists, skipping clone"
exit 0
fi
git clone {{ LINUX_REPO }} {{ LINUX_DIR }}
set -x
if [[ $(git -C {{ LINUX_DIR }} rev-parse HEAD) != "{{ LINUX_COMMIT }}" ]]; then
git -C {{ LINUX_DIR }} fetch {{ LINUX_REPO }} {{ LINUX_COMMIT }}
git -C {{ LINUX_DIR }} checkout "{{ LINUX_COMMIT }}"
fi
patch -d {{ LINUX_DIR }} -p1 < {{ PROJECT_ROOT }}/nix/patches/linux_event_record.patch
patch -d {{ LINUX_DIR }} -p1 < {{ PROJECT_ROOT }}/nix/patches/linux_tdx_allow_user_io.patch
patch -d {{ LINUX_DIR }} -p1 < {{ PROJECT_ROOT }}/nix/patches/linux_tdx_export_hypercall.patch
# kernel configuration for SEV-SNP guest
configure-linux-old:
#!/usr/bin/env bash
set -xeuo pipefail
if [[ ! -f {{ LINUX_DIR }}/.config ]]; then
cd {{ LINUX_DIR }}
{{ KERNEL_SHELL }} "make defconfig kvm_guest.config"
{{ KERNEL_SHELL }} "scripts/config \
--disable DRM \
--disable USB \
--disable WIRELESS \
--disable WLAN \
--disable SOUND \
--disable SND \
--disable HID \
--disable INPUT \
--disable NFS_FS \
--disable ETHERNET \
--disable NETFILTER \
--enable DEBUG \
--enable GDB_SCRIPTS \
--enable DEBUG_DRIVER \
--enable KVM \
--enable KVM_INTEL \
--enable KVM_AMD \
--enable KVM_IOREGION \
--enable BPF_SYSCALL \
--enable CONFIG_MODVERSIONS \
--enable IKHEADERS \
--enable IKCONFIG_PROC \
--enable VIRTIO_MMIO \
--enable VIRTIO_MMIO_CMDLINE_DEVICES \
--enable PTDUMP_CORE \
--enable PTDUMP_DEBUGFS \
--enable OVERLAY_FS \
--enable SQUASHFS \
--enable SQUASHFS_XZ \
--enable SQUASHFS_FILE_DIRECT \
--enable PVH \
--disable SQUASHFS_FILE_CACHE \
--enable SQUASHFS_DECOMP_MULTI \
--disable SQUASHFS_DECOMP_SINGLE \
--disable SQUASHFS_DECOMP_MULTI_PERCPU \
--enable EXPERT \
--enable AMD_MEM_ENCRYPT \
--disable AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT \
--enable KVM_AMD_SEV \
--enable CRYPTO_DEV_CCP \
--enable CRYPTO_DEV_CCP_DD \
--enable SEV_GUEST \
--enable X86_CPUID"
fi
# kernel configuration tested with v6.8
configure-linux debug="":
#!/usr/bin/env bash
set -xeuo pipefail
if [[ ! -f {{ LINUX_DIR }}/.config ]]; then
cd {{ LINUX_DIR }}
{{ KERNEL_SHELL }} "make defconfig kvm_guest.config"
{{ KERNEL_SHELL }} "scripts/config \
--enable AMD_MEM_ENCRYPT \
--disable AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT \
--enable VIRT_DRIVERS \
--enable SEV_GUEST"
if [[ "{{ debug }}" = "debug" ]]; then
{{ KERNEL_SHELL }} "scripts/config \
--enable CONFIG_IKCONFIG \
--enable CONFIG_IKCONFIG_PROC \
--enable KPROBES \
--enable KPROBES_ON_FTRACE \
--enable KPROBE_EVENTS \
--enable DYNAMIC_FTRACE \
--enable DYNAMIC_FTRACE_WITH_REGS \
--enable DYNAMIC_FTRACE_WITH_ARGS \
--enable DYNAMIC_EVENTS \
--enable BPF \
--enable BPF_SYSCALL \
--enable BPF_EVENTS \
--enable BPF_JIT \
--enable TRACEPOINTS \
--enable FUNCTION_TRACER \
--enable DEBUG_INFO \
--enable DEBUG_INFO_BTF \
--enable IKCONFIG \
--enable IKCONFIG_PROC \
--enable IKHEADERS"
fi
fi
# kernel configuration tested with v6.8
configure-linux-tdx:
#!/usr/bin/env bash
set -xeuo pipefail
if [[ ! -f {{ LINUX_DIR }}/.config ]]; then
cd {{ LINUX_DIR }}
{{ KERNEL_SHELL }} "make defconfig kvm_guest.config"
{{ KERNEL_SHELL }} "scripts/config \
--enable X86_X2APIC \
--enable INTEL_TDX_GUEST \
--enable VIRT_DRIVERS \
--enable CONFIGFS_FS \
--enable TSM_REPORTS \
--enable TDX_GUEST_DRIVER"
# for debug
#{{ KERNEL_SHELL }} "scripts/config \
# --enable KPROBES \
# --enable KPROBES_ON_FTRACE \
# --enable BPF \
# --enable BPF_SYSCALL \
# --enable BPF_EVENTS \
# --enable BPF_JIT \
# --enable TRACEPOINTS \
# --enable DEBUG_INFO_BTF \
# --enable IKCONFIG \
# --enable IKCONFIG_PROC \
# --enable IKHEADERS"
fi
menuconfig:
#!/usr/bin/env bash
cd {{ LINUX_DIR }}
{{ KERNEL_SHELL }} "make menuconfig"
build-linux:
#!/usr/bin/env bash
set -xeu
cd {{ LINUX_DIR }}
yes "" | {{ KERNEL_SHELL }} "make KCFLAGS=-Wno-error=missing-prototypes -C {{ LINUX_DIR }} -j$(nproc)"
build-perf:
#!/usr/bin/env bash
set -xeu
cd {{ LINUX_DIR }}/tools/perf
{{ KERNEL_SHELL }} "NIX_CFLAGS_COMPILE='-idirafter /usr/include -O2' make -j$(nproc)"
mkdir -p guest-tools
cp {{ LINUX_DIR }}/tools/perf/perf guest-tools
clean-linux:
{{ KERNEL_SHELL }} "make -C {{ LINUX_DIR }} clean"
setup-linux:
just clone-linux
just configure-linux
just build-linux
setup-linux-tdx:
just clone-linux
just configure-linux-tdx
just build-linux
# ------------------------------
# network settings
setup_bridge:
#!/usr/bin/env bash
ip a s {{BRIDGE_NAME}} >/dev/null 2>&1
if [ $? ]; then
sudo brctl addbr {{BRIDGE_NAME}}
sudo ip a a 172.44.0.1/24 dev {{BRIDGE_NAME}}
sudo ip l set dev {{BRIDGE_NAME}} up
fi
setup_tap:
sudo ip tuntap add {{TAP_NAME}} mode tap
sudo ip link set {{TAP_NAME}} master {{BRIDGE_NAME}}
sudo ip link set {{TAP_NAME}} up
sudo ip tuntap add {{MTAP_NAME}} mode tap multi_queue
sudo ip link set {{MTAP_NAME}} master {{BRIDGE_NAME}}
sudo ip link set {{MTAP_NAME}} up
remove_bridge:
#!/usr/bin/env bash
sudo ip link set dev {{TAP_NAME}} down
sudo ip link del {{TAP_NAME}}
sudo ip link set dev {{MTAP_NAME}} down
sudo ip link del {{MTAP_NAME}}
sudo ip link set dev {{BRIDGE_NAME}} down
sudo brctl delbr {{BRIDGE_NAME}}
# These commands should show info on virbr0
show_bridge_status:
#!/usr/bin/env bash
set -x
ip a show dev {{BRIDGE_NAME}}
brctl show
networkctl
# ------------------------------
# trace
trace name duration="20" interval="1":
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
bash {{PROJECT_ROOT}}/trace/all.sh {{name}} {{duration}} {{interval}} $DATE &
just ssh "bash /share/trace/all.sh {{name}} {{duration}} {{interval}} $DATE"
wait $(jobs -p)
sleep 1
just flamegraph {{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/host/perf.data {{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/host/perf.svg
just flamegraph-guest {{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/guest/perf.data {{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/guest/perf.svg
mpstat name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/host
export OUTDIR
bash {{PROJECT_ROOT}}/trace/mpstat.sh {{name}} &
OUTDIR=/share/trace-result/{{name}}/$DATE/guest
just ssh "OUTDIR=$OUTDIR bash /share/trace/mpstat.sh"
wait $(jobs -p)
vmstat name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE/host
export OUTDIR
bash {{PROJECT_ROOT}}/trace/vmstat.sh {{name}}
OUTDIR=/share/trace-result/{{name}}/$DATE/guest
just ssh "OUTDIR=$OUTDIR bash /share/trace/vmstat.sh"
trace-host name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE
export OUTDIR
bash {{PROJECT_ROOT}}/trace/all.sh
perf-host name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE
export OUTDIR
bash {{PROJECT_ROOT}}/trace/perf.sh
stat-host name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE
export OUTDIR
bash {{PROJECT_ROOT}}/trace/stat.sh {{name}}
mpstat-host name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR={{PROJECT_ROOT}}/trace-result/{{name}}/$DATE
export OUTDIR
bash {{PROJECT_ROOT}}/trace/mpstat.sh {{name}}
trace-guest name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR=/share/trace-result/{{name}}/$DATE
just ssh "OUTDIR=$OUTDIR bash /share/trace/all.sh"
perf-guest name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR=/share/trace-result/{{name}}/$DATE
just ssh "OUTDIR=$OUTDIR bash /share/trace/perf.sh"
stat-guest name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR=/share/trace-result/{{name}}/$DATE
just ssh "OUTDIR=$OUTDIR bash /share/trace/stat.sh"
mpstat-guest name:
#!/usr/bin/env bash
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
OUTDIR=/share/trace-result/{{name}}/$DATE
just ssh "OUTDIR=$OUTDIR bash /share/trace/mpstat.sh"
flamegraph in="perf.data" out="a.svg":
#!/usr/bin/env bash
TMP=$(mktemp -p /tmp)
trap 'rm -f $TMP' EXIT
perf script -i {{in}} | {{PROJECT_ROOT}}/../FlameGraph/stackcollapse-perf.pl > $TMP
{{PROJECT_ROOT}}/../FlameGraph/flamegraph.pl $TMP > {{out}}
flamegraph-guest in="perf.data" out="a.svg":
#!/usr/bin/env bash
TMP=$(mktemp -p /tmp)
trap 'rm -f $TMP' EXIT
perf script -k {{LINUX_DIR}}/vmlinux -i {{in}} | {{PROJECT_ROOT}}/../FlameGraph/stackcollapse-perf.pl > $TMP
{{PROJECT_ROOT}}/../FlameGraph/flamegraph.pl $TMP > {{out}}
# command for the guest (run in the guest)
perf-record sec="10" out="perf.data":
{{KERNEL_SHELL}} "{{PROJECT_ROOT}}/guest-tools/perf record --output {{out}} -a -g -- sleep {{sec}}"
perf-report in="perf.data" out="report.txt":
{{KERNEL_SHELL}} "{{PROJECT_ROOT}}/guest-tools/perf report -i {{in}} -k {{PROJECT_ROOT}}/guest-tools/vmlinux --no-children > {{out}}"