...
1
16
17 package v2
18
19 import (
20 "math"
21 "strconv"
22 "strings"
23 )
24
25 type CPUMax string
26
27 func NewCPUMax(quota *int64, period *uint64) CPUMax {
28 max := "max"
29 if quota != nil {
30 max = strconv.FormatInt(*quota, 10)
31 }
32 return CPUMax(strings.Join([]string{max, strconv.FormatUint(*period, 10)}, " "))
33 }
34
35 type CPU struct {
36 Weight *uint64
37 Max CPUMax
38 Cpus string
39 Mems string
40 }
41
42 func (c CPUMax) extractQuotaAndPeriod() (int64, uint64) {
43 var (
44 quota int64
45 period uint64
46 )
47 values := strings.Split(string(c), " ")
48 if values[0] == "max" {
49 quota = math.MaxInt64
50 } else {
51 quota, _ = strconv.ParseInt(values[0], 10, 64)
52 }
53 period, _ = strconv.ParseUint(values[1], 10, 64)
54 return quota, period
55 }
56
57 func (r *CPU) Values() (o []Value) {
58 if r.Weight != nil {
59 o = append(o, Value{
60 filename: "cpu.weight",
61 value: *r.Weight,
62 })
63 }
64 if r.Max != "" {
65 o = append(o, Value{
66 filename: "cpu.max",
67 value: r.Max,
68 })
69 }
70 if r.Cpus != "" {
71 o = append(o, Value{
72 filename: "cpuset.cpus",
73 value: r.Cpus,
74 })
75 }
76 if r.Mems != "" {
77 o = append(o, Value{
78 filename: "cpuset.mems",
79 value: r.Mems,
80 })
81 }
82 return o
83 }
84
View as plain text