[Skiboot] [PATCH] hw/occ: Only allocate what we need for pstate dt

Vaidyanathan Srinivasan svaidy at linux.vnet.ibm.com
Mon Feb 15 16:43:58 AEDT 2016


* Joel Stanley <joel at jms.id.au> [2016-02-11 15:38:25]:

> When constructing the pstate entries in the device tree we allocate
> MAX_PSTATES, even though we know that there are nr_pstates.
> 
> Use this information to allocate nr_pstates and potentially save us some
> heap.
> 
> Signed-off-by: Joel Stanley <joel at jms.id.au>
Acked-by: Vaidyanathan Srinivasan <svaidy at linux.vnet.ibm.com>
> ---
>  hw/occ.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/occ.c b/hw/occ.c
> index 0e3d95366b20..ac51cd4e2ed1 100644
> --- a/hw/occ.c
> +++ b/hw/occ.c
> @@ -191,25 +191,25 @@ static bool add_cpu_pstate_properties(s8 *pstate_nom)
>  
>  	/* Setup arrays for device-tree */
>  	/* Allocate memory */
> -	dt_id = (u32 *) malloc(MAX_PSTATES * sizeof(u32));
> +	dt_id = malloc(nr_pstates * sizeof(u32));
>  	if (!dt_id) {
>  		printf("OCC: dt_id array alloc failure\n");
>  		goto out;
>  	}
>  
> -	dt_freq = (u32 *) malloc(MAX_PSTATES * sizeof(u32));
> +	dt_freq = malloc(nr_pstates * sizeof(u32));
>  	if (!dt_freq) {
>  		printf("OCC: dt_freq array alloc failure\n");
>  		goto out_free_id;
>  	}
>  
> -	dt_vdd = (u8 *) malloc(MAX_PSTATES * sizeof(u8));
> +	dt_vdd = malloc(nr_pstates * sizeof(u8));
>  	if (!dt_vdd) {
>  		printf("OCC: dt_vdd array alloc failure\n");
>  		goto out_free_freq;
>  	}
>  
> -	dt_vcs = (u8 *) malloc(MAX_PSTATES * sizeof(u8));
> +	dt_vcs = malloc(nr_pstates * sizeof(u8));
>  	if (!dt_vcs) {
>  		printf("OCC: dt_vcs array alloc failure\n");
>  		goto out_free_vdd;

Thanks Joel.  This is a useful optimization with no corner cases.  We
do compute nr_pstates before allocating memory and hence no need to
allocate for MAX_PSTATES entries and then free them.

--Vaidy



More information about the Skiboot mailing list