// GetCPU - adds information about the host cpu to the supplied map
439013
func GetCPU() (info *CPU, err error) {
	info = &CPU{}

	// get physical cpu stats
	var cpus []cpu.InfoStat
	if cpus, err = cpuInfo(); err != nil {
		return info, err
	}

	info.HostPhysicalCPUs = len(cpus)

	// get logical cpu stats
	if info.HostLogicalCPUs, err = cpuCounts(true); err != nil {
		return info, err
	}

	// total number of cpu cores
	for _, cpu := range cpus {
		info.HostCPUCores += int64(cpu.Cores)
		// TODO: This is not ideal... if there are different processors
		// we will only report one of the models... This is unlikely to happen,
		// but it could
		info.HostCPUModel = cpu.ModelName
	}

	err = fillPlatformSpecificCPUData(info)
	return info, err
}
1154633
func (_class HostClass) GetPCIs(sessionID SessionRef, self HostRef) (_retval []PCIRef, _err error) {
	_method := "host.get_PCIs"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertHostRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertPCIRefSetToGo(_method + " -> ", _result.Value)
	return
}
811611
func (Ctx *Context) GetMaxCpus() (maxCpus int, err error) {
	err = Ctx.CheckOpen()
	if err != nil {
		return
	}

	ret := C.libxl_get_max_cpus(Ctx.ctx)
	if ret < 0 {
		err = Error(-ret)
		return
	}
	maxCpus = int(ret)
	return
}
442719
func (g *Generator) InitConfigLinuxResourcesCPU() {
	g.initConfigLinuxResources()
	if g.Config.Linux.Resources.CPU == nil {
		g.Config.Linux.Resources.CPU = &rspec.LinuxCPU{}
	}
}
827010
func (_class HostCPUClass) GetFamily(sessionID SessionRef, self HostCPURef) (_retval int, _err error) {
	_method := "host_cpu.get_family"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertHostCPURefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertIntToGo(_method + " -> ", _result.Value)
	return
}
462691
func (c CPUInfo) LogicalCPU() int {
	if c.maxFunc < 1 {
		return -1
	}
	_, ebx, _, _ := cpuid(1)
	return int(ebx >> 24)
}
1233615
func (_class HostCPUClass) GetAll(sessionID SessionRef) (_retval []HostCPURef, _err error) {
	_method := "host_cpu.get_all"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertHostCPURefSetToGo(_method + " -> ", _result.Value)
	return
}
954301
func setCPU(cpu string) error {
	var numCPU int

	availCPU := runtime.NumCPU()

	if strings.HasSuffix(cpu, "%") {
		// Percent
		var percent float32
		pctStr := cpu[:len(cpu)-1]
		pctInt, err := strconv.Atoi(pctStr)
		if err != nil || pctInt < 1 || pctInt > 100 {
			return errors.New("invalid CPU value: percentage must be between 1-100")
		}
		percent = float32(pctInt) / 100
		numCPU = int(float32(availCPU) * percent)
		if numCPU < 1 {
			numCPU = 1
		}
	} else {
		// Number
		num, err := strconv.Atoi(cpu)
		if err != nil || num < 1 {
			return errors.New("invalid CPU value: provide a number or percent greater than 0")
		}
		numCPU = num
	}

	if numCPU > availCPU {
		numCPU = availCPU
	}

	runtime.GOMAXPROCS(numCPU)
	return nil
}
172739
func (_class PGPUClass) GetHost(sessionID SessionRef, self PGPURef) (_retval HostRef, _err error) {
	_method := "PGPU.get_host"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertPGPURefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertHostRefToGo(_method + " -> ", _result.Value)
	return
}
517054
func (_class HostCPUClass) GetAllRecords(sessionID SessionRef) (_retval map[HostCPURef]HostCPURecord, _err error) {
	_method := "host_cpu.get_all_records"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertHostCPURefToHostCPURecordMapToGo(_method + " -> ", _result.Value)
	return
}
293527
func Get() (stat *CPUStats, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Get()
}
254924
func (pc DonutChart) GetDPI(defaults ...float64) float64 {
	if pc.DPI == 0 {
		if len(defaults) > 0 {
			return defaults[0]
		}
		return DefaultDPI
	}
	return pc.DPI
}
640469
func (d *Domain) SetGuestVcpus(cpus []bool, state bool, flags uint32) error {
	if C.LIBVIR_VERSION_NUMBER < 2000000 {
		return makeNotImplementedError("virDomainSetGuestVcpus")
	}

	cpumap := ""
	for i := 0; i < len(cpus); i++ {
		if cpus[i] {
			if cpumap == "" {
				cpumap = string(i)
			} else {
				cpumap += "," + string(i)
			}
		}
	}

	var cstate C.int
	if state {
		cstate = 1
	} else {
		cstate = 0
	}
	ccpumap := C.CString(cpumap)
	defer C.free(unsafe.Pointer(ccpumap))
	var err C.virError
	ret := C.virDomainSetGuestVcpusWrapper(d.ptr, ccpumap, cstate, C.uint(flags), &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
1174390
func (_class HostClass) GetPGPUs(sessionID SessionRef, self HostRef) (_retval []PGPURef, _err error) {
	_method := "host.get_PGPUs"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertHostRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertPGPURefSetToGo(_method + " -> ", _result.Value)
	return
}
20933
func (cg *CgroupV1) GetCPUData(pid int, cgPath string) (*rspec.LinuxCPU, error) {
	if filepath.IsAbs(cgPath) {
		path := filepath.Join(cg.MountPath, "cpu", cgPath)
		if _, err := os.Stat(path); err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
			}
			return nil, err
		}
	}
	lc := &rspec.LinuxCPU{}
	names := []string{"shares", "cfs_quota_us", "cfs_period_us"}
	for i, name := range names {
		fileName := strings.Join([]string{"cpu", name}, ".")
		filePath := filepath.Join(cg.MountPath, "cpu", cgPath, fileName)
		if !filepath.IsAbs(cgPath) {
			subPath, err := GetSubsystemPath(pid, "cpu")
			if err != nil {
				return nil, err
			}
			if !strings.Contains(subPath, cgPath) {
				return nil, fmt.Errorf("cgroup subsystem %s is not mounted as expected", "cpu")
			}
			filePath = filepath.Join(cg.MountPath, "cpu", subPath, fileName)
		}
		contents, err := ioutil.ReadFile(filePath)
		if err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
			}

			return nil, err
		}
		switch i {
		case 0:
			res, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 64)
			if err != nil {
				return nil, err
			}
			shares := res
			lc.Shares = &shares
		case 1:
			res, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
			if err != nil {
				return nil, err
			}
			quota := res
			lc.Quota = &quota
		case 2:
			res, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 64)
			if err != nil {
				return nil, err
			}
			period := res
			lc.Period = &period
		}
	}
	// CONFIG_RT_GROUP_SCHED may be not set
	// Can always get rt data from /proc
	contents, err := ioutil.ReadFile("/proc/sys/kernel/sched_rt_period_us")
	if err != nil {
		return nil, err
	}
	rtPeriod, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 64)
	if err != nil {
		return nil, err
	}
	lc.RealtimePeriod = &rtPeriod
	contents, err = ioutil.ReadFile("/proc/sys/kernel/sched_rt_runtime_us")
	if err != nil {
		return nil, err
	}
	rtQuota, err := strconv.ParseInt(strings.TrimSpace(string(contents)), 10, 64)
	if err != nil {
		return nil, err
	}
	lc.RealtimeRuntime = &rtQuota

	names = []string{"cpus", "mems"}
	for i, name := range names {
		fileName := strings.Join([]string{"cpuset", name}, ".")
		filePath := filepath.Join(cg.MountPath, "cpuset", cgPath, fileName)
		if !filepath.IsAbs(cgPath) {
			subPath, err := GetSubsystemPath(pid, "cpuset")
			if err != nil {
				return nil, err
			}
			if !strings.Contains(subPath, cgPath) {
				return nil, fmt.Errorf("cgroup subsystem %s is not mounted as expected", "cpuset")
			}
			filePath = filepath.Join(cg.MountPath, "cpuset", subPath, fileName)
		}
		contents, err := ioutil.ReadFile(filePath)
		if err != nil {
			return nil, err
		}
		switch i {
		case 0:
			lc.Cpus = strings.TrimSpace(string(contents))
		case 1:
			lc.Mems = strings.TrimSpace(string(contents))
		}
	}

	return lc, nil
}
649371
func getCompute(c context.Context) *compute.Service {
	return c.Value(&gceKey).(*compute.Service)
}
871294
func (_class VGPUTypeClass) GetVGPUs(sessionID SessionRef, self VGPUTypeRef) (_retval []VGPURef, _err error) {
	_method := "VGPU_type.get_VGPUs"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVGPUTypeRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVGPURefSetToGo(_method + " -> ", _result.Value)
	return
}