From patchwork Thu Jun 10 08:23:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 457840 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp177254jae; Thu, 10 Jun 2021 01:24:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGAHRSpSvn76II5xnQpcycSUCXpajvVuUSxwDSzhUegfrFVxDN4n+HXFJRIsvdD8p9QgEQ X-Received: by 2002:a17:906:8688:: with SMTP id g8mr3315073ejx.470.1623313464853; Thu, 10 Jun 2021 01:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623313464; cv=none; d=google.com; s=arc-20160816; b=JSZ0n+ldhMyjdAixmv1xlcNXzPL+mzaWGUav5d0wKFzKWdP7u62DYKkQYnlfU9xBRb 92dLimmQSg6tCRlnGCRGSo5BD7IbHzE53XpwMkZLjaNkzhnPOI2kc5noKoJMua3FBw06 2HRA0xYWVzm3tu0cddnGKKyBdXND+1RMgEP7KWvp4QO2rxeNVN+iPJJrLjxfgjRNtgSp jwnxWiBeQM25IGp8Bgv9QjErTGzLYQQe/FXyuSJs1RqSs1nD1b3wntwmhvpLcmMB4d3R FNRLTbvhd3mtHGpCxU64Ge74/y9VmRL/Vicq9T0+c+Zr406pBs4xPtdjQANrXNoRskBI KTXA== 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=YORa9oPGsIte4A9SIv+iSxyTgKDWii2V9/ngG7/TXzA=; b=BfLQq9pbxPxBt9zfErOOJfufPvuMQdAAMxo7Qv+oeEVpPbP5/3a5b4/7ijLwG+Vxx0 1IOHWnASN5XV/hNBWFoBrXvhL+ufRA4a7pzegQLiJagpkNQZC1PNfwpXF86IycI0uy6+ TXjbirimLQ2qNi1Y/H4bJn5C0fINY3eUfE7dlbrPQ7PDw6vnNP28JRDxAg+OMG5VpDh8 oOvHFg9QWvQfgvHRA13TVNKKoB2TXQUIRW5US726P3+uipRp9ESwhlM1ZEFQer7IJmLi sSettrFP/Obuf7tjuKN24tkHaWmdnWJk7KClvNPNbroDR0I0aQ0SB1ZkF1lsz5zsKwfu Zotw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QnZSOGTF; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si1828317edx.42.2021.06.10.01.24.24; Thu, 10 Jun 2021 01:24:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QnZSOGTF; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbhFJI0T (ORCPT + 8 others); Thu, 10 Jun 2021 04:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbhFJI0S (ORCPT ); Thu, 10 Jun 2021 04:26:18 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A44C061574 for ; Thu, 10 Jun 2021 01:24:12 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso3357692pjp.2 for ; Thu, 10 Jun 2021 01:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YORa9oPGsIte4A9SIv+iSxyTgKDWii2V9/ngG7/TXzA=; b=QnZSOGTFeWsKK1KHilKfDK4pafowlzadJ9TKAa+hmsV2BZzCj+/mzNGTDxGSaBhHA3 j/7avbEiKFpACZp0062Lhq8ApmUqDHyaUNM+2SVWL6t63Mw8Jzz3JvHS46Y2baQoz7PK Psc3SuhhpdtfnOaufzA9UXg8V6Tk3nmeGGQiHBD2OTApscMEaeu6rDPiayIHvoXeTNkO OzSaPi3D8jX9cmHFu0QqCMlaONZwPocDxFUjMhN5zsfaMm9H6rzAv1z+zMDteOM3yf7A slwe6pRxRWJX0x+NuFPRLD7cdIvGV1p5JICgyLJVmWhKqBMx3+hd/fDo6PZ/zuvhmjqe wXmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YORa9oPGsIte4A9SIv+iSxyTgKDWii2V9/ngG7/TXzA=; b=M6L4pK3KiTgQxdZBjlqR2Zv8JAN4STmgYCeoQgO/6VDbd8aI8bRHNhCiBSRQyRgRog b4sXAs4+ugYBmgzWHPys4ywOorGRnC4c5lVWVc8PXQzP5JigIATN9lLDIsmmXvrdEsv5 mG6/BCZ+ScGY8XrxlRClqsd4eW9xxBhYgJHdDpGXfD0+6DUa/L3BVTKBjQ8UfecdUCkI qOyhEoIFMEHaDZ2L4qXcjSKk/zPc3urb02qwqvuVSWpEGM25SXRbEC+zV4InCK8drpq2 y33UXLy234SKDLQiyK7ROXvjazX6dQbzF9P41WjI3sxTspRPijM8is5PMVc6WdfRkiDs DVCw== X-Gm-Message-State: AOAM531Vq2/2LojtItaknCThkCLv+6fygqHd6KN02uBLtGxupUjTHK3A WY97vmr4xQa/PaM3YMEkqRi8+bMirFQs6g== X-Received: by 2002:a17:90a:8816:: with SMTP id s22mr2211669pjn.231.1623313452088; Thu, 10 Jun 2021 01:24:12 -0700 (PDT) Received: from localhost ([136.185.169.128]) by smtp.gmail.com with ESMTPSA id j2sm6913313pji.34.2021.06.10.01.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:24:11 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Qian Cai , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Ionela Voinescu , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] cpufreq: cppc: Migrate to ->exit() callback instead of ->stop_cpu() Date: Thu, 10 Jun 2021 13:53:57 +0530 Message-Id: <07fa2077b682d026c47192507f320da5bbd4e10f.1623313323.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver interface") added the stop_cpu() callback to allow the drivers to do clean up before the CPU is completely down and its state cannot be modified. At that time the CPU hotplug framework used to call the cpufreq core's registered notifier for different events like CPU_DOWN_PREPARE and CPU_POST_DEAD. The stop_cpu() callback was called during the CPU_DOWN_PREPARE event. This is no longer the case, cpuhp_cpufreq_offline() is called only once by the CPU hotplug core now and we don't really need two separate callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything can be done from the exit() callback itself. Migrate to using the exit() callback instead of stop_cpu(). Signed-off-by: Viresh Kumar --- drivers/cpufreq/cppc_cpufreq.c | 46 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) -- 2.31.1.272.g89b43f80a514 diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 3848b4c222e1..30a861538784 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -384,27 +384,6 @@ static int cppc_verify_policy(struct cpufreq_policy_data *policy) return 0; } -static void cppc_cpufreq_stop_cpu(struct cpufreq_policy *policy) -{ - struct cppc_cpudata *cpu_data = policy->driver_data; - struct cppc_perf_caps *caps = &cpu_data->perf_caps; - unsigned int cpu = policy->cpu; - int ret; - - cpu_data->perf_ctrls.desired_perf = caps->lowest_perf; - - ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->lowest_perf, cpu, ret); - - /* Remove CPU node from list and free driver data for policy */ - free_cpumask_var(cpu_data->shared_cpu_map); - list_del(&cpu_data->node); - kfree(policy->driver_data); - policy->driver_data = NULL; -} - /* * The PCC subspace describes the rate at which platform can accept commands * on the shared PCC channel (including READs which do not count towards freq @@ -557,6 +536,29 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) return ret; } +static int cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + struct cppc_cpudata *cpu_data = policy->driver_data; + struct cppc_perf_caps *caps = &cpu_data->perf_caps; + unsigned int cpu = policy->cpu; + int ret; + + cpu_data->perf_ctrls.desired_perf = caps->lowest_perf; + + ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) + pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", + caps->lowest_perf, cpu, ret); + + /* Remove CPU node from list and free driver data for policy */ + free_cpumask_var(cpu_data->shared_cpu_map); + list_del(&cpu_data->node); + kfree(policy->driver_data); + policy->driver_data = NULL; + + return 0; +} + static inline u64 get_delta(u64 t1, u64 t0) { if (t1 > t0 || t0 > ~(u32)0) @@ -665,7 +667,7 @@ static struct cpufreq_driver cppc_cpufreq_driver = { .target = cppc_cpufreq_set_target, .get = cppc_cpufreq_get_rate, .init = cppc_cpufreq_cpu_init, - .stop_cpu = cppc_cpufreq_stop_cpu, + .exit = cppc_cpufreq_cpu_exit, .set_boost = cppc_cpufreq_set_boost, .attr = cppc_cpufreq_attr, .name = "cppc_cpufreq", From patchwork Thu Jun 10 08:23:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 457839 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp177209jae; Thu, 10 Jun 2021 01:24:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwegTpk6zDRhUOTfjVO2JqrkS1lkw3ngqJLZlj3FWeakUfmLrlOo/vdjnQqhcOzM/dQ9rOF X-Received: by 2002:a17:906:51d8:: with SMTP id v24mr3277822ejk.264.1623313458287; Thu, 10 Jun 2021 01:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623313458; cv=none; d=google.com; s=arc-20160816; b=vGFMY+j856fyHAIY1NrkZI8SLi1+wjRswRcxNQeI6wjZ3sOvxURy7k+b8ctl7Cs5U+ tymtcTt7pXhAHwEt7mi7GXaOgk7MdUJ+NcwJ1mZ+VQEmNedVPIDgUr4iAhV9u8MC+g23 CtVd1zhflUSVo+vMgGDqje44DlPTRzB2KL+XmJdr/H9C00aiJI0XfHNHwhjGdsxYSvY0 Vdh5/1LrO83VWyhc/DNdQ2b5nq0wDfwEPq0xQAZgtGMCxeMqpCfXQfkDIYJldT8J5BKP 2dBmXT0oYeVcN+Ypu5JDBD/OfgDd8V9AcBhH1d2hvpoNTtNE20ASpevOBI81E4gmA3mH WXUw== 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=e7B2ZK+wpxF4j3+qmLEZ4xXUKjyuONFX7C0C6Hmnb+s=; b=gWbxw1RrGG5XINwsFJcBHM3POIfSGySZViRTaOcaLlR/M1m8O5Z4yD9DjS2hryIfQs mQUYZjjofDUewmVEtdCXGVwE8bh6RF+sGYGYno0/8qOPNLg1u7Io3sVI8VgK9vYuBW3T flrRZK87n9KYwttQsJBF3q0BK0+yQOl0IeM7AP7wRYRqEd1PKs9QcwkcjbEA1B/YoGNA qKQhY9z3HV/UPHGSziul/stksxubLiOJVyml/tv+22GLcMCPCVVF0Htf9JHL8AEerf3F pILXzCE9vD7f/BaLpwaJRaBDzovtGjpkzCdKXujFcoqPkbUxSNMRlOwJXqR5ig59fkRW PSjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SvT3rRWl; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si1828317edx.42.2021.06.10.01.24.18; Thu, 10 Jun 2021 01:24:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SvT3rRWl; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbhFJI0M (ORCPT + 8 others); Thu, 10 Jun 2021 04:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbhFJI0K (ORCPT ); Thu, 10 Jun 2021 04:26:10 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4098FC0617A6 for ; Thu, 10 Jun 2021 01:24:15 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id e20so10050453pgg.0 for ; Thu, 10 Jun 2021 01:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e7B2ZK+wpxF4j3+qmLEZ4xXUKjyuONFX7C0C6Hmnb+s=; b=SvT3rRWlPJYK+5pRZfIdOS69PuLDlN+vLemcMKfxfEvZPAvgBg0a+oLjqkS0ZNb4XW /Tt2KQcPvnAsKzk5qOBYPfBNvR1ujyESsRd1uXJcSZe0hbF4DpgGYlS1EDIMUakxPvFL dXwaR1ygCUrSG9n0HfokdqT3TU6sNjot3TjJQmr4biXPxAL1PxHFtYU+SNED5ThZejmn Hc/UqMk/oju36bDipalENDyOQr504hK1fcQ6hruwr8P0hIb6/rPvDHzoeCVxKMXz1607 W70h2N4N/qRObY9w9kdB4xLgLEYF7eoUAjx9g2Utl6h8SUf01655cTr2peUgp0I8g0D3 CtOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e7B2ZK+wpxF4j3+qmLEZ4xXUKjyuONFX7C0C6Hmnb+s=; b=jamDZvaAYK56Ker/DYZpz9njKdvFjm27Sfs4btLGdm9WHdHjjLzDpJmofw+kL2mMOq iqGPwkP9mlVQnwmsSrsDSQ2jwz1gUDujm8qJAR6AfbWn+OO1B69M/tpNiZD0PyNlIMc6 +VGGXdF8u7hti8iqflrf6owqhspRRYNSDTmeAAmAfNcELkyLjAYCj0Np82v7YXivXHb1 b+HUT3OCjuMX82saopJ/Ccwm2Gs5UcUnrC170acZPHhVpAg/0YsP1s7S8174WhaGt/Fg DrxnmXKdh6Adze8OUpr0+OJFjYEluhcCd6lAdMxxgcDu0Oj3obqmsPhAi7lCvjHR5ugC W+Ug== X-Gm-Message-State: AOAM530erWDlHFmcOpdVTW/H6MF7Y32DLhsvjGyyrfXvmThB4qvgwXA8 mmn4fzPimkKCLY0Cw++l0QV7Sg== X-Received: by 2002:a62:804b:0:b029:2e9:c897:aa7c with SMTP id j72-20020a62804b0000b02902e9c897aa7cmr1904664pfd.12.1623313454836; Thu, 10 Jun 2021 01:24:14 -0700 (PDT) Received: from localhost ([136.185.169.128]) by smtp.gmail.com with ESMTPSA id m1sm1863638pfb.14.2021.06.10.01.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:24:14 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Qian Cai , Srinivas Pandruvada , Len Brown , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Ionela Voinescu , Dirk Brandewie , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] cpufreq: intel_pstate: Migrate to ->exit() callback instead of ->stop_cpu() Date: Thu, 10 Jun 2021 13:53:58 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver interface") added the stop_cpu() callback to allow the drivers to do clean up before the CPU is completely down and its state cannot be modified. At that time the CPU hotplug framework used to call the cpufreq core's registered notifier for different events like CPU_DOWN_PREPARE and CPU_POST_DEAD. The stop_cpu() callback was called during the CPU_DOWN_PREPARE event. This is no longer the case, cpuhp_cpufreq_offline() is called only once by the CPU hotplug core now and we don't really need two separate callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything can be done from the exit() callback itself. Migrate to using the exit() callback instead of stop_cpu(). Cc: Dirk Brandewie Signed-off-by: Viresh Kumar --- drivers/cpufreq/intel_pstate.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) -- 2.31.1.272.g89b43f80a514 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index f0401064d7aa..9d3191663925 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -2374,17 +2374,11 @@ static int intel_pstate_cpu_online(struct cpufreq_policy *policy) return 0; } -static void intel_pstate_stop_cpu(struct cpufreq_policy *policy) -{ - pr_debug("CPU %d stopping\n", policy->cpu); - - intel_pstate_clear_update_util_hook(policy->cpu); -} - static int intel_pstate_cpu_exit(struct cpufreq_policy *policy) { pr_debug("CPU %d exiting\n", policy->cpu); + intel_pstate_clear_update_util_hook(policy->cpu); policy->fast_switch_possible = false; return 0; @@ -2451,7 +2445,6 @@ static struct cpufreq_driver intel_pstate = { .resume = intel_pstate_resume, .init = intel_pstate_cpu_init, .exit = intel_pstate_cpu_exit, - .stop_cpu = intel_pstate_stop_cpu, .offline = intel_pstate_cpu_offline, .online = intel_pstate_cpu_online, .update_limits = intel_pstate_update_limits, From patchwork Thu Jun 10 08:23:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 457844 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp177867jae; Thu, 10 Jun 2021 01:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuPt9+geXmzeAogqIT3WSt9lXLQCYPmqQE9bl1015Hnd537S9rmhZYG4xF2VXFAPVpj8z1 X-Received: by 2002:a05:6402:2707:: with SMTP id y7mr3543998edd.0.1623313538429; Thu, 10 Jun 2021 01:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623313538; cv=none; d=google.com; s=arc-20160816; b=N8hQtsd9a85Xa5fPPD4tDA+lezxP7fSP4Z0ryHfjakdjU215LPLIsmQak4nkEf623Z ISvNNHLQwyhJ5LomBoJ2r6EcqHEgxEqV87J4DoihjBaGpgDNbAx+j5NX2DuOB05w3xcg P+pTjeoADm0zn+vtGHv66Z3gY8DRxKhmRIJJs4wkcItYzSy9NfjY/PetCMnWSNnHf829 94qdT23+M3c4EBL0lws9mCycE0u/NP5GkOiKCwlbsKnmCvAxOgqMFB63+cjGfWt12V4k tEBk6huI/glRt33lGOY0ruKQmL3jezkievGQ7cWCPzGoh2qfF/EwKUiO75XR5b7v51gl qbGg== 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=9brGsoPBB+d+RHY31m7cZqh3sPnjdxBD51bqiyGsmoM=; b=N774Rm4uuO8GjO8oBHkBJZKi6+MyJkqYuVICCyrr9SzNYd0p6YQO8Fhr3XTag7IEyY /aC3ILfL6mz1JTRa988B7XXvCA840ydsTgiC8zWnqNj2AAet5A8ICj8i+/zXfziG+3iH 0eLHVbz/T3Plq07BZ7R6ySY5CHO16MaDR+1k5PLZjQPm3foidBnqmT0p8Q8dkarRJFzj 8/qcWWd5JBdT9yyEDI7gE6dQfIB2WOG2eoxy5+u6sch9IvgUmq+ZW1+W+OJ1i3D+0euZ xf1hZVvbFyz5E6HkDgX71gy4FBqF6wZUoxWyMNaUKbsL4hx9zVQFnP2FqNJKCV8lwPtm xRLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z4oi+Qts; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be8si1721641edb.223.2021.06.10.01.25.38; Thu, 10 Jun 2021 01:25:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z4oi+Qts; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbhFJI1c (ORCPT + 8 others); Thu, 10 Jun 2021 04:27:32 -0400 Received: from mail-pl1-f177.google.com ([209.85.214.177]:34515 "EHLO mail-pl1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbhFJI12 (ORCPT ); Thu, 10 Jun 2021 04:27:28 -0400 Received: by mail-pl1-f177.google.com with SMTP id h1so601372plt.1 for ; Thu, 10 Jun 2021 01:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9brGsoPBB+d+RHY31m7cZqh3sPnjdxBD51bqiyGsmoM=; b=z4oi+QtsZIOkUCFtJ2RSljkQbvtIlKWhvmfPM3nkaTcx/SmP2SwZ/OG+gHmMtcJIVI Jz+fY/OSo8O9+ELcqVoo7u7WxCuKuZVq4HIvbp2fEaka2FusUdVtB2CaOnVDFdakQq1s WgD8eKYVt4xY7SKlklJT0+vTQaaOeIygjrFnC3E8n2TxgASfZSLqW6emrP4ePhogpd3p LCP0wfYPCSPY2fDENITlznVP5uwLlXyfFtXxpZyog9xudcUFU5hLh2OauKt2jpqkE710 p8BQ3NdkFzKdUP8qDnJ5S4CR/6RqEXkcXwAaVGtyWxW6VDOUnL24T7ElbtkSHdIK+Xas nWQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9brGsoPBB+d+RHY31m7cZqh3sPnjdxBD51bqiyGsmoM=; b=IwNCkSYc3MRXL/KYPCHyiTb1CVkJz/xAg+eOikJwJPXu52wzp/hKFDjHRGXjo0p+Ii yz66HwoaERO/2VjlzrfauWoFeCGEb8FgW+Iu4vxiaFWvR1M+/1o4tldNzcVIYtq0KCBK 3vfu7iSZjmwgSHCh1cBV1NXX/gFYG2uAtCFJzvSY+i37Vtnn7CVnSTbi2Pxrxi/VwKLB gYTnGkj+1t9gh21JtEP+Vwq4Y7eJlAT2kS3fPUNe6rI1OXlR8+EuQSdfXLvzfaHlcv92 wBsJzuYBurCmKAnnaUtNS6rX1Vfx1dHZV0h8Zkjq9v4Gz/9PLEYhi6LpW815s4ZN380o nTIg== X-Gm-Message-State: AOAM530B3el0lLt9DKJEsxBjf2Ua1ajciBWNp13CtD4rLJr7/bMtLkTv FM1l7E1NUnPTgY5PDBUgilmlgw== X-Received: by 2002:a17:90a:1141:: with SMTP id d1mr2224862pje.56.1623313457758; Thu, 10 Jun 2021 01:24:17 -0700 (PDT) Received: from localhost ([136.185.169.128]) by smtp.gmail.com with ESMTPSA id q13sm1741649pff.13.2021.06.10.01.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:24:17 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Qian Cai , Viresh Kumar , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras Cc: linux-pm@vger.kernel.org, Vincent Guittot , Ionela Voinescu , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] cpufreq: powerenv: Migrate to ->exit() callback instead of ->stop_cpu() Date: Thu, 10 Jun 2021 13:53:59 +0530 Message-Id: <0990172cba066ec7747e479f8f0a2069ae368339.1623313323.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org commit 367dc4aa932b ("cpufreq: Add stop CPU callback to cpufreq_driver interface") added the stop_cpu() callback to allow the drivers to do clean up before the CPU is completely down and its state cannot be modified. At that time the CPU hotplug framework used to call the cpufreq core's registered notifier for different events like CPU_DOWN_PREPARE and CPU_POST_DEAD. The stop_cpu() callback was called during the CPU_DOWN_PREPARE event. This is no longer the case, cpuhp_cpufreq_offline() is called only once by the CPU hotplug core now and we don't really need two separate callbacks for cpufreq drivers, i.e. stop_cpu() and exit(), as everything can be done from the exit() callback itself. Migrate to using the exit() callback instead of stop_cpu(). Signed-off-by: Viresh Kumar --- drivers/cpufreq/powernv-cpufreq.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) -- 2.31.1.272.g89b43f80a514 diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c index e439b43c19eb..005600cef273 100644 --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c @@ -875,7 +875,15 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy) static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy) { - /* timer is deleted in cpufreq_cpu_stop() */ + struct powernv_smp_call_data freq_data; + struct global_pstate_info *gpstates = policy->driver_data; + + freq_data.pstate_id = idx_to_pstate(powernv_pstate_info.min); + freq_data.gpstate_id = idx_to_pstate(powernv_pstate_info.min); + smp_call_function_single(policy->cpu, set_pstate, &freq_data, 1); + if (gpstates) + del_timer_sync(&gpstates->timer); + kfree(policy->driver_data); return 0; @@ -1007,18 +1015,6 @@ static struct notifier_block powernv_cpufreq_opal_nb = { .priority = 0, }; -static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy) -{ - struct powernv_smp_call_data freq_data; - struct global_pstate_info *gpstates = policy->driver_data; - - freq_data.pstate_id = idx_to_pstate(powernv_pstate_info.min); - freq_data.gpstate_id = idx_to_pstate(powernv_pstate_info.min); - smp_call_function_single(policy->cpu, set_pstate, &freq_data, 1); - if (gpstates) - del_timer_sync(&gpstates->timer); -} - static unsigned int powernv_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { @@ -1042,7 +1038,6 @@ static struct cpufreq_driver powernv_cpufreq_driver = { .target_index = powernv_cpufreq_target_index, .fast_switch = powernv_fast_switch, .get = powernv_cpufreq_get, - .stop_cpu = powernv_cpufreq_stop_cpu, .attr = powernv_cpu_freq_attr, }; From patchwork Thu Jun 10 08:24:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 457843 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp177816jae; Thu, 10 Jun 2021 01:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeO3rmxAA8N9NU0Dn7qWb1vRI+AlFc9zoeyZkO7ROMx+BYahNuaxTnVABEH7sp6HzEe5Cx X-Received: by 2002:a17:906:914f:: with SMTP id y15mr3528891ejw.354.1623313531664; Thu, 10 Jun 2021 01:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623313531; cv=none; d=google.com; s=arc-20160816; b=DZyJvpRlDdZvNYXVeqQfNLgfHgKyRnG2oJAF2ooD4MlquyEVsRlEN/YXQX9XTKIQrk ehirpbPesAu5VHWZKy6uui+gYHlX/qlrJefknWLEzQsQ1GYGT15qYouqlYa/hdLsEOxc EkIXm36vV4u+aoz04rcLQ3wNgjGdxHZ1kEPvHZHaQm3dZAOLTUZH0Gh+VVf0kC3kapPm yqXVGwLUyCKxbFjBTHk3NKh0fNTJdSpZW4QUSFTq+Ezsu2yANF2M2pfFLgonv8qjuzKw m8LDAgl7wWhYPvordnh7tS+N+HM8rEltfjLnuXXE5EEsCl8AG0WIaU+40KhRICSs+4LT 0Xxg== 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=CWh1Aokcvj2UQLotNOEP1WcKgv5ApFMcJuxcuwZzDnY=; b=Isdj3YKIDtaVY1Rc0Z5e/odVsJ5UlcVKAsj/QVkjF7spyWggIsBS17nWeI2kI4B4Co DbiWdhO3D7Kkgna/wtAqYaAWzY6hZHbmovUF3fz6ILJqiOoRCB9W44ANCX4dVyQWKwvk mH+sQ8tNYuFSR+fOAt+LcCpp6FIvVLnREtP5UJbNc0OarM4goSapsR8SrW4HxfV7FHzj f7N1UcUUvKIAED9G9UwtwzLzyYWMNqIJvwBUbvIXg6O5XjH3zKMPE8+jNHJYw3vmsvQ9 96vD2TTwBJR2nR8RbIKksotdZRxvTAb3VE0Pv6xEivBRrKTcmJmm0ZKScd7I3QMGglOE KVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yfdQVopR; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be8si1721641edb.223.2021.06.10.01.25.31; Thu, 10 Jun 2021 01:25:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yfdQVopR; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbhFJI1U (ORCPT + 8 others); Thu, 10 Jun 2021 04:27:20 -0400 Received: from mail-pj1-f53.google.com ([209.85.216.53]:39550 "EHLO mail-pj1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbhFJI1R (ORCPT ); Thu, 10 Jun 2021 04:27:17 -0400 Received: by mail-pj1-f53.google.com with SMTP id o17-20020a17090a9f91b029015cef5b3c50so3281865pjp.4 for ; Thu, 10 Jun 2021 01:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CWh1Aokcvj2UQLotNOEP1WcKgv5ApFMcJuxcuwZzDnY=; b=yfdQVopR5TI3meR02dYmXSyInvDr/3fhuuTS2PsKDcsKLC6x8NTEx3quKD6H2xTcyr hXwuuTiL2kCbiS5eVHWLzGnZEc3Ks6Q9Fa08m2lXkTLq1ygZ1WmoqMyyEWR+BX2eBHbe WX7pdOLNlu2PT45ePAJlWjm2y8tido3FmiO+ZknmtSDKH5fJbtc37Mnrx2IFMvCJTLVq bb+dnqC9aHYa3n3L9GqoKHCTPCmU25TD2GEwd5xUbqdV2hetEL+edqptR8vQWLscui2W lX2APi+adydBdmwI3t9qFgYUSXyzCHb91KzFb4+/dffecVL2MjhHgOvg39lq6UXspvqO W2nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CWh1Aokcvj2UQLotNOEP1WcKgv5ApFMcJuxcuwZzDnY=; b=fbLBGKmGzKReg2Apzu2Iah0HdFv0b9D4XgV90jBL+kLoUs8j/Xq+aJNUK86kV04C9g zSqLDMWYbFygeFj1K5Gwmtb/3I8q91C1Gz8/IO4p8X1PCCMGCIWdRNi3oXqH07Zt2CqD xfZT9eKjOIXP9rdfIyfIPfeCAJ/BxEZr2r4N2Co6qJyOOsG5jNXgfLPmpPI5BWe/75AP tFp1w/joPgiguwpO/KtKWO+eHOOihDDwGRk7de8fSVAH5vkDti/D/BBsPPK1URB+t/7z CboRz8qlwADrk2GNAkhgNEOgRagljEfa6f9mXvt+yT4dPrJynOkFRy6EJqsl/tMNBVXi VgLA== X-Gm-Message-State: AOAM531VbnllTa2fIhLD21vk2RXgq9aLHhLtY+ompa+IuO3DfhnmmvRB 4c8v/G//wT7pyZPeCIGRvTg/wQ== X-Received: by 2002:a17:902:a3c3:b029:f0:b297:7778 with SMTP id q3-20020a170902a3c3b02900f0b2977778mr3939702plb.16.1623313460999; Thu, 10 Jun 2021 01:24:20 -0700 (PDT) Received: from localhost ([136.185.169.128]) by smtp.gmail.com with ESMTPSA id s3sm2120419pgs.62.2021.06.10.01.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:24:20 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Qian Cai , Viresh Kumar , Jonathan Corbet Cc: linux-pm@vger.kernel.org, Vincent Guittot , Ionela Voinescu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] cpufreq: Add start_cpu() and stop_cpu() callbacks Date: Thu, 10 Jun 2021 13:54:00 +0530 Message-Id: <1d1c3ee64c0a5a701c8d7c66440fd2781512432c.1623313323.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On CPU hotplug, the cpufreq core doesn't call any driver specific callback unless all the CPUs of a policy went away. There is need for a callback to be called in such cases (for the CPPC cpufreq driver) now. Reuse the existing stop_cpu() callback and add a new one for start_cpu(). Signed-off-by: Viresh Kumar --- Documentation/cpu-freq/cpu-drivers.rst | 7 +++++-- drivers/cpufreq/cpufreq.c | 11 ++++++++--- include/linux/cpufreq.h | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) -- 2.31.1.272.g89b43f80a514 diff --git a/Documentation/cpu-freq/cpu-drivers.rst b/Documentation/cpu-freq/cpu-drivers.rst index a697278ce190..15cfe42b4075 100644 --- a/Documentation/cpu-freq/cpu-drivers.rst +++ b/Documentation/cpu-freq/cpu-drivers.rst @@ -71,8 +71,11 @@ And optionally .exit - A pointer to a per-policy cleanup function called during CPU_POST_DEAD phase of cpu hotplug process. - .stop_cpu - A pointer to a per-policy stop function called during - CPU_DOWN_PREPARE phase of cpu hotplug process. + .start_cpu - A pointer to a per-policy per-cpu start function called + during CPU online phase. + + .stop_cpu - A pointer to a per-policy per-cpu stop function called + during CPU offline phase. .suspend - A pointer to a per-policy suspend function which is called with interrupts disabled and _after_ the governor is stopped for the diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 802abc925b2a..fac2522be5c3 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1119,6 +1119,10 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp cpumask_set_cpu(cpu, policy->cpus); + /* Do CPU specific initialization if required */ + if (cpufreq_driver->start_cpu) + cpufreq_driver->start_cpu(policy, cpu); + if (has_target()) { ret = cpufreq_start_governor(policy); if (ret) @@ -1581,6 +1585,10 @@ static int cpufreq_offline(unsigned int cpu) policy->cpu = cpumask_any(policy->cpus); } + /* Do CPU specific de-initialization if required */ + if (cpufreq_driver->stop_cpu) + cpufreq_driver->stop_cpu(policy, cpu); + /* Start governor again for active policy */ if (!policy_is_inactive(policy)) { if (has_target()) { @@ -1597,9 +1605,6 @@ static int cpufreq_offline(unsigned int cpu) policy->cdev = NULL; } - if (cpufreq_driver->stop_cpu) - cpufreq_driver->stop_cpu(policy); - if (has_target()) cpufreq_exit_governor(policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 353969c7acd3..c281b3df4e2f 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -371,7 +371,10 @@ struct cpufreq_driver { int (*online)(struct cpufreq_policy *policy); int (*offline)(struct cpufreq_policy *policy); int (*exit)(struct cpufreq_policy *policy); - void (*stop_cpu)(struct cpufreq_policy *policy); + + /* CPU specific start/stop */ + void (*start_cpu)(struct cpufreq_policy *policy, unsigned int cpu); + void (*stop_cpu)(struct cpufreq_policy *policy, unsigned int cpu); int (*suspend)(struct cpufreq_policy *policy); int (*resume)(struct cpufreq_policy *policy); From patchwork Thu Jun 10 08:24:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 457841 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp177784jae; Thu, 10 Jun 2021 01:25:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuLGCIQvv9/irbHcEqXpOYpm4hHnqs4Y5L1oQMR+KefGPK0YS4rzKqLp/jmhnuM/HP7emg X-Received: by 2002:a17:907:1689:: with SMTP id hc9mr3380910ejc.552.1623313528565; Thu, 10 Jun 2021 01:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623313528; cv=none; d=google.com; s=arc-20160816; b=WYbvWHwWy2DbakncmRbJjqyzhVBzQNejdaCTxqIRTzmjlcQDitK58DCkbUr66Eob+y pje6gLMCo6k9gke465v7cl5nEvbXqw/faQasUtaIVHKZAq2pXUDLCMYB9n1FEdY3z5Pd GqYj0fqdIekQu7veLUGE5yRD1BJU63Q0Tu/DYVylmUWa0BCnOpsLk6fdRoVceXazI94q 4hBruPlybIBxhndxpI+0R2ApMrxVyWaTrsH556gzuPYzbLT1m+6VeA3M9JYDmTQ895xY V6iaQl3bescKr6zqkhzI+tEWdEWWOgQ6vpl6wDZ1shlSGZibOYmhDT73/FuD3cqyRLz0 FS8Q== 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=ts2ApCK9xnJQUj3HLY0ucjPpblWOxwdFx65VhUgZ2Z4=; b=eFLQ9OCaTk/Vk5zBcFRQcbDP4YEiObnUk+KUbukUQNOzRUccQQBgN57QAxfB6SzS9a 66+K2lbJvTyDqqaZn9FxiUVEgnyUWPwIPEkijGVJuEWmCh8Qj7gEzxcAUPmArcnZhoQo MS1znEEPp7lDIW4J19GUcKOSc4YoOpYPuw2flUiUh1w/2G1n4Yv00Mdg/+dhnpq1pmIK MKmdKSSQ27fBah5C5N8SQr2tNMd4+dSQN4OxTjHS5oT4cvgsTa/+hleM0U3m40DSRT3x gVbRZUFlcVB4ZL4toPhiFmlYbMGJVYJm8MFOaBgw7Qm/fWUltHga/b9mlswc8hkxVq4t tCkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="m3DlcIj/"; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be8si1721641edb.223.2021.06.10.01.25.28; Thu, 10 Jun 2021 01:25:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="m3DlcIj/"; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbhFJI0c (ORCPT + 8 others); Thu, 10 Jun 2021 04:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbhFJI0a (ORCPT ); Thu, 10 Jun 2021 04:26:30 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53069C0617AD for ; Thu, 10 Jun 2021 01:24:24 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id mp5-20020a17090b1905b029016dd057935fso3284756pjb.5 for ; Thu, 10 Jun 2021 01:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ts2ApCK9xnJQUj3HLY0ucjPpblWOxwdFx65VhUgZ2Z4=; b=m3DlcIj/aVptNqUHKX8oUUf+lJ5m3vlVM9aXVU8bLDIOpm2rSnifUHo0xvKS1bmSPP Z9+3xTMFL33TbexfAYLt9ByLW2mLUUFgDeg9JNE178xurzULxbZQuRFaevMs/qUGzubm V8EJzeBp0z+kYLjMIV0xRtqaHvkD220uIBG5erXbcRCk5kYbTBiKwTncOz0krO75n9rw 7Q0opG0COPQHi6Bj+2EKSvUBEZi7OezH8KXfzvc5zAtSjsUF/1h0dIDQ4A7aK34cq+Xm EEtDq/BiUaFJks4VJbbiTYfeb96gHqa+odSnqwWnZbcL/Q/G/D+BmaUyfDmatGU+xeTY BdZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ts2ApCK9xnJQUj3HLY0ucjPpblWOxwdFx65VhUgZ2Z4=; b=tiBD5ncfYZPIHJf+uq3lyOn6PlbzjPwJLtQGwC4W0HQnN/3Z+xIpHVGSLq6F3ztNg8 99dgovTT6WM7yZx9b7hNYmwvSf2hVQaB0XKTLRBx7YaRNT9Fzaatn/gbhtvYc4oqnAPg foB6giHuqG1Q9ztxwHtCUdPddgQUDvCUl/xCJy43eb/yFgGLUHhxHW9cIm4BqW25pMLI y/HLoNzjyXvPTdwwfDRtSYaUsItIjf6iBL1Dr1lb8+0LQVUQBpKl1P05dlR/xi8JiA3S 8ky25h2F2x5WTEnLuV5xdg7C5OnEf/60kQcEQqYKT6UC2ntLJ7fG++H1ymXE7fWnLzGr kc6w== X-Gm-Message-State: AOAM532ExRm33SlkasFATvQ1CevvbhI+LnjtGpWvh3Q6LT8NM3mNKBEs B8kAQd/bs6ssmnc0GeYMlBukug== X-Received: by 2002:a17:902:9a8c:b029:113:d891:2eaf with SMTP id w12-20020a1709029a8cb0290113d8912eafmr3878715plp.61.1623313463895; Thu, 10 Jun 2021 01:24:23 -0700 (PDT) Received: from localhost ([136.185.169.128]) by smtp.gmail.com with ESMTPSA id z8sm2081118pgi.94.2021.06.10.01.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 01:24:23 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Qian Cai , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Ionela Voinescu , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] cpufreq: cppc: Fix suspend/resume specific races with the FIE code Date: Thu, 10 Jun 2021 13:54:01 +0530 Message-Id: <1256ee94a515216ab58553181de175cc74f396bd.1623313323.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The CPPC driver currently stops the frequency invariance related kthread_work and irq_work from cppc_freq_invariance_exit() which is only called during driver's removal. This is not sufficient as the CPUs can get hot-plugged out while the driver is in use, the same also happens during system suspend/resume. In such a cases we can reach a state where the CPU is removed by the kernel but its kthread_work or irq_work aren't stopped. Fix this by implementing the start_cpu() and stop_cpu() callbacks of the cpufreq core, which will be called for each CPU's addition/removal. The FIE feature was marked BROKEN earlier, revert that. Reported-by: Qian Cai Signed-off-by: Viresh Kumar --- drivers/cpufreq/Kconfig.arm | 1 - drivers/cpufreq/cppc_cpufreq.c | 117 +++++++++++++++++++-------------- 2 files changed, 68 insertions(+), 50 deletions(-) -- 2.31.1.272.g89b43f80a514 diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm index 614c34350f41..a5c5f70acfc9 100644 --- a/drivers/cpufreq/Kconfig.arm +++ b/drivers/cpufreq/Kconfig.arm @@ -22,7 +22,6 @@ config ACPI_CPPC_CPUFREQ config ACPI_CPPC_CPUFREQ_FIE bool "Frequency Invariance support for CPPC cpufreq driver" depends on ACPI_CPPC_CPUFREQ && GENERIC_ARCH_TOPOLOGY - depends on BROKEN default y help This extends frequency invariance support in the CPPC cpufreq driver, diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 30a861538784..82167c657098 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -74,7 +74,6 @@ struct cppc_freq_invariance { static DEFINE_PER_CPU(struct cppc_freq_invariance, cppc_freq_inv); static struct kthread_worker *kworker_fie; -static bool fie_disabled; static struct cpufreq_driver cppc_cpufreq_driver; static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu); @@ -151,35 +150,64 @@ static struct scale_freq_data cppc_sftd = { .set_freq_scale = cppc_scale_freq_tick, }; -static void cppc_freq_invariance_policy_init(struct cpufreq_policy *policy, - struct cppc_cpudata *cpu_data) +static void cppc_cpufreq_start_cpu(struct cpufreq_policy *policy, + unsigned int cpu) { + struct cppc_freq_invariance *cppc_fi = &per_cpu(cppc_freq_inv, cpu); struct cppc_perf_fb_ctrs fb_ctrs = {0}; - struct cppc_freq_invariance *cppc_fi; - int i, ret; + int ret; - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) - return; + cppc_fi->cpu = cpu; + cppc_fi->cpu_data = policy->driver_data; + kthread_init_work(&cppc_fi->work, cppc_scale_freq_workfn); + init_irq_work(&cppc_fi->irq_work, cppc_irq_work); - if (fie_disabled) + ret = cppc_get_perf_ctrs(cpu, &fb_ctrs); + if (ret) { + pr_warn("%s: failed to read perf counters: %d\n", + __func__, ret); return; + } else { + cppc_fi->prev_perf_fb_ctrs = fb_ctrs; + } - for_each_cpu(i, policy->cpus) { - cppc_fi = &per_cpu(cppc_freq_inv, i); - cppc_fi->cpu = i; - cppc_fi->cpu_data = cpu_data; - kthread_init_work(&cppc_fi->work, cppc_scale_freq_workfn); - init_irq_work(&cppc_fi->irq_work, cppc_irq_work); + /* Register for freq-invariance */ + topology_set_scale_freq_source(&cppc_sftd, cpumask_of(cpu)); +} - ret = cppc_get_perf_ctrs(i, &fb_ctrs); - if (ret) { - pr_warn("%s: failed to read perf counters: %d\n", - __func__, ret); - fie_disabled = true; - } else { - cppc_fi->prev_perf_fb_ctrs = fb_ctrs; - } - } +static void cppc_cpufreq_stop_cpu(struct cpufreq_policy *policy, + unsigned int cpu) +{ + struct cppc_freq_invariance *cppc_fi = &per_cpu(cppc_freq_inv, cpu); + + topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_CPPC, cpumask_of(cpu)); + + irq_work_sync(&cppc_fi->irq_work); + kthread_cancel_work_sync(&cppc_fi->work); +} + +static int cppc_freq_invariance_policy_init(struct cpufreq_policy *policy) +{ + int cpu; + + if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + return 0; + + for_each_cpu(cpu, policy->cpus) + cppc_cpufreq_start_cpu(policy, cpu); + + return 0; +} + +static void cppc_freq_invariance_policy_exit(struct cpufreq_policy *policy) +{ + int cpu; + + if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) + return; + + for_each_cpu(cpu, policy->cpus) + cppc_cpufreq_stop_cpu(policy, cpu); } static void __init cppc_freq_invariance_init(void) @@ -202,9 +230,6 @@ static void __init cppc_freq_invariance_init(void) if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) return; - if (fie_disabled) - return; - kworker_fie = kthread_create_worker(0, "cppc_fie"); if (IS_ERR(kworker_fie)) return; @@ -217,36 +242,28 @@ static void __init cppc_freq_invariance_init(void) return; } - /* Register for freq-invariance */ - topology_set_scale_freq_source(&cppc_sftd, cpu_present_mask); + cppc_cpufreq_driver.start_cpu = cppc_cpufreq_start_cpu; + cppc_cpufreq_driver.stop_cpu = cppc_cpufreq_stop_cpu; } static void cppc_freq_invariance_exit(void) { - struct cppc_freq_invariance *cppc_fi; - int i; - if (cppc_cpufreq_driver.get == hisi_cppc_cpufreq_get_rate) return; - if (fie_disabled) - return; - - topology_clear_scale_freq_source(SCALE_FREQ_SOURCE_CPPC, cpu_present_mask); - - for_each_possible_cpu(i) { - cppc_fi = &per_cpu(cppc_freq_inv, i); - irq_work_sync(&cppc_fi->irq_work); - } - kthread_destroy_worker(kworker_fie); kworker_fie = NULL; } #else +static inline int +cppc_freq_invariance_policy_init(struct cpufreq_policy *polic) +{ + return 0; +} + static inline void -cppc_freq_invariance_policy_init(struct cpufreq_policy *policy, - struct cppc_cpudata *cpu_data) +cppc_freq_invariance_policy_exit(struct cpufreq_policy *policy) { } @@ -529,11 +546,10 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) if (ret) { pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", caps->highest_perf, cpu, ret); - } else { - cppc_freq_invariance_policy_init(policy, cpu_data); + return ret; } - return ret; + return cppc_freq_invariance_policy_init(policy); } static int cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) @@ -543,6 +559,8 @@ static int cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) unsigned int cpu = policy->cpu; int ret; + cppc_freq_invariance_policy_exit(policy); + cpu_data->perf_ctrls.desired_perf = caps->lowest_perf; ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); @@ -728,10 +746,11 @@ static int __init cppc_cpufreq_init(void) INIT_LIST_HEAD(&cpu_data_list); cppc_check_hisi_workaround(); + cppc_freq_invariance_init(); ret = cpufreq_register_driver(&cppc_cpufreq_driver); - if (!ret) - cppc_freq_invariance_init(); + if (ret) + cppc_freq_invariance_exit(); return ret; } @@ -750,8 +769,8 @@ static inline void free_cpu_data(void) static void __exit cppc_cpufreq_exit(void) { - cppc_freq_invariance_exit(); cpufreq_unregister_driver(&cppc_cpufreq_driver); + cppc_freq_invariance_exit(); free_cpu_data(); }