コード例 #1
0
ファイル: hwinfo.go プロジェクト: weldpua2008/deployer
func (c *Config) SetTopologySingleVirtualNUMA(numas host.NUMANodes, singleNuma bool) error {
	// file, _ := os.Create("/tmp/1SetTopologyMultipleVirtualNUMAs.txt")
	// defer file.Close()
	// file.WriteString("SetTopologySingleVirtualNUMA\n")

	if c.CPUs == 0 {
		return errors.New("A data memeber (CPUs) is not initialized")
	}
	if c.RamMb == 0 {
		return errors.New("A data memeber (RamMb) is not initialized")
	}

	c.NUMAs = nil
	gn := new(NUMA)
	gn.CellID = 0
	gn.MemoryMb = c.RamMb
	gn.NICs = nil
	gn.CPUPin = make(map[int][]int, 0)
	nicNumaMapping, _ := numaNicsMapping(c, numas)

	for _, n := range numas {
		l, ok := nicNumaMapping[n.CellID]
		if ok {
			gn.NICs.AppendList(l)
		}
	}

	if singleNuma {
		// file.WriteString("SetTopologySingleVirtualNUMA singleNuma\n")
		cpusNuma0, err := numas.CpusOnNUMA(0)
		if err != nil {
			// file.WriteString("SetTopologySingleVirtualNUMA  cpusNuma0 err: " + err.Error() + "\n")
			return err
		}
		// file.WriteString("SetTopologySingleVirtualNUMA len(cpusNuma0): " + strconv.Itoa(len(cpusNuma0)) + "\n")
		// file.WriteString("SetTopologySingleVirtualNUMA c.CPUs: " + strconv.Itoa(c.CPUs) + "\n")
		if c.CPUs <= len(cpusNuma0) {
			// file.WriteString("c.CPUs <= len(cpusNuma0) \n")
			for i := 0; i < c.CPUs; i++ {
				gn.CPUPin[i] = append(gn.CPUPin[i], i)
			}

		} else {
			// file.WriteString("c.CPUs > len(cpusNuma0) \n")
			for i := 0; i < c.CPUs; i++ {
				gn.CPUPin[i] = append(gn.CPUPin[i], i)
			}
		}
		c.HostNUMAIds = []int{0}
	} else {
		// file.WriteString("SetTopologySingleVirtualNUMA not singleNuma\n")
		// file.WriteString("SetTopologySingleVirtualNUMA c.CPUs " + strconv.Itoa(c.CPUs) + "\n")
		for i := 0; i < c.CPUs; i++ {
			// file.WriteString("SetTopologySingleVirtualNUMA i: " + strconv.Itoa(i) + "\n")
			for _, n := range numas {
				gn.CPUPin[i] = append(gn.CPUPin[i], n.CPUs...)
				c.HostNUMAIds = append(c.HostNUMAIds, n.CellID)
			}
		}
	}

	c.NUMAs = append(c.NUMAs, gn)
	return nil
}