Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752234AbdLKFY7 (ORCPT ); Mon, 11 Dec 2017 00:24:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:55290 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751871AbdLKFYy (ORCPT ); Mon, 11 Dec 2017 00:24:54 -0500 Date: Mon, 11 Dec 2017 10:54:45 +0530 From: Gautham R Shenoy To: Balbir Singh Cc: "Gautham R. Shenoy" , Shilpasri G Bhat , Viresh Kumar , "Rafael J. Wysocki" , huntbag@linux.vnet.ibm.com, Akshay Adiga , Michael Ellerman , Vaidyanathan Srinivasan , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , "linux-kernel@vger.kernel.org" , stable@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [v2 PATCH] cpufreq: powernv: Correctly parse the sign of pstates on POWER8 vs POWER9 Reply-To: ego@linux.vnet.ibm.com References: <1512626365-22845-1-git-send-email-ego@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-TM-AS-GCONF: 00 x-cbid: 17121105-0008-0000-0000-0000090302DE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008188; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00958501; UDB=6.00484662; IPR=6.00738522; BA=6.00005733; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018471; XFM=3.00000015; UTC=2017-12-11 05:24:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121105-0009-0000-0000-0000451BB7E3 Message-Id: <20171211052445.GA21437@in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-11_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712110081 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3170 Lines: 73 Hi Balbir, On Fri, Dec 08, 2017 at 02:44:40PM +1100, Balbir Singh wrote: > On Thu, Dec 7, 2017 at 4:59 PM, Gautham R. Shenoy > wrote: > > From: "Gautham R. Shenoy" > > > > On POWERNV platform, Pstates are 8-bit values. On POWER8 they are > > negatively numbered while on POWER9 they are positively > > numbered. Thus, on POWER9, the maximum number of pstates could be as > > high as 256. > > > > The current code interprets pstates as a signed 8-bit value. This > > causes a problem on POWER9 platforms which have more than 128 pstates. > > On such systems, on a CPU that is in a lower pstate whose number is > > greater than 128, querying the current pstate returns a "pstate X is > > out of bound" error message and the current pstate is reported as the > > nominal pstate. > > > > This patch fixes the aforementioned issue by correctly differentiating > > the sign whenever a pstate value read, depending on whether the > > pstates are positively numbered or negatively numbered. > > Yikes! Is there no better way of fixing this? There is. In fact, I am working on cleaning up the whole thing to make it not depend on the sign until it is really needed (and that is to check whether the pstate that we read from the PMSR is within bounds) Besides, currently the kernel code assumes a few things that the device-tree doesn't guarantee, such as the continguity of pstates. > > > > > Fixes: commit 09ca4c9b5958 ("cpufreq: powernv: Replacing pstate_id with frequency table index") > > Cc: #v4.8 > > Signed-off-by: Gautham R. Shenoy > > Tested-and-reviewed-by: Shilpasri G Bhat > > Acked-by: Viresh Kumar > > --- > > drivers/cpufreq/powernv-cpufreq.c | 43 ++++++++++++++++++++++++++++++--------- > > 1 file changed, 33 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c > > index b6d7c4c..bb7586e 100644 > > --- a/drivers/cpufreq/powernv-cpufreq.c > > +++ b/drivers/cpufreq/powernv-cpufreq.c > > @@ -41,11 +41,14 @@ > > #define POWERNV_MAX_PSTATES 256 > > #define PMSR_PSAFE_ENABLE (1UL << 30) > > #define PMSR_SPR_EM_DISABLE (1UL << 31) > > -#define PMSR_MAX(x) ((x >> 32) & 0xFF) > > +#define EXTRACT_BYTE(x, shift) (((x) >> shift) & 0xFF) > > +#define MAX_SHIFT 32 > > #define LPSTATE_SHIFT 48 > > #define GPSTATE_SHIFT 56 > > -#define GET_LPSTATE(x) (((x) >> LPSTATE_SHIFT) & 0xFF) > > -#define GET_GPSTATE(x) (((x) >> GPSTATE_SHIFT) & 0xFF) > > +#define GET_PMSR_MAX(x) EXTRACT_BYTE(x, MAX_SHIFT) > > +#define GET_LPSTATE(x) EXTRACT_BYTE(x, LPSTATE_SHIFT) > > +#define GET_GPSTATE(x) EXTRACT_BYTE(x, GPSTATE_SHIFT) > > + > > Can you hide all of this in pstate_to_idx(), do the casting inside? I > was reviewing this > code earlier before being distracted with something else, this did > come across as > strange and I was looking at using abs values to simplify the code, > but I did not get > to it. > > Balbir Singh. >