c7a2fecc69893ebbe934d6e25cc308ef382e6b2f
[kvmfornfv.git] / ci / envs / host-run-qemu.sh
1 #!/bin/bash
2
3 ##############################################################################
4 ## Copyright (c) 2015 Intel Corp.
5 ##
6 ## All rights reserved. This program and the accompanying materials
7 ## are made available under the terms of the Apache License, Version 2.0
8 ## which accompanies this distribution, and is available at
9 ## http://www.apache.org/licenses/LICENSE-2.0
10 ###############################################################################
11
12 source host-config
13
14 cpumask () {
15     m=$((1<<${1}))
16     printf 0x%x ${m}
17 }
18
19 qmp_sock="/tmp/qmp-sock-$$"
20
21 ${qemu} -smp ${guest_cpus} -monitor unix:${qmp_sock},server,nowait -daemonize \
22     -cpu host,migratable=off,+invtsc,+tsc-deadline,pmu=off \
23     -realtime mlock=on -mem-prealloc -enable-kvm -m 1G \
24     -mem-path /mnt/hugetlbfs-1g \
25     -drive file=/root/workspace/image/guest.img,cache=none,aio=threads \
26     -netdev user,id=guest0,hostfwd=tcp::5555-:22 \
27     -device virtio-net-pci,netdev=guest0 \
28     -nographic -serial /dev/null -parallel /dev/null
29
30 i=0
31 for c in `echo ${host_isolcpus} | sed 's/,/ /g'` ; do
32     cpu[$i]=${c}
33     i=`expr $i + 1`
34 done
35
36 threads=`echo "info cpus" | nc -U ${qmp_sock} | grep thread_id | cut -d= -f3`
37
38 # Bind QEMU processor threads to RT CPUs
39 i=0
40 for tid in ${threads} ; do
41     tid=`printf %d ${tid}`  # this is required to get rid of cr at end
42     mask=`cpumask ${cpu[$i]}`
43     taskset -p ${mask} ${tid}
44     i=`expr $i + 1`
45 done