| 45 | } |
| 46 | |
| 47 | func (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 | |
| 98 | func (c *cpuController) Update(path string, resources *specs.LinuxResources) error { |
| 99 | return c.Create(path, resources) |