lxd/util/resources.go
func CPUResource() (*api.ResourcesCPU, error) {
	c := api.ResourcesCPU{}

	threads, err := getThreads()
	if err != nil {
		return nil, err
	}

	var cur *api.ResourcesCPUSocket
	c.Total = uint64(len(threads))

	for _, v := range threads {
		if uint64(len(c.Sockets)) <= v.socketID {
			c.Sockets = append(c.Sockets, api.ResourcesCPUSocket{})
			cur = &c.Sockets[v.socketID]

			// Count the number of cores on the socket
			// Note that we can't assume sequential core IDs
			socketCores := map[uint64]bool{}
			for _, thread := range threads {
				if thread.socketID != v.socketID {
					continue
				}

				socketCores[thread.coreID] = true
			}
			cur.Cores = uint64(len(socketCores))
		} else {
			cur = &c.Sockets[v.socketID]
		}

		cur.Socket = v.socketID
		cur.NUMANode = v.numaNode
		cur.Threads++
		cur.Name = v.name
		cur.Vendor = v.vendor
		cur.Frequency = v.frequency
		cur.FrequencyTurbo = v.frequencyTurbo
	}

	return &c, nil
}
func CPUResource() (*api.ResourcesCPU, error) {
	c := api.ResourcesCPU{}

	threads, err := getThreads()
	if err != nil {
		return nil, err
	}

	var cur *api.ResourcesCPUSocket
	c.Total = uint64(len(threads))

	for _, v := range threads {
		if uint64(len(c.Sockets)) <= v.socketID {
			c.Sockets = append(c.Sockets, api.ResourcesCPUSocket{})
			cur = &c.Sockets[v.socketID]

			// Count the number of cores on the socket
			// Note that we can't assume sequential core IDs
			socketCores := map[uint64]bool{}
			for _, thread := range threads {
				if thread.socketID != v.socketID {
					continue
				}

				socketCores[thread.coreID] = true
			}
			cur.Cores = uint64(len(socketCores))
		} else {
			cur = &c.Sockets[v.socketID]
		}

		cur.Socket = v.socketID
		cur.NUMANode = v.numaNode
		cur.Threads++
		cur.Name = v.name
		cur.Vendor = v.vendor
		cur.Frequency = v.frequency
		cur.FrequencyTurbo = v.frequencyTurbo
	}

	return &c, nil
}
func CPUResource ( ) ( * api . ResourcesCPU , error ) { c := api . ResourcesCPU { } threads , err := getThreads ( ) if err != nil { return nil , err } var cur * api . ResourcesCPUSocket c . Total = uint64 ( len ( threads ) ) for _ , v := range threads { if uint64 ( len ( c . Sockets ) ) <= v . socketID { c . Sockets = append ( c . Sockets , api . ResourcesCPUSocket { } ) cur = & c . Sockets [ v . socketID ] // Count the number of cores on the socket // Note that we can't assume sequential core IDs socketCores := map [ uint64 ] bool { } for _ , thread := range threads { if thread . socketID != v . socketID { continue } socketCores [ thread . coreID ] = true } cur . Cores = uint64 ( len ( socketCores ) ) } else { cur = & c . Sockets [ v . socketID ] } cur . Socket = v . socketID cur . NUMANode = v . numaNode cur . Threads ++ cur . Name = v . name cur . Vendor = v . vendor cur . Frequency = v . frequency cur . FrequencyTurbo = v . frequencyTurbo } return & c , nil }
// CPUResource returns the system CPU information
CPUResource returns the system CPU information