github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/pkg/sysinfo/sysinfo.go (about) 1 package sysinfo // import "github.com/docker/docker/pkg/sysinfo" 2 3 import "github.com/docker/docker/pkg/parsers" 4 5 // SysInfo stores information about which features a kernel supports. 6 // TODO Windows: Factor out platform specific capabilities. 7 type SysInfo struct { 8 // Whether the kernel supports AppArmor or not 9 AppArmor bool 10 // Whether the kernel supports Seccomp or not 11 Seccomp bool 12 13 cgroupMemInfo 14 cgroupCPUInfo 15 cgroupBlkioInfo 16 cgroupCpusetInfo 17 cgroupPids 18 19 // Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work 20 IPv4ForwardingDisabled bool 21 22 // Whether bridge-nf-call-iptables is supported or not 23 BridgeNFCallIPTablesDisabled bool 24 25 // Whether bridge-nf-call-ip6tables is supported or not 26 BridgeNFCallIP6TablesDisabled bool 27 28 // Whether the cgroup has the mountpoint of "devices" or not 29 CgroupDevicesEnabled bool 30 } 31 32 type cgroupMemInfo struct { 33 // Whether memory limit is supported or not 34 MemoryLimit bool 35 36 // Whether swap limit is supported or not 37 SwapLimit bool 38 39 // Whether soft limit is supported or not 40 MemoryReservation bool 41 42 // Whether OOM killer disable is supported or not 43 OomKillDisable bool 44 45 // Whether memory swappiness is supported or not 46 MemorySwappiness bool 47 48 // Whether kernel memory limit is supported or not 49 KernelMemory bool 50 51 // Whether kernel memory TCP limit is supported or not 52 KernelMemoryTCP bool 53 } 54 55 type cgroupCPUInfo struct { 56 // Whether CPU shares is supported or not 57 CPUShares bool 58 59 // Whether CPU CFS(Completely Fair Scheduler) period is supported or not 60 CPUCfsPeriod bool 61 62 // Whether CPU CFS(Completely Fair Scheduler) quota is supported or not 63 CPUCfsQuota bool 64 65 // Whether CPU real-time period is supported or not 66 CPURealtimePeriod bool 67 68 // Whether CPU real-time runtime is supported or not 69 CPURealtimeRuntime bool 70 } 71 72 type cgroupBlkioInfo struct { 73 // Whether Block IO weight is supported or not 74 BlkioWeight bool 75 76 // Whether Block IO weight_device is supported or not 77 BlkioWeightDevice bool 78 79 // Whether Block IO read limit in bytes per second is supported or not 80 BlkioReadBpsDevice bool 81 82 // Whether Block IO write limit in bytes per second is supported or not 83 BlkioWriteBpsDevice bool 84 85 // Whether Block IO read limit in IO per second is supported or not 86 BlkioReadIOpsDevice bool 87 88 // Whether Block IO write limit in IO per second is supported or not 89 BlkioWriteIOpsDevice bool 90 } 91 92 type cgroupCpusetInfo struct { 93 // Whether Cpuset is supported or not 94 Cpuset bool 95 96 // Available Cpuset's cpus 97 Cpus string 98 99 // Available Cpuset's memory nodes 100 Mems string 101 } 102 103 type cgroupPids struct { 104 // Whether Pids Limit is supported or not 105 PidsLimit bool 106 } 107 108 // IsCpusetCpusAvailable returns `true` if the provided string set is contained 109 // in cgroup's cpuset.cpus set, `false` otherwise. 110 // If error is not nil a parsing error occurred. 111 func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { 112 return isCpusetListAvailable(provided, c.Cpus) 113 } 114 115 // IsCpusetMemsAvailable returns `true` if the provided string set is contained 116 // in cgroup's cpuset.mems set, `false` otherwise. 117 // If error is not nil a parsing error occurred. 118 func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { 119 return isCpusetListAvailable(provided, c.Mems) 120 } 121 122 func isCpusetListAvailable(provided, available string) (bool, error) { 123 parsedAvailable, err := parsers.ParseUintList(available) 124 if err != nil { 125 return false, err 126 } 127 // 8192 is the normal maximum number of CPUs in Linux, so accept numbers up to this 128 // or more if we actually have more CPUs. 129 max := 8192 130 for m := range parsedAvailable { 131 if m > max { 132 max = m 133 } 134 } 135 parsedProvided, err := parsers.ParseUintListMaximum(provided, max) 136 if err != nil { 137 return false, err 138 } 139 for k := range parsedProvided { 140 if !parsedAvailable[k] { 141 return false, nil 142 } 143 } 144 return true, nil 145 } 146 147 // Returns bit count of 1, used by NumCPU 148 func popcnt(x uint64) (n byte) { 149 x -= (x >> 1) & 0x5555555555555555 150 x = (x>>2)&0x3333333333333333 + x&0x3333333333333333 151 x += x >> 4 152 x &= 0x0f0f0f0f0f0f0f0f 153 x *= 0x0101010101010101 154 return byte(x >> 56) 155 }