Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2960137imm; Thu, 24 May 2018 19:57:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqVrnpbKxaO4E5RWcXpgDQBzReq9p4op9tZTPW2HPmrdjJwH8TDbAHXDIxA0sJXJURMwnW5 X-Received: by 2002:a17:902:740a:: with SMTP id g10-v6mr685619pll.246.1527217049779; Thu, 24 May 2018 19:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527217049; cv=none; d=google.com; s=arc-20160816; b=V8+daD+yZCeTup+NKZbtm5rspMCAjdpD3jucItX/0HvLVtRfQuT2JbY+2Whr2Pi1Eq QvnwG+xYmDz6P8kCVT4vQCZ3FaoCp5jVDoEhT76rVasFa1ZFQS+GE3chjfGglxNswdMe /op/ld4bsEClGtqXtzaV+ziIri79JubIq9MpYTj8tD4s0STQkVUN648ih825vg0Y2FsL vWEa9qM3XHLbuJ7ByUl+z5DaLMkNrLqP+n+6bKsW9s40Yf/hd9Sw0no1pGMjeKDQC20h ET176CbLDSpOtXCmMwv/Kx1tNZXNcQ6JveOY8om46IEi76rqfPSdFGGUGqQJbxv6/zGk GfIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:arc-authentication-results; bh=PxsLRgK7IkOkWcIKM1fOiYQ99RPKMQYUMvYxbddt8RQ=; b=bLEas/vp7bDdOrMf3UICfQ0a7zlaV7EOhXVUILyuuQxFggBVgQcDfb4y64rOHpxc54 5jUKmtZQzKHFx/+uM0frCwtAZn/qKTc9UszZMIzQaVBcTKI1T8jedEuCzJpWH5l+voe5 T+NaY7A5ybJcvOYgeoxUpQl5MhgJvcJlmB3IFqk47b1YamB8ppYiEezwz1hAeB9xcIe7 c562y+FKqDh7FZa95i9dM7Ti7Z0hip9h3BaZYy0FyzBiLQokA7omk5WRH/WK9g9iLitH 1ICemG/iBtKPlAJ0pSIJjjZLfNFdsN0rIg9ccFl5nclC/uNlBy6zmberr2UYZyjOLKIM /WUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si6951339pgn.73.2018.05.24.19.57.14; Thu, 24 May 2018 19:57:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751782AbeEYCyW (ORCPT + 99 others); Thu, 24 May 2018 22:54:22 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:46677 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750824AbeEYCyR (ORCPT ); Thu, 24 May 2018 22:54:17 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9702D5B4D2BB; Fri, 25 May 2018 10:54:14 +0800 (CST) Received: from [127.0.0.1] (10.121.90.40) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.382.0; Fri, 25 May 2018 10:54:06 +0800 Subject: Re: [PATCH] cpufreq: reinitialize new policy min/max when writing scaling_(max|min)_freq To: "Rafael J. Wysocki" CC: "Rafael J. Wysocki" , Viresh Kumar , Linux PM , "Linux Kernel Mailing List" , , References: <1527144234-96396-1-git-send-email-kevin.wangtao@hisilicon.com> From: "Wangtao (Kevin, Kirin)" Message-ID: <7700fad7-211d-d8b2-e4ee-975c1cf1f9dc@hisilicon.com> Date: Fri, 25 May 2018 10:54:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.121.90.40] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2018/5/24 15:45, Rafael J. Wysocki 写道: > On Thu, May 24, 2018 at 8:43 AM, Kevin Wangtao > wrote: >> consider such situation, current user_policy.min is 1000000, >> current user_policy.max is 1200000, in cpufreq_set_policy, >> other driver may update policy.min to 1200000, policy.max to >> 1300000. After that, If we input "echo 1300000 > scaling_min_freq", >> then user_policy.min will be 1300000, and user_policy.max is >> still 1200000, because the input value is checked with policy.max >> not user_policy.max. if we get all related cpus offline and >> online again, it will cause cpufreq_init_policy fail because >> user_policy.min is higher than user_policy.max. > > How do you reproduce this, exactly? I write a driver register CPUFREQ_POLICY_NOTIFIER, and when event is CPUFREQ_ADJUST, it will modify policy's min/max according to some conditions, I test it with writing scaling_(max|min)_freq to traverse all frequencies repeatly, and also repeat hotplug as background. > >> The solution is when user space tries to write scaling_(max|min)_freq, >> the min/max of new_policy should be reinitialized with min/max >> of user_policy, like what cpufreq_update_policy does. >> >> Signed-off-by: Kevin Wangtao >> --- >> drivers/cpufreq/cpufreq.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> index b79c532..8b33e08 100644 >> --- a/drivers/cpufreq/cpufreq.c >> +++ b/drivers/cpufreq/cpufreq.c >> @@ -697,6 +697,8 @@ static ssize_t store_##file_name \ >> struct cpufreq_policy new_policy; \ >> \ >> memcpy(&new_policy, policy, sizeof(*policy)); \ >> + new_policy->min = policy->user_policy.min; \ new_policy.min = policy->user_policy.min; >> + new_policy->max = policy->user_policy.max; \ new_policy.max = policy->user_policy.max > > It looks like you haven't even tried to build this, have you? sorry for that, I test it on another branch and write this patch manually without build > >> \ >> ret = sscanf(buf, "%u", &new_policy.object); \ >> if (ret != 1) \ >> -- >> 2.8.1 >> > > . >