Skip to content

Commit 907a06c

Browse files
committed
Detect kernel version when creating iouring
1 parent e0a2bef commit 907a06c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/coroutine/iouring.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ struct IouringEvent {
7979
};
8080
};
8181

82+
static void parse_kernel_version(const char *release, int *major, int *minor) {
83+
char copy[_UTSNAME_RELEASE_LENGTH];
84+
strcpy(copy, release);
85+
86+
char *token = strtok(copy, ".-");
87+
*major = token ? atoi(token) : 0;
88+
89+
token = strtok(NULL, ".-");
90+
*minor = token ? atoi(token) : 0;
91+
}
92+
8293
Iouring::Iouring(Reactor *_reactor) {
8394
reactor = _reactor;
8495
if (SwooleG.iouring_entries > 0) {
@@ -110,6 +121,25 @@ Iouring::Iouring(Reactor *_reactor) {
110121
}
111122
}
112123

124+
int major, minor;
125+
parse_kernel_version(SwooleG.uname.release, &major, &minor);
126+
127+
#ifdef HAVE_IOURING_FUTEX
128+
if (!(major >= 6 && minor >= 7)) {
129+
swoole_error_log(SW_LOG_WARNING,
130+
SW_ERROR_OPERATION_NOT_SUPPORT,
131+
"The Iouring::futex_wait()/Iouring::futex_wakeup() requires `6.7` or higher Linux kernel");
132+
}
133+
#endif
134+
135+
#ifdef HAVE_IOURING_FTRUNCATE
136+
if (!(major >= 6 && minor >= 9)) {
137+
swoole_error_log(SW_LOG_WARNING,
138+
SW_ERROR_OPERATION_NOT_SUPPORT,
139+
"The Iouring::ftruncate() requires `6.9` or higher Linux kernel");
140+
}
141+
#endif
142+
113143
ring_socket = make_socket(ring.ring_fd, SW_FD_IOURING);
114144
ring_socket->object = this;
115145

0 commit comments

Comments
 (0)