From patchwork Tue Nov 8 03:03:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 16830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2448202wru; Mon, 7 Nov 2022 19:05:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM638EYjjg6lVSMk9vRej4ZNx3G4u+VY0YO1fsB5coz8XehDm46t08jkV7UVEnttPHQpun9P X-Received: by 2002:a17:907:923:b0:781:ee12:814 with SMTP id au3-20020a170907092300b00781ee120814mr879755ejc.63.1667876732551; Mon, 07 Nov 2022 19:05:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667876732; cv=none; d=google.com; s=arc-20160816; b=FaYeyUspGitUKQtTcNykggkDA6dZpAe9GsOyxr+c27xnXsKjULDkFRsvSci0H0HsJK yT4160EcGr92iMwlQ6a3OmKMVHEAv4Ede0QivStqeXE8tc/Ybb4qrDlSxT8wSs9IQ6dG qre1BEkRvDWax/4IQRNmaSKkz3ncdwap2cZE0z05vQEhug6/AkhU1582XRMBF5JUHQu7 uyD6VtHjduPw6/xuL4fUPt7kZYj1RzZ3GkpH+H1J6sZ3mL95Ti1OAwTPs4zXT3GahQaw IvBFXFNtS4pHrc88rjQxEO7ufFIYXRlX5dOQfqefIRecAwZTLhsbq99MzaVicOw7RMcv Kq/w== 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=mKlTOtKjbhvjKTFA1N2ClrEr0nQT4VS9IBZRw2gJaGs=; b=oAZxBgOYCa+mQ95P470ejE86pFeGTtN3bZl4wYK1On7+fscZD27fEz+mPbooI1LYI4 cL9iKoaRgeK10117ICYWtsMAKwZTsggAiMlgbAm/oD/U+IN8Scsvcg0Xv4uRV5PNCwuk 4eHV9tYrTE6g76V1AJFj4B7NswMSWp8z7z1/N5u/MTGfMogl4d1QxpebWv350dqliD8D t3L/YeRrLDwj0AnTbK4yb9/6b/XwjwloYR8uIVVpFbz0NRHh/AvQdC+9uBVZT/iYFGV5 3xy/xp5E0ajpOkKJZ4Mz9TmItpWX1zY4dk6OZPJOBsrSM/W4+9mYyRAK9W37ygl9y38D eHUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kod4ktCa; 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 hb32-20020a170907162000b007ade82b938asi12735695ejc.784.2022.11.07.19.05.09; Mon, 07 Nov 2022 19:05: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=kod4ktCa; 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 S233314AbiKHDEW (ORCPT + 99 others); Mon, 7 Nov 2022 22:04:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233168AbiKHDEJ (ORCPT ); Mon, 7 Nov 2022 22:04:09 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202CB2FFDF; Mon, 7 Nov 2022 19:04: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=1667876648; x=1699412648; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZKUfgswrQzZt1xpgqXVm99HvJ16L7TugknFYChFNOY=; b=kod4ktCazBOaxYEIesnWtCk1WqxovrgDvX+SCBoDw9WjjcnGyNbp213t sP4r1U0p3hlQbcBK8CzKxrVfvVPHMg+oTEWCmCm6kP1zKYj+V7WR/a9XU j3SI5U+GopD2Tlf1hiXfmiSy+db9qmLpWDqd4RJrTlexMFpH3qXBVTYTG 5sZY5Qu30l+W7r0fFJq6ARpR15aAQtbaqfguZDSfPP5j591Z1klyb0jks i2KoGrGmuZQznixNpQxN5PAlqiexX+wXbiNYdxsl+OJDyu2mBvj1OM4aD Pzg2D5wNqXgdAauuwnc/5ApXTnpd42P1uHmLAm5Eb4hMMofLoN0KwBpi6 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="337310748" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="337310748" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 19:04:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="638612678" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="638612678" Received: from spandruv-desk.jf.intel.com ([10.54.75.8]) by fmsmga007.fm.intel.com with ESMTP; 07 Nov 2022 19:04:07 -0800 From: Srinivas Pandruvada To: rui.zhang@intel.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: amitk@kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 2/4] powercap: idle_inject: Add begin/end callbacks Date: Mon, 7 Nov 2022 19:03:40 -0800 Message-Id: <20221108030342.1127216-3-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221108030342.1127216-1-srinivas.pandruvada@linux.intel.com> References: <20221108030342.1127216-1-srinivas.pandruvada@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1748895512702885352?= X-GMAIL-MSGID: =?utf-8?q?1748895512702885352?= The actual CPU Idle percent can be different than what can be observed from the hardware. Since the objective for CPU Idle injection is for thermal control, the idle percent observed by the hardware is more relevant. To account for hardware feedback the actual runtime/idle time should be adjusted. Add a capability to register a begin and end callback during call to idle_inject_register(). If they are not NULL, then begin callback is called before calling play_idle_precise() and end callback is called after play_idle_precise(). If begin callback is present and returns non 0 value then play_idle_precise() is not called as it means there is some over compensation. Signed-off-by: Srinivas Pandruvada --- drivers/powercap/idle_inject.c | 19 ++++++++++++++++++- drivers/thermal/cpuidle_cooling.c | 2 +- include/linux/idle_inject.h | 4 +++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c index e73885bd9065..14968b0ff133 100644 --- a/drivers/powercap/idle_inject.c +++ b/drivers/powercap/idle_inject.c @@ -70,6 +70,8 @@ struct idle_inject_device { unsigned int idle_duration_us; unsigned int run_duration_us; unsigned int latency_us; + int (*idle_inject_begin)(unsigned int cpu); + void (*idle_inject_end)(unsigned int cpu); unsigned long cpumask[]; }; @@ -132,6 +134,7 @@ static void idle_inject_fn(unsigned int cpu) { struct idle_inject_device *ii_dev; struct idle_inject_thread *iit; + int ret; ii_dev = per_cpu(idle_inject_device, cpu); iit = per_cpu_ptr(&idle_inject_thread, cpu); @@ -141,8 +144,18 @@ static void idle_inject_fn(unsigned int cpu) */ iit->should_run = 0; + if (ii_dev->idle_inject_begin) { + ret = ii_dev->idle_inject_begin(cpu); + if (ret) + goto skip; + } + play_idle_precise(READ_ONCE(ii_dev->idle_duration_us) * NSEC_PER_USEC, READ_ONCE(ii_dev->latency_us) * NSEC_PER_USEC); + +skip: + if (ii_dev->idle_inject_end) + ii_dev->idle_inject_end(cpu); } /** @@ -302,7 +315,9 @@ static int idle_inject_should_run(unsigned int cpu) * Return: NULL if memory allocation fails, idle injection control device * pointer on success. */ -struct idle_inject_device *idle_inject_register(struct cpumask *cpumask) +struct idle_inject_device *idle_inject_register(struct cpumask *cpumask, + int (*idle_inject_begin)(unsigned int cpu), + void (*idle_inject_end)(unsigned int cpu)) { struct idle_inject_device *ii_dev; int cpu, cpu_rb; @@ -315,6 +330,8 @@ struct idle_inject_device *idle_inject_register(struct cpumask *cpumask) hrtimer_init(&ii_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ii_dev->timer.function = idle_inject_timer_fn; ii_dev->latency_us = UINT_MAX; + ii_dev->idle_inject_begin = idle_inject_begin; + ii_dev->idle_inject_end = idle_inject_end; for_each_cpu(cpu, to_cpumask(ii_dev->cpumask)) { diff --git a/drivers/thermal/cpuidle_cooling.c b/drivers/thermal/cpuidle_cooling.c index 4f41102e8b16..e8b35b3b5767 100644 --- a/drivers/thermal/cpuidle_cooling.c +++ b/drivers/thermal/cpuidle_cooling.c @@ -184,7 +184,7 @@ static int __cpuidle_cooling_register(struct device_node *np, goto out; } - ii_dev = idle_inject_register(drv->cpumask); + ii_dev = idle_inject_register(drv->cpumask, NULL, NULL); if (!ii_dev) { ret = -EINVAL; goto out_kfree; diff --git a/include/linux/idle_inject.h b/include/linux/idle_inject.h index fb88e23a99d3..73f3414fafe2 100644 --- a/include/linux/idle_inject.h +++ b/include/linux/idle_inject.h @@ -11,7 +11,9 @@ /* private idle injection device structure */ struct idle_inject_device; -struct idle_inject_device *idle_inject_register(struct cpumask *cpumask); +struct idle_inject_device *idle_inject_register(struct cpumask *cpumask, + int (*idle_inject_begin)(unsigned int cpu), + void (*idle_inject_end)(unsigned int cpu)); void idle_inject_unregister(struct idle_inject_device *ii_dev);