File tree 2 files changed +9
-3
lines changed
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import (
27
27
"os/exec"
28
28
"path/filepath"
29
29
"reflect"
30
+ "runtime"
30
31
"strconv"
31
32
"strings"
32
33
"sync"
@@ -821,7 +822,8 @@ func TestRuntimeSpec(t *testing.T) {
821
822
t .Errorf ("Wrong CPU period value: %d" , * runtimeSpec .Linux .Resources .CPU .Period )
822
823
}
823
824
824
- if * runtimeSpec .Linux .Resources .CPU .Quota != int64 (* serviceConfig .Quotas .CPULimit ) {
825
+ if * runtimeSpec .Linux .Resources .CPU .Quota != int64 (* serviceConfig .Quotas .CPULimit *
826
+ (* runtimeSpec .Linux .Resources .CPU .Period )* uint64 (runtime .NumCPU ())/ nodeInfoProvider .nodeInfo .MaxDMIPs ) {
825
827
t .Errorf ("Wrong CPU quota value: %d" , * runtimeSpec .Linux .Resources .CPU .Quota )
826
828
}
827
829
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import (
26
26
"os/user"
27
27
"path"
28
28
"path/filepath"
29
+ "runtime"
29
30
"strconv"
30
31
"strings"
31
32
@@ -45,6 +46,8 @@ import (
45
46
* Consts
46
47
**********************************************************************************************************************/
47
48
49
+ const defaultCPUPeriod uint64 = 100000
50
+
48
51
const cgroupsPath = "/system.slice/system-aos\\ x2dservice.slice/"
49
52
50
53
const (
@@ -112,9 +115,10 @@ func (spec *runtimeSpec) setCPULimit(cpuLimit uint64) {
112
115
spec .ociSpec .Linux .Resources .CPU = & runtimespec.LinuxCPU {}
113
116
}
114
117
115
- cpuQuota := int64 (cpuLimit )
118
+ cpuPeriod := defaultCPUPeriod
119
+ cpuQuota := int64 (cpuLimit * defaultCPUPeriod * uint64 (runtime .NumCPU ()) / spec .nodeInfo .MaxDMIPs )
116
120
117
- spec .ociSpec .Linux .Resources .CPU .Period = & spec . nodeInfo . MaxDMIPs
121
+ spec .ociSpec .Linux .Resources .CPU .Period = & cpuPeriod
118
122
spec .ociSpec .Linux .Resources .CPU .Quota = & cpuQuota
119
123
}
120
124
You can’t perform that action at this time.
0 commit comments