Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/mobyPublic

Commit36ad318

Browse files
authored
Merge pull request#49247 from thaJeztah/27.x_backport_deprecate_runtime_numcpu
[27.x backport] pkg/sysinfo: Deprecate NumCPU
2 parentsd9de1e2 +5b7034f commit36ad318

File tree

10 files changed

+18
-83
lines changed

10 files changed

+18
-83
lines changed

‎daemon/daemon_unix.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,11 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, sysIn
491491
// https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
492492
// Here we don't set the lower limit and it is up to the underlying platform (e.g., Linux) to return an error.
493493
// The error message is 0.01 so that this is consistent with Windows
494-
ifresources.NanoCPUs<0||resources.NanoCPUs>int64(sysinfo.NumCPU())*1e9 {
495-
returnwarnings,fmt.Errorf("Range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available",sysinfo.NumCPU(),sysinfo.NumCPU())
494+
ifresources.NanoCPUs!=0 {
495+
nc:=runtime.NumCPU()
496+
ifresources.NanoCPUs<0||resources.NanoCPUs>int64(nc)*1e9 {
497+
returnwarnings,fmt.Errorf("range of CPUs is from 0.01 to %[1]d.00, as there are only %[1]d CPUs available",nc)
498+
}
496499
}
497500

498501
ifresources.CPUShares>0&&!sysInfo.CPUShares {

‎daemon/daemon_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, isHyp
112112
}
113113
// The precision we could get is 0.01, because on Windows we have to convert to CPUPercent.
114114
// We don't set the lower limit here and it is up to the underlying platform (e.g., Windows) to return an error.
115-
ifresources.NanoCPUs<0||resources.NanoCPUs>int64(sysinfo.NumCPU())*1e9 {
116-
returnwarnings,fmt.Errorf("range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available",sysinfo.NumCPU(),sysinfo.NumCPU())
115+
ifresources.NanoCPUs!=0 {
116+
nc:=runtime.NumCPU()
117+
ifresources.NanoCPUs<0||resources.NanoCPUs>int64(nc)*1e9 {
118+
returnwarnings,fmt.Errorf("range of CPUs is from 0.01 to %[1]d.00, as there are only %[1]d CPUs available",nc)
119+
}
117120
}
118121

119122
iflen(resources.BlkioDeviceReadBps)>0 {

‎daemon/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (daemon *Daemon) SystemInfo(ctx context.Context) (*system.Info, error) {
6565
OSType:runtime.GOOS,
6666
Architecture:platform.Architecture(),
6767
RegistryConfig:doWithTrace(ctx,"registry.ServiceConfig",daemon.registryService.ServiceConfig),
68-
NCPU:doWithTrace(ctx,"sysinfo.NumCPU",sysinfo.NumCPU),
68+
NCPU:doWithTrace(ctx,"runtime.NumCPU",runtime.NumCPU),
6969
MemTotal:memInfo(ctx).MemTotal,
7070
GenericResources:daemon.genericResources,
7171
DockerRootDir:cfg.Root,

‎daemon/oci_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011

1112
"github.com/Microsoft/hcsshim"
@@ -18,7 +19,6 @@ import (
1819
"github.com/docker/docker/errdefs"
1920
"github.com/docker/docker/image"
2021
"github.com/docker/docker/oci"
21-
"github.com/docker/docker/pkg/sysinfo"
2222
"github.com/docker/docker/pkg/system"
2323
specs"github.com/opencontainers/runtime-spec/specs-go"
2424
"github.com/pkg/errors"
@@ -428,7 +428,7 @@ func setResourcesInSpec(c *container.Container, s *specs.Spec, isHyperV bool) {
428428
}
429429
}
430430
}else {
431-
cpuMaximum=uint16(c.HostConfig.NanoCPUs/int64(sysinfo.NumCPU())/ (1e9/10000))
431+
cpuMaximum=uint16(c.HostConfig.NanoCPUs/int64(runtime.NumCPU())/ (1e9/10000))
432432
ifcpuMaximum<1 {
433433
// The requested NanoCPUs is so small that we rounded to 0, use 1 instead
434434
cpuMaximum=1

‎libcontainerd/local/local_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path/filepath"
1212
"regexp"
13+
"runtime"
1314
"strings"
1415
"sync"
1516
"syscall"
@@ -23,7 +24,6 @@ import (
2324
"github.com/docker/docker/errdefs"
2425
"github.com/docker/docker/libcontainerd/queue"
2526
libcontainerdtypes"github.com/docker/docker/libcontainerd/types"
26-
"github.com/docker/docker/pkg/sysinfo"
2727
"github.com/docker/docker/pkg/system"
2828
specs"github.com/opencontainers/runtime-spec/specs-go"
2929
"github.com/pkg/errors"
@@ -366,7 +366,7 @@ func (c *client) extractResourcesFromSpec(spec *specs.Spec, configuration *hcssh
366366
// because we don't want to update the HostConfig in case this container
367367
// is moved to a host with more CPUs than this one.
368368
cpuCount:=*spec.Windows.Resources.CPU.Count
369-
hostCPUCount:=uint64(sysinfo.NumCPU())
369+
hostCPUCount:=uint64(runtime.NumCPU())
370370
ifcpuCount>hostCPUCount {
371371
c.logger.Warnf("Changing requested CPUCount of %d to current number of processors, %d",cpuCount,hostCPUCount)
372372
cpuCount=hostCPUCount

‎pkg/sysinfo/numcpu.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import (
44
"runtime"
55
)
66

7-
// NumCPU returns the number of CPUs.On Linux and Windows, it returns
8-
// the number of CPUs which are currently online. On other platforms,
9-
//it's the equivalent of[runtime.NumCPU].
7+
// NumCPU returns the number of CPUs.It's the equivalent of [runtime.NumCPU].
8+
//
9+
//Deprecated: Use[runtime.NumCPU] instead. It will be removed in the next release.
1010
funcNumCPU()int {
11-
ifncpu:=numCPU();ncpu>0 {
12-
returnncpu
13-
}
1411
returnruntime.NumCPU()
1512
}

‎pkg/sysinfo/numcpu_linux.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎pkg/sysinfo/numcpu_other.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎pkg/sysinfo/numcpu_windows.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎pkg/sysinfo/sysinfo_linux_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,3 @@ func TestNewCgroupNamespacesDisabled(t *testing.T) {
109109
sysInfo:=New()
110110
assert.Assert(t,!sysInfo.CgroupNamespaces)
111111
}
112-
113-
funcTestNumCPU(t*testing.T) {
114-
cpuNumbers:=NumCPU()
115-
ifcpuNumbers<=0 {
116-
t.Fatal("CPU returned must be greater than zero")
117-
}
118-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp