mirror of
https://github.com/ollama/ollama.git
synced 2026-04-26 18:55:53 +02:00
win: fix CPU query buffer handling
Try in a short loop until we get the size right.
This commit is contained in:
@@ -99,27 +99,22 @@ func (pkg *winPackage) IsMember(target *GROUP_AFFINITY) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLogicalProcessorInformationEx() ([]byte, error) {
|
func getLogicalProcessorInformationEx() ([]byte, error) {
|
||||||
buf := make([]byte, 1)
|
buf := make([]byte, 1024)
|
||||||
bufSize := len(buf)
|
bufSize := len(buf)
|
||||||
ret, _, err := GetLogicalProcessorInformationEx.Call(
|
var err error
|
||||||
uintptr(RelationAll),
|
for range 3 {
|
||||||
uintptr(unsafe.Pointer(&buf[0])),
|
var ret uintptr
|
||||||
uintptr(unsafe.Pointer(&bufSize)),
|
|
||||||
)
|
|
||||||
if ret != 0 {
|
|
||||||
return nil, fmt.Errorf("failed to determine size info ret:%d %w", ret, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = make([]byte, bufSize)
|
|
||||||
ret, _, err = GetLogicalProcessorInformationEx.Call(
|
ret, _, err = GetLogicalProcessorInformationEx.Call(
|
||||||
uintptr(RelationAll),
|
uintptr(RelationAll),
|
||||||
uintptr(unsafe.Pointer(&buf[0])),
|
uintptr(unsafe.Pointer(&buf[0])),
|
||||||
uintptr(unsafe.Pointer(&bufSize)),
|
uintptr(unsafe.Pointer(&bufSize)),
|
||||||
)
|
)
|
||||||
if ret == 0 {
|
if ret == 1 && bufSize <= len(buf) {
|
||||||
return nil, fmt.Errorf("failed to gather processor information ret:%d buflen:%d %w", ret, bufSize, err)
|
|
||||||
}
|
|
||||||
return buf, nil
|
return buf, nil
|
||||||
|
}
|
||||||
|
buf = make([]byte, bufSize)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unable to determine CPU details: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage {
|
func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage {
|
||||||
|
|||||||
Reference in New Issue
Block a user