Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp862346rdg; Fri, 13 Oct 2023 03:36:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXNd0Vh6Rna52S7+Wddg/xLAzYTfq09sv350aH1G2N6OQSGNx1YmS9UxUXn0ijF3gafzWz X-Received: by 2002:a05:6808:2382:b0:3a4:ccf:6a63 with SMTP id bp2-20020a056808238200b003a40ccf6a63mr31535241oib.55.1697193407609; Fri, 13 Oct 2023 03:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697193407; cv=none; d=google.com; s=arc-20160816; b=OB2CEJ9QmRfLAUpG89EI+q/Y7KsqzRnZXwq4pcl95kO1G9YlG1s5+YjPooWuO0cmKC KpoG2Z7WXEeGrHz7wGeeUNF/30PCmGGOU4Icl06OLndgUJBIi5r4T7t9SXxL9pFMCuhL GCE8QwE7hBaRUicaHUKbxBGPgm+2WLPoZTSYPeSCkcHjEwpUC02UpNSzRrZ4Dq0mXs7y 69N0re+9aj/EYPc+/lbyWmxvcz9SZfxouMCMuv6763jUtlHrMvhdQcsotzqzfKKnqpwn +KbzZujcaVI3JlVsCre430KyR24poJ90E/kxxABAvt0ne1Y30fnMFfJ/C6NklelTS52J Ro+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gQ25kx920go2pkBGpBHxx+jqIb59tb1/0X9rxCBHDWw=; fh=46Hc++IZxxwtJLU6+u8Lq9eoa9VwtqgYWMI3eFubqQY=; b=0Idsl30lXU6orIrJvlnYxFSHQs5D5TRG3rnQmGcTGMOCHZF/uOFjeczdUaqGrNJdyG jZJQv+I2EOauoqAeYF4poKSX9emv3cNeCbfV2NO5lt1w8HhUFCSZPNxCFwb4USZWd49P 8h5Lwv8xoLNHI9IUy16jxySp7iMgV9IxN2B5NsPTl86M8Yanfh9I3csbDj0TvQbg5dM6 /TVLf4TXPALBvYyfL+gBdYpgz3GKbHf3xYmF0RcndIj70ggNKGC0OVB9XMcI7/RuHueJ 58aOhbXsP8JQd6pjDlHv6c4eKQMXtFSOo55y2w+KmEH+AQOxcJXgbTHTvwrZc6yX7s3M 1nVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PqFwb6qD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id a62-20020a639041000000b00578d6cb1a16si1468146pge.178.2023.10.13.03.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 03:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PqFwb6qD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3AE5E80BD50E; Fri, 13 Oct 2023 03:36:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbjJMKgZ (ORCPT + 99 others); Fri, 13 Oct 2023 06:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbjJMKgY (ORCPT ); Fri, 13 Oct 2023 06:36:24 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 084D4B7 for ; Fri, 13 Oct 2023 03:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697193382; x=1728729382; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=h5eylseGlyKInganAtlR/cJWIKhdZQLtNfHjqZwm1Xc=; b=PqFwb6qDqfFitrXeMk6L9f+JcJyxXqh45Dketho/sKQg/WwPzrz8KbWL F0G4VWX13UaA9ajSdPuEZRhIyMfonEgStcQFPCYJoICgMNUOs5q9c4Sl4 0DebuRs8ymGA3HShJuFWPbFc3PhWT7AV3ns3mH/WWjjGp75dAXSfQWiIp /Fo/unBCsw6t0izgdJqfElYLaA9JLLvgIefbdQzLKHgR9MxrwCHnbcjjE 0XkC+7gUkvvVYHnodxEyA86AFRmZFsfsp2CVbe/7eXUKAF/AJJxDQJcuY hFtgQihC0Kbb4eTyeClghBao5SESndrm2tQPA9HCYCkik+Rms2/5sHuJa A==; X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="364516397" X-IronPort-AV: E=Sophos;i="6.03,221,1694761200"; d="scan'208";a="364516397" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 03:36:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10861"; a="758454698" X-IronPort-AV: E=Sophos;i="6.03,221,1694761200"; d="scan'208";a="758454698" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by fmsmga007.fm.intel.com with SMTP; 13 Oct 2023 03:36:17 -0700 Received: by stinkbox (sSMTP sendmail emulation); Fri, 13 Oct 2023 13:36:17 +0300 Date: Fri, 13 Oct 2023 13:36:17 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: Kuan-Wei Chiu Cc: zhenyuw@linux.intel.com, zhi.a.wang@intel.com, tvrtko.ursulin@linux.intel.com, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, rodrigo.vivi@intel.com Subject: Re: [PATCH] drm/i915/gvt: Optimize mmio_offset_compare() for efficiency Message-ID: References: <20231012230449.2109078-1-visitorckw@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231012230449.2109078-1-visitorckw@gmail.com> X-Patchwork-Hint: comment X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 03:36:42 -0700 (PDT) On Fri, Oct 13, 2023 at 07:04:49AM +0800, Kuan-Wei Chiu wrote: > The original code used conditional branching in the mmio_offset_compare > function to compare two values and return -1, 1, or 0 based on the > result. However, the list_sort comparison function only needs results > <0, >0, or =0. This patch optimizes the code to make the comparison > branchless, improving efficiency and reducing code size. This change > reduces the number of comparison operations from 1-2 to a single > subtraction operation, thereby saving the number of instructions. > > Signed-off-by: Kuan-Wei Chiu > --- > drivers/gpu/drm/i915/gvt/debugfs.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/i915/gvt/debugfs.c b/drivers/gpu/drm/i915/gvt/debugfs.c > index baccbf1761b7..998d82a259c8 100644 > --- a/drivers/gpu/drm/i915/gvt/debugfs.c > +++ b/drivers/gpu/drm/i915/gvt/debugfs.c > @@ -48,11 +48,7 @@ static int mmio_offset_compare(void *priv, > > ma = container_of(a, struct diff_mmio, node); > mb = container_of(b, struct diff_mmio, node); > - if (ma->offset < mb->offset) > - return -1; > - else if (ma->offset > mb->offset) > - return 1; > - return 0; > + return ma->offset - mb->offset; Those are unsigned ints effectively, so this only works due to the return value being the same size signed int. Might be better to add some explicit casts. > } > > static inline int mmio_diff_handler(struct intel_gvt *gvt, > -- > 2.25.1 -- Ville Syrj?l? Intel