summaryrefslogtreecommitdiff
path: root/qemu.in
blob: c3385f85d782226307609b43eb454141ee0d551e (plain)
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
#!/usr/bin/env bash
shopt -s lastpipe
set -euE -o pipefail

declare -A vcpu2cpulist
numactl=()
source "@pkgconfdir@/$1"
args+=(
	-name "$1",debug-threads=on
	-runas "$USER"
	-pidfile "@runstatedir@/qemu-$1/pid"

	-vnc     unix:"@runstatedir@/qemu-$1/vnc.sock"
	-monitor unix:"@runstatedir@/qemu-$1/monitor.sock",server,nowait
	-serial  file:"/dev/stdout"

	-daemonize
)

{
	numactl "${numactl[@]}" -- qemu-system-"${system}" "${args[@]}"

	if [[ ${vcpu2cpulist+${#vcpu2cpulist[@]}} -gt 0 ]]; then
		declare -A vcpu2tid
		while read -r line; do
			if [[ $line != ?' CPU #'*:*thread_id=* ]]; then
				continue
			fi
			vcpu=${line#?' CPU #'}; vcpu=${vcpu%%:*}
			tid=${line#thread_id=}; tid=${tid%% *}
			vcpu2tid[$vcpu]=$tid
		done < <(socat STDIO UNIX-CONNECT:"@runstatedir@/qemu-$1/monitor.sock" <<<'info cpus')

		for vcpu in "${!vcpu_pins[@]}"; do
			taskset --cpu-list --pid -- "${vcpu2cpulist[@]}" "${vcpu2tid[$vcpu]}"
		done
	fi

	systemd-notify --ready
} | exec cat