Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3691704ybv; Mon, 10 Feb 2020 04:48:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzfyA75yUWr54WwjHvPkdB8tMDVPuKnZRoWz5e4Y1fpBMlQ51jiCSVGMUS3ijF/T8T070v2 X-Received: by 2002:a05:6808:8d0:: with SMTP id k16mr712810oij.68.1581338888583; Mon, 10 Feb 2020 04:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338888; cv=none; d=google.com; s=arc-20160816; b=NyciVmg3cb+egEVKdHYUfwP6T3bD8OkEcGWUJp9aEfKmS7E0g5N9gJPINHriDwgUdw PRXGRXcLlbSYYEkQWWPdL26fci3PQvZPra0M+6TnNvdAld2jsfX/uoI51LfQVEVaHgUH YNEAvpbCgWHBXy6cnE47N3Gfx1o23Xfyzjhh4WpHxJXUJ2vxdstjNoqVEKavOE52RxOu tUX337o0pSQRUhKixu9sbgJ0X+aKfjhEJWZfRRiF9u5PaquVEcFWq6oyGw1SjdTVabMb A/S+Ysw+2mj7YY2Cf07FVyurvGZAt/V11MHVg4+S6joA/4WIfo2N9Z5PTQV31k0e3zNh qU6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=32vmMAstsMi2lqRwo2tUPzO9geDkLmv9Wz5Zve5+QxQ=; b=jWpTFBAQ7d+R6q40uZRNuN4CI5RmLrqawau9G2OeB1yXhTsLCasfXxPLsvzHniXHpo kk0S0GL40UDnUxWiG4T7PTNSzbIyO4EDLFpzpP2UXtniS9Qle6pw77rT2TFLua3oJVzX jmf5BQ+CMxE0iNKVzD5MxFE0xzasbIMmK7cfxvthhle1cZ1l952DwxKO2CX4T5q4Up2u Cds/HjuXnTNYHWELKIuHNRlFPRQVpWNeZTmvYu23945AnWmvN8CHNTMm0sX7iHH4fUwv QpMJKm5vsaQz9zHu1iMOqHzSUvkySv1TEFXuV6gJkMlJuRimd7mY/oj15Mur28sjcnyT AyPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UupmilbB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x72si129641oia.194.2020.02.10.04.47.57; Mon, 10 Feb 2020 04:48:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UupmilbB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730164AbgBJMrX (ORCPT + 99 others); Mon, 10 Feb 2020 07:47:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:45952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730175AbgBJMmL (ORCPT ); Mon, 10 Feb 2020 07:42:11 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DC7821739; Mon, 10 Feb 2020 12:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338530; bh=AyQSEYvegNu1Fb7bnvoK/WzAV6v/dvNilSNKqB61r44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UupmilbBJkXFkjshMj9XL+uvSFQA3gSD630F1WGVAgxVwiJPmL038nLvYdVYMysga 0P0CX9ua3JHO1Eb3ZH0E6ALv1vL345jhXblAVbl01ct9gSa23w6PAQCJjZpaL2XlBQ VxPqdtxPmc2MqzBECib+EgiN1aifNMGYScMPd4vc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Papadakis , Jens Axboe , Sasha Levin Subject: [PATCH 5.5 354/367] io_uring: enable option to only trigger eventfd for async completions Date: Mon, 10 Feb 2020 04:34:27 -0800 Message-Id: <20200210122455.155382765@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit f2842ab5b72d7ee5f7f8385c2d4f32c133f5837b ] If an application is using eventfd notifications with poll to know when new SQEs can be issued, it's expecting the following read/writes to complete inline. And with that, it knows that there are events available, and don't want spurious wakeups on the eventfd for those requests. This adds IORING_REGISTER_EVENTFD_ASYNC, which works just like IORING_REGISTER_EVENTFD, except it only triggers notifications for events that happen from async completions (IRQ, or io-wq worker completions). Any completions inline from the submission itself will not trigger notifications. Suggested-by: Mark Papadakis Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 17 ++++++++++++++++- include/uapi/linux/io_uring.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 95fc5c5a85968..131087782bec9 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -188,6 +188,7 @@ struct io_ring_ctx { bool account_mem; bool cq_overflow_flushed; bool drain_next; + bool eventfd_async; /* * Ring buffer of indices into array of io_uring_sqe, which is @@ -735,13 +736,20 @@ static struct io_uring_cqe *io_get_cqring(struct io_ring_ctx *ctx) return &rings->cqes[tail & ctx->cq_mask]; } +static inline bool io_should_trigger_evfd(struct io_ring_ctx *ctx) +{ + if (!ctx->eventfd_async) + return true; + return io_wq_current_is_worker() || in_interrupt(); +} + static void io_cqring_ev_posted(struct io_ring_ctx *ctx) { if (waitqueue_active(&ctx->wait)) wake_up(&ctx->wait); if (waitqueue_active(&ctx->sqo_wait)) wake_up(&ctx->sqo_wait); - if (ctx->cq_ev_fd) + if (ctx->cq_ev_fd && io_should_trigger_evfd(ctx)) eventfd_signal(ctx->cq_ev_fd, 1); } @@ -5486,10 +5494,17 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, ret = io_sqe_files_update(ctx, arg, nr_args); break; case IORING_REGISTER_EVENTFD: + case IORING_REGISTER_EVENTFD_ASYNC: ret = -EINVAL; if (nr_args != 1) break; ret = io_eventfd_register(ctx, arg); + if (ret) + break; + if (opcode == IORING_REGISTER_EVENTFD_ASYNC) + ctx->eventfd_async = 1; + else + ctx->eventfd_async = 0; break; case IORING_UNREGISTER_EVENTFD: ret = -EINVAL; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 55cfcb71606db..88693fed2c4b4 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -175,6 +175,7 @@ struct io_uring_params { #define IORING_REGISTER_EVENTFD 4 #define IORING_UNREGISTER_EVENTFD 5 #define IORING_REGISTER_FILES_UPDATE 6 +#define IORING_REGISTER_EVENTFD_ASYNC 7 struct io_uring_files_update { __u32 offset; -- 2.20.1