Skip to content

Commit 58c870f

Browse files
committed
Optimize the compilation detection script for io_uring, fix #5653
1 parent 016bec5 commit 58c870f

File tree

7 files changed

+74
-32
lines changed

7 files changed

+74
-32
lines changed

config.m4

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,42 @@ AC_DEFUN([AC_SWOOLE_HAVE_BOOST_STACKTRACE],
285285
AC_LANG_POP([C++])
286286
])
287287

288+
AC_DEFUN([AC_SWOOLE_HAVE_IOURING_FUTEX],
289+
[
290+
AC_MSG_CHECKING([for io_uring futex])
291+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
292+
#define _GNU_SOURCE
293+
#include <liburing.h>
294+
]], [[
295+
int op = IORING_OP_FUTEX_WAIT;
296+
]])],[
297+
AC_DEFINE([HAVE_IOURING_FUTEX], 1, [have io_uring futex?])
298+
AC_MSG_RESULT([yes])
299+
],[
300+
AC_MSG_RESULT([no])
301+
])
302+
])
303+
304+
AC_DEFUN([AC_SWOOLE_HAVE_IOURING_STATX],
305+
[
306+
AC_MSG_CHECKING([for io_uring statx])
307+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
308+
#define _GNU_SOURCE
309+
#include <sys/stat.h>
310+
#include <string.h>
311+
#include <liburing.h>
312+
]], [[
313+
struct statx _statxbuf;
314+
memset(&_statxbuf, 0, sizeof(_statxbuf));
315+
int op = IORING_OP_STATX;
316+
]])],[
317+
AC_DEFINE([HAVE_IOURING_STATX], 1, [have io_uring statx?])
318+
AC_MSG_RESULT([yes])
319+
],[
320+
AC_MSG_RESULT([no])
321+
])
322+
])
323+
288324
AC_DEFUN([AC_SWOOLE_CHECK_SOCKETS], [
289325
AC_CHECK_FUNCS([hstrerror socketpair if_nametoindex if_indextoname])
290326
AC_CHECK_HEADERS([netdb.h netinet/tcp.h sys/un.h sys/sockio.h])
@@ -615,6 +651,7 @@ EOF
615651
dnl odbc end
616652

617653
dnl SWOOLE_ORACLE start
654+
618655
if test -z "$SED"; then
619656
SWOOLE_PDO_OCI_SED="sed";
620657
else
@@ -674,9 +711,9 @@ EOF
674711
PHP_ARG_WITH([swoole-oracle],
675712
[whether to enable oracle build flags],
676713
[AS_HELP_STRING([[--with-swoole-oracle[=DIR]]],
677-
[PDO: Oracle OCI support. DIR defaults to $ORACLE_HOME. Use
714+
["PDO: Oracle OCI support. DIR defaults to ${ORACLE_HOME}. Use
678715
--with-swoole-oracle=instantclient,/path/to/instant/client/lib for an Oracle
679-
Instant Client installation.])], [no], [no])
716+
Instant Client installation."])], [no], [no])
680717

681718
if test "$PHP_SWOOLE_ORACLE" != "no"; then
682719
if test "$PHP_PDO" = "no" && test "$ext_shared" = "no"; then
@@ -814,7 +851,7 @@ EOF
814851

815852
dnl sqlite start
816853
PHP_ARG_ENABLE([swoole-sqlite],
817-
[for sqlite 3 support for PDO],
854+
["for sqlite 3 support for PDO"],
818855
[AS_HELP_STRING([--enable-swoole-sqlite],
819856
[PDO: sqlite 3 support.])], [no], [no])
820857

@@ -962,35 +999,19 @@ EOF
962999
CFLAGS="-Wall -pthread $CFLAGS"
9631000
LDFLAGS="$LDFLAGS -lpthread"
9641001

965-
dnl Check should we link to librt
966-
9671002
if test "$PHP_IOURING" = "yes" && test "$SW_OS" = "LINUX"; then
968-
PKG_CHECK_MODULES([URING], [liburing >= 2.5])
1003+
PKG_CHECK_MODULES([URING], [liburing >= 2.0])
1004+
1005+
AC_SWOOLE_HAVE_IOURING_STATX
1006+
AC_SWOOLE_HAVE_IOURING_FUTEX
1007+
9691008
PHP_EVAL_LIBLINE($URING_LIBS, SWOOLE_SHARED_LIBADD)
9701009
PHP_EVAL_INCLINE($URING_CFLAGS)
9711010
AC_DEFINE(SW_USE_IOURING, 1, [have io_uring])
972-
973-
LINUX_VERSION=`uname -r | cut -d '-' -f 1`
974-
LINUX_MAJOR_VERSION=`echo $LINUX_VERSION | cut -d '.' -f 1`
975-
LINUX_MINOR_VERSION=`echo $LINUX_VERSION | cut -d '.' -f 2`
976-
977-
_PKG_CONFIG(URING_VERSION, [modversion], [liburing])
978-
IOURING_MAJOR_VERSION=`echo $pkg_cv_URING_VERSION | cut -d '.' -f 1`
979-
IOURING_MINOR_VERSION=`echo $pkg_cv_URING_VERSION | cut -d '.' -f 2`
980-
981-
AC_MSG_CHECKING([checking for io_uring futex feature])
982-
if test $IOURING_MAJOR_VERSION -gt 2 || (test $IOURING_MAJOR_VERSION -eq 2 && test $IOURING_MINOR_VERSION -ge 6); then
983-
if test $LINUX_MAJOR_VERSION -gt 6 || (test $LINUX_MAJOR_VERSION -eq 6 && test $LINUX_MINOR_VERSION -ge 7); then
984-
AC_MSG_RESULT(yes)
985-
AC_DEFINE(HAVE_IOURING_FUTEX, 1, [have io_uring futex feature])
986-
else
987-
AC_MSG_RESULT([no, Linux $LINUX_VERSION is too old])
988-
fi
989-
else
990-
AC_MSG_RESULT([no, liburing $IOURING_MAJOR_VERSION.$IOURING_MINOR_VERSION is too old])
991-
fi
9921011
fi
9931012

1013+
dnl Check should we link to librt
1014+
9941015
if test "$SW_OS" = "LINUX"; then
9951016
GLIBC_VERSION=$(getconf GNU_LIBC_VERSION | awk '{print $2}')
9961017
AC_MSG_NOTICE([glibc version: $GLIBC_VERSION])

include/swoole_coroutine_c_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ ssize_t swoole_coroutine_iouring_write(int sockfd, const void *buf, size_t count
7676
int swoole_coroutine_iouring_rename(const char *oldpath, const char *newpath);
7777
int swoole_coroutine_iouring_mkdir(const char *pathname, mode_t mode);
7878
int swoole_coroutine_iouring_unlink(const char *pathname);
79+
#ifdef HAVE_IOURING_STATX
7980
int swoole_coroutine_iouring_fstat(int fd, struct stat *statbuf);
8081
int swoole_coroutine_iouring_stat(const char *path, struct stat *statbuf);
8182
int swoole_coroutine_iouring_lstat(const char *path, struct stat *statbuf);
83+
#endif
8284
int swoole_coroutine_iouring_rmdir(const char *pathname);
8385
int swoole_coroutine_iouring_fsync(int fd);
8486
int swoole_coroutine_iouring_fdatasync(int fd);

include/swoole_file_hook.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#define rename(oldpath, newpath) swoole_coroutine_iouring_rename(oldpath, newpath)
2828
#define mkdir(pathname, mode) swoole_coroutine_iouring_mkdir(pathname, mode)
2929
#define unlink(pathname) swoole_coroutine_iouring_unlink(pathname)
30-
#define fstat(fd, statbuf) swoole_coroutine_iouring_fstat(fd, statbuf)
31-
#define stat(path, statbuf) swoole_coroutine_iouring_stat(path, statbuf)
32-
#define lstat(path, statbuf) swoole_coroutine_iouring_lstat(path, statbuf)
3330
#define rmdir(pathname) swoole_coroutine_iouring_rmdir(pathname)
3431
#define fsync(fd) swoole_coroutine_iouring_fsync(fd)
3532
#define fdatasync(fd) swoole_coroutine_iouring_fdatasync(fd)
@@ -39,9 +36,6 @@
3936
#define read(fd, buf, count) swoole_coroutine_read(fd, buf, count)
4037
#define write(fd, buf, count) swoole_coroutine_write(fd, buf, count)
4138
#define lseek(fd, offset, whence) swoole_coroutine_lseek(fd, offset, whence)
42-
#define fstat(fd, statbuf) swoole_coroutine_fstat(fd, statbuf)
43-
#define stat(path, statbuf) swoole_coroutine_stat(path, statbuf)
44-
#define lstat(path, statbuf) swoole_coroutine_lstat(path, statbuf)
4539
#define readlink(fd, buf, size) swoole_coroutine_readlink(fd, buf, size)
4640
#define unlink(pathname) swoole_coroutine_unlink(pathname)
4741
#define mkdir(pathname, mode) swoole_coroutine_mkdir(pathname, mode)
@@ -51,6 +45,16 @@
5145
#define fdatasync(fd) swoole_coroutine_fdatasync(fd)
5246
#endif
5347

48+
#ifdef HAVE_IOURING_STATX
49+
#define fstat(fd, statbuf) swoole_coroutine_iouring_fstat(fd, statbuf)
50+
#define stat(path, statbuf) swoole_coroutine_iouring_stat(path, statbuf)
51+
#define lstat(path, statbuf) swoole_coroutine_iouring_lstat(path, statbuf)
52+
#else
53+
#define fstat(fd, statbuf) swoole_coroutine_fstat(fd, statbuf)
54+
#define stat(path, statbuf) swoole_coroutine_stat(path, statbuf)
55+
#define lstat(path, statbuf) swoole_coroutine_lstat(path, statbuf)
56+
#endif
57+
5458
#define access(pathname, mode) swoole_coroutine_access(pathname, mode)
5559
#define fopen(pathname, mode) swoole_coroutine_fopen(pathname, mode)
5660
#define fdopen(fd, mode) swoole_coroutine_fdopen(fd, mode)

include/swoole_iouring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ class Iouring {
8383
static ssize_t rename(const char *oldpath, const char *newpath);
8484
static int mkdir(const char *pathname, mode_t mode);
8585
static int unlink(const char *pathname);
86+
#ifdef HAVE_IOURING_STATX
8687
static int fstat(int fd, struct stat *statbuf);
8788
static int stat(const char *path, struct stat *statbuf);
89+
#endif
8890
static int rmdir(const char *pathname);
8991
static int fsync(int fd);
9092
static int fdatasync(int fd);

scripts/make.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ if [ -n "$__HAVE_ZTS__" ]; then
1616
COMPILE_PARAMS="$COMPILE_PARAMS --enable-swoole-thread"
1717
fi
1818

19+
if [ "$(uname)" = "Linux" ]; then
20+
COMPILE_PARAMS="$COMPILE_PARAMS --enable-iouring"
21+
fi
22+
1923
if [ "$(uname | grep -i darwin)"x != ""x ]; then
2024
CPU_COUNT="$(sysctl -n machdep.cpu.core_count)"
2125
else
@@ -84,13 +88,18 @@ if [ "$1" = "help" ] ;then
8488
fi
8589

8690
phpize
91+
8792
if [ "$1" = "debug" ] ;then
8893
./configure ${COMPILE_PARAMS} --enable-debug-log
8994
elif [ "$1" = "trace" ] ;then
9095
./configure ${COMPILE_PARAMS} --enable-trace-log
96+
elif [ "$1" = "config" ] ;then
97+
./configure ${COMPILE_PARAMS}
98+
exit 0
9199
else
92100
./configure ${COMPILE_PARAMS}
93101
fi
102+
94103
make clean
95104
make -j ${CPU_COUNT}
96105
make install

src/coroutine/hook.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ int swoole_coroutine_iouring_unlink(const char *pathname) {
662662
return Iouring::unlink(pathname);
663663
}
664664

665+
#ifdef HAVE_IOURING_STATX
665666
int swoole_coroutine_iouring_fstat(int fd, struct stat *statbuf) {
666667
if (sw_unlikely(is_no_coro())) {
667668
return fstat(fd, statbuf);
@@ -683,6 +684,7 @@ int swoole_coroutine_iouring_lstat(const char *path, struct stat *statbuf) {
683684
// Iouring cannot distinguish between lstat and stat; these two operations are the same
684685
return Iouring::stat(path, statbuf);
685686
}
687+
#endif
686688

687689
int swoole_coroutine_iouring_rmdir(const char *pathname) {
688690
if (sw_unlikely(is_no_coro())) {

src/coroutine/iouring.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ int Iouring::fdatasync(int fd) {
456456
return execute(&event);
457457
}
458458

459+
#ifdef HAVE_IOURING_STATX
459460
static void swoole_statx_to_stat(const struct statx *statxbuf, struct stat *statbuf) {
460461
statbuf->st_dev = (((unsigned int) statxbuf->stx_dev_major) << 8) | (unsigned int) statxbuf->stx_dev_minor;
461462
statbuf->st_mode = statxbuf->stx_mode;
@@ -500,6 +501,7 @@ int Iouring::stat(const char *path, struct stat *statbuf) {
500501
}
501502
return retval;
502503
}
504+
#endif
503505

504506
#ifdef HAVE_IOURING_FUTEX
505507
int Iouring::futex_wait(uint32_t *futex) {

0 commit comments

Comments
 (0)