MCPcopy
hub / github.com/opencontainers/runc / startWithCPUAffinity

Method startWithCPUAffinity

libcontainer/process_linux.go:215–240  ·  view source on GitHub ↗

Starts setns process with specified initial CPU affinity.

()

Source from the content-addressed store, hash-verified

213
214// Starts setns process with specified initial CPU affinity.
215func (p *setnsProcess) startWithCPUAffinity() error {
216 aff := p.config.CPUAffinity
217 if aff == nil || aff.Initial == nil {
218 return p.cmd.Start()
219 }
220 errCh := make(chan error)
221 defer close(errCh)
222
223 // Use a goroutine to dedicate an OS thread.
224 go func() {
225 runtime.LockOSThread()
226 // Command inherits the CPU affinity.
227 if err := unix.SchedSetaffinity(unix.Gettid(), aff.Initial); err != nil {
228 errCh <- fmt.Errorf("error setting initial CPU affinity: %w", err)
229 return
230 }
231
232 errCh <- p.cmd.Start()
233 // Deliberately omit runtime.UnlockOSThread here.
234 // https://pkg.go.dev/runtime#LockOSThread says:
235 // "If the calling goroutine exits without unlocking the
236 // thread, the thread will be terminated".
237 }()
238
239 return <-errCh
240}
241
242func (p *setnsProcess) setFinalCPUAffinity() error {
243 aff := p.config.CPUAffinity

Callers 1

startWithCgroupFDMethod · 0.95

Calls 1

StartMethod · 0.80

Tested by

no test coverage detected