Starts setns process with specified initial CPU affinity.
()
| 213 | |
| 214 | // Starts setns process with specified initial CPU affinity. |
| 215 | func (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 | |
| 242 | func (p *setnsProcess) setFinalCPUAffinity() error { |
| 243 | aff := p.config.CPUAffinity |
no test coverage detected