Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp913677rdg; Fri, 13 Oct 2023 05:14:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQaVuv6z0HXup8dEdpkDTbqt8hgrO+iZRJLgpYXKXouCJUHiZM1RNqE1b6Bn04N+RwW8Zx X-Received: by 2002:a05:6e02:1aa7:b0:352:749b:720e with SMTP id l7-20020a056e021aa700b00352749b720emr33421454ilv.12.1697199272490; Fri, 13 Oct 2023 05:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697199272; cv=none; d=google.com; s=arc-20160816; b=N6sktlcTP8IbCEsCN4Nfng3Hqbgz09bSMaOyn97qpU13kXLGbtLE9Cx+Zox38hSLFY zmis4cmngtkG1h9fYh7PklngauGbQYh8QwgJz7R8G8sphah6OE67wRr8LVg0OA27KUfk cA9n7HV/57z2HIp9+qSUUX9ArL8GGHwB+lhTmDu2F3KoS6Riunxe+88DyUsylnz9Xvyr PrbKOaFlPI1p2I5KuFzlmseuURyZzRJUdrc/oU/5C3MqTWT2/ajmSmr5yVucopSImOm+ SbVBwInOeoVMxRRN9M67CxByI3Lb1FXDqGIRMdltqtJJ55l6/MIelsZ4IhIzhxp7PsOs 1N9w== 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=X4z+hjgZoqLiz+otFUtzfcX1EPVHUCZR+4Ag5x9f1fQ=; fh=5kMG9hdDu/2C95X6UxKSBOLGUk/xidAoSUPh+KmHYjw=; b=QF7L95FjVxSx7YSpkAli2z0+waUMKVv77uJ/iKiJEVmwnnfopz4OjrRWwmdgzj4WIZ +SlphZPDBfgZZWvHwIkQEXgIIyQPqh8+PqxyurCGRrvUY6DFtuYNAHqXpVYzBuqXdxD9 kOYv5rOSNGN9opZlicIhwC/wEz4ku8WsDXmPFwQvlwTGsesvCoWbA+C23MaR79uSyI9S 5YuDDNizGpi2nPYpVQyh1D5bNkCxvdcehTO0LkloDgTHSPMmsO7hgnAU1Rgh7cP+1W+f l1w4+TxJE1MpEeFlp3xuiHtbnka4lqsznxZapLPz0OHKXlEeEgU1dRbXqYgM1qGzikBk QblQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TvxZdjPP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 85-20020a630058000000b005aa833a5337si1540777pga.600.2023.10.13.05.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TvxZdjPP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 229BA822E565; Fri, 13 Oct 2023 05:14:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbjJMMOG (ORCPT + 99 others); Fri, 13 Oct 2023 08:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbjJMMOE (ORCPT ); Fri, 13 Oct 2023 08:14:04 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3911BBD for ; Fri, 13 Oct 2023 05:14:03 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c9d132d92cso5612825ad.0 for ; Fri, 13 Oct 2023 05:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697199242; x=1697804042; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X4z+hjgZoqLiz+otFUtzfcX1EPVHUCZR+4Ag5x9f1fQ=; b=TvxZdjPP1S4lzY1RK+OoFohvLhNRZEFKdidXfK0oKNMREN6Uywy0rt9hNyVQjGBLuT dCe8/xP1OZidNdiegunFjo8UkO5NiIi/WcG+QA+GaJDFa3cGlCPeDvyWDrbMfntN8dfP ilPyxMPxJ/EjCd3o4SQxtaHEF4NA9o5PUolsfko+CMJ9LM079z6BSk/t3GDey3wLn0bt Fb3Tbx/8jFoFdga1F8UgBqy7vDvGirimqPxFgSXw3E5ZcJSzh/EgaMYCm9N65x7fXbjP ++EHJCoSUYUj/xm7S8tYwpNYZp2vx8D6YYq9cdsToOBGp9/cGGqJYVGVgIJyB+pQsL0w rVZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697199242; x=1697804042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X4z+hjgZoqLiz+otFUtzfcX1EPVHUCZR+4Ag5x9f1fQ=; b=pr1UB01SMJSCzgqPyNBzPQH99HmfUD3LU3iIre8k+a/xuxsOp5/8eVz6q12tuoIghj naeMU/T6Vcm8/lRUUotHNs2zlKmhwtLzNE7z6F4JP15gOfRtWafPk0Xz1wZMj9Ngk3uY vl9yx1JiZlPJWE8Wmj53PoTi3+WKqScSjrkvGieJ6b8wm/CIr45hvXsXdYCn2LmKtLVI BSgpHoE/b36TM4aitkiBibU3t7l5y2qY8zd+vQgOU3/oaOroQ3L9ojM4skgvFRrCyiH4 indoGmRnjWOKHVybu4tH7QHY/NVEIoQSUTvyPBceOsuFArgclzGieKTAwaFWQH+itdGC +RZQ== X-Gm-Message-State: AOJu0Yyq7F4KE4m5Guk4NG6cJwnwT6OmICLFbzYZyunQ045KEg07rkNW UBlDZaggrQqKrUWUqSRougo= X-Received: by 2002:a17:902:ce84:b0:1c6:9312:187 with SMTP id f4-20020a170902ce8400b001c693120187mr29212356plg.3.1697199242587; Fri, 13 Oct 2023 05:14:02 -0700 (PDT) Received: from localhost.localdomain ([140.116.154.65]) by smtp.gmail.com with ESMTPSA id ja20-20020a170902efd400b001c1f4edfb9csm3747683plb.173.2023.10.13.05.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:14:01 -0700 (PDT) From: Kuan-Wei Chiu To: ville.syrjala@linux.intel.com, zhenyuw@linux.intel.com, zhi.a.wang@intel.com Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, tvrtko.ursulin@linux.intel.com, airlied@gmail.com, daniel@ffwll.ch, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v2] drm/i915/gvt: Optimize mmio_offset_compare() for efficiency Date: Fri, 13 Oct 2023 20:13:55 +0800 Message-Id: <20231013121355.2125824-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 05:14:30 -0700 (PDT) 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 --- v1 -> v2: - Add explicit type cast in case the sizes of u32 and int differ. 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..d85d8a3b5ae5 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 (int)ma->offset - (int)mb->offset; } static inline int mmio_diff_handler(struct intel_gvt *gvt, -- 2.25.1