Skip to content

Commit e66a3bb

Browse files
committed
Merge branch 'master' into linux-612
2 parents d2a63d6 + df4a4da commit e66a3bb

31 files changed

+1071
-559
lines changed

Diff for: cpu/cpu_linux_arm64.go

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func doinit() {
110110
ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM)
111111
ARM64.HasDIT = isSet(hwCap, hwcap_DIT)
112112

113-
114113
// HWCAP2 feature bits
115114
ARM64.HasSVE2 = isSet(hwCap2, hwcap2_SVE2)
116115
ARM64.HasI8MM = isSet(hwCap2, hwcap2_I8MM)

Diff for: unix/ioctl_linux.go

+96
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,102 @@ func IoctlGetEthtoolDrvinfo(fd int, ifname string) (*EthtoolDrvinfo, error) {
5858
return &value, err
5959
}
6060

61+
// IoctlGetEthtoolTsInfo fetches ethtool timestamping and PHC
62+
// association for the network device specified by ifname.
63+
func IoctlGetEthtoolTsInfo(fd int, ifname string) (*EthtoolTsInfo, error) {
64+
ifr, err := NewIfreq(ifname)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
value := EthtoolTsInfo{Cmd: ETHTOOL_GET_TS_INFO}
70+
ifrd := ifr.withData(unsafe.Pointer(&value))
71+
72+
err = ioctlIfreqData(fd, SIOCETHTOOL, &ifrd)
73+
return &value, err
74+
}
75+
76+
// IoctlGetHwTstamp retrieves the hardware timestamping configuration
77+
// for the network device specified by ifname.
78+
func IoctlGetHwTstamp(fd int, ifname string) (*HwTstampConfig, error) {
79+
ifr, err := NewIfreq(ifname)
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
value := HwTstampConfig{}
85+
ifrd := ifr.withData(unsafe.Pointer(&value))
86+
87+
err = ioctlIfreqData(fd, SIOCGHWTSTAMP, &ifrd)
88+
return &value, err
89+
}
90+
91+
// IoctlSetHwTstamp updates the hardware timestamping configuration for
92+
// the network device specified by ifname.
93+
func IoctlSetHwTstamp(fd int, ifname string, cfg *HwTstampConfig) error {
94+
ifr, err := NewIfreq(ifname)
95+
if err != nil {
96+
return err
97+
}
98+
ifrd := ifr.withData(unsafe.Pointer(cfg))
99+
return ioctlIfreqData(fd, SIOCSHWTSTAMP, &ifrd)
100+
}
101+
102+
// FdToClockID derives the clock ID from the file descriptor number
103+
// - see clock_gettime(3), FD_TO_CLOCKID macros. The resulting ID is
104+
// suitable for system calls like ClockGettime.
105+
func FdToClockID(fd int) int32 { return int32((int(^fd) << 3) | 3) }
106+
107+
// IoctlPtpClockGetcaps returns the description of a given PTP device.
108+
func IoctlPtpClockGetcaps(fd int) (*PtpClockCaps, error) {
109+
var value PtpClockCaps
110+
err := ioctlPtr(fd, PTP_CLOCK_GETCAPS2, unsafe.Pointer(&value))
111+
return &value, err
112+
}
113+
114+
// IoctlPtpSysOffsetPrecise returns a description of the clock
115+
// offset compared to the system clock.
116+
func IoctlPtpSysOffsetPrecise(fd int) (*PtpSysOffsetPrecise, error) {
117+
var value PtpSysOffsetPrecise
118+
err := ioctlPtr(fd, PTP_SYS_OFFSET_PRECISE2, unsafe.Pointer(&value))
119+
return &value, err
120+
}
121+
122+
// IoctlPtpSysOffsetExtended returns an extended description of the
123+
// clock offset compared to the system clock. The samples parameter
124+
// specifies the desired number of measurements.
125+
func IoctlPtpSysOffsetExtended(fd int, samples uint) (*PtpSysOffsetExtended, error) {
126+
value := PtpSysOffsetExtended{Samples: uint32(samples)}
127+
err := ioctlPtr(fd, PTP_SYS_OFFSET_EXTENDED2, unsafe.Pointer(&value))
128+
return &value, err
129+
}
130+
131+
// IoctlPtpPinGetfunc returns the configuration of the specified
132+
// I/O pin on given PTP device.
133+
func IoctlPtpPinGetfunc(fd int, index uint) (*PtpPinDesc, error) {
134+
value := PtpPinDesc{Index: uint32(index)}
135+
err := ioctlPtr(fd, PTP_PIN_GETFUNC2, unsafe.Pointer(&value))
136+
return &value, err
137+
}
138+
139+
// IoctlPtpPinSetfunc updates configuration of the specified PTP
140+
// I/O pin.
141+
func IoctlPtpPinSetfunc(fd int, pd *PtpPinDesc) error {
142+
return ioctlPtr(fd, PTP_PIN_SETFUNC2, unsafe.Pointer(pd))
143+
}
144+
145+
// IoctlPtpPeroutRequest configures the periodic output mode of the
146+
// PTP I/O pins.
147+
func IoctlPtpPeroutRequest(fd int, r *PtpPeroutRequest) error {
148+
return ioctlPtr(fd, PTP_PEROUT_REQUEST2, unsafe.Pointer(r))
149+
}
150+
151+
// IoctlPtpExttsRequest configures the external timestamping mode
152+
// of the PTP I/O pins.
153+
func IoctlPtpExttsRequest(fd int, r *PtpExttsRequest) error {
154+
return ioctlPtr(fd, PTP_EXTTS_REQUEST2, unsafe.Pointer(r))
155+
}
156+
61157
// IoctlGetWatchdogInfo fetches information about a watchdog device from the
62158
// Linux watchdog API. For more information, see:
63159
// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html.

