From patchwork Thu Nov 28 21:11:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11266603 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 051A6921 for ; Thu, 28 Nov 2019 21:12:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6ED921781 for ; Thu, 28 Nov 2019 21:12:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JXtMTc7o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfK1VMX (ORCPT ); Thu, 28 Nov 2019 16:12:23 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42029 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbfK1VMX (ORCPT ); Thu, 28 Nov 2019 16:12:23 -0500 Received: by mail-wr1-f66.google.com with SMTP id a15so32647501wrf.9; Thu, 28 Nov 2019 13:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fIuQVSLMX/1X5Z+UmWPRtwbnLZp5pF/aLYF24EqxQ1U=; b=JXtMTc7ocPvqqjhWGwL4N5XfTDj8IvidBJQBGqSy8ay6tVNlfhLMbwLCktvdaCLDUj g2jup+T3ajILxGPZ5JSmGNH83XvXWl9GqSDsdG2Ww81oJyOhmWbFWH8LUZwJmsorW++T WfD8SUnBT2p9Mc05X0HTlWYzTN+YpltX/UNH3zVBmWfmjMEmbaB0chJJxQb3KhoN5icz 7DJGUMHpKJLlqL/IfLWQ0YLKaElaF9gSOfTGPVUsVUKwMtMVlPdsZgtYd0FwS9M/wmNb Z5OOPpGvRYhfFgQvyVlmaDhNqGxNxSGw2MG2zA/8zdSuLZEo/K5nFPyBuMIl/ssCrNQS lGtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fIuQVSLMX/1X5Z+UmWPRtwbnLZp5pF/aLYF24EqxQ1U=; b=rDQkJB5Vno0PiIJwwR8D5II81bx4VC7Itu0czFIaQs3ImAwi7ja9IfP304nFNPkKOl a0hNgWZA1RL/4BNV/71hpZBi+BC42jJFWJux9B1kS42NO0voCEBOXQlc7Oz4IOPHXuhi BF5NWL/Q1mtszU32OT0cXWsHZg0srm5rTDVMumA1uHQ+kFRfC9mHQQQCUaMV3ubQcAew b1pjDND1Jc2h4+v5LLhaQ09R8XhqEREulwSpKo5HDSFaLFp/p+1Znlla9p2ui7h9RfcG g81ZHAio+x0U2dvExbDRr8rqvFkTybh5MHD6rRiiaDB7lGaOaU+tP5f5AtCuSZnZ7gOU dsmw== X-Gm-Message-State: APjAAAXGZawhaoAhvSUKfczkuYg7kTDLk3Iib2BegKARVKMpTwfXDgsa VeV7/ihlJi/pQNhcBeNr92c= X-Google-Smtp-Source: APXvYqw9YPzhZ5G3E2CqjZguJrFN2rKInPTXGrl7fNNH7DDUc1clMMTdpDu41ANSrPWnVFCvDl5mKw== X-Received: by 2002:adf:ec48:: with SMTP id w8mr2500286wrn.19.1574975539807; Thu, 28 Nov 2019 13:12:19 -0800 (PST) Received: from localhost.localdomain ([109.126.143.74]) by smtp.gmail.com with ESMTPSA id l26sm11620809wmj.48.2019.11.28.13.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 13:12:19 -0800 (PST) From: Pavel Begunkov To: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] blk-mq: optimise rq sort function Date: Fri, 29 Nov 2019 00:11:53 +0300 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Check "!=" in multi-layer comparisons. The same memory usage, fewer instructions, and 2 from 4 jumps are replaced with SETcc. Note, that list_sort() doesn't differ 0 and <0. Signed-off-by: Pavel Begunkov Reviewed-by: Nikolay Borisov --- block/blk-mq.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 323c9cb28066..f32a3cfdd34e 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1668,14 +1668,10 @@ static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b) struct request *rqa = container_of(a, struct request, queuelist); struct request *rqb = container_of(b, struct request, queuelist); - if (rqa->mq_ctx < rqb->mq_ctx) - return -1; - else if (rqa->mq_ctx > rqb->mq_ctx) - return 1; - else if (rqa->mq_hctx < rqb->mq_hctx) - return -1; - else if (rqa->mq_hctx > rqb->mq_hctx) - return 1; + if (rqa->mq_ctx != rqb->mq_ctx) + return rqa->mq_ctx > rqb->mq_ctx; + if (rqa->mq_hctx != rqb->mq_hctx) + return rqa->mq_hctx > rqb->mq_hctx; return blk_rq_pos(rqa) > blk_rq_pos(rqb); }