Commit Graph

8 Commits

Author SHA1 Message Date
Jeff Moyer 2d421fea35 io_uring/napi: check napi_enabled in io_napi_add() before proceeding
JIRA: https://issues.redhat.com/browse/RHEL-64867
Conflicts: RHEL does not have commit 342b2e395d5f ("io_uring/napi: use
ktime in busy polling"), which renames napi_busy_poll_to to
napi_busy_poll_dt.

commit 84f2eecf95018386c145ada19bb45b03bdb80d9e
Author: Olivier Langlois <olivier@trillion01.com>
Date:   Sun Aug 11 14:07:11 2024 -0400

    io_uring/napi: check napi_enabled in io_napi_add() before proceeding
    
    doing so avoids the overhead of adding napi ids to all the rings that do
    not enable napi.
    
    if no id is added to napi_list because napi is disabled,
    __io_napi_busy_loop() will not be called.
    
    Signed-off-by: Olivier Langlois <olivier@trillion01.com>
    Fixes: b4ccc4dd1330 ("io_uring/napi: enable even with a timeout of 0")
    Link: https://lore.kernel.org/r/bd989ccef5fda14f5fd9888faf4fefcf66bd0369.1723400131.git.olivier@trillion01.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-12-02 11:14:52 -05:00
Jeff Moyer a9fec1e278 io_uring: don't allow netpolling with SETUP_IOPOLL
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit bd44d7e902c2b34c217d3b48874b079760ca7b6e
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Wed Jul 24 12:16:17 2024 +0100

    io_uring: don't allow netpolling with SETUP_IOPOLL
    
    IORING_SETUP_IOPOLL rings don't have any netpoll handling, let's fail
    attempts to register netpolling in this case, there might be people who
    will mix up IOPOLL and netpoll.
    
    Cc: stable@vger.kernel.org
    Fixes: ef1186c1a875b ("io_uring: add register/unregister napi function")
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/1e7553aee0a8ae4edec6742cd6dd0c1e6914fba8.1721819383.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-12-02 11:14:52 -05:00
Jeff Moyer 34f8648721 io_uring/napi: fix timeout calculation
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 415ce0ea55c5a3afea501a773e002be9ed7149f5
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Jun 3 13:56:53 2024 -0600

    io_uring/napi: fix timeout calculation
    
    Not quite sure what __io_napi_adjust_timeout() was attemping to do, it's
    adjusting both the NAPI timeout and the general overall timeout, and
    calculating a value that is never used. The overall timeout is a super
    set of the NAPI timeout, and doesn't need adjusting. The only thing we
    really need to care about is that the NAPI timeout doesn't exceed the
    overall timeout. If a user asked for a timeout of eg 5 usec and NAPI
    timeout is 10 usec, then we should not spin for 10 usec.
    
    While in there, sanitize the time checking a bit. If we have a negative
    value in the passed in timeout, discard it. Round up the value as well,
    so we don't end up with a NAPI timeout for the majority of the wait,
    with only a tiny sleep value at the end.
    
    Hence the only case we need to care about is if the NAPI timeout is
    larger than the overall timeout. If it is, cap the NAPI timeout at what
    the overall timeout is.
    
    Cc: stable@vger.kernel.org
    Fixes: 8d0c12a80cde ("io-uring: add napi busy poll support")
    Reported-by: Lewis Baker <lewissbaker@gmail.com>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-12-02 11:12:48 -05:00
Jeff Moyer d60be5481b io_uring/napi: enable even with a timeout of 0
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit b4ccc4dd1330a4d0db6aa4c6781631d1bab76c45
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Feb 15 15:30:33 2024 -0700

    io_uring/napi: enable even with a timeout of 0
    
    1 usec is not as short as it used to be, and it makes sense to allow 0
    for a busy poll timeout - this means just do one loop to check if we
    have anything available. Add a separate ->napi_enabled to check if napi
    has been enabled or not.
    
    While at it, move the writing of the ctx napi values after we've copied
    the old values back to userspace. This ensures that if the call fails,
    we'll be in the same state as we were before, rather than some
    indeterminate state.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:48:44 -05:00
Jeff Moyer ee6e5ff7da io_uring/napi: ensure napi polling is aborted when work is available
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 428f13826855e3eea44bf13cedbf33f382ef8794
Author: Jens Axboe <axboe@kernel.dk>
Date:   Wed Feb 14 12:59:36 2024 -0700

    io_uring/napi: ensure napi polling is aborted when work is available
    
    While testing io_uring NAPI with DEFER_TASKRUN, I ran into slowdowns and
    stalls in packet delivery. Turns out that while
    io_napi_busy_loop_should_end() aborts appropriately on regular
    task_work, it does not abort if we have local task_work pending.
    
    Move io_has_work() into the private io_uring.h header, and gate whether
    we should continue polling on that as well. This makes NAPI polling on
    send/receive work as designed with IORING_SETUP_DEFER_TASKRUN as well.
    
    Fixes: 8d0c12a80cde ("io-uring: add napi busy poll support")
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:44:44 -05:00
Jeff Moyer 99e9be3e6c io_uring: add register/unregister napi function
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit ef1186c1a875bfa8a8cbfc2a9670b14b082187a9
Author: Stefan Roesch <shr@devkernel.io>
Date:   Thu Jun 8 09:38:38 2023 -0700

    io_uring: add register/unregister napi function
    
    This adds an api to register and unregister the napi for io-uring. If
    the arg value is specified when unregistering, the current napi setting
    for the busy poll timeout is copied into the user structure. If this is
    not required, NULL can be passed as the arg value.
    
    Signed-off-by: Stefan Roesch <shr@devkernel.io>
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Link: https://lore.kernel.org/r/20230608163839.2891748-7-shr@devkernel.io
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:42:44 -05:00
Jeff Moyer 2a41c78e02 io-uring: add sqpoll support for napi busy poll
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit ff183d427da0a733b0dbe11bd7acaf2dcb37b4cc
Author: Stefan Roesch <shr@devkernel.io>
Date:   Thu Jun 8 09:38:37 2023 -0700

    io-uring: add sqpoll support for napi busy poll
    
    This adds the sqpoll support to the io-uring napi.
    
    Signed-off-by: Stefan Roesch <shr@devkernel.io>
    Suggested-by: Olivier Langlois <olivier@trillion01.com>
    Link: https://lore.kernel.org/r/20230608163839.2891748-6-shr@devkernel.io
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:41:44 -05:00
Jeff Moyer 7abbe65ada io-uring: add napi busy poll support
JIRA: https://issues.redhat.com/browse/RHEL-64867

commit 8d0c12a80cdeb80d5e0510e96d38fe551ed8e9b5
Author: Stefan Roesch <shr@devkernel.io>
Date:   Thu Jun 8 09:38:36 2023 -0700

    io-uring: add napi busy poll support
    
    This adds the napi busy polling support in io_uring.c. It adds a new
    napi_list to the io_ring_ctx structure. This list contains the list of
    napi_id's that are currently enabled for busy polling. The list is
    synchronized by the new napi_lock spin lock. The current default napi
    busy polling time is stored in napi_busy_poll_to. If napi busy polling
    is not enabled, the value is 0.
    
    In addition there is also a hash table. The hash table store the napi
    id and the pointer to the above list nodes. The hash table is used to
    speed up the lookup to the list elements. The hash table is synchronized
    with rcu.
    
    The NAPI_TIMEOUT is stored as a timeout to make sure that the time a
    napi entry is stored in the napi list is limited.
    
    The busy poll timeout is also stored as part of the io_wait_queue. This
    is necessary as for sq polling the poll interval needs to be adjusted
    and the napi callback allows only to pass in one value.
    
    This has been tested with two simple programs from the liburing library
    repository: the napi client and the napi server program. The client
    sends a request, which has a timestamp in its payload and the server
    replies with the same payload. The client calculates the roundtrip time
    and stores it to calculate the results.
    
    The client is running on host1 and the server is running on host 2 (in
    the same rack). The measured times below are roundtrip times. They are
    average times over 5 runs each. Each run measures 1 million roundtrips.
    
                       no rx coal          rx coal: frames=88,usecs=33
    Default              57us                    56us
    
    client_poll=100us    47us                    46us
    
    server_poll=100us    51us                    46us
    
    client_poll=100us+   40us                    40us
    server_poll=100us
    
    client_poll=100us+   41us                    39us
    server_poll=100us+
    prefer napi busy poll on client
    
    client_poll=100us+   41us                    39us
    server_poll=100us+
    prefer napi busy poll on server
    
    client_poll=100us+   41us                    39us
    server_poll=100us+
    prefer napi busy poll on client + server
    
    Signed-off-by: Stefan Roesch <shr@devkernel.io>
    Suggested-by: Olivier Langlois <olivier@trillion01.com>
    Acked-by: Jakub Kicinski <kuba@kernel.org>
    Link: https://lore.kernel.org/r/20230608163839.2891748-5-shr@devkernel.io
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-11-28 15:40:44 -05:00