From patchwork Sun Aug 18 18:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13767586 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D4FB145A07 for ; Sun, 18 Aug 2024 18:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007330; cv=none; b=tg/dBlme4m4DcjzLGARBiQrY5qIW1rfNY5ysye3ZkNxoFtqof1hKmep8O/zheH6/s0wiRJ+kmYChQKWoVSnK2eNCOVnZM82KpCrgAsYzTNhyMi86oMb2GXYAR7ndTRdPZec1BYFyzDhEG4J6xPTogPPfGRqUVJnxS7Qds8TV/Sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007330; c=relaxed/simple; bh=vDKYFSd6WIDGzxYRQAgA8Y6OXbyH3BGxmEHucEII6/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mPTyqFi22PvYJOXrq0I8HCKj0StxRg7s1o/7P9Fn1NJS9UC90dxoEiOFkYjbQEqm9DnU1ndyekoHXCjcWPuTt67OvXiqCuPGB0exfqKStUvKgnfgLtc/D9UPKhUjRp9cJwGGcLXHWV6I2mNvjg0mzrfjPMEVRAM0clOXsg6mC8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TyYOGSnW; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TyYOGSnW" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5bd1a9bdce4so4490456a12.3 for ; Sun, 18 Aug 2024 11:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724007326; x=1724612126; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VFiiYnDLsEJ9nMUfwvkt3h/S99VDnPvziXfLLXPYz7s=; b=TyYOGSnWzAglIJSumDgj9qChn9R/Y7noePXepOYW7UvDaiWGZ5Y1YmIwFjikg3bi6L buvHRW4y7hPJ+pviK7J/MucT49spBgh8SEur+/OxDF11tkRCBiTxqAxJs6y838L2It9S 1OTs7l6S+1wYkmLNsD51Acqeeg9IrNZtbMypIuYsfslo1RWD9N9AKEpQEEQWmQ8ysNMb Gbx3d9/zCz4GxF8q7wbwqGNLDnumutuclIDpwAX2OFmKmizJ4CbPrSkp45Xrh2duN0+t FNNevUG0C2vw4ESJbmDjz0uwdAvaHRW+xxfUECULO7nQb1Uc5/Rf6NXjRpbmaeW4FnoV OahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724007326; x=1724612126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VFiiYnDLsEJ9nMUfwvkt3h/S99VDnPvziXfLLXPYz7s=; b=G/M24eLEUb/FWW1g7ob3wQhiho1qpF8/6Bx+GYpam/L6y1sD3CvP3v+r4sqGZA8ada XgjVDHCUWS/rREd7JFUvX4y+H5VPBr8/6ot2DZeXWWmZDQbj0yAU+ywEUb3BLu+jOwkc z1ig533+EOZ/Ci6SpVKDCb74OgOtogVrnqS8qUVqUVO+f8OPzZWD90c36CiUoKvYXVnl KwatUGEq0kO6VsAr3g/BwivBMxD0pBHT4KjURlXmDoFmn92XgMP2PXTE0OCKUUd9TVKo N3gTxG1el0oJ6eCKRD9eDYp86ecpqFs+ZwqkAmR2mLBMTnYcjLOg8gU+Pyh9E/nBaPYn VFrQ== X-Gm-Message-State: AOJu0YzNDen7nstlo6cn0GEvhxN77AWyUOYxRk1E+jJlQooEl0aDwiOP 05gu5jefKT58UCAYxxbsrhdbG73mQBN9Q3AYrhKDtkQpOGzF9obMmTny2Q== X-Google-Smtp-Source: AGHT+IE6uv5fpilHFJKHnzQ6vumTwk3lM8Yz9w2D7wejQpQ4lyuc9dB5clrWzGbGfu2W5MXGDo3DSg== X-Received: by 2002:a50:8dc7:0:b0:5a4:622f:63c6 with SMTP id 4fb4d7f45d1cf-5beca56264emr4394177a12.13.1724007326038; Sun, 18 Aug 2024 11:55:26 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.74]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bebbbe274asm4867959a12.8.2024.08.18.11.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 11:55:25 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 1/4] Sync kernel headers Date: Sun, 18 Aug 2024 19:55:41 +0100 Message-ID: <4a613f7a38b4c9df7e1e7679a6e7e9cecc581ecc.1724007045.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Synchronise io_uring.h with kernel, pull IORING_REGISTER_CLOCK and all other changes. Signed-off-by: Pavel Begunkov --- src/include/liburing/io_uring.h | 67 ++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 01c36a8..48c440e 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -116,7 +116,7 @@ struct io_uring_sqe { */ #define IORING_FILE_INDEX_ALLOC (~0U) -enum { +enum io_uring_sqe_flags_bit { IOSQE_FIXED_FILE_BIT, IOSQE_IO_DRAIN_BIT, IOSQE_IO_LINK_BIT, @@ -184,7 +184,7 @@ enum { #define IORING_SETUP_DEFER_TASKRUN (1U << 13) /* - * Application provides ring memory + * Application provides the memory for the rings */ #define IORING_SETUP_NO_MMAP (1U << 14) @@ -265,11 +265,12 @@ enum io_uring_op { }; /* - * sqe->uring_cmd_flags + * sqe->uring_cmd_flags top 8bits aren't available for userspace * IORING_URING_CMD_FIXED use registered buffer; pass this flag * along with setting sqe->buf_index. */ #define IORING_URING_CMD_FIXED (1U << 0) +#define IORING_URING_CMD_MASK IORING_URING_CMD_FIXED /* @@ -317,15 +318,19 @@ enum io_uring_op { * ASYNC_CANCEL flags. * * IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key - * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the + * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the * request 'user_data' * IORING_ASYNC_CANCEL_ANY Match any request * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor + * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key + * IORING_ASYNC_CANCEL_OP Match request based on opcode */ #define IORING_ASYNC_CANCEL_ALL (1U << 0) #define IORING_ASYNC_CANCEL_FD (1U << 1) #define IORING_ASYNC_CANCEL_ANY (1U << 2) #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3) +#define IORING_ASYNC_CANCEL_USERDATA (1U << 4) +#define IORING_ASYNC_CANCEL_OP (1U << 5) /* * send/sendmsg and recv/recvmsg flags (sqe->ioprio) @@ -350,13 +355,13 @@ enum io_uring_op { * IORING_NOTIF_USAGE_ZC_COPIED if data was copied * (at least partially). * - * IORING_RECVSEND_BUNDLE Used with IOSQE_BUFFER_SELECT. If set, send wil - * grab as many buffers from the buffer group ID - * given and send them all. The completion result - * will be the number of buffers send, with the - * starting buffer ID in cqe->flags as per usual - * for provided buffer usage. The buffers will be - * contigious from the starting buffer ID. + * IORING_RECVSEND_BUNDLE Used with IOSQE_BUFFER_SELECT. If set, send or + * recv will grab as many buffers from the buffer + * group ID given and send them all. The completion + * result will be the number of buffers send, with + * the starting buffer ID in cqe->flags as per + * usual for provided buffer usage. The buffers + * will be contigious from the starting buffer ID. */ #define IORING_RECVSEND_POLL_FIRST (1U << 0) #define IORING_RECV_MULTISHOT (1U << 1) @@ -383,7 +388,7 @@ enum io_uring_op { /* * IORING_OP_MSG_RING command types, stored in sqe->addr */ -enum { +enum io_uring_msg_ring_flags { IORING_MSG_DATA, /* pass sqe->len as 'res' and off as user_data */ IORING_MSG_SEND_FD, /* send a registered fd to another ring */ }; @@ -416,7 +421,7 @@ enum { * IO completion data structure (Completion Queue Entry) */ struct io_uring_cqe { - __u64 user_data; /* sqe->user_data value passed back */ + __u64 user_data; /* sqe->data submission passed back */ __s32 res; /* result code for this event */ __u32 flags; @@ -441,9 +446,7 @@ struct io_uring_cqe { #define IORING_CQE_F_SOCK_NONEMPTY (1U << 2) #define IORING_CQE_F_NOTIF (1U << 3) -enum { - IORING_CQE_BUFFER_SHIFT = 16, -}; +#define IORING_CQE_BUFFER_SHIFT 16 /* * Magic offsets for the application to mmap the data it needs @@ -504,6 +507,7 @@ struct io_cqring_offsets { #define IORING_ENTER_SQ_WAIT (1U << 2) #define IORING_ENTER_EXT_ARG (1U << 3) #define IORING_ENTER_REGISTERED_RING (1U << 4) +#define IORING_ENTER_ABS_TIMER (1U << 5) /* * Passed in for io_uring_setup(2). Copied back with updated info on success @@ -543,7 +547,7 @@ struct io_uring_params { /* * io_uring_register(2) opcodes and arguments */ -enum { +enum io_uring_register_op { IORING_REGISTER_BUFFERS = 0, IORING_UNREGISTER_BUFFERS = 1, IORING_REGISTER_FILES = 2, @@ -592,6 +596,8 @@ enum { IORING_REGISTER_NAPI = 27, IORING_UNREGISTER_NAPI = 28, + IORING_REGISTER_CLOCK = 29, + /* this goes last */ IORING_REGISTER_LAST, @@ -600,7 +606,7 @@ enum { }; /* io-wq worker categories */ -enum { +enum io_wq_type { IO_WQ_BOUND, IO_WQ_UNBOUND, }; @@ -672,6 +678,11 @@ struct io_uring_restriction { __u32 resv2[3]; }; +struct io_uring_clock_register { + __u32 clockid; + __u32 __resv[3]; +}; + struct io_uring_buf { __u64 addr; __u32 len; @@ -691,7 +702,7 @@ struct io_uring_buf_ring { __u16 resv3; __u16 tail; }; - struct io_uring_buf bufs[0]; + __DECLARE_FLEX_ARRAY(struct io_uring_buf, bufs); }; }; @@ -705,7 +716,7 @@ struct io_uring_buf_ring { * IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT) * to get a virtual mapping for the ring. */ -enum { +enum io_uring_register_pbuf_ring_flags { IOU_PBUF_RING_MMAP = 1, }; @@ -727,16 +738,16 @@ struct io_uring_buf_status { /* argument for IORING_(UN)REGISTER_NAPI */ struct io_uring_napi { - __u32 busy_poll_to; - __u8 prefer_busy_poll; - __u8 pad[3]; - __u64 resv; + __u32 busy_poll_to; + __u8 prefer_busy_poll; + __u8 pad[3]; + __u64 resv; }; /* * io_uring_restriction->opcode values */ -enum { +enum io_uring_register_restriction_op { /* Allow an io_uring_register(2) opcode */ IORING_RESTRICTION_REGISTER_OP = 0, @@ -767,7 +778,9 @@ struct io_uring_sync_cancel_reg { __s32 fd; __u32 flags; struct __kernel_timespec timeout; - __u64 pad[4]; + __u8 opcode; + __u8 pad[7]; + __u64 pad2[3]; }; /* @@ -790,7 +803,7 @@ struct io_uring_recvmsg_out { /* * Argument for IORING_OP_URING_CMD when file is a socket */ -enum { +enum io_uring_socket_op { SOCKET_URING_OP_SIOCINQ = 0, SOCKET_URING_OP_SIOCOUTQ, SOCKET_URING_OP_GETSOCKOPT, From patchwork Sun Aug 18 18:55:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13767587 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4CB3145B26 for ; Sun, 18 Aug 2024 18:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007330; cv=none; b=Sy0GZ0/wo0KQ+/eVo8Z/9qK27ZYkRJGSkPTZLNJBfdJUQG+ZJPMlSIh7Te6JNO4EEaU15zJjPzln+ORYj3KjgVZBf3oVy2cOVqs7szb92HYA837p4C4lb6e1bw9IXtEM5OiUIJ7FMC/OiFsqcyfJtVZ2/lPXXrfUef5Qv2KPdpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007330; c=relaxed/simple; bh=FGikn6XePRAfCT1OgXm3UI93niF4mDZfTpgatgOQ9xE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HWN7SmOgqqg+b6a2h9XuqVjWKSNcp9CfmduYNSWqC+WFyUGnNSeOcjka/3s1l9CLbl8jkX7/kc0NwCJtb9mYURQedKHGSv5SSY87nk3qxYtaYHcnXqgoYVnAK2OeTU1l06oYknUq8DyKffFEIp8MnHHHN9kZfW2iB/p83j3SASo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XICVtIUD; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XICVtIUD" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5becdf7d36aso2307590a12.1 for ; Sun, 18 Aug 2024 11:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724007327; x=1724612127; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DwTtmvG5xQ2kbqf9TLb/9oN0eEv+JOHQx6L7riycuOI=; b=XICVtIUDZXAXtbsc/6zz/dvgyITCyriDU4mJymzjoQ6AXFmrE95Jdj4jSR4kQTlzN8 sNIfGG8x0NegF5QSkCrwH0NTUK3E3JLsrYsvEbeZTNjp9U1Hp1LvxsoyAz49q/oJoHIj YKcrd/kuYtYUZZD32yjaWnx+GGSl/8d+0Y+fN6Vqpenv5JYqqIHEITWG0fcu+68jbHqT Fbmlc/JICm3aeN8vf0FWqXvXJbo5+sNEyBlH8b3d8/WTKHONvLpi5L1cty9oWKdAFLwi ngP7K8PU3mhhMcpBz0l+y68tncP1+n2kKiKbQv/r2oi5p7I5D6TNNTy7iyUVHUII1Yev 3bTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724007327; x=1724612127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DwTtmvG5xQ2kbqf9TLb/9oN0eEv+JOHQx6L7riycuOI=; b=mycUJkc3miQvN1ZjWd2iio41rhipocBF4Tr9R0SgBupCOwBMj50vRFEpxagkToJCGG yu90m9HHgIcUSo2ONxbEGd07GlK5o78pK7uitm0vMlKdmttRDdJyGeME3JFFwlc+POta X2pEcSHXxLi1slujr3yZTTSmviCOI2N5n8IsM0G055lu3R2tb7/k+kr5XoP1VUoIoTRs QjGfYJGH1NfJX8doT5owZjQGf+JesmwRwHEU8s4Rsk5Y42psDUM2oOEMh5tJhZY3PKYO iHk5irkR94POf8RtZyOlz3/eZbuhSGFLJjxvqBIYroKdQ+mI348R596H8tg/4sKDWY62 zdDw== X-Gm-Message-State: AOJu0YxeQ9ce/Sd5sQE+aH7/07JxIE8jIJycrhVhHsvK6XeKoD2Yq/Nq jUJ0ETKUCFJ1r811srxQ4R1Ppm9x3lxHzPPS5v+1pQBzj96jFy/4ehLROg== X-Google-Smtp-Source: AGHT+IE5Pai9Nxi1buPJHdLQHRDpStoidzxnpoQ7hNQqQMN+ggbfMYipdnrGT9k0X/mqj4yEJcyIrg== X-Received: by 2002:a05:6402:520c:b0:5be:fa5f:565 with SMTP id 4fb4d7f45d1cf-5befa5f0661mr1066777a12.13.1724007326619; Sun, 18 Aug 2024 11:55:26 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.74]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bebbbe274asm4867959a12.8.2024.08.18.11.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 11:55:26 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 2/4] src/register: add clock id registration helper Date: Sun, 18 Aug 2024 19:55:42 +0100 Message-ID: <54a3393887e816ebf27ce3d50b7128adff6425dd.1724007045.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- src/include/liburing.h | 3 +++ src/liburing-ffi.map | 2 ++ src/liburing.map | 2 ++ src/register.c | 6 ++++++ 4 files changed, 13 insertions(+) diff --git a/src/include/liburing.h b/src/include/liburing.h index 1092f3b..53c94c4 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -241,6 +241,9 @@ int io_uring_register_file_alloc_range(struct io_uring *ring, int io_uring_register_napi(struct io_uring *ring, struct io_uring_napi *napi); int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi); +int io_uring_register_clock(struct io_uring *ring, + struct io_uring_clock_register *arg); + int io_uring_get_events(struct io_uring *ring); int io_uring_submit_and_get_events(struct io_uring *ring); diff --git a/src/liburing-ffi.map b/src/liburing-ffi.map index 476d7fd..a0bea31 100644 --- a/src/liburing-ffi.map +++ b/src/liburing-ffi.map @@ -206,4 +206,6 @@ LIBURING_2.7 { } LIBURING_2.6; LIBURING_2.8 { + global: + io_uring_register_clock; } LIBURING_2.7; diff --git a/src/liburing.map b/src/liburing.map index fa096bb..79f6068 100644 --- a/src/liburing.map +++ b/src/liburing.map @@ -97,4 +97,6 @@ LIBURING_2.7 { } LIBURING_2.6; LIBURING_2.8 { + global: + io_uring_register_clock; } LIBURING_2.7; diff --git a/src/register.c b/src/register.c index 9acc36f..c0690a8 100644 --- a/src/register.c +++ b/src/register.c @@ -366,3 +366,9 @@ int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi) { return do_register(ring, IORING_UNREGISTER_NAPI, napi, 1); } + +int io_uring_register_clock(struct io_uring *ring, + struct io_uring_clock_register *arg) +{ + return do_register(ring, IORING_REGISTER_CLOCK, arg, 0); +} From patchwork Sun Aug 18 18:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13767588 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DE7C149E0E for ; Sun, 18 Aug 2024 18:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007331; cv=none; b=knzp9AYdKqH3m0F/u9CO3lAzb6T0ZIJ7hLRYmt6pQgPO6OixXivnVSpYro4cWt5EiWbydB8VvKH7f/L+IKwut2XNxMm6dXECUhjHseLYxkzd2ty4Htt1a0uQZPX/wk5TgNxqjNQ0hIN4EFhaIzrF0j6J2GTN5Q538d8AfIgsz6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007331; c=relaxed/simple; bh=d+z5SZ1ad6FhR/lLYbiMXXdlt72Kyy2Ry6VChQOKQ5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cmte4GClyLkIeGSGOiXYBtO22jNS2DwDA835Vzaiy18qX6ty1BPHAvxCQfkI9yLtPy0j6wrVB68mfzjC7ihvM7NVZ0Wz5biwFXIPRr5sESq/5iM7DxsWFrKx91j+kPPKG6HVwwypaKrpn2qaZcoYk1Ixwy66O+1nbonBCprVCSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k6TLI/RB; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k6TLI/RB" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5becfd14353so2230568a12.1 for ; Sun, 18 Aug 2024 11:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724007327; x=1724612127; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8bDDMZa4VbATfcTZDsTX6UoY3yLV2EktRii/eFuFOvo=; b=k6TLI/RBYiVKDjfjIiuVN1+tkzvDDIPuEYDWV6eA9m+NaSuzCKRf0A4pe2KEzKnNOg zw90oK2uF919NGccZkTu4gw8e8/6UCr4pi2ixydpyMck9p4iXOfQGzLNGKh6SFGH4WZ3 iqf6KFZc3/5/u0O15LTA1Nu7CzHaEoLOmHCqbrWU4CKdtDvvkn6dmQy/DBMhntHlemDz YCV8nTBaYgR4g7O6nV9mltI4PJB5GxoChQNKxphWa5oI2ujzEUNEkfJs8i1gzOqpF1f4 QCftBEJw2OJdDam/Sr8ExavDLJIiaJzhReK5h/1zXB2nW4jqxug072ZgjmTxpW2mx4M0 pT5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724007327; x=1724612127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8bDDMZa4VbATfcTZDsTX6UoY3yLV2EktRii/eFuFOvo=; b=j1OwOyhEwlKL+HR1uEf4Py2RHBaFyt+HpZanQhZJUAUmkcTBNIb5Uyf9+ykUiDK52F YlEJJtsdejDrtcsejOm5q11KIvrylMD8XMAzBVxxnuk0pj7/V8V6n4uTepqZ8FXLVkmZ B5GYKDglqzAQCDTStDNxFbVcf20clGwpQbOe3EzGzhG7rAvYf/nPeWrRzWQ53DMcGQ8C JzPj6rrbA3cvnTbX29/yTd8j3E/HRkOYTMupzdYCcm4f72Bfb1CUATaK2lmKMni6tfWT Y/6/t9/eJEFag/g2NgPtDJhhvDyT1YM1UJDqBk276bSJ5jCkG1APl+zVvrfygS+rRiO3 ICdQ== X-Gm-Message-State: AOJu0Yx7WKkTUcGR1R2PPh+5BMWaH+N4PBo3x8Q8O/+1HYU6/yhtRO2C Tsgt/Irzo8szKe0lydekEohf10v8brJVT753O0w2vMJ1bwB2cbW/jk2nFA== X-Google-Smtp-Source: AGHT+IEs7ECGutv1dI2WpPoA/ugE9t8J+KRXAInQQtiKBaGncW2sA9N95SuSNzBG8y+t0MgfwoYDPw== X-Received: by 2002:a05:6402:518e:b0:5be:f3f7:a8ff with SMTP id 4fb4d7f45d1cf-5bef3f7ab42mr1303032a12.21.1724007327345; Sun, 18 Aug 2024 11:55:27 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.74]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bebbbe274asm4867959a12.8.2024.08.18.11.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 11:55:26 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 3/4] test: test clockids and abs timeouts Date: Sun, 18 Aug 2024 19:55:43 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- test/Makefile | 1 + test/wait-timeout.c | 283 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 284 insertions(+) create mode 100644 test/wait-timeout.c diff --git a/test/Makefile b/test/Makefile index 0538a75..f4fccd7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -213,6 +213,7 @@ test_srcs := \ unlink.c \ version.c \ waitid.c \ + wait-timeout.c \ wakeup-hang.c \ wq-aff.c \ xattr.c \ diff --git a/test/wait-timeout.c b/test/wait-timeout.c new file mode 100644 index 0000000..1fc8e28 --- /dev/null +++ b/test/wait-timeout.c @@ -0,0 +1,283 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Description: run various timeout tests + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "helpers.h" +#include "liburing.h" +#include "../src/syscall.h" + +#define IO_NSEC_PER_SEC 1000000000LU + +static bool support_abs = false; +static bool support_clock = false; + +static unsigned long long timespec_to_ns(struct timespec *ts) +{ + return ts->tv_nsec + ts->tv_sec * IO_NSEC_PER_SEC; +} +static struct timespec ns_to_timespec(unsigned long long t) +{ + struct timespec ts; + + ts.tv_sec = t / IO_NSEC_PER_SEC; + ts.tv_nsec = t - ts.tv_sec * IO_NSEC_PER_SEC; + return ts; +} + +static long long ns_since(struct timespec *ts) +{ + struct timespec now; + int ret; + + ret = clock_gettime(CLOCK_MONOTONIC, &now); + if (ret) { + fprintf(stderr, "clock_gettime failed\n"); + exit(T_EXIT_FAIL); + } + + return timespec_to_ns(&now) - timespec_to_ns(ts); + +} + +static int t_io_uring_wait(struct io_uring *ring, int nr, unsigned enter_flags, + struct timespec *ts) +{ + struct io_uring_getevents_arg arg = { + .sigmask = 0, + .sigmask_sz = _NSIG / 8, + .ts = (unsigned long)ts + }; + int ret; + + enter_flags |= IORING_ENTER_GETEVENTS | IORING_ENTER_EXT_ARG; + ret = io_uring_enter2(ring->ring_fd, 0, nr, enter_flags, + (void *)&arg, sizeof(arg)); + return ret; +} + +static int probe_timers(void) +{ + struct io_uring_clock_register cr = { .clockid = CLOCK_MONOTONIC, }; + struct io_uring ring; + struct timespec ts; + int ret; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "probe ring setup failed: %d\n", ret); + return ret; + } + + ret = clock_gettime(CLOCK_MONOTONIC, &ts); + if (ret) { + fprintf(stderr, "clock_gettime failed\n"); + return ret; + } + + ret = t_io_uring_wait(&ring, 0, IORING_ENTER_ABS_TIMER, &ts); + if (!ret) { + support_abs = true; + } else if (ret != -EINVAL) { + fprintf(stderr, "wait failed %i\n", ret); + return ret; + } + + ret = io_uring_register_clock(&ring, &cr); + if (!ret) { + support_clock = true; + } else if (ret != -EINVAL) { + fprintf(stderr, "io_uring_register_clock %i\n", ret); + return ret; + } + + io_uring_queue_exit(&ring); + return 0; +} + +static int test_timeout(bool abs, bool set_clock) +{ + unsigned enter_flags = abs ? IORING_ENTER_ABS_TIMER : 0; + struct io_uring ring; + struct timespec start, end, ts; + long long dt; + int ret; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "ring setup failed: %d\n", ret); + return 1; + } + + if (set_clock) { + struct io_uring_clock_register cr = {}; + + cr.clockid = CLOCK_BOOTTIME; + ret = io_uring_register_clock(&ring, &cr); + if (ret) { + fprintf(stderr, "io_uring_register_clock failed\n"); + return 1; + } + } + + /* pass current time */ + ret = clock_gettime(CLOCK_MONOTONIC, &start); + assert(ret == 0); + + ts = abs ? start : ns_to_timespec(0); + ret = t_io_uring_wait(&ring, 1, enter_flags, &ts); + if (ret != -ETIME) { + fprintf(stderr, "wait current time failed, %i\n", ret); + return 1; + } + + if (ns_since(&start) >= IO_NSEC_PER_SEC) { + fprintf(stderr, "current time test failed\n"); + return 1; + } + + if (abs) { + /* expired time */ + ret = clock_gettime(CLOCK_MONOTONIC, &start); + assert(ret == 0); + ts = ns_to_timespec(timespec_to_ns(&start) - IO_NSEC_PER_SEC); + + ret = t_io_uring_wait(&ring, 1, enter_flags, &ts); + if (ret != -ETIME) { + fprintf(stderr, "expired timeout wait failed, %i\n", ret); + return 1; + } + + ret = clock_gettime(CLOCK_MONOTONIC, &end); + assert(ret == 0); + + if (ns_since(&start) >= IO_NSEC_PER_SEC) { + fprintf(stderr, "expired timer test failed\n"); + return 1; + } + } + + /* 1s wait */ + ret = clock_gettime(CLOCK_MONOTONIC, &start); + assert(ret == 0); + + dt = 2 * IO_NSEC_PER_SEC + (abs ? timespec_to_ns(&start) : 0); + ts = ns_to_timespec(dt); + ret = t_io_uring_wait(&ring, 1, enter_flags, &ts); + if (ret != -ETIME) { + fprintf(stderr, "wait timeout failed, %i\n", ret); + return 1; + } + + dt = ns_since(&start); + if (dt < IO_NSEC_PER_SEC || dt > 3 * IO_NSEC_PER_SEC) { + fprintf(stderr, "early wake up, %lld\n", dt); + return 1; + } + return 0; +} + +static int test_clock_setup(void) +{ + struct io_uring ring; + struct io_uring_clock_register cr = {}; + int ret; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret) { + fprintf(stderr, "ring setup failed: %d\n", ret); + return T_EXIT_FAIL; + } + + ret = __sys_io_uring_register(ring.ring_fd, IORING_REGISTER_CLOCK, NULL, 0); + if (!ret) { + fprintf(stderr, "invalid null clock registration %i\n", ret); + return T_EXIT_FAIL; + } + + cr.clockid = -1; + ret = __sys_io_uring_register(ring.ring_fd, IORING_REGISTER_CLOCK, &cr, 0); + if (ret != -EINVAL) { + fprintf(stderr, "invalid clockid registration %i\n", ret); + return T_EXIT_FAIL; + } + + cr.clockid = CLOCK_MONOTONIC; + ret = __sys_io_uring_register(ring.ring_fd, IORING_REGISTER_CLOCK, &cr, 0); + if (ret) { + fprintf(stderr, "clock monotonic registration failed %i\n", ret); + return T_EXIT_FAIL; + } + + cr.clockid = CLOCK_BOOTTIME; + ret = __sys_io_uring_register(ring.ring_fd, IORING_REGISTER_CLOCK, &cr, 0); + if (ret) { + fprintf(stderr, "clock boottime registration failed %i\n", ret); + return T_EXIT_FAIL; + } + + cr.clockid = CLOCK_MONOTONIC; + ret = __sys_io_uring_register(ring.ring_fd, IORING_REGISTER_CLOCK, &cr, 0); + if (ret) { + fprintf(stderr, "2nd clock monotonic registration failed %i\n", ret); + return T_EXIT_FAIL; + } + + io_uring_queue_exit(&ring); + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret, i; + + if (argc > 1) + return 0; + + ret = probe_timers(); + if (ret) { + fprintf(stderr, "probe failed\n"); + return T_EXIT_FAIL; + } + if (!support_abs && !support_clock) + return T_EXIT_SKIP; + + if (support_clock) { + ret = test_clock_setup(); + if (ret) { + fprintf(stderr, "test_clock_setup failed\n"); + return T_EXIT_FAIL; + } + } + + for (i = 0; i < 4; i++) { + bool abs = i & 1; + bool clock = i & 2; + + if (abs && !support_abs) + continue; + if (clock && !support_clock) + continue; + + ret = test_timeout(abs, clock); + if (ret) { + fprintf(stderr, "test_timeout failed %i %i\n", + abs, clock); + return ret; + } + } + + return 0; +} From patchwork Sun Aug 18 18:55:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13767589 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28DD2145A07 for ; Sun, 18 Aug 2024 18:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007332; cv=none; b=QDw39t8O/HIS0OczInQ8JohFEiBzfFq/i/4w+QTUybg/v649hgTO1DGk+JiLkpydGF266+JnXBbhvmiwj0Gu0zDeBYa2Pz+u/C4CweUPFz9IKrax2CbjCRuzwPUERCx718Be0EP3eFMgWinKG/Q9cmkI3atLtWXdycMK9+lSr1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724007332; c=relaxed/simple; bh=EQ1cVTgvrS1yxyAPhs3J+3/SaP+QHDOB/vB1YXhhe4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j3S5i13YDlLG1WJzprM9G6MsEN0FXvjUsuIbiUWGaf6h8HQ6Ru0VU0vu8O56mlpQQUkxxIGXW3IkWamxLcvVYa7bh7EUAudx6zOdWR+FixOqhASmtUI3qHd0ytXY75bMyq4VOnq/WlK9IGfTb859QxlkDo7s9JguTzLfNsBhLzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Crkih9gn; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Crkih9gn" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2f0dfdc9e16so42878011fa.2 for ; Sun, 18 Aug 2024 11:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724007329; x=1724612129; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O4sCPII+pcoa6DUxzxkE+8aJquhC6c6yaoUGcQMg4OE=; b=Crkih9gnp1vk1DieMOUrY0W11d3JqQjulxwMooJ7j6g5jxjZ9bqYqlLb0L2MQM8lAz zzr6qoUma0JssmhdUJqMI/sqcBSd629VgGEsjAQWbVWlf4m+EYzTRSbMMhx/dB2q7ahf UxcQVe2U75Z3W2kNUXdIZf7XTRNttYZWnbroQc4r4b57qcJTIl8/R5osq5sK+c7klvBD rgu+NoSfYCjpfogIqAHo9r0nfZTaOh/yu2QkWQ0yvPil15VP0+16rOuGoSYWrX0KrD6l TrhhJ/hHANaC9wg7syWQj03wYXvbzK76eM0dspouSpHlfudIrYHauZ/7tEBf28LNLqgX k8qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724007329; x=1724612129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O4sCPII+pcoa6DUxzxkE+8aJquhC6c6yaoUGcQMg4OE=; b=wr1OknaIkDYGgG2ZgaH+HWSurMAa84bUUpHISvuxVnHqC4z+UFyBpM+jlhAMsXOHK/ Tl1PgqSo1J64OZu5iVUsfbjsMIdVWvfQIEsr02Xn1e+WyPSSZOZr59CXmJOwARnjw0Hc /sJatNVMmmefX+XpTNGx3drqgd58fqmRGDkPuazCEXZd1vP0FNQegUK4GcdeIgG4XugK Jurt3oXH+uIKYTfqnp7wYZakD/p/o+XwFv0s9e7L9PtAy9mx3KnoFSeNyw3Q8uRjpCYC 9dkfto/egWnp0lzgCyKQ5avce31PEFfw/C2nR+jur7SGjDczNAiRbkoc+CcNpvVUmDye UJEw== X-Gm-Message-State: AOJu0YyYK7hXPzGHyVCS8cwwzIXPXh7gwB2/7uAtvRSQ1Af2K18SwEtX SNzzhCfftb6HBYxt6LVXwo0uqtvZ1CerpHDSmLd1gykeweOV76DjVfA9OA== X-Google-Smtp-Source: AGHT+IF5C4MSeAsF30EQjEuT+9sf551D6Xp2Vyc9WtmjSYXKPXV82k5w2jialAxZCSKIq+t4tKkcJw== X-Received: by 2002:a2e:b04a:0:b0:2f3:b74b:fbec with SMTP id 38308e7fff4ca-2f3c8ed6dccmr32393291fa.20.1724007328336; Sun, 18 Aug 2024 11:55:28 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.74]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bebbbe274asm4867959a12.8.2024.08.18.11.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 11:55:27 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 4/4] man: document clock id and IORING_ENTER_ABS_TIMER Date: Sun, 18 Aug 2024 19:55:44 +0100 Message-ID: <24844efb9ef46691fa15a1da5198aaae3f759d1c.1724007045.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- man/io_uring_enter.2 | 12 ++++++++++++ man/io_uring_register.2 | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/man/io_uring_enter.2 b/man/io_uring_enter.2 index 5e4121b..8c79771 100644 --- a/man/io_uring_enter.2 +++ b/man/io_uring_enter.2 @@ -105,6 +105,18 @@ then setting this flag will tell the kernel that the .I ring_fd passed in is the registered ring offset rather than a normal file descriptor. +.TP +.B IORING_ENTER_ABS_TIMER + +When this flag is set, the timeout argument passed in +.I struct io_uring_getevents_arg +will be interpreted as an absolute +time of the registered clock (see +.B IORING_REGISTER_CLOCK +) until which the waiting should end. + +Available since 6.12 + .PP .PP If the io_uring instance was configured for polling, by specifying diff --git a/man/io_uring_register.2 b/man/io_uring_register.2 index 4590588..c8521b7 100644 --- a/man/io_uring_register.2 +++ b/man/io_uring_register.2 @@ -720,6 +720,26 @@ The application must have registered a file table first. Available since 6.0. +.TP +.B IORING_REGISTER_CLOCK +Specifies which clock id io_uring will use for timers while waiting for +completion events with +.B IORING_ENTER_GETEVENTS. +It's only effective if the timeout argument in +.I struct io_uring_getevents_arg +is passed, ignored otherwise. +When used in conjunction with +.B IORING_ENTER_ABS_TIMER, +interprets the timeout argument as absolute time of the specified clock. + +The default clock is +.B CLOCK_MONOTONIC. + +Available since 6.12 and supports +.B CLOCK_MONOTONIC +and +.B CLOCK_BOOTTIME. + .SH RETURN VALUE On success,