From patchwork Thu Oct 27 14:25:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Bringmann X-Patchwork-Id: 687689 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t4TyD21Wlz9sXx for ; Fri, 28 Oct 2016 01:37:56 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3t4TyD1Bd8zDvbH for ; Fri, 28 Oct 2016 01:37:56 +1100 (AEDT) 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 3t4Tnw3qdmzDvKh for ; Fri, 28 Oct 2016 01:30:44 +1100 (AEDT) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u9RESerI085281 for ; Thu, 27 Oct 2016 10:30:42 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 26bk0vhy09-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 27 Oct 2016 10:30:42 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 27 Oct 2016 08:30:41 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 27 Oct 2016 08:30:38 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 3C1C219D8065 for ; Thu, 27 Oct 2016 08:30:02 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u9REU0OX10551592 for ; Thu, 27 Oct 2016 07:30:37 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57EA0BE047 for ; Thu, 27 Oct 2016 08:30:37 -0600 (MDT) Received: from powerkvm6.aus.stglabs.ibm.com (unknown [9.40.192.78]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 420E8BE038 for ; Thu, 27 Oct 2016 08:30:37 -0600 (MDT) Received: from powerkvm6.aus.stglabs.ibm.com (localhost [IPv6:::1]) by powerkvm6.aus.stglabs.ibm.com (Postfix) with ESMTP id 94229C203E35 for ; Thu, 27 Oct 2016 09:25:20 -0500 (CDT) Subject: [PATCH V8 5/8] pseries/drc-info: Search new DRC properties for CPU indexes From: Michael Bringmann To: linuxppc-dev@lists.ozlabs.org Date: Thu, 27 Oct 2016 09:25:20 -0500 In-Reply-To: <147757821176.2995.6400281020620333555.stgit@powerkvm6.aus.stglabs.ibm.com> References: <147757821176.2995.6400281020620333555.stgit@powerkvm6.aus.stglabs.ibm.com> User-Agent: StGit/0.17.1-19-gef93c MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102714-0020-0000-0000-00000A1DBF69 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005988; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000188; SDB=6.00773499; UDB=6.00371415; IPR=6.00550331; BA=6.00004836; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013115; XFM=3.00000011; UTC=2016-10-27 14:30:39 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102714-0021-0000-0000-000056C9EAA5 Message-Id: <147757831242.2995.15901624227458436059.stgit@powerkvm6.aus.stglabs.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-27_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610270240 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] [V7: Correct mail threading] [v8: Insert more useful variable names] Signed-off-by: Michael Bringmann --- arch/powerpc/platforms/pseries/pseries_energy.c | 189 ++++++++++++++++++++--- 1 file changed, 165 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c index 164a13d..05fb5e8 100644 --- a/arch/powerpc/platforms/pseries/pseries_energy.c +++ b/arch/powerpc/platforms/pseries/pseries_energy.c @@ -35,10 +35,73 @@ 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 *drc_index_start_p, + unsigned long int *num_sequential_elems_p, + unsigned long int *sequential_inc_p, + unsigned long int *last_drc_index_p) +{ + char *drc_type, *drc_name_prefix, *pc; + u32 drc_index_start, num_sequential_elems; + u32 sequential_inc, last_drc_index; + + drc_index_start = num_sequential_elems = 0; + sequential_inc = last_drc_index = 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_prefix = (char *)pc; + pc += (strlen(drc_name_prefix) + 1); + + /* Get drc-index-start:encode-int */ + memcpy(&drc_index_start, pc, 4); + drc_index_start = be32_to_cpu(drc_index_start); + pc += 4; + + /* Get/skip drc-name-suffix-start:encode-int */ + pc += 4; + + /* Get number-sequential-elements:encode-int */ + memcpy(&num_sequential_elems, pc, 4); + num_sequential_elems = be32_to_cpu(num_sequential_elems); + pc += 4; + + /* Get sequential-increment:encode-int */ + memcpy(&sequential_inc, pc, 4); + sequential_inc = be32_to_cpu(sequential_inc); + pc += 4; + + /* Get/skip drc-power-domain:encode-int */ + pc += 4; + + /* Should now know end of current entry */ + last_drc_index = drc_index_start + + ((num_sequential_elems-1)*sequential_inc); + + (*info) = (int *)pc; + + if (dtype) + *dtype = drc_type; + if (dname) + *dname = drc_name_prefix; + if (drc_index_start_p) + *drc_index_start_p = drc_index_start; + if (num_sequential_elems_p) + *num_sequential_elems_p = num_sequential_elems; + if (sequential_inc_p) + *sequential_inc_p = sequential_inc; + if (last_drc_index_p) + *last_drc_index_p = last_drc_index; +} +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 +109,60 @@ 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, check_val = i; + unsigned long int drc_index_start = 0; + unsigned long int last_drc_index = 0; + unsigned long int num_sequential_elems = 0; + unsigned long int sequential_inc = 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, + &drc_index_start, + &num_sequential_elems, + &sequential_inc, &last_drc_index); + if (strcmp(dtype, "CPU")) + goto err; + + if (check_val < last_drc_index) + break; + + WARN_ON(((check_val-drc_index_start)% + sequential_inc) != 0); + } + WARN_ON((num_sequential_elems == 0) | (sequential_inc == 0)); + + ret = last_drc_index + (check_val*sequential_inc); + } 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 +183,57 @@ 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 drc_index_start = 0; + unsigned long int last_drc_index = 0; + unsigned long int num_sequential_elems = 0; + unsigned long int sequential_inc = 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, + &drc_index_start, + &num_sequential_elems, + &sequential_inc, &last_drc_index); + if (strcmp(dtype, "CPU")) + goto err; + + WARN_ON(drc_index < drc_index_start); + if (drc_index > last_drc_index) + continue; + + WARN_ON(((drc_index-drc_index_start)% + sequential_inc) != 0); + + ret = ((drc_index-drc_index_start)/sequential_inc); 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);