Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp816563rdg; Fri, 13 Oct 2023 01:49:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEm5mK6m0NJIMb6If2GCoWW9l/AITuj7l8inFUqGVCHuAparSgx1l/0MIjr3eh6gkqrRkr X-Received: by 2002:a17:90b:238d:b0:27d:6dd:fb7e with SMTP id mr13-20020a17090b238d00b0027d06ddfb7emr6629225pjb.17.1697186954735; Fri, 13 Oct 2023 01:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697186954; cv=none; d=google.com; s=arc-20160816; b=oCCAV6/m12CX6oEkeQFy2WRdtGptCjBQCC4w0MwgDDcVGPeZfTDtQPJg3olyUpxPQ5 xIkngrU9uJFPpZFo6UynB+MAHblBXJfxoU5iWtwiNJzcAl8cY7/i3T8SENlISdvEbrcf 2PrIWo58dQjRLongZ240PeWXEZ+aTMYOlgZ1cVbHyWUWfWuYE02mNiimQuYX8TZph1qM qf5+4h3hFPpXTKHpb/vUH9eQ1BIslaxhtqlGLAFgc/ToRyPiw9HR0/cKks1gV4+vn5kv p4Hh8/0ssfiqhWjOgKIHiosQp3mnpcGh8/MToQdXZH8U6Gm+7kSj7ZQ0VpFUE8pkMDVr 0k0w== 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=Il8qfrUz/VvYSn9zWibaW2EcrYf9IhDD8qWnA/nDM/0=; fh=gqvArZzT56mpbWZPbgkVieHv+0GTgVLQCUEWHP+2lYM=; b=0lTrDgr+6gH8C/qsp409Nf90Xk/+oIwe46cg98mhn5MpGO2GxJpkuU2tQ9VvjwgALc Mn6KZhwHcGHyllWpGB606zmb9Cx5h0v7UDrwSw5KmL4IJEMcZGaJRJF2LAjBOdyg+kQG OpAzzmw7sYSoRF9pOLnHkm2w8Q/tUDzT0mSJENyYauP1ymUj7zY/id1k0VV9v/V+NeZ1 r+hwWbSubNct/5T8ZKn9qZQlS3kdNKQ6u5dy/T0XxmMouyw1YoCWkDK4S6ixFy6KbLIQ 2ICuECsq935j1/msW3K+iW/HBXrZWMzD+qaszKVTV4KLBLiE7rPZk7fUQ5s5CMmv6SgT VNTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zFvuZ+v6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ng13-20020a17090b1a8d00b0027d3c6f8ab2si1001736pjb.66.2023.10.13.01.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:49:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zFvuZ+v6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A935382C06F3; Fri, 13 Oct 2023 01:49:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbjJMItF (ORCPT + 99 others); Fri, 13 Oct 2023 04:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbjJMItC (ORCPT ); Fri, 13 Oct 2023 04:49:02 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A31ACDA for ; Fri, 13 Oct 2023 01:48:59 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6969b391791so1468877b3a.3 for ; Fri, 13 Oct 2023 01:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697186939; x=1697791739; 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=Il8qfrUz/VvYSn9zWibaW2EcrYf9IhDD8qWnA/nDM/0=; b=zFvuZ+v6bcwUvKVEs+3fLEJhusLNtle5frH1gamu5LxaQSETaab5Aozpa6sGqw9qMT SeSmIxsc+ccqs/p+lveeerVxz4jHK1vGW2yXxcbFs9pbV72ge2///v4NJ6etsg5fnS/O jBl+qz7wLlkQxgSUN3yJuNZ6VLHqokTsEjBRD4yjJl9h5QP5cDpeYAbzU/sReQzli2p+ JgeJJvEgzZf/IDiR285Ev88BcpAfwZMlrxsJyplKi+s5EV/8oJzphjTXQe/shl5IGXSE B/rmGG4rVYoNPppTbjMidByz4p7KhBOpUe0PJnIbK9cZQ7TYd4Gje1CLVA/dp+s1VAOH WADg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697186939; x=1697791739; 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=Il8qfrUz/VvYSn9zWibaW2EcrYf9IhDD8qWnA/nDM/0=; b=CxZypTH7iP0mBRsxW/GP623ctC1HjOUiRZaFvHCV804B0+RPFhra72m5YAtH/dpAlt TIu9UarJZWEnSbsG+/r60osunokX4k7G5Hey5CgW7jnCnL6/ERP2gIxJPBSJ1J/ApkH7 7NqwHl9hQ1FKNMf0a4SnNwhR2b+HEeMM3ZKiDY3nAUv6OnoH+f5RKeWdx3IkWSCS6zsd VBcBhs4dtwGIK0AIcTMXWnem2dwskjNa4VazLiW9uZ0DUwVAEAmp6fuB9mn5oFdC56FS 1loLMqbOs3TL8r8FIP3kpthPVOYddj5Th2Ye6NOWc56ShDRpPseWTQn5ZT4ZEZ9CUIRM ikPA== X-Gm-Message-State: AOJu0YwmFUdQLz+vJpvuplOvLnHE5cO0Jcl1bIDirfwEC3bKQ+dgT/YE VJwVTfN9e7td/VwQJPhg3AXOPg== X-Received: by 2002:a05:6a00:b8f:b0:693:4202:b535 with SMTP id g15-20020a056a000b8f00b006934202b535mr29675823pfj.27.1697186939127; Fri, 13 Oct 2023 01:48:59 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id g24-20020a62e318000000b00696e8215d28sm13025120pfh.20.2023.10.13.01.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 01:48:58 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] OPP: Reorder code in _opp_set_required_opps_genpd() Date: Fri, 13 Oct 2023 14:18:39 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 13 Oct 2023 01:49:12 -0700 (PDT) Reorder code in _opp_set_required_opps_genpd() to reduce duplicate code. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index f42b663a4d8b..3516e79cf743 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1076,7 +1076,18 @@ static int _opp_set_required_opps_genpd(struct device *dev, { struct device **genpd_virt_devs = opp_table->genpd_virt_devs ? opp_table->genpd_virt_devs : &dev; - int i, ret = 0; + int index, target, delta, ret; + + /* Scaling up? Set required OPPs in normal order, else reverse */ + if (!scaling_down) { + index = 0; + target = opp_table->required_opp_count; + delta = 1; + } else { + index = opp_table->required_opp_count - 1; + target = -1; + delta = -1; + } /* * Acquire genpd_virt_dev_lock to make sure we don't use a genpd_dev @@ -1084,24 +1095,17 @@ static int _opp_set_required_opps_genpd(struct device *dev, */ mutex_lock(&opp_table->genpd_virt_dev_lock); - /* Scaling up? Set required OPPs in normal order, else reverse */ - if (!scaling_down) { - for (i = 0; i < opp_table->required_opp_count; i++) { - ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i); - if (ret) - break; - } - } else { - for (i = opp_table->required_opp_count - 1; i >= 0; i--) { - ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i); - if (ret) - break; - } + while (index != target) { + ret = _set_performance_state(dev, genpd_virt_devs[index], opp, index); + if (ret) + break; + + index += delta; } mutex_unlock(&opp_table->genpd_virt_dev_lock); - return ret; + return 0; } /* This is only called for PM domain for now */ -- 2.31.1.272.g89b43f80a514