5
5
"github.com/pnsafonov/pind/pkg/config"
6
6
"github.com/pnsafonov/pind/pkg/http_api"
7
7
"github.com/pnsafonov/pind/pkg/numa"
8
+ "github.com/prometheus/procfs"
8
9
log "github.com/sirupsen/logrus"
10
+ "golang.org/x/sys/unix"
9
11
"os"
10
12
"os/signal"
11
13
"syscall"
@@ -68,6 +70,12 @@ func RunService(ctx *Context) error {
68
70
return err
69
71
}
70
72
73
+ err = pinSelfProcess (ctx )
74
+ if err != nil {
75
+ log .Errorf ("RunService, pinSelfProcess err = %v" , err )
76
+ return err
77
+ }
78
+
71
79
err = doHttpApi (ctx )
72
80
if err != nil {
73
81
log .Errorf ("RunService, doHttpApi err = %v" , err )
@@ -80,6 +88,31 @@ func RunService(ctx *Context) error {
80
88
return nil
81
89
}
82
90
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
+
83
116
func doHttpApi (ctx * Context ) error {
84
117
if ! ctx .HttpApi .Config .Enabled {
85
118
return nil
0 commit comments