Diff for: unix/linux/Dockerfile

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.10
22

33
# Disable interactive prompts on package installation
4-
ENV DEBIAN_FRONTEND noninteractive
4+
ENV DEBIAN_FRONTEND=noninteractive
55

66
# Dependencies to get the git sources and go binaries
77
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -21,16 +21,16 @@ RUN git clone --branch v6.12-rc4 --depth 1 https://kernel.googlesource.com/pub/s
2121
RUN git clone --branch release/2.40/master --depth 1 https://sourceware.org/git/glibc.git
2222

2323
# Get Go
24-
ENV GOLANG_VERSION 1.23.0
25-
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
26-
ENV GOLANG_DOWNLOAD_SHA256 905a297f19ead44780548933e0ff1a1b86e8327bb459e92f9c0012569f76f5e3
24+
ENV GOLANG_VERSION=1.23.0
25+
ENV GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
26+
ENV GOLANG_DOWNLOAD_SHA256=905a297f19ead44780548933e0ff1a1b86e8327bb459e92f9c0012569f76f5e3
2727

2828
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
2929
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
3030
&& tar -C /usr/local -xzf golang.tar.gz \
3131
&& rm golang.tar.gz
3232

33-
ENV PATH /usr/local/go/bin:$PATH
33+
ENV PATH=/usr/local/go/bin:$PATH
3434

