Unverified Commit 97e05d2a authored by Daniel Hiltgen's avatar Daniel Hiltgen Committed by GitHub
Browse files

win: revert CPU discovery logic to 0.12.3 (#12969)

The behavior change in 0.12.4 is the most likely the root cause of hangs some
users are seeing.  This reverts to the 0.12.3 code, with some added trace
logging.
parent 8bbc7395
...@@ -5,6 +5,8 @@ import ( ...@@ -5,6 +5,8 @@ import (
"log/slog" "log/slog"
"syscall" "syscall"
"unsafe" "unsafe"
"github.com/ollama/ollama/logutil"
) )
type MEMORYSTATUSEX struct { type MEMORYSTATUSEX struct {
...@@ -99,22 +101,29 @@ func (pkg *winPackage) IsMember(target *GROUP_AFFINITY) bool { ...@@ -99,22 +101,29 @@ func (pkg *winPackage) IsMember(target *GROUP_AFFINITY) bool {
} }
func getLogicalProcessorInformationEx() ([]byte, error) { func getLogicalProcessorInformationEx() ([]byte, error) {
buf := make([]byte, 1024) buf := make([]byte, 1)
bufSize := len(buf) bufSize := len(buf)
var err error ret, _, err := GetLogicalProcessorInformationEx.Call(
for range 3 {
var ret uintptr
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 == 1 && bufSize <= len(buf) { if ret != 0 {
return buf, nil logutil.Trace("failed to retrieve CPU payload size", "ret", ret, "size", bufSize, "error", err)
return nil, fmt.Errorf("failed to determine size info ret:%d %w", ret, err)
} }
buf = make([]byte, bufSize) buf = make([]byte, bufSize)
ret, _, err = GetLogicalProcessorInformationEx.Call(
uintptr(RelationAll),
uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(&bufSize)),
)
if ret == 0 {
logutil.Trace("failed to retrieve CPU information", "ret", ret, "size", len(buf), "new_size", bufSize, "error", err)
return nil, fmt.Errorf("failed to gather processor information ret:%d buflen:%d %w", ret, bufSize, err)
} }
return nil, fmt.Errorf("unable to determine CPU details: %w", err) return buf, nil
} }
func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage { func processSystemLogicalProcessorInforationList(buf []byte) []*winPackage {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment