mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Merge pull request #4927 from cyphar/1.4-cpuset-fill
[1.4] libct: switch to (*CPUSet).Fill
This commit is contained in:
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased 1.4.z]
|
||||
|
||||
### Fixed
|
||||
* Switched to `(*CPUSet).Fill` rather than our hacky optimisation when
|
||||
resetting the CPU affinity of runc. (#4926, #4927)
|
||||
|
||||
## [1.4.0-rc.2] - 2025-10-10
|
||||
|
||||
> 私の役目は信じるかどうかではない。行うかどうかだ。
|
||||
|
||||
@@ -23,7 +23,7 @@ require (
|
||||
github.com/vishvananda/netlink v1.3.1
|
||||
github.com/vishvananda/netns v0.0.5
|
||||
golang.org/x/net v0.43.0
|
||||
golang.org/x/sys v0.35.0
|
||||
golang.org/x/sys v0.37.0
|
||||
google.golang.org/protobuf v1.36.8
|
||||
)
|
||||
|
||||
|
||||
@@ -84,8 +84,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -185,16 +185,8 @@ func tryResetCPUAffinity(pid int) {
|
||||
//
|
||||
// So we can just pass a very large array of set cpumask bits and the
|
||||
// kernel will silently convert that to the correct value very cheaply.
|
||||
|
||||
// Ideally, we would just set the array to 0xFF...FF. Unfortunately, the
|
||||
// size depends on the architecture. It is also a private newtype, so we
|
||||
// can't use (^0) or generics since those require us to be able to name the
|
||||
// type. However, we can just underflow the zero value instead.
|
||||
// TODO: Once <https://golang.org/cl/698015> is merged, switch to that.
|
||||
cpuset := unix.CPUSet{}
|
||||
for i := range cpuset {
|
||||
cpuset[i]-- // underflow to 0xFF..FF
|
||||
}
|
||||
var cpuset unix.CPUSet
|
||||
cpuset.Fill() // set all bits
|
||||
if err := unix.SchedSetaffinity(pid, &cpuset); err != nil {
|
||||
logrus.WithError(
|
||||
os.NewSyscallError("sched_setaffinity", err),
|
||||
|
||||
+8
-1
@@ -38,8 +38,15 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
|
||||
|
||||
// Zero clears the set s, so that it contains no CPUs.
|
||||
func (s *CPUSet) Zero() {
|
||||
clear(s[:])
|
||||
}
|
||||
|
||||
// Fill adds all possible CPU bits to the set s. On Linux, [SchedSetaffinity]
|
||||
// will silently ignore any invalid CPU bits in [CPUSet] so this is an
|
||||
// efficient way of resetting the CPU affinity of a process.
|
||||
func (s *CPUSet) Fill() {
|
||||
for i := range s {
|
||||
s[i] = 0
|
||||
s[i] = ^cpuMask(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -23,7 +23,5 @@ func (fds *FdSet) IsSet(fd int) bool {
|
||||
|
||||
// Zero clears the set fds.
|
||||
func (fds *FdSet) Zero() {
|
||||
for i := range fds.Bits {
|
||||
fds.Bits[i] = 0
|
||||
}
|
||||
clear(fds.Bits[:])
|
||||
}
|
||||
|
||||
+1
-3
@@ -111,9 +111,7 @@ func (ifr *Ifreq) SetUint32(v uint32) {
|
||||
// clear zeroes the ifreq's union field to prevent trailing garbage data from
|
||||
// being sent to the kernel if an ifreq is reused.
|
||||
func (ifr *Ifreq) clear() {
|
||||
for i := range ifr.raw.Ifru {
|
||||
ifr.raw.Ifru[i] = 0
|
||||
}
|
||||
clear(ifr.raw.Ifru[:])
|
||||
}
|
||||
|
||||
// TODO(mdlayher): export as IfreqData? For now we can provide helpers such as
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ esac
|
||||
if [[ "$GOOS" = "linux" ]]; then
|
||||
# Use the Docker-based build system
|
||||
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
|
||||
set -e
|
||||
$cmd docker build --tag generate:$GOOS $GOOS
|
||||
$cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && pwd):/build generate:$GOOS
|
||||
exit
|
||||
|
||||
+1
-3
@@ -801,9 +801,7 @@ func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
// one. The kernel expects SID to be in network byte order.
|
||||
binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID)
|
||||
copy(sa.raw[8:14], sa.Remote)
|
||||
for i := 14; i < 14+IFNAMSIZ; i++ {
|
||||
sa.raw[i] = 0
|
||||
}
|
||||
clear(sa.raw[14 : 14+IFNAMSIZ])
|
||||
copy(sa.raw[14:], sa.Dev)
|
||||
return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil
|
||||
}
|
||||
|
||||
+17
@@ -248,6 +248,23 @@ func Statvfs(path string, buf *Statvfs_t) (err error) {
|
||||
return Statvfs1(path, buf, ST_WAIT)
|
||||
}
|
||||
|
||||
func Getvfsstat(buf []Statvfs_t, flags int) (n int, err error) {
|
||||
var (
|
||||
_p0 unsafe.Pointer
|
||||
bufsize uintptr
|
||||
)
|
||||
if len(buf) > 0 {
|
||||
_p0 = unsafe.Pointer(&buf[0])
|
||||
bufsize = unsafe.Sizeof(Statvfs_t{}) * uintptr(len(buf))
|
||||
}
|
||||
r0, _, e1 := Syscall(SYS_GETVFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
|
||||
n = int(r0)
|
||||
if e1 != 0 {
|
||||
err = e1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
* Exposed directly
|
||||
*/
|
||||
|
||||
+1
-1
@@ -629,7 +629,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
|
||||
//sys Kill(pid int, signum syscall.Signal) (err error)
|
||||
//sys Lchown(path string, uid int, gid int) (err error)
|
||||
//sys Link(path string, link string) (err error)
|
||||
//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_llisten
|
||||
//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_listen
|
||||
//sys Lstat(path string, stat *Stat_t) (err error)
|
||||
//sys Madvise(b []byte, advice int) (err error)
|
||||
//sys Mkdir(path string, mode uint32) (err error)
|
||||
|
||||
+4
-4
@@ -72,7 +72,7 @@ import (
|
||||
//go:cgo_import_dynamic libc_kill kill "libc.so"
|
||||
//go:cgo_import_dynamic libc_lchown lchown "libc.so"
|
||||
//go:cgo_import_dynamic libc_link link "libc.so"
|
||||
//go:cgo_import_dynamic libc___xnet_llisten __xnet_llisten "libsocket.so"
|
||||
//go:cgo_import_dynamic libc___xnet_listen __xnet_listen "libsocket.so"
|
||||
//go:cgo_import_dynamic libc_lstat lstat "libc.so"
|
||||
//go:cgo_import_dynamic libc_madvise madvise "libc.so"
|
||||
//go:cgo_import_dynamic libc_mkdir mkdir "libc.so"
|
||||
@@ -221,7 +221,7 @@ import (
|
||||
//go:linkname procKill libc_kill
|
||||
//go:linkname procLchown libc_lchown
|
||||
//go:linkname procLink libc_link
|
||||
//go:linkname proc__xnet_llisten libc___xnet_llisten
|
||||
//go:linkname proc__xnet_listen libc___xnet_listen
|
||||
//go:linkname procLstat libc_lstat
|
||||
//go:linkname procMadvise libc_madvise
|
||||
//go:linkname procMkdir libc_mkdir
|
||||
@@ -371,7 +371,7 @@ var (
|
||||
procKill,
|
||||
procLchown,
|
||||
procLink,
|
||||
proc__xnet_llisten,
|
||||
proc__xnet_listen,
|
||||
procLstat,
|
||||
procMadvise,
|
||||
procMkdir,
|
||||
@@ -1178,7 +1178,7 @@ func Link(path string, link string) (err error) {
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Listen(s int, backlog int) (err error) {
|
||||
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_llisten)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0)
|
||||
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_listen)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0)
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
|
||||
+41
@@ -632,6 +632,8 @@ const (
|
||||
IFA_FLAGS = 0x8
|
||||
IFA_RT_PRIORITY = 0x9
|
||||
IFA_TARGET_NETNSID = 0xa
|
||||
IFAL_LABEL = 0x2
|
||||
IFAL_ADDRESS = 0x1
|
||||
RT_SCOPE_UNIVERSE = 0x0
|
||||
RT_SCOPE_SITE = 0xc8
|
||||
RT_SCOPE_LINK = 0xfd
|
||||
@@ -689,6 +691,7 @@ const (
|
||||
SizeofRtAttr = 0x4
|
||||
SizeofIfInfomsg = 0x10
|
||||
SizeofIfAddrmsg = 0x8
|
||||
SizeofIfAddrlblmsg = 0xc
|
||||
SizeofIfaCacheinfo = 0x10
|
||||
SizeofRtMsg = 0xc
|
||||
SizeofRtNexthop = 0x8
|
||||
@@ -740,6 +743,15 @@ type IfAddrmsg struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
type IfAddrlblmsg struct {
|
||||
Family uint8
|
||||
_ uint8
|
||||
Prefixlen uint8
|
||||
Flags uint8
|
||||
Index uint32
|
||||
Seq uint32
|
||||
}
|
||||
|
||||
type IfaCacheinfo struct {
|
||||
Prefered uint32
|
||||
Valid uint32
|
||||
@@ -3052,6 +3064,23 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
TCA_UNSPEC = 0x0
|
||||
TCA_KIND = 0x1
|
||||
TCA_OPTIONS = 0x2
|
||||
TCA_STATS = 0x3
|
||||
TCA_XSTATS = 0x4
|
||||
TCA_RATE = 0x5
|
||||
TCA_FCNT = 0x6
|
||||
TCA_STATS2 = 0x7
|
||||
TCA_STAB = 0x8
|
||||
TCA_PAD = 0x9
|
||||
TCA_DUMP_INVISIBLE = 0xa
|
||||
TCA_CHAIN = 0xb
|
||||
TCA_HW_OFFLOAD = 0xc
|
||||
TCA_INGRESS_BLOCK = 0xd
|
||||
TCA_EGRESS_BLOCK = 0xe
|
||||
TCA_DUMP_FLAGS = 0xf
|
||||
TCA_EXT_WARN_MSG = 0x10
|
||||
RTNLGRP_NONE = 0x0
|
||||
RTNLGRP_LINK = 0x1
|
||||
RTNLGRP_NOTIFY = 0x2
|
||||
@@ -3086,6 +3115,18 @@ const (
|
||||
RTNLGRP_IPV6_MROUTE_R = 0x1f
|
||||
RTNLGRP_NEXTHOP = 0x20
|
||||
RTNLGRP_BRVLAN = 0x21
|
||||
RTNLGRP_MCTP_IFADDR = 0x22
|
||||
RTNLGRP_TUNNEL = 0x23
|
||||
RTNLGRP_STATS = 0x24
|
||||
RTNLGRP_IPV4_MCADDR = 0x25
|
||||
RTNLGRP_IPV6_MCADDR = 0x26
|
||||
RTNLGRP_IPV6_ACADDR = 0x27
|
||||
TCA_ROOT_UNSPEC = 0x0
|
||||
TCA_ROOT_TAB = 0x1
|
||||
TCA_ROOT_FLAGS = 0x2
|
||||
TCA_ROOT_COUNT = 0x3
|
||||
TCA_ROOT_TIME_DELTA = 0x4
|
||||
TCA_ROOT_EXT_WARN_MSG = 0x5
|
||||
)
|
||||
|
||||
type CapUserHeader struct {
|
||||
|
||||
+2
@@ -321,6 +321,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
||||
//sys SetConsoleOutputCP(cp uint32) (err error) = kernel32.SetConsoleOutputCP
|
||||
//sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW
|
||||
//sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW
|
||||
//sys GetNumberOfConsoleInputEvents(console Handle, numevents *uint32) (err error) = kernel32.GetNumberOfConsoleInputEvents
|
||||
//sys FlushConsoleInputBuffer(console Handle) (err error) = kernel32.FlushConsoleInputBuffer
|
||||
//sys resizePseudoConsole(pconsole Handle, size uint32) (hr error) = kernel32.ResizePseudoConsole
|
||||
//sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot
|
||||
//sys Module32First(snapshot Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32FirstW
|
||||
|
||||
+22
@@ -65,6 +65,22 @@ var signals = [...]string{
|
||||
15: "terminated",
|
||||
}
|
||||
|
||||
// File flags for [os.OpenFile]. The O_ prefix is used to indicate
|
||||
// that these flags are specific to the OpenFile function.
|
||||
const (
|
||||
O_FILE_FLAG_OPEN_NO_RECALL = FILE_FLAG_OPEN_NO_RECALL
|
||||
O_FILE_FLAG_OPEN_REPARSE_POINT = FILE_FLAG_OPEN_REPARSE_POINT
|
||||
O_FILE_FLAG_SESSION_AWARE = FILE_FLAG_SESSION_AWARE
|
||||
O_FILE_FLAG_POSIX_SEMANTICS = FILE_FLAG_POSIX_SEMANTICS
|
||||
O_FILE_FLAG_BACKUP_SEMANTICS = FILE_FLAG_BACKUP_SEMANTICS
|
||||
O_FILE_FLAG_DELETE_ON_CLOSE = FILE_FLAG_DELETE_ON_CLOSE
|
||||
O_FILE_FLAG_SEQUENTIAL_SCAN = FILE_FLAG_SEQUENTIAL_SCAN
|
||||
O_FILE_FLAG_RANDOM_ACCESS = FILE_FLAG_RANDOM_ACCESS
|
||||
O_FILE_FLAG_NO_BUFFERING = FILE_FLAG_NO_BUFFERING
|
||||
O_FILE_FLAG_OVERLAPPED = FILE_FLAG_OVERLAPPED
|
||||
O_FILE_FLAG_WRITE_THROUGH = FILE_FLAG_WRITE_THROUGH
|
||||
)
|
||||
|
||||
const (
|
||||
FILE_READ_DATA = 0x00000001
|
||||
FILE_READ_ATTRIBUTES = 0x00000080
|
||||
@@ -1976,6 +1992,12 @@ const (
|
||||
SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
|
||||
)
|
||||
|
||||
// FILE_ZERO_DATA_INFORMATION from winioctl.h
|
||||
type FileZeroDataInformation struct {
|
||||
FileOffset int64
|
||||
BeyondFinalZero int64
|
||||
}
|
||||
|
||||
const (
|
||||
ComputerNameNetBIOS = 0
|
||||
ComputerNameDnsHostname = 1
|
||||
|
||||
+501
-483
File diff suppressed because it is too large
Load Diff
Vendored
+2
-2
@@ -94,8 +94,8 @@ github.com/vishvananda/netns
|
||||
# golang.org/x/net v0.43.0
|
||||
## explicit; go 1.23.0
|
||||
golang.org/x/net/bpf
|
||||
# golang.org/x/sys v0.35.0
|
||||
## explicit; go 1.23.0
|
||||
# golang.org/x/sys v0.37.0
|
||||
## explicit; go 1.24.0
|
||||
golang.org/x/sys/unix
|
||||
golang.org/x/sys/windows
|
||||
# google.golang.org/protobuf v1.36.8
|
||||
|
||||
Reference in New Issue
Block a user