hypervisor: make getThreadIDs return vcpu to threadid mapping

We need such mapping information to put vcpus in container cpuset properly.

Fixes: #1435

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2019-03-27 02:03:23 -07:00
parent ad697cc763
commit 6fda03ec92
5 changed files with 17 additions and 15 deletions

View File

@ -227,7 +227,7 @@ func (s *Sandbox) constrainHypervisor(cgroup cgroups.Cgroup) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to get thread ids from hypervisor: %v", err) return fmt.Errorf("failed to get thread ids from hypervisor: %v", err)
} }
if tids == nil || len(tids.vcpus) == 0 { if len(tids.vcpus) == 0 {
// If there's no tid returned from the hypervisor, this is not // If there's no tid returned from the hypervisor, this is not
// a bug. It simply means there is nothing to constrain, hence // a bug. It simply means there is nothing to constrain, hence
// let's return without any error from here. // let's return without any error from here.

View File

@ -700,10 +700,10 @@ func (fc *firecracker) resizeVCPUs(reqVCPUs uint32) (currentVCPUs uint32, newVCP
// Need to see if there's an easy way to ask firecracker for thread ids associated with // Need to see if there's an easy way to ask firecracker for thread ids associated with
// the vCPUs. Issue opened to ask for per vCPU thread IDs: // the vCPUs. Issue opened to ask for per vCPU thread IDs:
// https://github.com/firecracker-microvm/firecracker/issues/718 // https://github.com/firecracker-microvm/firecracker/issues/718
func (fc *firecracker) getThreadIDs() (*threadIDs, error) { func (fc *firecracker) getThreadIDs() (vcpuThreadIDs, error) {
//TODO: this may not be exactly supported in Firecracker. Closest is cpu-template as part //TODO: this may not be exactly supported in Firecracker. Closest is cpu-template as part
// of get /machine-config // of get /machine-config
return nil, nil return vcpuThreadIDs{}, nil
} }
func (fc *firecracker) cleanup() error { func (fc *firecracker) cleanup() error {

View File

@ -279,8 +279,9 @@ type HypervisorConfig struct {
GuestHookPath string GuestHookPath string
} }
type threadIDs struct { // vcpu mapping from vcpu number to thread number
vcpus []int type vcpuThreadIDs struct {
vcpus map[int]int
} }
func (conf *HypervisorConfig) checkTemplateConfig() error { func (conf *HypervisorConfig) checkTemplateConfig() error {
@ -597,7 +598,7 @@ type hypervisor interface {
disconnect() disconnect()
capabilities() types.Capabilities capabilities() types.Capabilities
hypervisorConfig() HypervisorConfig hypervisorConfig() HypervisorConfig
getThreadIDs() (*threadIDs, error) getThreadIDs() (vcpuThreadIDs, error)
cleanup() error cleanup() error
pid() int pid() int
fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, store *store.VCStore, j []byte) error fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, store *store.VCStore, j []byte) error

View File

@ -94,9 +94,9 @@ func (m *mockHypervisor) resizeVCPUs(cpus uint32) (uint32, uint32, error) {
func (m *mockHypervisor) disconnect() { func (m *mockHypervisor) disconnect() {
} }
func (m *mockHypervisor) getThreadIDs() (*threadIDs, error) { func (m *mockHypervisor) getThreadIDs() (vcpuThreadIDs, error) {
vcpus := []int{os.Getpid()} vcpus := map[int]int{0: os.Getpid()}
return &threadIDs{vcpus}, nil return vcpuThreadIDs{vcpus}, nil
} }
func (m *mockHypervisor) cleanup() error { func (m *mockHypervisor) cleanup() error {

View File

@ -1509,28 +1509,29 @@ func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOff
return memory return memory
} }
func (q *qemu) getThreadIDs() (*threadIDs, error) { func (q *qemu) getThreadIDs() (vcpuThreadIDs, error) {
span, _ := q.trace("getThreadIDs") span, _ := q.trace("getThreadIDs")
defer span.Finish() defer span.Finish()
tid := vcpuThreadIDs{}
err := q.qmpSetup() err := q.qmpSetup()
if err != nil { if err != nil {
return nil, err return tid, err
} }
cpuInfos, err := q.qmpMonitorCh.qmp.ExecQueryCpus(q.qmpMonitorCh.ctx) cpuInfos, err := q.qmpMonitorCh.qmp.ExecQueryCpus(q.qmpMonitorCh.ctx)
if err != nil { if err != nil {
q.Logger().WithError(err).Error("failed to query cpu infos") q.Logger().WithError(err).Error("failed to query cpu infos")
return nil, err return tid, err
} }
var tid threadIDs tid.vcpus = make(map[int]int, len(cpuInfos))
for _, i := range cpuInfos { for _, i := range cpuInfos {
if i.ThreadID > 0 { if i.ThreadID > 0 {
tid.vcpus = append(tid.vcpus, i.ThreadID) tid.vcpus[i.CPU] = i.ThreadID
} }
} }
return &tid, nil return tid, nil
} }
func calcHotplugMemMiBSize(mem uint32, memorySectionSizeMB uint32) (uint32, error) { func calcHotplugMemMiBSize(mem uint32, memorySectionSizeMB uint32) (uint32, error) {