ACK: [PATCH] lib: fwts_cpu: force compiler to increment i rather than optimize it out

Alex Hung alex.hung at canonical.com
Wed Jan 25 07:20:38 UTC 2017


On 2017-01-24 08:22 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Currently the increment of i is being optimized out, so force it to be
> volatile (to force stores) and return it too to force the compiler not
> to optimize the cycle wasting increment out.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_cpu.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index b4f256e..148857e 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -512,15 +512,16 @@ uint64_t fwts_cpu_benchmark_best_result(fwts_cpu_benchmark_result *res)
>   *  fwts_cpu_consume_cycles()
>   *	eat up CPU cycles
>   */
> -static void fwts_cpu_consume_cycles(void)
> +static uint64_t fwts_cpu_consume_cycles(void)
>  {
>  	fwts_sig_handler_set(SIGUSR1, fwts_cpu_consume_sighandler, NULL);
> -	uint64_t i = 0;
> +	volatile uint64_t i = 0;
>
>  	for (;;) {
>  		fwts_cpu_burn_cycles();
>  		i++;
>  	}
> +	return i;
>  }
>
>  /*
> @@ -554,7 +555,7 @@ int fwts_cpu_consume_start(void)
>  		pid = fork();
>  		switch (pid) {
>  		case 0: /* Child */
> -			fwts_cpu_consume_cycles();
> +			(void)fwts_cpu_consume_cycles();
>  			break;
>  		case -1:
>  			/* Went wrong */
>

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list