MCPcopy Create free account
hub / github.com/containerd/cgroups / Create

Method Create

cgroup1/cpu.go:47–96  ·  view source on GitHub ↗
(path string, resources *specs.LinuxResources)

Source from the content-addressed store, hash-verified

45}
46
47func (c *cpuController) Create(path string, resources *specs.LinuxResources) error {
48 if err := os.MkdirAll(c.Path(path), defaultDirPerm); err != nil {
49 return err
50 }
51 if cpu := resources.CPU; cpu != nil {
52 for _, t := range []struct {
53 name string
54 ivalue *int64
55 uvalue *uint64
56 }{
57 {
58 name: "rt_period_us",
59 uvalue: cpu.RealtimePeriod,
60 },
61 {
62 name: "rt_runtime_us",
63 ivalue: cpu.RealtimeRuntime,
64 },
65 {
66 name: "shares",
67 uvalue: cpu.Shares,
68 },
69 {
70 name: "cfs_period_us",
71 uvalue: cpu.Period,
72 },
73 {
74 name: "cfs_quota_us",
75 ivalue: cpu.Quota,
76 },
77 } {
78 var value []byte
79 if t.uvalue != nil {
80 value = []byte(strconv.FormatUint(*t.uvalue, 10))
81 } else if t.ivalue != nil {
82 value = []byte(strconv.FormatInt(*t.ivalue, 10))
83 }
84 if value != nil {
85 if err := os.WriteFile(
86 filepath.Join(c.Path(path), "cpu."+t.name),
87 value,
88 defaultFilePerm,
89 ); err != nil {
90 return err
91 }
92 }
93 }
94 }
95 return nil
96}
97
98func (c *cpuController) Update(path string, resources *specs.LinuxResources) error {
99 return c.Create(path, resources)

Callers 1

UpdateMethod · 0.95

Calls 1

PathMethod · 0.95

Tested by

no test coverage detected