-
Notifications
You must be signed in to change notification settings - Fork 63
/
qemu_smp.go
68 lines (56 loc) · 1.83 KB
/
qemu_smp.go
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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package qemu
import (
"strconv"
"strings"
)
type QemuSMP struct {
// CPUs sets the number of CPUs (default is 1)
CPUs uint64 `json:"cpus,omitempty"`
// MaxCPUs is the maximum number of total CPUs, including offline CPUs for
// hotplug, etc.
MaxCPUs uint64 `json:"max_cpus,omitempty"`
// Cores is the number of CPU cores on one socket (for PC, it's on one die)
Cores uint64 `json:"cores,omitempty"`
// Threads is the number of threads on one CPU core
Threads uint64 `json:"threads,omitempty"`
// Dies is the number of CPU dies on one socket (for PC only)
Dies uint64 `json:"dies,omitempty"`
// Sockets is the number of discrete sockets in the system
Sockets uint64 `json:"sockets,omitempty"`
}
// String returns a QEMU command-line compatible -smp flag value in the format:
// [cpus=]n[,maxcpus=cpus][,cores=cores][,threads=threads][,dies=dies]
// [,sockets=sockets]
func (qsmp QemuSMP) String() string {
if qsmp.CPUs <= 0 {
return ""
}
var ret strings.Builder
ret.WriteString("cpus=")
ret.WriteString(strconv.FormatUint(qsmp.CPUs, 10))
if qsmp.MaxCPUs > 0 {
ret.WriteString(",maxcpus=")
ret.WriteString(strconv.FormatUint(qsmp.MaxCPUs, 10))
}
if qsmp.Cores > 0 {
ret.WriteString(",cores=")
ret.WriteString(strconv.FormatUint(qsmp.Cores, 10))
}
if qsmp.Threads > 0 {
ret.WriteString(",threads=")
ret.WriteString(strconv.FormatUint(qsmp.Threads, 10))
}
if qsmp.Dies > 0 {
ret.WriteString(",dies=")
ret.WriteString(strconv.FormatUint(qsmp.Dies, 10))
}
if qsmp.Sockets > 0 {
ret.WriteString(",sockets=")
ret.WriteString(strconv.FormatUint(qsmp.Sockets, 10))
}
return ret.String()
}