diff --git a/util/cgroup/cgroup_cpu.go b/util/cgroup/cgroup_cpu.go index bafa319f5ad62..fdfdf2c9f979d 100644 --- a/util/cgroup/cgroup_cpu.go +++ b/util/cgroup/cgroup_cpu.go @@ -21,6 +21,8 @@ import ( "github.com/pingcap/errors" ) +var errNoCPUControllerDetected = errors.New("no cpu controller detected") + // Helper function for getCgroupCPU. Root is always "/", except in tests. func getCgroupCPU(root string) (CPUUsage, error) { path, err := detectControlPath(filepath.Join(root, procPathCGroup), "cpu,cpuacct") @@ -30,7 +32,7 @@ func getCgroupCPU(root string) (CPUUsage, error) { // No CPU controller detected if path == "" { - return CPUUsage{}, errors.New("no cpu controller detected") + return CPUUsage{}, errNoCPUControllerDetected } mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct") diff --git a/util/cgroup/cgroup_cpu_test.go b/util/cgroup/cgroup_cpu_test.go index 481ed3e32ccf8..7c74994a7dbb0 100644 --- a/util/cgroup/cgroup_cpu_test.go +++ b/util/cgroup/cgroup_cpu_test.go @@ -42,9 +42,13 @@ func TestGetCgroupCPU(t *testing.T) { }() } cpu, err := GetCgroupCPU() - require.NoError(t, err) - require.NotZero(t, cpu.Period) - require.Less(t, int64(1), cpu.Period) + if err == errNoCPUControllerDetected { + require.False(t, InContainer(), "Please check linux version > v4.7.x. This is related to cgroup compatibility.") + } else { + require.NoError(t, err) + require.NotZero(t, cpu.Period) + require.Less(t, int64(1), cpu.Period) + } close(exit) wg.Wait() }