From patchwork Tue Jun 14 23:09:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12881711 X-Patchwork-Delegate: cw00.choi@samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A990C433EF for ; Wed, 15 Jun 2022 00:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233456AbiFOAD5 (ORCPT ); Tue, 14 Jun 2022 20:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232916AbiFOAD4 (ORCPT ); Tue, 14 Jun 2022 20:03:56 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21565186D4; Tue, 14 Jun 2022 17:03:55 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k19so13180557wrd.8; Tue, 14 Jun 2022 17:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j0z4pjcptcunW3Z06jtQN0IsyiyXwTKoHZqtl2Ou09s=; b=KgpCqTRfEGlf3dwe8pDO/nofFrcQWOdl1Ueb4bKfDZttESpHrAMwEy67E31EopjSYP OJZegYI5PMy9wtdL3qOfwenIoA37aPYn2K8N/v8onwMANEUtZVaRk39w7btWvoKTKbeG AkYa0O3/jh5+4ukRyn38cA/CjzUBq4fbMiSxTibT8FOqhO/NmKvNuxolp63EK/FrJ8K9 r7BKaZ8TIvAYb186tEQFYl69QkCYWceNEmP7z6FucmGhwSlyHZH4RilHU0GJweYHVW+1 9AJYlD1h2VqXJmMAkT+3zJnFgzFFRJ0dHH6bL1n427fXg+DzEUgIS+lqtOlL6KafgiKh 0DtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j0z4pjcptcunW3Z06jtQN0IsyiyXwTKoHZqtl2Ou09s=; b=t0I/kHukftplEbIQmQZXr4DBOP90MMQSgVSW+1z6Sw8CUjhOV0ogKUl1nAXL2E8B4k hsbDxH/tYEbsAjpLluk9ZfZzfZlzSeR1K6N+9CkKWkzHaQlPtgOnRp7xVkmvhZRMW480 S3TRlLOXvMPsIVSyTAGC8Fs1fkGZjY0EVp7GRcn4JxA76UCx9x4aknAG6xeyDVsQoKRT RVsD9ESIkkeYKJalRjXhVFAR/jlkgob6hOo0T3/BJ9b8icmUUcg/TdaosR6Hl8mpk1Z0 XcYyGf8YwEhzBzTD/3/BWbF5flBUTFG48k3xDXKCN/FEAVB61rtxkVRJFQERY0uIXeJF fFPQ== X-Gm-Message-State: AJIora/qoBxuQrwZLsD+I1C3uhwYBcMo4UP1lcKACYLUV8if/9qGvYs+ /CeeRXG8dx0IGjdzAPpVOeg= X-Google-Smtp-Source: AGRyM1tYIfaQCWcS658ac6B0oKaAAzYroYkLsEdrjkdKjhUR9xE30wDBkIpsd9g4d8IM2wGT1SmSBw== X-Received: by 2002:a5d:47c3:0:b0:219:b471:f7d with SMTP id o3-20020a5d47c3000000b00219b4710f7dmr6955919wrc.242.1655251433495; Tue, 14 Jun 2022 17:03:53 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id l7-20020a05600c4f0700b00397342e3830sm5546821wmq.0.2022.06.14.17.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 17:03:52 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v4 1/4] PM / devfreq: Fix cpufreq passive unregister erroring on PROBE_DEFER Date: Wed, 15 Jun 2022 01:09:47 +0200 Message-Id: <20220614230950.426-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614230950.426-1-ansuelsmth@gmail.com> References: <20220614230950.426-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org With the passive governor, the cpu based scaling can PROBE_DEFER due to the fact that CPU policy are not ready. The cpufreq passive unregister notifier is called both from the GOV_START errors and for the GOV_STOP and assume the notifier is successfully registred every time. With GOV_START failing it's wrong to loop over each possible CPU since the register path has failed for some CPU policy not ready. Change the logic and unregister the notifer based on the current allocated parent_cpu_data list to correctly handle errors and the governor unregister path. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/governor_passive.c | 39 +++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 72c67979ebe1..95de336f20d5 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -34,6 +34,20 @@ get_parent_cpu_data(struct devfreq_passive_data *p_data, return NULL; } +static void delete_parent_cpu_data(struct devfreq_passive_data *p_data) +{ + struct devfreq_cpu_data *parent_cpu_data, *tmp; + + list_for_each_entry_safe(parent_cpu_data, tmp, &p_data->cpu_data_list, node) { + list_del(&parent_cpu_data->node); + + if (parent_cpu_data->opp_table) + dev_pm_opp_put_opp_table(parent_cpu_data->opp_table); + + kfree(parent_cpu_data); + } +} + static unsigned long get_target_freq_by_required_opp(struct device *p_dev, struct opp_table *p_opp_table, struct opp_table *opp_table, @@ -222,8 +236,7 @@ static int cpufreq_passive_unregister_notifier(struct devfreq *devfreq) { struct devfreq_passive_data *p_data = (struct devfreq_passive_data *)devfreq->data; - struct devfreq_cpu_data *parent_cpu_data; - int cpu, ret = 0; + int ret; if (p_data->nb.notifier_call) { ret = cpufreq_unregister_notifier(&p_data->nb, @@ -232,27 +245,9 @@ static int cpufreq_passive_unregister_notifier(struct devfreq *devfreq) return ret; } - for_each_possible_cpu(cpu) { - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - if (!policy) { - ret = -EINVAL; - continue; - } - - parent_cpu_data = get_parent_cpu_data(p_data, policy); - if (!parent_cpu_data) { - cpufreq_cpu_put(policy); - continue; - } - - list_del(&parent_cpu_data->node); - if (parent_cpu_data->opp_table) - dev_pm_opp_put_opp_table(parent_cpu_data->opp_table); - kfree(parent_cpu_data); - cpufreq_cpu_put(policy); - } + delete_parent_cpu_data(p_data); - return ret; + return 0; } static int cpufreq_passive_register_notifier(struct devfreq *devfreq) From patchwork Tue Jun 14 23:09:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12881712 X-Patchwork-Delegate: cw00.choi@samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 526D5C43334 for ; Wed, 15 Jun 2022 00:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234248AbiFOAEF (ORCPT ); Tue, 14 Jun 2022 20:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233809AbiFOAD7 (ORCPT ); Tue, 14 Jun 2022 20:03:59 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17803186CD; Tue, 14 Jun 2022 17:03:57 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id n185so5460377wmn.4; Tue, 14 Jun 2022 17:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DMTuvNRz1WP/wtYWEwAgZhtGlOYc4vZGQjh27l1KtGI=; b=j0v8Hc4uhX8Rwje+TwFKDBkE0s+n+7EeYfgd0FHCVN6K+uq/sZIIN+faP0pb9U2QrF 10ASdlgVGj9Yi5I0Lm1ApHXISvVw9ISMvzLYXD4gOmlHfx8VtayiT7ca0uCUESqwDYUD jXXi+U1vnG8zy7k0LZ/IVK9wkL9fj5a1a00rhjON7ByojAhSG9YTNzxb3eWNIJENsBoC UBMrHWPeFepk6DeuM5uXTLuCd4MevPHQoFFK3NPqfxM0NavPwV1y5QDMXMgWZC83Vs3K FdFllAYjezWk/HrgFGBn2piPfFgwZnjlWf87c4P1+ZEBOGb8dHG21qjBiVs4YFUgqrNt LQhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DMTuvNRz1WP/wtYWEwAgZhtGlOYc4vZGQjh27l1KtGI=; b=bXBk+SHgUNfGanHBss4RgfaYBiiWVVO97VnyhlnVOT+PmgrUhwvrmu1FSS823J7tGM tqYa4kagh7FrdyD9oiSmrUvkOMwQ8ZddfWOr1HsWV9WI7jlVeiOJZWNCb5MHi6GKxARP PnPFLhtbhS7LN6GgFBfsSMaaT2QmSfzNYLBGly1WJr6URZb/RnIhaTgW9ib+CDzbjOu1 LkxJB952bkO+GGamlTGshP+iIk/uaVqs9hMkmq9mrgIVTAJ1EFmHAjdcx9YWCnzSNswj y1b6gb+lhLG6nr+gEDi/5K6RwA3CitpCoPjLMHpfXollt3+iiHQjKhhfFPrcVr7cdHJu z57w== X-Gm-Message-State: AOAM530QXCr2Hl0eSHrMit5kpuDM1CISAGjHwG458QSfFNbm1/3eobfb xcAfLS8k7S6OWTMXve39xJ0Dhtt1U1M= X-Google-Smtp-Source: ABdhPJzEwGYR3qR4dRsdnfq3T1H7/7WZfH25RqJBOXAGOWcgPN2pp1IVgsZv2WzTGijrhIWpZI4Ihg== X-Received: by 2002:a05:600c:378d:b0:39c:4950:aef8 with SMTP id o13-20020a05600c378d00b0039c4950aef8mr6701943wmr.96.1655251435470; Tue, 14 Jun 2022 17:03:55 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id l7-20020a05600c4f0700b00397342e3830sm5546821wmq.0.2022.06.14.17.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 17:03:54 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v4 2/4] PM / devfreq: Fix kernel warning with cpufreq passive register fail Date: Wed, 15 Jun 2022 01:09:48 +0200 Message-Id: <20220614230950.426-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614230950.426-1-ansuelsmth@gmail.com> References: <20220614230950.426-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When the cpufreq passive register path from the passive governor fails, the cpufreq_passive_unregister is called and a kernel WARNING is always reported. This is caused by the fact that the devfreq driver already call the governor unregister with the GOV_STOP, for this reason the second cpufreq_passive_unregister always return error and a WARN is printed from the WARN_ON function. Remove the unregister call from the error handling of the cpufreq register notifier as it's fundamentally wrong and already handled by the devfreq core code. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/governor_passive.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 95de336f20d5..dcc9dd518197 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -331,7 +331,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq) err_put_policy: cpufreq_cpu_put(policy); err: - WARN_ON(cpufreq_passive_unregister_notifier(devfreq)); return ret; } From patchwork Tue Jun 14 23:09:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12881713 X-Patchwork-Delegate: cw00.choi@samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EF5BC433EF for ; Wed, 15 Jun 2022 00:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235244AbiFOAEJ (ORCPT ); Tue, 14 Jun 2022 20:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234294AbiFOAEB (ORCPT ); Tue, 14 Jun 2022 20:04:01 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D339186F0; Tue, 14 Jun 2022 17:03:59 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id c21so13233429wrb.1; Tue, 14 Jun 2022 17:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ve0N11OoR1kACtG4t9OOSk62hvoo82ZyK31hQbQ3OLY=; b=ewdX52KUO99fwHu0VBtshYc9MFwtoRJAD73RyVeI2qW4Ly3kTx7lBwkfk+Zk1X4QCb btLgqbWsZ416/B/9QKQjo9tbK0Km7CQdtXfitABHKnMLm4s7dCKbCLhC22hizmlhb9xf csBn+kYEAzKX4OP/I+2BNkyVBKuFL3qMrj4lbnb1mSfVAhdwOPskEu+LP4pp3ea4ouCf Inx0/sPjIEt5Vheyhwr9hdGyD4VtuBx7EMb5fdkHRZqEqSjxEprQ69LjIVGpavTY5unT XN3AJdRy0vwLP1w5eBs3HM+tt+SOjP1qVPn0G/Z+EZ2xL/T5EULT+d/cVwpkMIPMCtg9 WpJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ve0N11OoR1kACtG4t9OOSk62hvoo82ZyK31hQbQ3OLY=; b=LA7q12tUtphK7nv0vLXxrCcKJCIeJkmjIJzDx4kUbWPaBI7B6CnLYeyPrshMm+UK27 HQwKTB5mUYrJ3nq0ospkLOaOFRs+gVTpzePzOxROXBrIgH4kWSWx1Q3LvMSlYvfoZrYH EddUTibivxEJFtOp+e5/bvoVnD9/0rJDVk3oyfjpCLFVvEZSPMoHtRVySDPhOzYsFzbS XeKXGaMNlfZwJlEVCQ1fbXBzjJxil4EWQb/+SHjez/WDhpP4+c/as7qbTdPoXBTyR0xZ zZzdogGTrKOwHYsMEw/w3cjcwnHPUSs3AKCwBLI6yZBXkwv91XSVPN0YwnSyfTiPMAj3 SCqA== X-Gm-Message-State: AJIora8UGJIq2IS9P5II1DKH7MDUaEBugDvmDGoGrm1KdtOnro9+QQBF LkKJGbUvsbb1y4ZrxTN/neM= X-Google-Smtp-Source: AGRyM1tatGVwUH4AHlh7dw4uIRQOfMx5GLicluHvTv1NkZLH/GCHNDlngTF47+czBlj8I5V+Dp8hfQ== X-Received: by 2002:a5d:59a7:0:b0:218:5584:e3b1 with SMTP id p7-20020a5d59a7000000b002185584e3b1mr7118456wrr.421.1655251437618; Tue, 14 Jun 2022 17:03:57 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id l7-20020a05600c4f0700b00397342e3830sm5546821wmq.0.2022.06.14.17.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 17:03:56 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v4 3/4] PM / devfreq: Rework freq_table to be local to devfreq struct Date: Wed, 15 Jun 2022 01:09:49 +0200 Message-Id: <20220614230950.426-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614230950.426-1-ansuelsmth@gmail.com> References: <20220614230950.426-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently we reference the freq_table to the profile defined one and we make changes on it. Devfreq never supported PROBE_DEFER before the cpu based scaling support to the passive governor and assumed that a devfreq device could only had error and be done with it. Now that a device can PROBE_DEFER a rework to the freq_table logic is required. If a device PROBE_DEFER on the GOV_START, the freq_table is already set in the device profile struct and its init is skipped. This is due to the fact that it's common for devs to declare this kind of struct static. This cause the devfreq logic to find a freq table declared (freq_table not NULL) with random data and poiting to the old addrs freed by devm. This problem CAN be solved by devs by clearing the freq_table in their profile struct on driver exit path but it should not be trusted and it looks to use a flawed logic. A better solution is to move the freq_table and max_state to the devfreq struct and never change the profile struct. This permit to correctly handle PROBE_DEFER since the devfreq struct is reallocated and contains new values. Also the profile struct should only be used to init the driver and should not be used by the devfreq to write the freq_table if it's not provided by the driver. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/devfreq.c | 71 ++++++++++++++---------------- drivers/devfreq/governor_passive.c | 14 +++--- include/linux/devfreq.h | 4 ++ 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 01474daf4548..2e2b3b414d67 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -123,7 +123,7 @@ void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq, unsigned long *max_freq) { - unsigned long *freq_table = devfreq->profile->freq_table; + unsigned long *freq_table = devfreq->freq_table; s32 qos_min_freq, qos_max_freq; lockdep_assert_held(&devfreq->lock); @@ -133,11 +133,11 @@ void devfreq_get_freq_range(struct devfreq *devfreq, * The devfreq drivers can initialize this in either ascending or * descending order and devfreq core supports both. */ - if (freq_table[0] < freq_table[devfreq->profile->max_state - 1]) { + if (freq_table[0] < freq_table[devfreq->max_state - 1]) { *min_freq = freq_table[0]; - *max_freq = freq_table[devfreq->profile->max_state - 1]; + *max_freq = freq_table[devfreq->max_state - 1]; } else { - *min_freq = freq_table[devfreq->profile->max_state - 1]; + *min_freq = freq_table[devfreq->max_state - 1]; *max_freq = freq_table[0]; } @@ -169,8 +169,8 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) { int lev; - for (lev = 0; lev < devfreq->profile->max_state; lev++) - if (freq == devfreq->profile->freq_table[lev]) + for (lev = 0; lev < devfreq->max_state; lev++) + if (freq == devfreq->freq_table[lev]) return lev; return -EINVAL; @@ -178,7 +178,6 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) static int set_freq_table(struct devfreq *devfreq) { - struct devfreq_dev_profile *profile = devfreq->profile; struct dev_pm_opp *opp; unsigned long freq; int i, count; @@ -188,25 +187,22 @@ static int set_freq_table(struct devfreq *devfreq) if (count <= 0) return -EINVAL; - profile->max_state = count; - profile->freq_table = devm_kcalloc(devfreq->dev.parent, - profile->max_state, - sizeof(*profile->freq_table), - GFP_KERNEL); - if (!profile->freq_table) { - profile->max_state = 0; + devfreq->max_state = count; + devfreq->freq_table = devm_kcalloc(devfreq->dev.parent, + devfreq->max_state, + sizeof(*devfreq->freq_table), + GFP_KERNEL); + if (!devfreq->freq_table) return -ENOMEM; - } - for (i = 0, freq = 0; i < profile->max_state; i++, freq++) { + for (i = 0, freq = 0; i < devfreq->max_state; i++, freq++) { opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq); if (IS_ERR(opp)) { - devm_kfree(devfreq->dev.parent, profile->freq_table); - profile->max_state = 0; + devm_kfree(devfreq->dev.parent, devfreq->freq_table); return PTR_ERR(opp); } dev_pm_opp_put(opp); - profile->freq_table[i] = freq; + devfreq->freq_table[i] = freq; } return 0; @@ -246,7 +242,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) if (lev != prev_lev) { devfreq->stats.trans_table[ - (prev_lev * devfreq->profile->max_state) + lev]++; + (prev_lev * devfreq->max_state) + lev]++; devfreq->stats.total_trans++; } @@ -835,6 +831,9 @@ struct devfreq *devfreq_add_device(struct device *dev, if (err < 0) goto err_dev; mutex_lock(&devfreq->lock); + } else { + devfreq->freq_table = devfreq->profile->freq_table; + devfreq->max_state = devfreq->profile->max_state; } devfreq->scaling_min_freq = find_available_min_freq(devfreq); @@ -870,8 +869,8 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->stats.trans_table = devm_kzalloc(&devfreq->dev, array3_size(sizeof(unsigned int), - devfreq->profile->max_state, - devfreq->profile->max_state), + devfreq->max_state, + devfreq->max_state), GFP_KERNEL); if (!devfreq->stats.trans_table) { mutex_unlock(&devfreq->lock); @@ -880,7 +879,7 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->stats.time_in_state = devm_kcalloc(&devfreq->dev, - devfreq->profile->max_state, + devfreq->max_state, sizeof(*devfreq->stats.time_in_state), GFP_KERNEL); if (!devfreq->stats.time_in_state) { @@ -1665,9 +1664,9 @@ static ssize_t available_frequencies_show(struct device *d, mutex_lock(&df->lock); - for (i = 0; i < df->profile->max_state; i++) + for (i = 0; i < df->max_state; i++) count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), - "%lu ", df->profile->freq_table[i]); + "%lu ", df->freq_table[i]); mutex_unlock(&df->lock); /* Truncate the trailing space */ @@ -1690,7 +1689,7 @@ static ssize_t trans_stat_show(struct device *dev, if (!df->profile) return -EINVAL; - max_state = df->profile->max_state; + max_state = df->max_state; if (max_state == 0) return sprintf(buf, "Not Supported.\n"); @@ -1707,19 +1706,17 @@ static ssize_t trans_stat_show(struct device *dev, len += sprintf(buf + len, " :"); for (i = 0; i < max_state; i++) len += sprintf(buf + len, "%10lu", - df->profile->freq_table[i]); + df->freq_table[i]); len += sprintf(buf + len, " time(ms)\n"); for (i = 0; i < max_state; i++) { - if (df->profile->freq_table[i] - == df->previous_freq) { + if (df->freq_table[i] == df->previous_freq) len += sprintf(buf + len, "*"); - } else { + else len += sprintf(buf + len, " "); - } - len += sprintf(buf + len, "%10lu:", - df->profile->freq_table[i]); + + len += sprintf(buf + len, "%10lu:", df->freq_table[i]); for (j = 0; j < max_state; j++) len += sprintf(buf + len, "%10u", df->stats.trans_table[(i * max_state) + j]); @@ -1743,7 +1740,7 @@ static ssize_t trans_stat_store(struct device *dev, if (!df->profile) return -EINVAL; - if (df->profile->max_state == 0) + if (df->max_state == 0) return count; err = kstrtoint(buf, 10, &value); @@ -1751,11 +1748,11 @@ static ssize_t trans_stat_store(struct device *dev, return -EINVAL; mutex_lock(&df->lock); - memset(df->stats.time_in_state, 0, (df->profile->max_state * + memset(df->stats.time_in_state, 0, (df->max_state * sizeof(*df->stats.time_in_state))); memset(df->stats.trans_table, 0, array3_size(sizeof(unsigned int), - df->profile->max_state, - df->profile->max_state)); + df->max_state, + df->max_state)); df->stats.total_trans = 0; df->stats.last_update = get_jiffies_64(); mutex_unlock(&df->lock); diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index dcc9dd518197..1810966fd61d 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -145,18 +145,18 @@ static int get_target_freq_with_devfreq(struct devfreq *devfreq, goto out; /* Use interpolation if required opps is not available */ - for (i = 0; i < parent_devfreq->profile->max_state; i++) - if (parent_devfreq->profile->freq_table[i] == *freq) + for (i = 0; i < parent_devfreq->max_state; i++) + if (parent_devfreq->freq_table[i] == *freq) break; - if (i == parent_devfreq->profile->max_state) + if (i == parent_devfreq->max_state) return -EINVAL; - if (i < devfreq->profile->max_state) { - child_freq = devfreq->profile->freq_table[i]; + if (i < devfreq->max_state) { + child_freq = devfreq->freq_table[i]; } else { - count = devfreq->profile->max_state; - child_freq = devfreq->profile->freq_table[count - 1]; + count = devfreq->max_state; + child_freq = devfreq->freq_table[count - 1]; } out: diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index dc10bee75a72..770a7532655c 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -185,6 +185,10 @@ struct devfreq { struct notifier_block nb; struct delayed_work work; + /* devfreq local freq_table */ + unsigned long *freq_table; + unsigned int max_state; + unsigned long previous_freq; struct devfreq_dev_status last_status; From patchwork Tue Jun 14 23:09:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12881714 X-Patchwork-Delegate: cw00.choi@samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4CD7C43334 for ; Wed, 15 Jun 2022 00:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235492AbiFOAEL (ORCPT ); Tue, 14 Jun 2022 20:04:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234912AbiFOAEF (ORCPT ); Tue, 14 Jun 2022 20:04:05 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B20AB289A9; Tue, 14 Jun 2022 17:04:00 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x17so13199110wrg.6; Tue, 14 Jun 2022 17:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c2/QDJKQUYJdg67+qXw7NrZ4cn1DkdhNkxlezX0Iqcg=; b=f9VtERyCX3duWDopI90LJQYHVvSnJljwRZL6y/m2d6HzkM+7yuQIrmgQAuvVvXClCZ ZOs4McY4Jo15yzZN7T2b2TuxT9tHcepi/YAvt8LGbHLYMv+6cwB8OMON1yPtzDfFLCB2 4WALceBcPodYt5QkyOUu16WU2hSaOZ+48qQMFppAOFwFbSRKRNfU8gLP9Ouq2gCX1DtF 2ALbFUAhdmfqkpmlWyvigeUsWa2dfati4eQ/KMw849pm5N1F881OKrAvESBb2QsFicuZ 26yVTgOdYcJv/i+BFQJPYz0+13PyBVLUB4GH7chYjrATZrAvuvgqzDm0k7APR4P1Lg+l 4nVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c2/QDJKQUYJdg67+qXw7NrZ4cn1DkdhNkxlezX0Iqcg=; b=x3umG8N7F26J07QmoKMo90ZncVd22aCAZgir3LRafYimLYUrexMMUSEvbyeWxl6sYF n2jSWiwjRg+UaA8hfWae9Dcv98hlegNnzD/IWKKuVCEGiF8yhcPcd9y25P85h3AAbjxw yOKg/GkeUOjI0/ynscUe5KXqbHotArenV+Insjo0ylOZ/veWvyUH2cPj6L5bmyv235Pm aehqhXp7LoDME1bKepciHFvyDzuBpEjz3pNCAi88x2gzSqijlzDF3vbLGDqIk167kQ0t 69gFacyIqtg1kr3/882LK2mawlR3TksYBiiBMfNeEgj4mloUdEtOLYaa3QmJ9/uNynJ8 voVA== X-Gm-Message-State: AJIora+8ypAFVYpDp431lxUyD/115ZqnawZjq0slefAWSMVF0iK35ZrI ry64v/Bxe/O6LUVDRc8OkEM= X-Google-Smtp-Source: AGRyM1tpYj1qhLCK+1qDQJI/vr8WVmMz2VhWVGj/7ePdBMHIu9jmtZlxhsBhCTcyRFK31WealWrz4w== X-Received: by 2002:a05:6000:11:b0:210:302d:e787 with SMTP id h17-20020a056000001100b00210302de787mr7084509wrx.535.1655251439110; Tue, 14 Jun 2022 17:03:59 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id l7-20020a05600c4f0700b00397342e3830sm5546821wmq.0.2022.06.14.17.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 17:03:58 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v4 4/4] PM / devfreq: Mute warning on governor PROBE_DEFER Date: Wed, 15 Jun 2022 01:09:50 +0200 Message-Id: <20220614230950.426-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614230950.426-1-ansuelsmth@gmail.com> References: <20220614230950.426-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Don't print warning when a governor PROBE_DEFER as it's not a real GOV_START fail. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/devfreq.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 2e2b3b414d67..6a39638ed064 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -931,8 +931,9 @@ struct devfreq *devfreq_add_device(struct device *dev, err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START, NULL); if (err) { - dev_err(dev, "%s: Unable to start governor for the device\n", - __func__); + dev_err_probe(dev, err, + "%s: Unable to start governor for the device\n", + __func__); goto err_init; } create_sysfs_files(devfreq, devfreq->governor);