mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-25 07:34:58 -04:00
fix(xsysinfo): avoid startup hang on intel_gpu_top (#12206)
Use -n 1 for a single JSON sample instead of -s 1, which sets a 1 ms refresh period and runs until interrupted on current intel_gpu_top. Fixes #12205 Signed-off-by: leilei3167 <imleilei123@gmail.com>
This commit is contained in:
1 parent
e7306a087a
commit
9cbfa88a5c
2 files changed
+25
-2
No files matched your search
+13
-2
@@ -3,6 +3,7 @@ package xsysinfo
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/jaypipes/ghw"
|
||||
"github.com/jaypipes/ghw/pkg/gpu"
|
||||
@@ -926,14 +928,23 @@ func getIntelXPUSMI() []GPUMemoryInfo {
|
||||
return gpus
|
||||
}
|
||||
|
||||
// intelGPUTopArgs returns flags for a single JSON sample from intel_gpu_top.
|
||||
// Do not use -s 1: on current intel_gpu_top, -s is the refresh period in
|
||||
// milliseconds and the default iteration count is infinite, which blocks startup.
|
||||
func intelGPUTopArgs() []string {
|
||||
return []string{"-J", "-n", "1"}
|
||||
}
|
||||
|
||||
// getIntelGPUTop queries Intel GPUs using intel_gpu_top
|
||||
func getIntelGPUTop() []GPUMemoryInfo {
|
||||
if _, err := exec.LookPath("intel_gpu_top"); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// intel_gpu_top with -J outputs JSON, -s 1 for single sample
|
||||
cmd := exec.Command("intel_gpu_top", "-J", "-s", "1")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
cmd := exec.CommandContext(ctx, "intel_gpu_top", intelGPUTopArgs()...)
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package xsysinfo
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("intelGPUTopArgs", func() {
|
||||
It("requests one JSON sample instead of an infinite 1ms refresh loop", func() {
|
||||
Expect(intelGPUTopArgs()).To(Equal([]string{"-J", "-n", "1"}))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user