[ltt-dev] [UST PATCH] Add getcpu error validation

Mathieu Desnoyers compudj at krystal.dyndns.org
Wed Feb 9 14:11:11 EST 2011


I did commit 8f09cb9340387a52b483752c5d2d6c36035b26bc which replaces
this patch. It's a cleanup on the style. Please look at the style of my
version to see coding style tricks to make code cleaner in with #ifdef:
usually, ifdefs wrap whole functions only.

Thanks,

Mathieu

* David Goulet (david.goulet at polymtl.ca) wrote:
> This check is important for the case where getcpu(2) is not
> implemented by the Kernel. So, the CPU 0 is the fallback.
> 
> Signed-off-by: David Goulet <david.goulet at polymtl.ca>
> ---
>  libust/tracer.h |   10 ++++++++--
>  1 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libust/tracer.h b/libust/tracer.h
> index 64996b2..dd524af 100644
> --- a/libust/tracer.h
> +++ b/libust/tracer.h
> @@ -345,8 +345,14 @@ static __inline__ void ltt_write_trace_header(struct ust_trace *trace,
>  
>  static __inline__ int ust_get_cpu(void)
>  {
> +	int cpu = 0;
>  #ifndef UST_VALGRIND
> -	return sched_getcpu();
> +	if ((cpu = sched_getcpu()) < 0) {
> +		/* If getcpu(2) is not implemented in the Kernel
> +		 * use CPU 0 as fallback.
> +		 */
> +		cpu = 0;
> +	}
>  #else
>  	/* Valgrind does not support the sched_getcpu() vsyscall.
>  	 * It causes it to detect a segfault in the program and stop it.
> @@ -354,7 +360,7 @@ static __inline__ int ust_get_cpu(void)
>  	 * from using this call. TODO: it would probably be better to return
>  	 * other values too, to better test it.
>  	 */
> -	return 0;
> +	return cpu;
>  #endif
>  }
>  
> -- 
> 1.7.4
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list