3535
# Linux and Glibc build dependencies and emulator
3636
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -48,25 +48,11 @@ RUN apt-get update && apt-get install -y \
4848
gcc-powerpc-linux-gnu gcc-powerpc64-linux-gnu \
4949
gcc-powerpc64le-linux-gnu gcc-riscv64-linux-gnu \
5050
gcc-s390x-linux-gnu gcc-sparc64-linux-gnu \
51+
gcc-loongarch64-linux-gnu \
5152
&& apt-get clean \
5253
&& rm -rf /var/lib/apt/lists/*
5354

54-
# Only for loong64, getting tools of qemu-user and gcc-cross-compiler
55-
ENV LOONG64_BASE_URL https://github.com/loongson/build-tools/releases/download/2023.08.08
56-
ENV LOONG64_GCC CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz
57-
ENV LOONG64_QEMU qemu-loongarch64
58-
ENV LOONG64_GCC_DOWNLOAD_URL $LOONG64_BASE_URL/$LOONG64_GCC
59-
ENV LOONG64_QEMU_DOWNLOAD_URL $LOONG64_BASE_URL/$LOONG64_QEMU
60-
61-
RUN apt-get update && apt-get install xz-utils -y && mkdir /loong64 && cd /loong64 \
62-
&& curl -fsSL "$LOONG64_QEMU_DOWNLOAD_URL" -o /usr/bin/"$LOONG64_QEMU" \
63-
&& chmod +x /usr/bin/"$LOONG64_QEMU" \
64-
&& curl -fsSL "$LOONG64_GCC_DOWNLOAD_URL" -o "$LOONG64_GCC" \
65-
&& tar xf "$LOONG64_GCC" -C /usr/local/ \
66-
&& ln -s /usr/local/cross-tools/bin/loongarch64-unknown-linux-gnu-gcc /usr/bin/loongarch64-linux-gnu-gcc \
67-
&& rm -rf /loong64
68-
6955
# Let the scripts know they are in the docker environment
70-
ENV GOLANG_SYS_BUILD docker
56+
ENV GOLANG_SYS_BUILD=docker
7157
WORKDIR /build/unix
7258
ENTRYPOINT ["go", "run", "linux/mkall.go", "/git/linux", "/git/glibc"]

Diff for: unix/linux/types.go

+65
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ package unix
2020
#define _FILE_OFFSET_BITS 64
2121
#define _GNU_SOURCE
2222
23+
// Ref: include/linux/time32.h
24+
//
25+
// On Linux, in order to solve the overflow problem of time_t type variables on
26+
// 32-bit arm, mips, and powerpc in 2038, the definition of time_t is switched
27+
// from a 32-bit field to a 64-bit field. For backward compatibility, we force
28+
// the use of 32-bit fields.
29+
#if defined(__ARM_EABI__) || \
30+
(defined(__mips__) && (_MIPS_SIM == _ABIO32)) || \
31+
(defined(__powerpc__) && (!defined(__powerpc64__)))
32+
# ifdef _TIME_BITS
33+
# undef _TIME_BITS
34+
# endif
35+
# define _TIME_BITS 32
36+
#endif
37+
2338
#include <dirent.h>
2439
#include <fcntl.h>
2540
#include <poll.h>
@@ -129,12 +144,14 @@ struct termios2 {
129144
#include <linux/netfilter.h>
130145
#include <linux/netfilter_ipv4.h>
131146
#include <linux/netlink.h>
147+
#include <linux/net_tstamp.h>
132148
#include <linux/nexthop.h>
133149
#include <linux/nfc.h>
134150
#include <linux/nl80211.h>
135151
#include <linux/openat2.h>
136152
#include <linux/perf_event.h>
137153
#include <linux/pps.h>
154+
#include <linux/ptp_clock.h>
138155
#include <linux/random.h>
139156
#include <linux/rtc.h>
140157
#include <linux/rtnetlink.h>
@@ -509,6 +526,15 @@ struct cachestat {
509526
__u64 nr_evicted;
510527
__u64 nr_recently_evicted;
511528
};
529+
530+
// the one defined in linux/ptp_clock.h has unions
531+
struct my_ptp_perout_request {
532+
struct ptp_clock_time startOrPhase; // start or phase
533+
struct ptp_clock_time period;
534+
unsigned int index;
535+
unsigned int flags;
536+
struct ptp_clock_time on;
537+
};
512538
*/
513539
import "C"
514540

@@ -4090,6 +4116,45 @@ const SPEED_UNKNOWN = C.SPEED_UNKNOWN
40904116

40914117
type EthtoolDrvinfo C.struct_ethtool_drvinfo
40924118

