diff mbox

hw/occ: Only allocate what we need for pstate dt

Message ID 1455167305-6322-1-git-send-email-joel@jms.id.au
State Accepted
Headers show

Commit Message

Joel Stanley Feb. 11, 2016, 5:08 a.m. UTC
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@jms.id.au>
---
 hw/occ.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Vaidyanathan Srinivasan Feb. 15, 2016, 5:43 a.m. UTC | #1
* Joel Stanley <joel@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@jms.id.au>
Acked-by: Vaidyanathan Srinivasan <svaidy@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
Stewart Smith Feb. 23, 2016, 6:50 a.m. UTC | #2
Joel Stanley <joel@jms.id.au> writes:
> 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@jms.id.au>

Thanks, merged to master as of 1aa5187
diff mbox

Patch

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;