From patchwork Tue Jan 17 18:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 44784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1936762wrn; Tue, 17 Jan 2023 11:15:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXsM+Si3mlijxGHdbK5aaCTA5qyb7iwX85idL5UDu59mG1BcWVxb9tWNe3bSwa6hnWsNQvj0 X-Received: by 2002:a62:6144:0:b0:583:9b05:d1f0 with SMTP id v65-20020a626144000000b005839b05d1f0mr4514577pfb.33.1673982932470; Tue, 17 Jan 2023 11:15:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673982932; cv=none; d=google.com; s=arc-20160816; b=LizZf8p38ZMdf2UcF/fOFkzgsrDVhD4ECnSpYgiySZlWSpdTVXUD2PhRjWK55wGFPj kleI/YxBJOFHk7ouQyka+Is5bXraEyHQeZiGn6LRiCG0p9slSq8ums9OJC2CFPgBa7Wk wJ4iaOxcWtKGgfSkWVuHjyNwdCX++tZIvkiRF70SAz87Dc6zAliX6wLLsZ02v4Gx3252 e3yMm8oC+WEuDX39Q090DcsEcr6ExZZbIK9XrGeDEQRFpejWtZCgrFbd20sL8WQkTV0o bEkoxSsCZAbdKuUA4KkdPSvxAyOACiU23SHWSHir6hpy0IkcEXEbbziN7gMXIGsgiG/1 ljZQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=C3/Uw45OkFzkInNj0WnatGNQT7Ar6COPWgQpgZ77wK8=; b=PNizHUBlEYrpDtf2FOdLyT6dFGmGGuiiCD9oUkWnnJrmO3WLsLWhfw8cTfzKEA8zTW e/GaC3aSf6JwX+sJWzZvl2Yu3pwlSuOaRrBNNMdhFdzHyg55qbgYD13U2fW3IyYneZG+ nWX2wVnnvmHih9hKmtWLdUD50PYuwfwE6Ra4so5oPtrKdFiui+nLjWPCOW5tGMyy/E9v Ka5QuhQyUbEc40iuMiPFY8mb4rBvJnUig50wMbdUn9ita6PS6/13bIXQy6LJndM0NqER USTgGVBDRpirLO4grG6l9wE6eQbzRDUrYsJ/nEeEFOsmrC9Cnv5b59BKB03wiHoXnj3J re6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AtBTZbxr; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a056a00198b00b0056d480f7b92si35083309pfl.378.2023.01.17.11.15.19; Tue, 17 Jan 2023 11:15:32 -0800 (PST) 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=@intel.com header.s=Intel header.b=AtBTZbxr; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbjAQTLs (ORCPT + 99 others); Tue, 17 Jan 2023 14:11:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjAQTJP (ORCPT ); Tue, 17 Jan 2023 14:09:15 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D3B37F31; Tue, 17 Jan 2023 10:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673979788; x=1705515788; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=IlDh+Dysr/T/XY5HyMKzy4u/jUEYxfwAxA0eTJ167wQ=; b=AtBTZbxr9IYJgBvAgkQ0uoaHrX6gk4H+mmhAu40ivUwWTvWbrvgwxdXb fJjL8MY+Vl3i5WG/tOfiJ4FYAAWDYKjjjFA65vch8VlIt0OBks3UEmq1r drVnrQMC1EzqjoPNzXzPejj88C7fTyNQDXac1MHG3XefvANNO4MRY0YSr 3Nf2eB599FnzsaR7ENjUrYLjADfiSOvllmxCiBDTtJ2XNnzuT3r2YYkwL lIcnsuELSrqV+IZFpEsXFgZQ0gTDBMYGul8o1DCybNTEsziFdwNRMjkQ4 gLdZ8dfPmOfdWYgenC1V10zKONPnL2bw83BbWpCzl2gyRC3pLjN89QPup A==; X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="326850252" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="326850252" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 10:22:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10593"; a="748133276" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="748133276" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by FMSMGA003.fm.intel.com with ESMTP; 17 Jan 2023 10:22:54 -0800 From: Srinivas Pandruvada To: rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, Srinivas Pandruvada Subject: [PATCH] thermal/idle_inject: Support 100% idle injection Date: Tue, 17 Jan 2023 10:22:40 -0800 Message-Id: <20230117182240.2817822-1-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham 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?1755298327088861773?= X-GMAIL-MSGID: =?utf-8?q?1755298327088861773?= The users of idle injection framework allow 100% idle injection. For example: thermal/cpuidle_cooling.c driver. When the ratio set to 100%, the runtime_duration becomes zero. In the function idle_inject_set_duration() in idle injection framework run_duration_us == 0 is silently ignored, without any error (it is a void function). So, the caller will assume that everything is fine and 100% idle is effective. But in reality the idle inject will be whatever set before. There are two options: - The caller change their max state to 99% instead of 100% and document that 100% is not supported by idle inject framework - Support 100% idle support in idle inject framework Since there are other protections via RT throttling, this framework can allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle, should be aware that CPU can't be used at all. The idle inject timer is started for (run_duration_us + idle_duration_us) duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration(). Also check for !(run_duration_us + idle_duration_us) to return -EINVAL in the function idle_inject_start(). Signed-off-by: Srinivas Pandruvada Acked-by: Daniel Lezcano --- Change log: Compared to RFC/RFT - Add a pr_debug for 100% idle drivers/powercap/idle_inject.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c index c57b40477246..3ac81086d71f 100644 --- a/drivers/powercap/idle_inject.c +++ b/drivers/powercap/idle_inject.c @@ -170,10 +170,12 @@ void idle_inject_set_duration(struct idle_inject_device *ii_dev, unsigned int run_duration_us, unsigned int idle_duration_us) { - if (run_duration_us && idle_duration_us) { + if (run_duration_us + idle_duration_us) { WRITE_ONCE(ii_dev->run_duration_us, run_duration_us); WRITE_ONCE(ii_dev->idle_duration_us, idle_duration_us); } + if (!run_duration_us) + pr_debug("CPU is forced to 100 percent idle\n"); } EXPORT_SYMBOL_NS_GPL(idle_inject_set_duration, IDLE_INJECT); @@ -219,7 +221,7 @@ int idle_inject_start(struct idle_inject_device *ii_dev) unsigned int idle_duration_us = READ_ONCE(ii_dev->idle_duration_us); unsigned int run_duration_us = READ_ONCE(ii_dev->run_duration_us); - if (!idle_duration_us || !run_duration_us) + if (!(idle_duration_us + run_duration_us)) return -EINVAL; pr_debug("Starting injecting idle cycles on CPUs '%*pbl'\n",