[coreboot] printing TSC in printk

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sun Feb 17 00:51:59 CET 2008


Any reviews/opinions?

Regards,
Carl-Daniel

On 10.02.2008 00:49, Carl-Daniel Hailfinger wrote:
> On 09.02.2008 21:50, ron minnich wrote:
>   
>> Define a new format letter, T, such that %T as a format means "time".
>>
>> [...] allows us to completely tailor the printing of
>> time, but you have to explicitly add %T when you want time printed.  
>>     
>
> Preliminary patch[...] does not compile yet, but you get the idea.
>   

Needs an additional declaration in some header to fix compilation, code 
itself should be sound.

> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
>
> Index: LinuxBIOSv3-printktimestamp/include/console.h
> ===================================================================
> --- LinuxBIOSv3-printktimestamp/include/console.h	(Revision 582)
> +++ LinuxBIOSv3-printktimestamp/include/console.h	(Arbeitskopie)
> @@ -37,6 +37,7 @@
>  unsigned char console_rx_byte(void);
>  int console_tst_byte(void);
>  void die(const char *msg);
> +u32 get_timestamp(void);
>  
>  struct console_driver {
>  	void (*init)(void);
> Index: LinuxBIOSv3-printktimestamp/lib/vtxprintf.c
> ===================================================================
> --- LinuxBIOSv3-printktimestamp/lib/vtxprintf.c	(Revision 582)
> +++ LinuxBIOSv3-printktimestamp/lib/vtxprintf.c	(Arbeitskopie)
> @@ -12,6 +12,7 @@
>  #include <stdarg.h>
>  #include <string.h>
>  #include <div64.h>
> +#include <console.h>
>  
>  #define isdigit(c)	((c) >= '0' && (c) <= '9')
>  #define is_digit isdigit
> @@ -118,6 +119,7 @@
>  	int qualifier;		/* 'h', 'l', or 'L' for integer fields */
>  	
>  	int count;
> +	u32 tstamp;
>  
>  	for (count=0; *fmt ; ++fmt) {
>  		if (*fmt != '%') {
> @@ -218,6 +220,16 @@
>  				field_width, precision, flags);
>  			continue;
>  
> +		/* Timestamp in 32bit hex */
> +		case 'T':
> +			if (field_width == -1) {
> +				field_width = 2 * sizeof(unsigned long);
> +				flags |= ZEROPAD;
> +			}
> +			tstamp = get_timestamp();
> +			count += number(tx_byte, arg, tstamp, 16,
> +				field_width, precision, flags);
> +			continue;
>  
>  		case 'n':
>  			if (qualifier == 'L') {
> Index: LinuxBIOSv3-printktimestamp/arch/x86/geodelx/cpu.c
> ===================================================================
> --- LinuxBIOSv3-printktimestamp/arch/x86/geodelx/cpu.c	(Revision 582)
> +++ LinuxBIOSv3-printktimestamp/arch/x86/geodelx/cpu.c	(Arbeitskopie)
> @@ -37,6 +37,25 @@
>  /* TODO: Better comment on vsm_end_post_smi, and define 0x05a2 down below. */
>  
>  /**
> + * Retrieve a 32-bit time stamp. The generic get_timestamp() offers no guarantee
> + * whatsoever about monotony, granularity, absence of wraparounds or linear
> + * relationship between the time stamp and real time.
> + * This implementation has wraparounds after 2^32 cycles of the TSC register
> + * and will usually have a linear dependency on real time.
> + * Qemu and Geode LX support the rdtsc instruction.
> + * If v3 ever is used on x86 architectures which don't support rdtsc, we have
> + * to provide an alternative.
> + *
> + * @return 32-bit truncated number of TSC cycles since poweron.
> + */
> +u32 get_timestamp(void)
> +{
> +	u32 tstamp;
> +	__asm__ __volatile__ ("rdtsc" : "=a" (tstamp) : : "edx");
> +	return tstamp;
> +}
> +
> +/**
>   * This is a call to the VSM.
>   *
>   * TODO: We need to know what it does.
>
>
>   


-- 
http://www.hailfinger.org/





More information about the coreboot mailing list