Repository: opencontainers/runc (go)

Issue:
There is no cpuacct.usage_all file in CentOS 7
There is no cpuacct.usage_all file in CentOS 7. Reading of cpuacct.usage_all was introduced in #2271. 
Issue observed on:
Operating System: CentOS Linux 7 (Core)
Kernel: Linux 3.10.0-1062.18.1.el7.x86_64

I provide a fix for this issue in next week.


Pull request description:
Fix #2440 omit cpuacct.usage_all when not available
Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>

Patch:
diff --git a/libcontainer/cgroups/fs/cpuacct.go b/libcontainer/cgroups/fs/cpuacct.go
index 008bc529..dd8aea0c 100644
--- a/libcontainer/cgroups/fs/cpuacct.go
+++ b/libcontainer/cgroups/fs/cpuacct.go
@@ -144,7 +144,9 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) {
 	usageUserMode := []uint64{}
 
 	file, err := os.Open(filepath.Join(path, cgroupCpuacctUsageAll))
-	if err != nil {
+	if os.IsNotExist(err) {
+		return usageKernelMode, usageUserMode, nil
+	} else if err != nil {
 		return nil, nil, err
 	}
 	defer file.Close()


Test patch:
diff --git a/libcontainer/cgroups/fs/cpuacct_test.go b/libcontainer/cgroups/fs/cpuacct_test.go
index 73623311..bb69d9be 100644
--- a/libcontainer/cgroups/fs/cpuacct_test.go
+++ b/libcontainer/cgroups/fs/cpuacct_test.go
@@ -59,3 +59,35 @@ func TestCpuacctStats(t *testing.T) {
 			expectedStats, actualStats.CpuStats.CpuUsage)
 	}
 }
+
+func TestCpuacctStatsWithoutUsageAll(t *testing.T) {
+	helper := NewCgroupTestUtil("cpuacct.", t)
+	defer helper.cleanup()
+	helper.writeFileContents(map[string]string{
+		"cpuacct.usage":        cpuAcctUsageContents,
+		"cpuacct.usage_percpu": cpuAcctUsagePerCPUContents,
+		"cpuacct.stat":         cpuAcctStatContents,
+	})
+
+	cpuacct := &CpuacctGroup{}
+	actualStats := *cgroups.NewStats()
+	err := cpuacct.GetStats(helper.CgroupPath, &actualStats)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	expectedStats := cgroups.CpuUsage{
+		TotalUsage: uint64(12262454190222160),
+		PercpuUsage: []uint64{1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
+			1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086},
+		PercpuUsageInKernelmode: []uint64{},
+		PercpuUsageInUsermode:   []uint64{},
+		UsageInKernelmode:       (uint64(291429664) * nanosecondsInSecond) / clockTicks,
+		UsageInUsermode:         (uint64(452278264) * nanosecondsInSecond) / clockTicks,
+	}
+
+	if !reflect.DeepEqual(expectedStats, actualStats.CpuStats.CpuUsage) {
+		t.Errorf("Expected CPU usage %#v but found %#v\n",
+			expectedStats, actualStats.CpuStats.CpuUsage)
+	}
+}