Conversation
Spec: opencontainers/runtime-spec#1188 Fix: opencontainers#3895 Signed-off-by: utam0k <k0ma@utam0k.jp>
| SchedDeadline: scheduler.Deadline, | ||
| SchedPeriod: scheduler.Period, | ||
| } | ||
| _, _, errno := syscall.Syscall(C.SYS_sched_setattr, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(0)) |
There was a problem hiding this comment.
| _, _, errno := syscall.Syscall(C.SYS_sched_setattr, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(0)) | |
| _, _, errno := syscall.Syscall(unix.SYS_SCHED_SETATTR, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(0)) |
| [ "$status" -eq 0 ] | ||
| [[ "${lines[0]}" == *"scheduling policy: SCHED_DEADLINE"* ]] | ||
| [[ "${lines[1]}" == *"priority: 0"* ]] | ||
| [[ "${lines[2]}" == *"runtime/deadline/period parameters: 42000/1000000/1000000"* ]] |
There was a problem hiding this comment.
* should be avoided for comparing numbers
| [[ "${lines[2]}" == *"runtime/deadline/period parameters: 42000/1000000/1000000"* ]] | |
| [[ "${lines[2]}" == "runtime/deadline/period parameters: 42000/1000000/1000000" ]] |
| return os.NewFile(uintptr(fds[1]), name+"-p"), os.NewFile(uintptr(fds[0]), name+"-c"), nil | ||
| } | ||
|
|
||
| type schedAttr struct { |
There was a problem hiding this comment.
I would want to be very sure that the padding is handled here exactly the same as with C. Can we make this a CGo structure? Or does Go have padding guarantees that match C?
| // SetSchedAttr sets the scheduler attributes for the process with the given pid. | ||
| // Please refer to the following link for kernel-specific values: | ||
| // https://github.com/torvalds/linux/blob/c1a515d3c0270628df8ae5f5118ba859b85464a2/include/uapi/linux/sched.h#L111-L134 | ||
| func SetSchedAttr(pid int, scheduler *configs.Scheduler) error { |
There was a problem hiding this comment.
Is there a reason golang.org/x/sys/unix doesn't have a wrapper for this? This syscall is fairly old -- first added in Linux 3.14.
There was a problem hiding this comment.
My best guess is "no one bothered to". Let me give it a try.
There was a problem hiding this comment.
Here's my attempt https://go-review.googlesource.com/c/sys/+/516756
(my best guess is "because of this ugly linux/glibc header conflict" now)
| } | ||
| _, _, errno := syscall.Syscall(C.SYS_sched_setattr, uintptr(pid), uintptr(unsafe.Pointer(attr)), uintptr(0)) | ||
| if errno != 0 { | ||
| return errno |
There was a problem hiding this comment.
I think we should wrap an new error to indicate what's the error's exact means.
There is a case, if cpus in config.json doesn't include all CPUs in the system, sched_setattr(2) will fail with EPERM, but the error msg of runc is:
ERRO[0000] runc run failed: unable to start container process: error during container init: error setting scheduler: operation not permitted
Most of us may not know what happened.
Please refer: https://man7.org/linux/man-pages/man2/sched_setattr.2.html,
| return (st1.Dev == st2.Dev) && (st1.Ino == st2.Ino), nil | ||
| } | ||
|
|
||
| func scheduler(config *configs.Config) error { |
There was a problem hiding this comment.
Shall we need to check the conflict with CPUs?
EPERM The CPU affinity mask of the thread specified by pid does
not include all CPUs in the system
|
ping @utam0k Could you please rebase and resolve the conflicting files? |
| // Scheduler is based on the Linux sched_setattr(2) syscall. | ||
| type Scheduler struct { | ||
| Policy specs.LinuxSchedulerPolicy `json:"policy"` | ||
| Nice int32 `json:"nice,omitempty"` | ||
| Priority int32 `json:"priority,omitempty"` | ||
| Flags []specs.LinuxSchedulerFlag `json:"flags,omitempty"` | ||
| Runtime uint64 `json:"runtime,omitempty"` | ||
| Deadline uint64 `json:"deadline,omitempty"` | ||
| Period uint64 `json:"period,omitempty"` |
There was a problem hiding this comment.
So, can we maybe do type Scheduler = specs.Scheduler here?
| NoMountFallback bool `json:"no_mount_fallback,omitempty"` | ||
|
|
||
| // Scheduler represents the scheduling attributes for a process. | ||
| Scheduler *Scheduler `json:"shceduler,omitempty"` |
There was a problem hiding this comment.
typo in json attribute name
| if spec.Process.Scheduler != nil { | ||
| config.Scheduler = &configs.Scheduler{ | ||
| Policy: spec.Process.Scheduler.Policy, | ||
| Nice: spec.Process.Scheduler.Nice, | ||
| Priority: spec.Process.Scheduler.Priority, | ||
| Flags: spec.Process.Scheduler.Flags, | ||
| Runtime: spec.Process.Scheduler.Runtime, | ||
| Deadline: spec.Process.Scheduler.Deadline, | ||
| Period: spec.Process.Scheduler.Period, | ||
| } | ||
| } |
There was a problem hiding this comment.
Since spec.Process.Scheduler is of the same type as config.Scheduler, you can just assign it directly, no need to go field-by-field.
|
Needs rebase. |
|
@lifubang I have been away from this PR. If you are interested, please do 🙏 |
Spec: opencontainers/runtime-spec#1188
Fix: #3895