4119+
type EthtoolTsInfo C.struct_ethtool_ts_info
4120+
4121+
type HwTstampConfig C.struct_hwtstamp_config
4122+
4123+
const (
4124+
HWTSTAMP_FILTER_NONE = C.HWTSTAMP_FILTER_NONE
4125+
HWTSTAMP_FILTER_ALL = C.HWTSTAMP_FILTER_ALL
4126+
HWTSTAMP_FILTER_SOME = C.HWTSTAMP_FILTER_SOME
4127+
HWTSTAMP_FILTER_PTP_V1_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V1_L4_EVENT
4128+
HWTSTAMP_FILTER_PTP_V2_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L4_EVENT
4129+
HWTSTAMP_FILTER_PTP_V2_L2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L2_EVENT
4130+
HWTSTAMP_FILTER_PTP_V2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_EVENT
4131+
)
4132+
4133+
const (
4134+
HWTSTAMP_TX_OFF = C.HWTSTAMP_TX_OFF
4135+
HWTSTAMP_TX_ON = C.HWTSTAMP_TX_ON
4136+
HWTSTAMP_TX_ONESTEP_SYNC = C.HWTSTAMP_TX_ONESTEP_SYNC
4137+
)
4138+
4139+
type (
4140+
PtpClockCaps C.struct_ptp_clock_caps
4141+
PtpClockTime C.struct_ptp_clock_time
4142+
PtpExttsEvent C.struct_ptp_extts_event
4143+
PtpExttsRequest C.struct_ptp_extts_request
4144+
PtpPeroutRequest C.struct_my_ptp_perout_request
4145+
PtpPinDesc C.struct_ptp_pin_desc
4146+
PtpSysOffset C.struct_ptp_sys_offset
4147+
PtpSysOffsetExtended C.struct_ptp_sys_offset_extended
4148+
PtpSysOffsetPrecise C.struct_ptp_sys_offset_precise
4149+
)
4150+
4151+
const (
4152+
PTP_PF_NONE = C.PTP_PF_NONE
4153+
PTP_PF_EXTTS = C.PTP_PF_EXTTS
4154+
PTP_PF_PEROUT = C.PTP_PF_PEROUT
4155+
PTP_PF_PHYSYNC = C.PTP_PF_PHYSYNC
4156+
)
4157+
40934158
type (
40944159
HIDRawReportDescriptor C.struct_hidraw_report_descriptor
40954160
HIDRawDevInfo C.struct_hidraw_devinfo

Diff for: unix/mkerrors.sh

+12
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ includes_Linux='
158158
#endif
159159
#define _GNU_SOURCE
160160
161+
// See the description in unix/linux/types.go
162+
#if defined(__ARM_EABI__) || \
163+
(defined(__mips__) && (_MIPS_SIM == _ABIO32)) || \
164+
(defined(__powerpc__) && (!defined(__powerpc64__)))
165+
# ifdef _TIME_BITS
166+
# undef _TIME_BITS
167+
# endif
168+
# define _TIME_BITS 32
169+
#endif
170+
161171
// <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of
162172
// these structures. We just include them copied from <bits/termios.h>.
163173
#if defined(__powerpc__)
@@ -256,6 +266,7 @@ struct ltchars {
256266
#include <linux/nsfs.h>
257267
#include <linux/perf_event.h>
258268
#include <linux/pps.h>
269+
#include <linux/ptp_clock.h>
259270
#include <linux/ptrace.h>
260271
#include <linux/random.h>
261272
#include <linux/reboot.h>
@@ -527,6 +538,7 @@ ccflags="$@"
527538
$2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MREMAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ ||
528539
$2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ ||
529540
$2 ~ /^NFC_.*_(MAX)?SIZE$/ ||
541+
$2 ~ /^PTP_/ ||
530542
$2 ~ /^RAW_PAYLOAD_/ ||
531543
$2 ~ /^[US]F_/ ||
532544
$2 ~ /^TP_STATUS_/ ||

Diff for: unix/mkpost.go

+9
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ func main() {
185185
b = bytes.Replace(b, s, newNames, 1)
186186
}
187187

188+
// Convert []int8 to []byte in PtpPinDesc
189+
ptpBytesRegex := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]u?int8`)
190+
ptpIoctlType := regexp.MustCompile(`PtpPinDesc\s+struct {[^}]*}`)
191+
ptpStructs := ptpIoctlType.FindAll(b, -1)
192+
for _, s := range ptpStructs {
193+
newNames := ptpBytesRegex.ReplaceAll(s, []byte("$1$2[$3]byte"))
194+
b = bytes.Replace(b, s, newNames, 1)
195+
}
196+
188197
// Convert []int8 to []byte in ctl_info ioctl interface
189198
convertCtlInfoName := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]int8`)
190199
ctlInfoType := regexp.MustCompile(`type CtlInfo struct {[^}]*}`)

