From 402d645c5c642a4965439a156181cff3fc2f3817 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 3 May 2020 15:46:29 +0200 Subject: [PATCH] Simplify ticks, as the value is a constant See for example in the Musl libc source code https://git.musl-libc.org/cgit/musl/tree/src/conf/sysconf.c#n29 This removes the cgo dependency for the system package. Signed-off-by: Sebastiaan van Stijn --- libcontainer/cgroups/fs/cpuacct.go | 9 ++++++--- libcontainer/system/sysconfig.go | 12 ------------ libcontainer/system/sysconfig_notcgo.go | 15 --------------- 3 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 libcontainer/system/sysconfig.go delete mode 100644 libcontainer/system/sysconfig_notcgo.go diff --git a/libcontainer/cgroups/fs/cpuacct.go b/libcontainer/cgroups/fs/cpuacct.go index 95dc9a1e..0b334b23 100644 --- a/libcontainer/cgroups/fs/cpuacct.go +++ b/libcontainer/cgroups/fs/cpuacct.go @@ -12,15 +12,18 @@ import ( "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups/fscommon" "github.com/opencontainers/runc/libcontainer/configs" - "github.com/opencontainers/runc/libcontainer/system" ) const ( cgroupCpuacctStat = "cpuacct.stat" nanosecondsInSecond = 1000000000 -) -var clockTicks = uint64(system.GetClockTicks()) + // The value comes from `C.sysconf(C._SC_CLK_TCK)`, and + // on Linux it's a constant which is safe to be hard coded, + // so we can avoid using cgo here. For details, see: + // https://github.com/containerd/cgroups/pull/12 + clockTicks uint64 = 100 +) type CpuacctGroup struct { } diff --git a/libcontainer/system/sysconfig.go b/libcontainer/system/sysconfig.go deleted file mode 100644 index b8434f10..00000000 --- a/libcontainer/system/sysconfig.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build cgo,linux - -package system - -/* -#include -*/ -import "C" - -func GetClockTicks() int { - return int(C.sysconf(C._SC_CLK_TCK)) -} diff --git a/libcontainer/system/sysconfig_notcgo.go b/libcontainer/system/sysconfig_notcgo.go deleted file mode 100644 index d93b5d5f..00000000 --- a/libcontainer/system/sysconfig_notcgo.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !cgo windows - -package system - -func GetClockTicks() int { - // TODO figure out a better alternative for platforms where we're missing cgo - // - // TODO Windows. This could be implemented using Win32 QueryPerformanceFrequency(). - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx - // - // An example of its usage can be found here. - // https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx - - return 100 -}