[coreboot] printing TSC in printk

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sun Feb 10 00:49:58 CET 2008


On 09.02.2008 21:50, ron minnich wrote:
> Here's a simple proposal.
>
> Define an option
> PRINTK_TSC
>
> What it does: each time printk would print a newline, it will instead
> print this:
> (16 hex digits of TSC)\n
>
> Here's another simpler option:
>
> Define a new format letter, T, such that %T as a format means "time".
>
> first option allows comprehensive timing, but it will slow things down
> a bit. Second option allows us to completely tailor the printing of
> time, but you have to explicitly add %T when you want time printed.
>   

Try this:
Regards,
Carl-Daniel

Preliminary patch for the second option, does not compile yet, but you
get the idea.
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