From 1637d63eb1f896ce3b662607bd19000bbfaef3e3 Mon Sep 17 00:00:00 2001 From: bpopovschi Date: Fri, 15 Nov 2019 13:54:51 +0200 Subject: [PATCH] Added RDMA controller Signed-off-by: bpopovschi --- v2/manager.go | 6 + v2/rdma.go | 46 +++ v2/stats/metrics.pb.go | 646 ++++++++++++++++++++++++++++++++++++---- v2/stats/metrics.pb.txt | 51 ++++ v2/stats/metrics.proto | 12 + v2/utils.go | 65 ++++ 6 files changed, 773 insertions(+), 53 deletions(-) create mode 100644 v2/rdma.go diff --git a/v2/manager.go b/v2/manager.go index a7137190..42476788 100644 --- a/v2/manager.go +++ b/v2/manager.go @@ -46,6 +46,7 @@ type Resources struct { Memory *Memory Pids *Pids IO *IO + RDMA *RDMA } // Values returns the raw filenames and values that @@ -56,6 +57,7 @@ func (r *Resources) Values() (o []Value) { r.Memory, r.Pids, r.IO, + r.RDMA, } for _, v := range values { if v == nil { @@ -326,6 +328,10 @@ func (c *Manager) Stat() (*stats.Metrics, error) { ThpFaultAlloc: out["thp_fault_alloc"].(uint64), ThpCollapseAlloc: out["thp_collapse_alloc"].(uint64), } + + metrics.Rdma.Current = rdmaStats(filepath.Join(c.path, "rdma.current")) + metrics.Rdma.Limit = rdmaStats(filepath.Join(c.path, "rdma.max")) + return &metrics, nil } diff --git a/v2/rdma.go b/v2/rdma.go new file mode 100644 index 00000000..44caa4f5 --- /dev/null +++ b/v2/rdma.go @@ -0,0 +1,46 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package v2 + +import ( + "fmt" +) + +type RDMA struct { + Limit []RDMAEntry +} + +type RDMAEntry struct { + Device string + HcaHandles uint32 + HcaObjects uint32 +} + +func (r RDMAEntry) String() string { + return fmt.Sprintf("%s hca_handle=%d hca_object=%d", r.Device, r.HcaHandles, r.HcaObjects) +} + +func (r *RDMA) Values() (o []Value) { + for _, e := range r.Limit { + o = append(o, Value{ + filename: "rdma.max", + value: e.String(), + }) + } + + return o +} diff --git a/v2/stats/metrics.pb.go b/v2/stats/metrics.pb.go index 4c366da4..ab26a5ca 100644 --- a/v2/stats/metrics.pb.go +++ b/v2/stats/metrics.pb.go @@ -28,6 +28,7 @@ type Metrics struct { Pids *PidsStat `protobuf:"bytes,1,opt,name=pids,proto3" json:"pids,omitempty"` CPU *CPUStat `protobuf:"bytes,2,opt,name=cpu,proto3" json:"cpu,omitempty"` Memory *MemoryStat `protobuf:"bytes,4,opt,name=memory,proto3" json:"memory,omitempty"` + Rdma *RdmaStat `protobuf:"bytes,5,opt,name=rdma,proto3" json:"rdma,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -218,11 +219,94 @@ func (m *MemoryStat) XXX_DiscardUnknown() { var xxx_messageInfo_MemoryStat proto.InternalMessageInfo +type RdmaStat struct { + Current []*RdmaEntry `protobuf:"bytes,1,rep,name=current,proto3" json:"current,omitempty"` + Limit []*RdmaEntry `protobuf:"bytes,2,rep,name=limit,proto3" json:"limit,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RdmaStat) Reset() { *m = RdmaStat{} } +func (*RdmaStat) ProtoMessage() {} +func (*RdmaStat) Descriptor() ([]byte, []int) { + return fileDescriptor_2fc6005842049e6b, []int{4} +} +func (m *RdmaStat) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RdmaStat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RdmaStat.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RdmaStat) XXX_Merge(src proto.Message) { + xxx_messageInfo_RdmaStat.Merge(m, src) +} +func (m *RdmaStat) XXX_Size() int { + return m.Size() +} +func (m *RdmaStat) XXX_DiscardUnknown() { + xxx_messageInfo_RdmaStat.DiscardUnknown(m) +} + +var xxx_messageInfo_RdmaStat proto.InternalMessageInfo + +type RdmaEntry struct { + Device string `protobuf:"bytes,1,opt,name=device,proto3" json:"device,omitempty"` + HcaHandles uint32 `protobuf:"varint,2,opt,name=hca_handles,json=hcaHandles,proto3" json:"hca_handles,omitempty"` + HcaObjects uint32 `protobuf:"varint,3,opt,name=hca_objects,json=hcaObjects,proto3" json:"hca_objects,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RdmaEntry) Reset() { *m = RdmaEntry{} } +func (*RdmaEntry) ProtoMessage() {} +func (*RdmaEntry) Descriptor() ([]byte, []int) { + return fileDescriptor_2fc6005842049e6b, []int{5} +} +func (m *RdmaEntry) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RdmaEntry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RdmaEntry.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RdmaEntry) XXX_Merge(src proto.Message) { + xxx_messageInfo_RdmaEntry.Merge(m, src) +} +func (m *RdmaEntry) XXX_Size() int { + return m.Size() +} +func (m *RdmaEntry) XXX_DiscardUnknown() { + xxx_messageInfo_RdmaEntry.DiscardUnknown(m) +} + +var xxx_messageInfo_RdmaEntry proto.InternalMessageInfo + func init() { proto.RegisterType((*Metrics)(nil), "io.containerd.cgroups.v2.Metrics") proto.RegisterType((*PidsStat)(nil), "io.containerd.cgroups.v2.PidsStat") proto.RegisterType((*CPUStat)(nil), "io.containerd.cgroups.v2.CPUStat") proto.RegisterType((*MemoryStat)(nil), "io.containerd.cgroups.v2.MemoryStat") + proto.RegisterType((*RdmaStat)(nil), "io.containerd.cgroups.v2.RdmaStat") + proto.RegisterType((*RdmaEntry)(nil), "io.containerd.cgroups.v2.RdmaEntry") } func init() { @@ -230,59 +314,65 @@ func init() { } var fileDescriptor_2fc6005842049e6b = []byte{ - // 818 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x55, 0x4d, 0x6f, 0x1b, 0x37, - 0x10, 0x8d, 0x6a, 0xc5, 0x92, 0x47, 0x76, 0xec, 0x30, 0x8e, 0xcb, 0x38, 0xb5, 0x9c, 0xa8, 0x1f, - 0x68, 0x81, 0x56, 0x02, 0xdc, 0x8f, 0x43, 0x91, 0x8b, 0xe3, 0x22, 0x37, 0x17, 0x86, 0x12, 0xa3, - 0xc7, 0x05, 0xb5, 0x4b, 0xaf, 0x58, 0xef, 0x2e, 0x09, 0x92, 0xeb, 0xc0, 0x3d, 0xf5, 0x77, 0xf4, - 0xbf, 0xf4, 0x9e, 0x5b, 0x7b, 0xec, 0xa9, 0x68, 0xf4, 0x4b, 0x8a, 0x19, 0x72, 0xb5, 0x9b, 0x83, - 0x6f, 0x9c, 0xf7, 0xde, 0x0c, 0xdf, 0xbc, 0x15, 0x21, 0xf8, 0x2e, 0x57, 0x7e, 0x59, 0x2f, 0xa6, - 0xa9, 0x2e, 0x67, 0xa9, 0xae, 0xbc, 0x50, 0x95, 0xb4, 0xd9, 0x2c, 0xcd, 0xad, 0xae, 0x8d, 0x9b, - 0xdd, 0x9c, 0xcc, 0x9c, 0x17, 0xde, 0xcd, 0x4a, 0xe9, 0xad, 0x4a, 0xdd, 0xd4, 0x58, 0xed, 0x35, - 0xe3, 0x4a, 0x4f, 0x5b, 0xf5, 0x34, 0xaa, 0xa7, 0x37, 0x27, 0x87, 0xfb, 0xb9, 0xce, 0x35, 0x89, - 0x66, 0x78, 0x0a, 0xfa, 0xc9, 0x9f, 0x3d, 0x18, 0x9c, 0x87, 0x09, 0xec, 0x07, 0xe8, 0x1b, 0x95, - 0x39, 0xde, 0x7b, 0xd6, 0xfb, 0x72, 0x74, 0x32, 0x99, 0xde, 0x35, 0x6a, 0x7a, 0xa1, 0x32, 0xf7, - 0xda, 0x0b, 0x3f, 0x27, 0x3d, 0x7b, 0x01, 0x1b, 0xa9, 0xa9, 0xf9, 0x47, 0xd4, 0xf6, 0xfc, 0xee, - 0xb6, 0xb3, 0x8b, 0x4b, 0xec, 0x7a, 0x39, 0x58, 0xfd, 0x7b, 0xbc, 0x71, 0x76, 0x71, 0x39, 0xc7, - 0x36, 0xf6, 0x02, 0x36, 0x4b, 0x59, 0x6a, 0x7b, 0xcb, 0xfb, 0x34, 0xe0, 0xb3, 0xbb, 0x07, 0x9c, - 0x93, 0x8e, 0x6e, 0x8e, 0x3d, 0x93, 0x1f, 0x61, 0xd8, 0xb8, 0x61, 0x1c, 0x06, 0x69, 0x6d, 0xad, - 0xac, 0x3c, 0xad, 0xd0, 0x9f, 0x37, 0x25, 0xdb, 0x87, 0xfb, 0x85, 0x2a, 0x95, 0x27, 0x8f, 0xfd, - 0x79, 0x28, 0x26, 0x7f, 0xf5, 0x60, 0x10, 0x3d, 0xb1, 0x23, 0x80, 0xda, 0x89, 0x5c, 0x26, 0xb5, - 0x93, 0x69, 0x6c, 0xdf, 0x22, 0xe4, 0xd2, 0xc9, 0x94, 0x3d, 0x85, 0xad, 0xda, 0x49, 0x1b, 0xd8, - 0x30, 0x64, 0x88, 0x00, 0x91, 0xc7, 0x30, 0x72, 0xb7, 0xce, 0xcb, 0x32, 0xd0, 0x1b, 0x44, 0x43, - 0x80, 0x48, 0x70, 0x04, 0x50, 0xd9, 0xc4, 0x48, 0xab, 0x74, 0xe6, 0x68, 0xcd, 0xfe, 0x7c, 0xab, - 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, 0x08, - 0x61, 0x6d, 0xf6, 0xb0, 0x09, 0xa1, 0x41, 0xd8, 0x04, 0xb6, 0x4d, 0x9e, 0xc9, 0xb5, 0xe2, 0x69, - 0xf8, 0xfe, 0x5d, 0x2c, 0xcc, 0x28, 0xc4, 0x6f, 0xb7, 0x57, 0x56, 0x4a, 0xfe, 0x49, 0x33, 0xa3, - 0x41, 0xf0, 0xf3, 0xb7, 0x55, 0xc6, 0x8f, 0xc2, 0xe7, 0xef, 0x40, 0xec, 0x0b, 0xd8, 0xf5, 0x4b, - 0x93, 0x50, 0x90, 0x89, 0x28, 0x0a, 0x9d, 0xf2, 0x71, 0xf3, 0xdc, 0xcd, 0x2b, 0x44, 0x4f, 0x11, - 0x64, 0x5f, 0x03, 0x43, 0x5d, 0xaa, 0x8b, 0x42, 0x18, 0x27, 0xa3, 0xf4, 0x98, 0xa4, 0x7b, 0x7e, - 0x69, 0xce, 0x22, 0x41, 0xea, 0x97, 0xfc, 0xdd, 0xfb, 0xf1, 0xbd, 0x7f, 0xde, 0x8f, 0xef, 0xfd, - 0xbe, 0x1a, 0xf7, 0xde, 0xad, 0xc6, 0xbd, 0xbf, 0x57, 0xe3, 0xde, 0x7f, 0xab, 0x71, 0x6f, 0xb1, - 0x49, 0xff, 0x05, 0xdf, 0xfe, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x72, 0x49, 0x6e, 0x1c, 0x73, 0x06, - 0x00, 0x00, + // 921 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x4d, 0x6f, 0x1c, 0x45, + 0x10, 0xcd, 0xe2, 0x8d, 0xbd, 0x5b, 0x6b, 0xc7, 0x4e, 0xc7, 0x31, 0x1d, 0x07, 0xaf, 0x93, 0x0d, + 0xa0, 0x20, 0xc1, 0xae, 0x64, 0x3e, 0x24, 0x50, 0x38, 0x38, 0x86, 0x88, 0x8b, 0xc1, 0x9a, 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x50, 0x27, 0xcb, 0x2c, 0x13, 0x95, 0x51, + 0x5e, 0x7a, 0x48, 0xd2, 0x1d, 0x9b, 0x54, 0x27, 0x9e, 0x20, 0xf5, 0xe4, 0x97, 0x1e, 0x0c, 0x9a, + 0xed, 0xc9, 0xbe, 0xee, 0xee, 0xca, 0xb5, 0xc7, 0xa3, 0xa3, 0x47, 0xff, 0xbd, 0x72, 0xbf, 0x2d, + 0xac, 0x5e, 0xb4, 0x0b, 0xf5, 0xcb, 0x76, 0xa1, 0xbe, 0x75, 0xb2, 0xdf, 0xba, 0x0a, 0x86, 0x2b, + 0x0c, 0xbf, 0x50, 0x84, 0x3f, 0x7b, 0x45, 0x3b, 0x6a, 0x18, 0xf8, 0x08, 0xdf, 0x50, 0x22, 0x45, + 0x98, 0x88, 0x22, 0xca, 0x94, 0xa1, 0x65, 0xb5, 0x15, 0x40, 0x22, 0xc5, 0x77, 0x0e, 0x69, 0x04, + 0xe5, 0xfc, 0xa5, 0x92, 0xd6, 0xd0, 0xc6, 0x72, 0x82, 0x1f, 0x1c, 0xf2, 0x94, 0xbf, 0x7e, 0x33, + 0xbe, 0xf1, 0xc7, 0x9b, 0xf1, 0x8d, 0x9f, 0x97, 0xe3, 0xde, 0xeb, 0xe5, 0xb8, 0xf7, 0xfb, 0x72, + 0xdc, 0xfb, 0x6b, 0x39, 0xee, 0xcd, 0xd7, 0xe9, 0x1f, 0xf3, 0xd3, 0x7f, 0x02, 0x00, 0x00, 0xff, + 0xff, 0xca, 0x96, 0x65, 0x07, 0x99, 0x07, 0x00, 0x00, } func (m *Metrics) Marshal() (dAtA []byte, err error) { @@ -330,6 +420,16 @@ func (m *Metrics) MarshalTo(dAtA []byte) (int, error) { } i += n3 } + if m.Rdma != nil { + dAtA[i] = 0x2a + i++ + i = encodeVarintMetrics(dAtA, i, uint64(m.Rdma.Size())) + n4, err := m.Rdma.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n4 + } if m.XXX_unrecognized != nil { i += copy(dAtA[i:], m.XXX_unrecognized) } @@ -626,6 +726,88 @@ func (m *MemoryStat) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *RdmaStat) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RdmaStat) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Current) > 0 { + for _, msg := range m.Current { + dAtA[i] = 0xa + i++ + i = encodeVarintMetrics(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if len(m.Limit) > 0 { + for _, msg := range m.Limit { + dAtA[i] = 0x12 + i++ + i = encodeVarintMetrics(dAtA, i, uint64(msg.Size())) + n, err := msg.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n + } + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + +func (m *RdmaEntry) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RdmaEntry) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Device) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintMetrics(dAtA, i, uint64(len(m.Device))) + i += copy(dAtA[i:], m.Device) + } + if m.HcaHandles != 0 { + dAtA[i] = 0x10 + i++ + i = encodeVarintMetrics(dAtA, i, uint64(m.HcaHandles)) + } + if m.HcaObjects != 0 { + dAtA[i] = 0x18 + i++ + i = encodeVarintMetrics(dAtA, i, uint64(m.HcaObjects)) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + func encodeVarintMetrics(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -653,6 +835,10 @@ func (m *Metrics) Size() (n int) { l = m.Memory.Size() n += 1 + l + sovMetrics(uint64(l)) } + if m.Rdma != nil { + l = m.Rdma.Size() + n += 1 + l + sovMetrics(uint64(l)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -812,6 +998,52 @@ func (m *MemoryStat) Size() (n int) { return n } +func (m *RdmaStat) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Current) > 0 { + for _, e := range m.Current { + l = e.Size() + n += 1 + l + sovMetrics(uint64(l)) + } + } + if len(m.Limit) > 0 { + for _, e := range m.Limit { + l = e.Size() + n += 1 + l + sovMetrics(uint64(l)) + } + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *RdmaEntry) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Device) + if l > 0 { + n += 1 + l + sovMetrics(uint64(l)) + } + if m.HcaHandles != 0 { + n += 1 + sovMetrics(uint64(m.HcaHandles)) + } + if m.HcaObjects != 0 { + n += 1 + sovMetrics(uint64(m.HcaObjects)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + func sovMetrics(x uint64) (n int) { for { n++ @@ -833,6 +1065,7 @@ func (this *Metrics) String() string { `Pids:` + strings.Replace(fmt.Sprintf("%v", this.Pids), "PidsStat", "PidsStat", 1) + `,`, `CPU:` + strings.Replace(fmt.Sprintf("%v", this.CPU), "CPUStat", "CPUStat", 1) + `,`, `Memory:` + strings.Replace(fmt.Sprintf("%v", this.Memory), "MemoryStat", "MemoryStat", 1) + `,`, + `Rdma:` + strings.Replace(fmt.Sprintf("%v", this.Rdma), "RdmaStat", "RdmaStat", 1) + `,`, `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, `}`, }, "") @@ -907,6 +1140,31 @@ func (this *MemoryStat) String() string { }, "") return s } +func (this *RdmaStat) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&RdmaStat{`, + `Current:` + strings.Replace(fmt.Sprintf("%v", this.Current), "RdmaEntry", "RdmaEntry", 1) + `,`, + `Limit:` + strings.Replace(fmt.Sprintf("%v", this.Limit), "RdmaEntry", "RdmaEntry", 1) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} +func (this *RdmaEntry) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&RdmaEntry{`, + `Device:` + fmt.Sprintf("%v", this.Device) + `,`, + `HcaHandles:` + fmt.Sprintf("%v", this.HcaHandles) + `,`, + `HcaObjects:` + fmt.Sprintf("%v", this.HcaObjects) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} func valueToStringMetrics(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -1052,6 +1310,42 @@ func (m *Metrics) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Rdma", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMetrics + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMetrics + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Rdma == nil { + m.Rdma = &RdmaStat{} + } + if err := m.Rdma.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMetrics(dAtA[iNdEx:]) @@ -1980,6 +2274,252 @@ func (m *MemoryStat) Unmarshal(dAtA []byte) error { } return nil } +func (m *RdmaStat) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RdmaStat: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RdmaStat: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Current", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMetrics + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMetrics + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Current = append(m.Current, &RdmaEntry{}) + if err := m.Current[len(m.Current)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Limit", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMetrics + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMetrics + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Limit = append(m.Limit, &RdmaEntry{}) + if err := m.Limit[len(m.Limit)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMetrics(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMetrics + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthMetrics + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RdmaEntry) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RdmaEntry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RdmaEntry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Device", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMetrics + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMetrics + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Device = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HcaHandles", wireType) + } + m.HcaHandles = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HcaHandles |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HcaObjects", wireType) + } + m.HcaObjects = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetrics + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HcaObjects |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipMetrics(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMetrics + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthMetrics + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipMetrics(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/v2/stats/metrics.pb.txt b/v2/stats/metrics.pb.txt index bc4a0a6d..6489d55f 100755 --- a/v2/stats/metrics.pb.txt +++ b/v2/stats/metrics.pb.txt @@ -31,6 +31,14 @@ file { type_name: ".io.containerd.cgroups.v2.MemoryStat" json_name: "memory" } + field { + name: "rdma" + number: 5 + label: LABEL_OPTIONAL + type: TYPE_MESSAGE + type_name: ".io.containerd.cgroups.v2.RdmaStat" + json_name: "rdma" + } } message_type { name: "PidsStat" @@ -314,5 +322,48 @@ file { json_name: "thpCollapseAlloc" } } + message_type { + name: "RdmaStat" + field { + name: "current" + number: 1 + label: LABEL_REPEATED + type: TYPE_MESSAGE + type_name: ".io.containerd.cgroups.v2.RdmaEntry" + json_name: "current" + } + field { + name: "limit" + number: 2 + label: LABEL_REPEATED + type: TYPE_MESSAGE + type_name: ".io.containerd.cgroups.v2.RdmaEntry" + json_name: "limit" + } + } + message_type { + name: "RdmaEntry" + field { + name: "device" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "device" + } + field { + name: "hca_handles" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_UINT32 + json_name: "hcaHandles" + } + field { + name: "hca_objects" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_UINT32 + json_name: "hcaObjects" + } + } syntax: "proto3" } diff --git a/v2/stats/metrics.proto b/v2/stats/metrics.proto index 1f71ce23..abc31c1d 100644 --- a/v2/stats/metrics.proto +++ b/v2/stats/metrics.proto @@ -8,6 +8,7 @@ message Metrics { PidsStat pids = 1; CPUStat cpu = 2 [(gogoproto.customname) = "CPU"]; MemoryStat memory = 4; + RdmaStat rdma = 5; } message PidsStat { @@ -58,5 +59,16 @@ message MemoryStat { uint64 thp_collapse_alloc = 31; } +message RdmaStat { + repeated RdmaEntry current = 1; + repeated RdmaEntry limit = 2; +} + +message RdmaEntry { + string device = 1; + uint32 hca_handles = 2; + uint32 hca_objects = 3; +} + // iostat // fmt: 230:0 rbytes=394211328 wbytes=65044480 rios=16313 wios=2006 dbytes=0 dios=0 diff --git a/v2/utils.go b/v2/utils.go index 7d5f711e..79fe28be 100644 --- a/v2/utils.go +++ b/v2/utils.go @@ -21,11 +21,13 @@ import ( "fmt" "io" "io/ioutil" + "math" "os" "strconv" "strings" "time" + "github.com/containerd/cgroups/v2/stats" "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" ) @@ -214,5 +216,68 @@ func ToResources(spec *specs.LinuxResources) *Resources { } } } + if i := spec.Rdma; i != nil { + resources.RDMA = &RDMA{} + for device, value := range spec.Rdma { + if device != "" && (value.HcaHandles != nil || value.HcaObjects != nil) { + resources.RDMA.Limit = append(resources.RDMA.Limit, RDMAEntry{ + Device: device, + HcaHandles: *value.HcaHandles, + HcaObjects: *value.HcaObjects, + }) + } + } + } + return &resources } + +func rdmaStats(filepath string) []*stats.RdmaEntry { + currentData, err := ioutil.ReadFile(filepath) + if err != nil { + return []*stats.RdmaEntry{} + } + return toRdmaEntry(strings.Split(string(currentData), "\n")) +} + +func parseRdmaKV(raw string, entry *stats.RdmaEntry) { + var value uint64 + var err error + + parts := strings.Split(raw, "=") + switch len(parts) { + case 2: + if parts[1] == "max" { + value = math.MaxUint32 + } else { + value, err = parseUint(parts[1], 10, 32) + if err != nil { + return + } + } + if parts[0] == "hca_handle" { + entry.HcaHandles = uint32(value) + } else if parts[0] == "hca_object" { + entry.HcaObjects = uint32(value) + } + } +} + +func toRdmaEntry(strEntries []string) []*stats.RdmaEntry { + var rdmaEntries []*stats.RdmaEntry + for i := range strEntries { + parts := strings.Fields(strEntries[i]) + switch len(parts) { + case 3: + entry := new(stats.RdmaEntry) + entry.Device = parts[0] + parseRdmaKV(parts[1], entry) + parseRdmaKV(parts[2], entry) + + rdmaEntries = append(rdmaEntries, entry) + default: + continue + } + } + return rdmaEntries +}