Skip to content

Commit eac142e

Browse files
committed
pin pind to idle cores
1 parent ff919c9 commit eac142e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

info.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
git tag v1.0.1
33
git push origin tag v1.0.1
44

5+
taskset -a -c -p 337547
56
sched_getaffinity
67

78
go get github.com/sirupsen/[email protected]

pkg/service.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"github.com/pnsafonov/pind/pkg/config"
66
"github.com/pnsafonov/pind/pkg/http_api"
77
"github.com/pnsafonov/pind/pkg/numa"
8+
"github.com/prometheus/procfs"
89
log "github.com/sirupsen/logrus"
10+
"golang.org/x/sys/unix"
911
"os"
1012
"os/signal"
1113
"syscall"
@@ -68,6 +70,12 @@ func RunService(ctx *Context) error {
6870
return err
6971
}
7072

73+
err = pinSelfProcess(ctx)
74+
if err != nil {
75+
log.Errorf("RunService, pinSelfProcess err = %v", err)
76+
return err
77+
}
78+
7179
err = doHttpApi(ctx)
7280
if err != nil {
7381
log.Errorf("RunService, doHttpApi err = %v", err)
@@ -80,6 +88,31 @@ func RunService(ctx *Context) error {
8088
return nil
8189
}
8290

91+
// pinSelfProcess - привязать все потоки текущего процесса
92+
// к idle ядрам
93+
func pinSelfProcess(ctx *Context) error {
94+
pid := os.Getpid()
95+
log.Printf("pid = %d", pid)
96+
set := &ctx.state.Idle.CpuSet
97+
98+
threads, err := procfs.AllThreads(pid)
99+
if err != nil {
100+
log.Errorf("pinSelfProcess, procfs.AllThreads err = %v, pid = %d", err, pid)
101+
return err
102+
}
103+
l1 := len(threads)
104+
for j := 0; j < l1; j++ {
105+
thread := threads[j]
106+
err := unix.SchedSetaffinity(thread.PID, set)
107+
if err != nil {
108+
log.Errorf("pinSelfProcess, schedSetaffinity err = %v, thread pid = %d", err, thread.PID)
109+
return err
110+
}
111+
}
112+
113+
return nil
114+
}
115+
83116
func doHttpApi(ctx *Context) error {
84117
if !ctx.HttpApi.Config.Enabled {
85118
return nil

0 commit comments

Comments
 (0)