From patchwork Thu Mar 30 11:36:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 77137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1064336vqo; Thu, 30 Mar 2023 04:51:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bjFBnwQw2Rub2v6SObYAFnRmjmAJfw3gugoV/Ll6WuyNz1GGoX5b4YMfRNODcACY5AGgfB X-Received: by 2002:a17:90b:1bc6:b0:23f:7666:c8a2 with SMTP id oa6-20020a17090b1bc600b0023f7666c8a2mr25687995pjb.47.1680177065330; Thu, 30 Mar 2023 04:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177065; cv=none; d=google.com; s=arc-20160816; b=gbjtz02975goMNdkl2Pscg6N3GjUHoXZKFU+J1qOIykfdrJn/wNLbEzg5Hmw+HJFAH oMraHocdN/AN7TtxKyYHE51G6SqmNSFe8VijnrBhZmiePF5Pp3vEZJp0TWkSoO4vrTZn iuvOApB+RFhrc8LxB+PclmuXBiu4KbPvhhDemk0+4tmX7dsgPFDnPIEXd546B7iOnvHn ALg87upgGwEP1U2X1921hPtCnDjFKJUPVgLPlM/9b0AlbKgFa+To6YcY05pAyBbyX5GV qV9jdWGp0QEX856k83kJyozOyURqThDlhxDjmwuKmR0ABQFDMnwqIVQKv3bk2XkeXNq3 MELw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cMvtAiZrEHr/RuIr5EK3Qcf9yPL0DeQpzw5d26wmtC4=; b=f0f6qB8da36+qomXHk2vn4mTkxS87wUvz/uUOh1zy52D9x29zL20R1NubLTi1PhFVG ftwgJUmlBk/RzVTOEKxF71wgepojzYjVGKi6EQvO1ozP0hPimHj9PzU2jXAtDQo99nI8 gpJKrv91lMYkzcl1CLFt1fG4Ckp6VO3M3R2eRYyWki2L1UTKZjcOb6biZNrHLualxBfD bbaCrM4ONzFx9l+WEGngBiWjf0F7QD/vfgC9KrVSMCoCYUJnANzKPQULplxwWugsqkpV 5S08bK4QvUw2NY7WcbWI8+Ds1unGtxkWExUgYqS406+wHHioFVOna2wd7uR/1NZf5WVQ sxtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Be/dJhip"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h186-20020a636cc3000000b0051353d86539si9438439pgc.687.2023.03.30.04.50.52; Thu, 30 Mar 2023 04:51:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Be/dJhip"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231690AbjC3Li0 (ORCPT + 99 others); Thu, 30 Mar 2023 07:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbjC3LiX (ORCPT ); Thu, 30 Mar 2023 07:38:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC00C86AB for ; Thu, 30 Mar 2023 04:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680176220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cMvtAiZrEHr/RuIr5EK3Qcf9yPL0DeQpzw5d26wmtC4=; b=Be/dJhipBE42JZPO/8IL4CjR9JYQvKhcd/C2kvfHob7zA374nzcUPCrQaMwQP9sg6VEMsw xAUcFycLyg/OtMX+FT56iVcB2PI/cYEPXdm8K3oJx/C82LjSaAJ0Ea+o5B69ex+eGbcza4 JZvlXh6voxR9FlpUXyiqAxXSAIuXy4o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-528-PTeUdGuBPCWYIzRDacSIJA-1; Thu, 30 Mar 2023 07:36:54 -0400 X-MC-Unique: PTeUdGuBPCWYIzRDacSIJA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5717585A588; Thu, 30 Mar 2023 11:36:54 +0000 (UTC) Received: from localhost (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 675CE14171BE; Thu, 30 Mar 2023 11:36:52 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miklos Szeredi , ZiyangZhang , Xiaoguang Wang , Bernd Schubert , Pavel Begunkov , Stefan Hajnoczi , Dan Williams , Ming Lei Subject: [PATCH V6 02/17] io_uring: use ctx->cached_sq_head to calculate left sqes Date: Thu, 30 Mar 2023 19:36:15 +0800 Message-Id: <20230330113630.1388860-3-ming.lei@redhat.com> In-Reply-To: <20230330113630.1388860-1-ming.lei@redhat.com> References: <20230330113630.1388860-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761793346166828328?= X-GMAIL-MSGID: =?utf-8?q?1761793346166828328?= Use ctx->cached_sq_head to calculate 'left' sqes, and prepare for supporting fused requests, which need to get req/sqe in its own ->prep() callback. ctx->cached_sq_head should always be cached or to be fetched, so this change is just fine. Signed-off-by: Ming Lei --- io_uring/io_uring.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 693558c4b10b..25a940f0ab68 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2429,15 +2429,16 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) __must_hold(&ctx->uring_lock) { unsigned int entries = io_sqring_entries(ctx); - unsigned int left; + unsigned old_head = ctx->cached_sq_head; + unsigned int left = 0; int ret; if (unlikely(!entries)) return 0; /* make sure SQ entry isn't read before tail */ - ret = left = min3(nr, ctx->sq_entries, entries); - io_get_task_refs(left); - io_submit_state_start(&ctx->submit_state, left); + ret = min3(nr, ctx->sq_entries, entries); + io_get_task_refs(ret); + io_submit_state_start(&ctx->submit_state, ret); do { const struct io_uring_sqe *sqe; @@ -2456,11 +2457,12 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr) */ if (unlikely(io_submit_sqe(ctx, req, sqe)) && !(ctx->flags & IORING_SETUP_SUBMIT_ALL)) { - left--; + left = 1; break; } - } while (--left); + } while ((ctx->cached_sq_head - old_head) < ret); + left = ret - (ctx->cached_sq_head - old_head) - left; if (unlikely(left)) { ret -= left; /* try again if it submitted nothing and can't allocate a req */