Diff for: unix/syscall_linux.go

+1
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
18601860
//sys ClockAdjtime(clockid int32, buf *Timex) (state int, err error)
18611861
//sys ClockGetres(clockid int32, res *Timespec) (err error)
18621862
//sys ClockGettime(clockid int32, time *Timespec) (err error)
1863+
//sys ClockSettime(clockid int32, time *Timespec) (err error)
18631864
//sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error)
18641865
//sys Close(fd int) (err error)
18651866
//sys CloseRange(first uint, last uint, flags uint) (err error)

Diff for: unix/syscall_linux_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,44 @@ func TestIoctlGetEthtoolDrvinfo(t *testing.T) {
6868
}
6969
}
7070

71+
func TestIoctlGetEthtoolTsInfo(t *testing.T) {
72+
if runtime.GOOS == "android" {
73+
t.Skip("ethtool driver info is not available on android, skipping test")
74+
}
75+
76+
s, err := unix.Socket(unix.AF_INET, unix.SOCK_STREAM, 0)
77+
if err != nil {
78+
t.Fatalf("failed to open socket: %v", err)
79+
}
80+
defer unix.Close(s)
81+
82+
ifis, err := net.Interfaces()
83+
if err != nil {
84+
t.Fatalf("failed to get network interfaces: %v", err)
85+
}
86+
87+
// Print the interface name and associated PHC information for each
88+
// network interface supported by ethtool.
89+
for _, ifi := range ifis {
90+
tsi, err := unix.IoctlGetEthtoolTsInfo(s, ifi.Name)
91+
if err != nil {
92+
if err == unix.EOPNOTSUPP {
93+
continue
94+
}
95+
96+
if err == unix.EBUSY {
97+
// See https://go.dev/issues/67350
98+
t.Logf("%s: ethtool driver busy, possible kernel bug", ifi.Name)
99+
continue
100+
}
101+
102+
t.Fatalf("failed to get ethtool PHC info for %q: %v", ifi.Name, err)
103+
}
104+
105+
t.Logf("%s: ptp%d", ifi.Name, tsi.Phc_index)
106+
}
107+
}
108+
71109
func TestIoctlGetInt(t *testing.T) {
72110
f, err := os.Open("/dev/random")
73111
if err != nil {

Diff for: unix/syscall_zos_s390x.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,10 @@ func Lstat(path string, stat *Stat_t) (err error) {
816816
// for checking symlinks begins with $VERSION/ $SYSNAME/ $SYSSYMR/ $SYSSYMA/
817817
func isSpecialPath(path []byte) (v bool) {
818818
var special = [4][8]byte{
819-
[8]byte{'V', 'E', 'R', 'S', 'I', 'O', 'N', '/'},
820-
[8]byte{'S', 'Y', 'S', 'N', 'A', 'M', 'E', '/'},
821-
[8]byte{'S', 'Y', 'S', 'S', 'Y', 'M', 'R', '/'},
822-
[8]byte{'S', 'Y', 'S', 'S', 'Y', 'M', 'A', '/'}}
819+
{'V', 'E', 'R', 'S', 'I', 'O', 'N', '/'},
820+
{'S', 'Y', 'S', 'N', 'A', 'M', 'E', '/'},
821+
{'S', 'Y', 'S', 'S', 'Y', 'M', 'R', '/'},
822+
{'S', 'Y', 'S', 'S', 'Y', 'M', 'A', '/'}}
823823

824824
var i, j int
825825
for i = 0; i < len(special); i++ {

0 commit comments

Comments
 (0)