From: Nathan Fontenot <nfont@linux.vnet.ibm.com>
To: Michael Bringmann <mwb@linux.vnet.ibm.com>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH V2 5/8] pseries/drc-info: Search new DRC properties for CPU indexes
Date: Mon, 1 Aug 2016 10:23:43 -0500 [thread overview]
Message-ID: <b55b0efe-3c92-8870-bec1-a3a459737e1a@linux.vnet.ibm.com> (raw)
In-Reply-To: <1259a754-1269-228a-8d63-47ead60df1f4@linux.vnet.ibm.com>
On 07/27/2016 09:23 AM, Michael Bringmann wrote:
> 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".
>
> Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
> ---
> 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);
Could this be done with just using the drc-start-index directly? Such
as fdi = be32_to_cpu(*(u32 *)pc)? Just curious if the memcpy could be avoided.
> + 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;
Why initialize info to this?
> + 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);
I think some variable names other than the very short ones used would make
this code a lot easier to understand, otherwise it is not very clear exactly
what is being calculated here.
-Nathan
> + } 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);
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>
next prev parent reply other threads:[~2016-08-01 15:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-27 14:23 [PATCH V2 5/8] pseries/drc-info: Search new DRC properties for CPU indexes Michael Bringmann
2016-08-01 15:23 ` Nathan Fontenot [this message]
2016-08-01 20:17 ` Michael Bringmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b55b0efe-3c92-8870-bec1-a3a459737e1a@linux.vnet.ibm.com \
--to=nfont@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mwb@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).