From patchwork Wed Sep 21 14:17:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Bringmann X-Patchwork-Id: 672907 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfMNQ3Rt9z9sQw for ; Thu, 22 Sep 2016 00:25:26 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sfMNQ2hlkzDsyG for ; Thu, 22 Sep 2016 00:25:26 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sfMCf0MkCzDshY for ; Thu, 22 Sep 2016 00:17:49 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8LEHmNu058852 for ; Wed, 21 Sep 2016 10:17:48 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 25kta9cys6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 21 Sep 2016 10:17:41 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Sep 2016 08:17:41 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 21 Sep 2016 08:17:38 -0600 Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 8D9F11FF004F for ; Wed, 21 Sep 2016 08:17:18 -0600 (MDT) Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8LEHdsS15859974; Wed, 21 Sep 2016 14:17:42 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA34528041; Wed, 21 Sep 2016 10:17:36 -0400 (EDT) Received: from oc1376853207.ibm.com (unknown [9.53.92.233]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 9486F28077; Wed, 21 Sep 2016 10:17:36 -0400 (EDT) To: linuxppc-dev@lists.ozlabs.org, Nathan Fontenot , Michael Bringmann From: Michael Bringmann Subject: [PATCH V6 5/8] pseries/drc-info: Search new DRC properties for CPU indexes Organization: IBM Linux Technology Center Date: Wed, 21 Sep 2016 09:17:36 -0500 User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16092114-0024-0000-0000-0000149F0011 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005797; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000185; SDB=6.00759874; UDB=6.00361328; IPR=6.00534285; BA=6.00004744; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012737; XFM=3.00000011; UTC=2016-09-21 14:17:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16092114-0025-0000-0000-000044AD3E83 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-09-21_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609210262 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" pseries/drc-info: Provide parallel routines to convert between drc_index and CPU numbers at runtime, using the older device-tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types" and "ibm,drc-power-domains"), or the new property "ibm,drc-info". [V2: Revise contant names.] [V3: No change.] [V4: No change.] [V5: Resynchronize/resubmit] [V6: No change] Signed-off-by: Michael Bringmann diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c index 9276779..10c4200 100644 --- a/arch/powerpc/platforms/pseries/pseries_energy.c +++ b/arch/powerpc/platforms/pseries/pseries_energy.c @@ -35,10 +35,68 @@ static int sysfs_entries; /* Helper Routines to convert between drc_index to cpu numbers */ +void read_one_drc_info(int **info, char **dtype, char **dname, + unsigned long int *fdi_p, unsigned long int *nsl_p, + unsigned long int *si_p, unsigned long int *ldi_p) +{ + char *drc_type, *drc_name, *pc; + u32 fdi, nsl, si, ldi; + + fdi = nsl = si = ldi = 0; + + /* Get drc-type:encode-string */ + pc = (char *)info; + drc_type = pc; + pc += (strlen(drc_type) + 1); + + /* Get drc-name-prefix:encode-string */ + drc_name = (char *)pc; + pc += (strlen(drc_name) + 1); + + /* Get drc-index-start:encode-int */ + memcpy(&fdi, pc, 4); + fdi = be32_to_cpu(fdi); + pc += 4; + + /* Get/skip drc-name-suffix-start:encode-int */ + pc += 4; + + /* Get number-sequential-elements:encode-int */ + memcpy(&nsl, pc, 4); + nsl = be32_to_cpu(nsl); + pc += 4; + + /* Get sequential-increment:encode-int */ + memcpy(&si, pc, 4); + si = be32_to_cpu(si); + pc += 4; + + /* Get/skip drc-power-domain:encode-int */ + pc += 4; + + /* Should now know end of current entry */ + ldi = fdi + ((nsl-1)*si); + + (*info) = (int *)pc; + + if (dtype) + *dtype = drc_type; + if (dname) + *dname = drc_name; + if (fdi_p) + *fdi_p = fdi; + if (nsl_p) + *nsl_p = nsl; + if (si_p) + *si_p = si; + if (ldi_p) + *ldi_p = ldi; +} +EXPORT_SYMBOL(read_one_drc_info); + static u32 cpu_to_drc_index(int cpu) { struct device_node *dn = NULL; - const int *indexes; int i; int rc = 1; u32 ret = 0; @@ -46,18 +104,54 @@ static u32 cpu_to_drc_index(int cpu) dn = of_find_node_by_path("/cpus"); if (dn == NULL) goto err; - indexes = of_get_property(dn, "ibm,drc-indexes", NULL); - if (indexes == NULL) - goto err_of_node_put; + /* Convert logical cpu number to core number */ i = cpu_core_index_of_thread(cpu); - /* - * The first element indexes[0] is the number of drc_indexes - * returned in the list. Hence i+1 will get the drc_index - * corresponding to core number i. - */ - WARN_ON(i > indexes[0]); - ret = indexes[i + 1]; + + if (firmware_has_feature(FW_FEATURE_DRC_INFO)) { + int *info = (int *)4; + unsigned long int num_set_entries, j, iw = i, fdi = 0; + unsigned long int ldi = 0, nsl = 0, si = 0; + char *dtype; + char *dname; + + info = (int *)of_get_property(dn, "ibm,drc-info", NULL); + if (info == NULL) + goto err_of_node_put; + + num_set_entries = be32_to_cpu(*info++); + + for (j = 0; j < num_set_entries; j++) { + + read_one_drc_info(&info, &dtype, &dname, &fdi, + &nsl, &si, &ldi); + if (strcmp(dtype, "CPU")) + goto err; + + if (iw < ldi) + break; + + WARN_ON(((iw-fdi)%si) != 0); + } + WARN_ON((nsl == 0) | (si == 0)); + + ret = ldi + (iw*si); + } else { + const int *indexes; + + indexes = of_get_property(dn, "ibm,drc-indexes", NULL); + if (indexes == NULL) + goto err_of_node_put; + + /* + * The first element indexes[0] is the number of drc_indexes + * returned in the list. Hence i+1 will get the drc_index + * corresponding to core number i. + */ + WARN_ON(i > indexes[0]); + ret = indexes[i + 1]; + } + rc = 0; err_of_node_put: @@ -78,21 +172,51 @@ static int drc_index_to_cpu(u32 drc_index) dn = of_find_node_by_path("/cpus"); if (dn == NULL) goto err; - indexes = of_get_property(dn, "ibm,drc-indexes", NULL); - if (indexes == NULL) - goto err_of_node_put; - /* - * First element in the array is the number of drc_indexes - * returned. Search through the list to find the matching - * drc_index and get the core number - */ - for (i = 0; i < indexes[0]; i++) { - if (indexes[i + 1] == drc_index) + + if (firmware_has_feature(FW_FEATURE_DRC_INFO)) { + int *info = (int *)dn; + unsigned long int num_set_entries, j, ret; + unsigned long int fdi = 0, ldi = 0, nsl = 0, si = 0; + char *dtype, *dname; + + info = (int *)of_get_property(dn, "ibm,drc-info", NULL); + if (info == NULL) + goto err_of_node_put; + + num_set_entries = be32_to_cpu(*info++); + + for (j = 0; j < num_set_entries; j++) { + read_one_drc_info(&info, &dtype, &dname, &fdi, + &nsl, &si, &ldi); + if (strcmp(dtype, "CPU")) + goto err; + + WARN_ON(drc_index < fdi); + if (drc_index > ldi) + continue; + + WARN_ON(((drc_index-fdi)%si) != 0); + + ret = ((drc_index-fdi)/si); break; + } + } else { + indexes = of_get_property(dn, "ibm,drc-indexes", NULL); + if (indexes == NULL) + goto err_of_node_put; + /* + * First element in the array is the number of drc_indexes + * returned. Search through the list to find the matching + * drc_index and get the core number + */ + for (i = 0; i < indexes[0]; i++) { + if (indexes[i + 1] == drc_index) + break; + } + /* Convert core number to logical cpu number */ + cpu = cpu_first_thread_of_core(i); + rc = 0; } - /* Convert core number to logical cpu number */ - cpu = cpu_first_thread_of_core(i); - rc = 0; err_of_node_put: of_node_put(dn);