Improvements to console timestamps
v3 cover Improvements to console timestamps
This series aims to improve on the current implementation of console timestamps in Xen.
Patch 1 is just movement of wallclock_time()s declaration to common code.
Patch 2 changes Xen's idea of when time starts, from when the BSPs TSC was 0, to when Xen boots.
Patch 3 guesses at AP time calibration earlier during boot, so printk()s using the new console timestamp have a real stamp, rather than 0s.
Patch 4 is the meat of the series, adding a new timestamp implementation to printk_start_of_line().
Patch 5 comes as a intermediate suggestion, to retain the old timestamp style, but to display milliseconds as well.
Finally, from discussion in the office, it has been suggested that the timestamp mode/format would be better as build-time configuration rather than boot-time configuration. I am on the fence with this regard, but comments/thoughts are very welcome.
~Andrew
PATCH v3 1/5 xen/time: Move wallclock_time() declaration into common code
It is called from common code, but has architecture specific implementations. Have one declaration instead of two.
No functional change.
--- xen/include/asm-arm/time.h | 3 --- xen/include/asm-x86/time.h | 3 --- xen/include/xen/time.h | 1 + 3 files changed, 1 insertion(+), 6 deletions(-)
xen/include/asm-arm/time.h +0 -3
@@ -12,9 +12,6 @@ static inline cycles_t get_cycles (void)return 0 ; } -struct tm ; -struct tm wallclock_time (void ); -/* List of timer's IRQ */ enum timer_ppi {
xen/include/asm-x86/time.h +0 -3
@@ -48,9 +48,6 @@ int dom0_pit_access(struct ioreq *ioreq);int cpu_frequency_change (u64 freq); -struct tm ; -struct tm wallclock_time (void ); -void pit_broadcast_enter (void );void pit_broadcast_exit (void );int pit_broadcast_is_available (void );
xen/include/xen/time.h +1 -0
@@ -48,6 +48,7 @@ struct tm {int tm_isdst;/* daylight saving time */ };struct tm gmtime (unsigned long t); +struct tm wallclock_time (void );#define SYSTEM_TIME_HZ 1000000000ULL#define NOW () ((s_time_t)get_s_time())
Signature · 1 line
1.7.10.4
PATCH v3 2/5 x86/time: Always count s_time from Xen boot
In reply to Andrew CooperFrom: Tim Deegan <[email protected]>
Timestamped printks() can call NOW() before init_xen_time(). Set a baseline TSC as soon as we've calibrated the TSC rate, so that NOW() consistently counts from boot time.
---
v2: use TSC from __start() rather than from early_time_init().
v3: remove later reset of TSC baseline from init_xen_time().
v4: shuffle boot_tsc_stamp definition and use of 'this_cpu()'.
--- xen/arch/x86/boot/head.S | 6 ++++++ xen/arch/x86/time.c | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/boot/head.S +6 -0
@@ -136,6 +136,12 @@ __start: /* Check for availability of long mode. */ bt $29,%edx jnc bad_cpu + + /* Stash TSC to calculate a good approximation of time-since-boot */ + rdtsc + mov %eax,sym_phys(boot_tsc_stamp) + mov %edx,sym_phys(boot_tsc_stamp+4) + /* Initialise L2 boot-map page table entries (16MB). */ mov $sym_phys(l2_bootmap),%edx mov $PAGE_HYPERVISOR|_PAGE_PSE,%eax
xen/arch/x86/time.c +6 -4
@@ -84,6 +84,9 @@ static u16 pit_stamp16;static u32 pit_stamp32;static bool_t __read_mostly using_pit; +/* Boot timestamp, filled in head.S */ +u64 __initdata boot_tsc_stamp; +/* * 32-bit division of integer dividend and integer divisor yielding * 32-bit fractional quotient.
@@ -1433,9 +1436,6 @@ int __init init_xen_time(void)open_softirq (TIME_CALIBRATE_SOFTIRQ , local_time_calibration); -/* System time (get_s_time()) starts ticking from now. */ -rdtscll (this_cpu (cpu_time).local_tsc_stamp); -/* NB. get_cmos_time() can take over one second to execute. */ do_settime (get_cmos_time (),0 ,NOW ());
@@ -1453,9 +1453,11 @@ int __init init_xen_time(void)/* Early init function. */ void __init early_time_init (void ) { +struct cpu_time *t = &this_cpu (cpu_time);u64 tmp =init_pit_and_calibrate_tsc (); -set_time_scale (&this_cpu (cpu_time).tsc_scale, tmp); +set_time_scale (&t->tsc_scale, tmp); + t->local_tsc_stamp = boot_tsc_stamp;do_div (tmp,1000 ); cpu_khz = (unsigned long )tmp;
Signature · 1 line
1.7.10.4
PATCH v3 3/5 x86/time: Initialise time earlier during start_secondary()
In reply to Andrew CooperIt is safe to do so, and useful for "[second.microseconds]" style timestamps on printk()s during secondary bringup.
--- xen/arch/x86/smpboot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/smpboot.c +2 -2
@@ -347,6 +347,8 @@ void start_secondary(void *unused)percpu_traps_init (); +init_percpu_time (); +cpu_init ();smp_callin ();
@@ -381,8 +383,6 @@ void start_secondary(void *unused)cpumask_set_cpu (cpu, &cpu_online_map);unlock_vector_lock (); -init_percpu_time (); -/* We can take interrupts now: we're officially "up". */ local_irq_enable ();mtrr_ap_init ();
Signature · 1 line
1.7.10.4
PATCH v3 4/5 xen/console: Provide timestamps as an offset since boot
In reply to Andrew CooperThis adds a new "Linux style" console timestamp method, which is shorter and more useful than the current date/time timestamps with single-second granularity.
--- docs/misc/xen-command-line.markdown | 15 +++++++-- xen/drivers/char/console.c | 58 +++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 12 deletions(-)
docs/misc/xen-command-line.markdown +12 -3
@@ -275,11 +275,20 @@ cleared. This allows a single port to be shared by two subsystems makes sense on its own. ### console\_timestamps -> `= <boolean>` +> `= none | date | boot` -> Default: `false` +> Default: `boot` + +Specify which timestamp format Xen should use for each console line. + +* `none`: No timestamps +* `date`: Date and time information + * `[YYYY-MM-DD HH:MM:SS]` +* `boot`: Seconds and microseconds since boot + * `[SSSSSS.uuuuuu]` -Flag to indicate whether include a timestamp with each console line. +For compatibility with the older boolean parameter, specifying +`console_timestamps` alone will enable the `date` option. ### console\_to\_ring > `= <boolean>`
xen/drivers/char/console.c +49 -9
80 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v3 4/5] xen/console: Provide timestamps as an offset since boot
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
docs/misc/xen-command-line.markdown +0
-0@@ -275,11 +275,20 @@ cleared. This allows a single port to be shared by twosubsystems
makes sense on its own.
Quoted 6 lines
### console\_timestamps
->= <boolean>
+>= none | date | boot-> Default:
false
+> Default:boot
I'd prefer the default to remain "no time stamps". They're useful occasionally but not generally, and they consume serial console bandwidth.
docs/misc/xen-command-line.markdown
Quoted 11 lines
docs/misc/xen-command-line.markdown +11
-0+static void __init parse_console_timestamps(char *s) +{ + if ( *s == '\0' || /* Compat for old booleanparam() */ + !strcmp(s, "date") ) + opt_con_timestamp_mode = TSM_DATE; + else if ( !strcmp(s, "boot") ) + opt_con_timestamp_mode = TSM_BOOT; + else if ( !strcmp(s, "none") ) + opt_con_timestamp_mode = TSM_NONE; + else + printk(XENLOG_ERR "Unrecognised timestamp mode '%s'\n", s);
Printing from command line parsing routines is IIRC rather pointless (i.e. ISTR it goes no-where), and in the majority of other cases I think we don't warn about improper arguments of options. With the command line being logged as a whole, there's also not much point since the incorrect value can be easily determined by looking there.
Jan
Re: [PATCH v3 4/5] xen/console: Provide timestamps as an offset since boot
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
docs/misc/xen-command-line.markdown +0
-0@@ -275,11 +275,20 @@ cleared. This allows a single port to be shared by twosubsystems
makes sense on its own.### console\_timestamps
->= <boolean>
+>= none | date | boot
Quoted 5 lines
Quoted 2 lines
-> Default:
false
+> Default:bootI'd prefer the default to remain "no time stamps". They're useful occasionally but not generally, and they consume serial console bandwidth.
I would disgree with usefulness, but can see your point - I shall revert the default back to none.
Quoted 19 lines
docs/misc/xen-command-line.markdown
Quoted 12 lines
docs/misc/xen-command-line.markdown +11
-0+static void __init parse_console_timestamps(char *s) +{ + if ( *s == '\0' || /* Compat for old booleanparam() */ + !strcmp(s, "date") ) + opt_con_timestamp_mode = TSM_DATE; + else if ( !strcmp(s, "boot") ) + opt_con_timestamp_mode = TSM_BOOT; + else if ( !strcmp(s, "none") ) + opt_con_timestamp_mode = TSM_NONE; + else + printk(XENLOG_ERR "Unrecognised timestamp mode '%s'\n", s);Printing from command line parsing routines is IIRC rather pointless (i.e. ISTR it goes no-where), and in the majority of other cases I think we don't warn about improper arguments of options. With the command line being logged as a whole, there's also not much point since the incorrect value can be easily determined by looking there.
Quoted 2 lines
Jan
It appears at the top of xl dmesg, but not on the serial console. I shall drop it.
~Andrew
PATCH v3 5/5 xen/console: Traditional console timestamps including milliseconds
In reply to Andrew Cooper---
The change in arm is only for the sake of compilation - the function is a no-op.
--- docs/misc/xen-command-line.markdown | 4 +++- xen/arch/arm/time.c | 2 +- xen/arch/x86/time.c | 10 +++++++--- xen/drivers/char/console.c | 11 ++++++++++- xen/include/xen/time.h | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-)
docs/misc/xen-command-line.markdown +3 -1
@@ -275,7 +275,7 @@ cleared. This allows a single port to be shared by two subsystems makes sense on its own. ### console\_timestamps -> `= none | date | boot` +> `= none | date | datems | boot` > Default: `boot`
@@ -284,6 +284,8 @@ Specify which timestamp format Xen should use for each console line. * `none`: No timestamps * `date`: Date and time information * `[YYYY-MM-DD HH:MM:SS]` +* `datems`: Date and time, with milliseconds + * `[YYYY-MM-DD HH:MM:SS.mmm]` * `boot`: Seconds and microseconds since boot * `[SSSSSS.uuuuuu]`
xen/arch/arm/time.c +1 -1
@@ -282,7 +282,7 @@ void domain_set_time_offset(struct domain *d, int32_t time_offset_seconds)/* XXX update guest visible wallclock time */ } -struct tm wallclock_time (void ) +struct tm wallclock_time (uint64_t *ns) {return (struct tm ) {0 }; }
xen/arch/x86/time.c +7 -3
@@ -1646,15 +1646,19 @@ int dom0_pit_access(struct ioreq *ioreq)return 0 ; } -struct tm wallclock_time (void ) +struct tm wallclock_time (uint64_t *ns) { -uint64_t seconds; +uint64_t seconds, nsec;if ( !wc_sec )return (struct tm ) {0 }; seconds =NOW () +SECONDS (wc_sec) + wc_nsec; -do_div (seconds,1000000000 ); + nsec =do_div (seconds,1000000000 ); + +if ( *ns ) + *ns = nsec; +return gmtime (seconds); }
xen/drivers/char/console.c +10 -1
@@ -53,6 +53,7 @@ enum con_timestamp_mode {TSM_NONE ,/* No timestamps */ TSM_DATE ,/* [YYYY-MM-DD HH:MM:SS] */ +TSM_DATE_MS ,/* [YYYY-MM-DD HH:MM:SS.mmm] */ TSM_BOOT /* [SSSSSS.uuuuuu] */ };
@@ -560,6 +561,8 @@ static void __init parse_console_timestamps(char *s)if ( *s =='\0' ||/* Compat for old booleanparam() */ !strcmp (s,"date" ) ) opt_con_timestamp_mode =TSM_DATE ; +else if ( !strcmp (s,"datems" ) ) + opt_con_timestamp_mode =TSM_DATE_MS ;else if ( !strcmp (s,"boot" ) ) opt_con_timestamp_mode =TSM_BOOT ;else if ( !strcmp (s,"none" ) )
@@ -579,7 +582,8 @@ static void printk_start_of_line(const char *prefix)switch ( opt_con_timestamp_mode ) {case TSM_DATE : - tm =wallclock_time (); +case TSM_DATE_MS : + tm =wallclock_time (&nsec);if ( tm.tm_mday ==0 )return ;
@@ -588,6 +592,11 @@ static void printk_start_of_line(const char *prefix)snprintf (tstr,sizeof (tstr),"[%04u-%02u-%02u %02u:%02u:%02u] " ,1900 + tm.tm_year, tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + else + snprintf(tstr, sizeof(tstr), +"[%04u-%02u-%02u %02u:%02u:%02u.%03" PRIu64"] " , +1900 + tm.tm_year, tm.tm_mon +1 , tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, nsec / 1000000);break ;case TSM_BOOT :
xen/include/xen/time.h +1 -1
@@ -48,7 +48,7 @@ struct tm {int tm_isdst;/* daylight saving time */ };struct tm gmtime (unsigned long t); -struct tm wallclock_time (void ); +struct tm wallclock_time (uint64_t *ns);#define SYSTEM_TIME_HZ 1000000000ULL#define NOW () ((s_time_t)get_s_time())
Signature · 1 line
1.7.10.4
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 47 lines · Andrew Cooper
Suggested-by Don Slutz <[email protected]>Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Ian Campbell <[email protected]>CC Stefano Stabellini <[email protected]>CC Tim Deegan <[email protected]>---
The change in arm is only for the sake of compilation - the function is a no-op.
--- docs/misc/xen-command-line.markdown | 4 +++- xen/arch/arm/time.c | 2 +- xen/arch/x86/time.c | 10 +++++++--- xen/drivers/char/console.c | 11 ++++++++++- xen/include/xen/time.h | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-)docs/misc/xen-command-line.markdown +3
-1@@ -275,7 +275,7 @@ cleared. This allows a single port to be shared by two subsystems makes sense on its own. ### console\_timestamps -> `= none | date | boot` +> `= none | date | datems | boot` > Default: `boot`@@ -284,6 +284,8 @@ Specify which timestamp format Xen should use for each console line. * `none`: No timestamps * `date`: Date and time information * `[YYYY-MM-DD HH:MM:SS]` +* `datems`: Date and time, with milliseconds + * `[YYYY-MM-DD HH:MM:SS.mmm]` * `boot`: Seconds and microseconds since boot * `[SSSSSS.uuuuuu]`xen/arch/arm/time.c +0
-0
xen/arch/arm/time.c void domain_set_time_offset(struct domain *d, int32_t time_offset_seconds) · line 286
Quoted 6 lines
xen/arch/arm/time.c +1
-1@@ -282,7 +282,7 @@ void domain_set_time_offset(struct domain *d, int32_t time_offset_seconds)/* XXX update guest visible wallclock time */ } -struct tm wallclock_time (void ) +struct tm wallclock_time (uint64_t *ns) {
Adding:
if ( ns )
*ns = 0;Makes sense here.
Quoted 7 lines
xen/arch/arm/time.c +0
-0return (struct tm ) {0 }; }xen/arch/x86/time.c +0
-0
xen/arch/x86/time.c int dom0_pit_access(struct ioreq *ioreq) · line 1653
Quoted 10 lines
xen/arch/x86/time.c +2
-2@@ -1646,15 +1646,19 @@ int dom0_pit_access(struct ioreq *ioreq)return 0 ; } -struct tm wallclock_time (void ) +struct tm wallclock_time (uint64_t *ns) { -uint64_t seconds; +uint64_t seconds, nsec;if ( !wc_sec )
And here.
xen/arch/x86/time.c int dom0_pit_access(struct ioreq *ioreq) · line 1659
Quoted 7 lines
xen/arch/x86/time.c +3
-1return (struct tm ) {0 }; seconds =NOW () +SECONDS (wc_sec) + wc_nsec; -do_div (seconds,1000000000 ); + nsec =do_div (seconds,1000000000 ); + +if ( *ns )
This should be just
if ( ns )
-Don Slutz
Quoted 61 lines
xen/arch/x86/time.c +2
-0+ *ns = nsec; +return gmtime (seconds); }xen/drivers/char/console.c +10
-1@@ -53,6 +53,7 @@ enum con_timestamp_mode {TSM_NONE ,/* No timestamps */ TSM_DATE ,/* [YYYY-MM-DD HH:MM:SS] */ +TSM_DATE_MS ,/* [YYYY-MM-DD HH:MM:SS.mmm] */ TSM_BOOT /* [SSSSSS.uuuuuu] */ };@@ -560,6 +561,8 @@ static void __init parse_console_timestamps(char *s)if ( *s =='\0' ||/* Compat for old booleanparam() */ !strcmp (s,"date" ) ) opt_con_timestamp_mode =TSM_DATE ; +else if ( !strcmp (s,"datems" ) ) + opt_con_timestamp_mode =TSM_DATE_MS ;else if ( !strcmp (s,"boot" ) ) opt_con_timestamp_mode =TSM_BOOT ;else if ( !strcmp (s,"none" ) )@@ -579,7 +582,8 @@ static void printk_start_of_line(const char *prefix)switch ( opt_con_timestamp_mode ) {case TSM_DATE : - tm =wallclock_time (); +case TSM_DATE_MS : + tm =wallclock_time (&nsec);if ( tm.tm_mday ==0 )return ;@@ -588,6 +592,11 @@ static void printk_start_of_line(const char *prefix)snprintf (tstr,sizeof (tstr),"[%04u-%02u-%02u %02u:%02u:%02u] " ,1900 + tm.tm_year, tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + else + snprintf(tstr, sizeof(tstr), +"[%04u-%02u-%02u %02u:%02u:%02u.%03" PRIu64"] " , +1900 + tm.tm_year, tm.tm_mon +1 , tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, nsec / 1000000);break ;case TSM_BOOT :xen/include/xen/time.h +1
-1@@ -48,7 +48,7 @@ struct tm {int tm_isdst;/* daylight saving time */ };struct tm gmtime (unsigned long t); -struct tm wallclock_time (void ); +struct tm wallclock_time (uint64_t *ns);#define SYSTEM_TIME_HZ 1000000000ULL#define NOW () ((s_time_t)get_s_time())
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 39 lines · Don Slutz
Quoted 5 lines · Andrew Cooper
}
-struct tmwallclock_time(void)
+struct tmwallclock_time(uint64_t *ns)
{Adding:
if ( ns ) *ns = 0;Makes sense here.
Quoted 7 lines
return (struct tm) { 0 };}
xen/arch/x86/time.c +0
-0xen/arch/x86/time.c int dom0_pit_access(struct ioreq *ioreq) · line 1652
Quoted 8 lines
xen/arch/x86/time.c +2
-1@@ -1646,15 +1646,19 @@ int dom0_pit_access(struct ioreq *ioreq)return 0 ; } -struct tm wallclock_time(void) +struct tmwallclock_time (uint64_t *ns) { -uint64_t seconds; +uint64_t seconds, nsec;if ( !wc_sec )And here.
xen/arch/x86/time.c int dom0_pit_access(struct ioreq *ioreq) · line 1659
Quoted 6 lines
xen/arch/x86/time.c +3
-1return (struct tm ) {0 }; seconds =NOW () +SECONDS (wc_sec) + wc_nsec; -do_div (seconds,1000000000 ); + nsec =do_div (seconds,1000000000 ); + +if ( *ns )
Quoted 3 lines
This should be just
if ( ns )
Oops - so it should.
As for the other changes, I am a bit ambivalent. printk_start_of_line() is the sole caller of wallclock_time(), which means that tm.tm_day being 0 means *ns will never get looked at.
While it is not exactly a hot codepath, unconditionally clearing it seems silly, especially as it is not exactly the most likely candidate to get a new caller in the near future.
~Andrew
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 36 lines · Andrew Cooper
Quoted 35 lines · Don Slutz
Quoted 4 lines · Andrew Cooper
}
-struct tmwallclock_time(void)
+struct tmwallclock_time(uint64_t *ns)
{Adding:
if ( ns )
*ns = 0;Makes sense here.
Quoted 7 lines
return (struct tm) { 0 };}
xen/arch/x86/time.c +0
-0xen/arch/x86/time.c int dom0_pit_access(struct ioreq *ioreq) · line 1652
Quoted 8 lines
xen/arch/x86/time.c +2
-1@@ -1646,15 +1646,19 @@ int dom0_pit_access(struct ioreq *ioreq)return 0 ; } -struct tm wallclock_time(void) +struct tmwallclock_time (uint64_t *ns) { -uint64_t seconds; +uint64_t seconds, nsec;if ( !wc_sec )And here.
Quoted 6 lines
xen/arch/x86/time.c +3
-1return (struct tm ) {0 }; seconds =NOW () +SECONDS (wc_sec) + wc_nsec; -do_div (seconds,1000000000 ); + nsec =do_div (seconds,1000000000 ); + +if ( *ns )
Quoted 8 lines
Quoted 3 lines
This should be just
if ( ns )
Oops - so it should.
As for the other changes, I am a bit ambivalent.
printk_start_of_line()is the sole caller ofwallclock_time(), which means that tm.tm_day being 0 means *ns will never get looked at.
This is not 100% true. Last I knew (struct tm) { 0 } is
struct tm {
int tm_sec; /* seconds */ = 0
int tm_min; /* minutes */ <undef>
int tm_hour; /* hours */ <undef>
int tm_mday; /* day of the month */ <undef>
int tm_mon; /* month */ <undef>
int tm_year; /* year */ <undef>
int tm_wday; /* day of the week */ <undef>
int tm_yday; /* day in the year */ <undef>
int tm_isdst; /* daylight saving time */ <undef>};
But not having looked at the code, and the compilers could have changed what this means (i.e. if not provided they are zero in which case this should be {}. { 0, 0, 0, 0 } or { .tm_mday = 0 } is the way I know of to say "tm_mday" is zero).
So the test for tm.tm_mday == 0 may just be working because the undefined value is zero...
Quoted 3 lines
While it is not exactly a hot codepath, unconditionally clearing it seems silly, especially as it is not exactly the most likely candidate to get a new caller in the near future.
There is no clear right answer here. So I have no issue with not doing the "extra" work.
-Don Slutz
Quoted 2 lines
~Andrew
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 12 lines · Don Slutz
Last I knew (struct tm) { 0 } is
struct tm {
int tm_sec; /* seconds */ = 0 int tm_min; /* minutes */ <undef> int tm_hour; /* hours */ <undef> int tm_mday; /* day of the month */ <undef> int tm_mon; /* month */ <undef> int tm_year; /* year */ <undef> int tm_wday; /* day of the week */ <undef> int tm_yday; /* day in the year */ <undef> int tm_isdst; /* daylight saving time */ <undef>
Quoted 2 lines
};
Actually I believe the affect of "struct foo = { 0 }" is to zero everything (possibly implicitly by causing it to be placed in .bss), but I don't have my copy of the spec to hand to quote chapter and verse on that.
Ian.
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 16 lines · Ian Campbell
Quoted 12 lines · Don Slutz
Last I knew (struct tm) { 0 } is
struct tm {
int tm_sec; /* seconds */ = 0 int tm_min; /* minutes */ <undef> int tm_hour; /* hours */ <undef> int tm_mday; /* day of the month */ <undef> int tm_mon; /* month */ <undef> int tm_year; /* year */ <undef> int tm_wday; /* day of the week */ <undef> int tm_yday; /* day in the year */ <undef> int tm_isdst; /* daylight saving time */ <undef>Quoted 2 lines
};
Quoted 7 lines
Actually I believe the affect of "struct foo = { 0 }" is to zero everything (possibly implicitly by causing it to be placed in .bss), but I don't have my copy of the spec to hand to quote chapter and verse on that.
Ian.
This is a stack entry, so no .bss involved. Sadly, all the time functions pass struct tms around by value rather than pointer, and there is probably easy room for optimisation there.
As for { 0 }, it is indeed special, but even with a copy of the C spec to hand, I cant see where it is exactly specified. The disassembly of wallclock_time() does indeed confirm that the entire structure is zeroed.
~Andrew
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
Quoted 25 lines · Andrew Cooper
Quoted 16 lines · Ian Campbell
Quoted 12 lines · Don Slutz
Last I knew (struct tm) { 0 } is
struct tm {
int tm_sec; /* seconds */ = 0 int tm_min; /* minutes */ <undef> int tm_hour; /* hours */ <undef> int tm_mday; /* day of the month */ <undef> int tm_mon; /* month */ <undef> int tm_year; /* year */ <undef> int tm_wday; /* day of the week */ <undef> int tm_yday; /* day in the year */ <undef> int tm_isdst; /* daylight saving time */ <undef>Quoted 2 lines
};
Quoted 7 lines
Actually I believe the affect of "struct foo = { 0 }" is to zero everything (possibly implicitly by causing it to be placed in .bss), but I don't have my copy of the spec to hand to quote chapter and verse on that.
Ian.
Quoted 7 lines
This is a stack entry, so no .bss involved. Sadly, all the time functions pass
struct tms around by value rather than pointer, and there is probably easy room for optimisation there.As for { 0 }, it is indeed special, but even with a copy of the C spec to hand, I cant see where it is exactly specified. The disassembly of
wallclock_time()does indeed confirm that the entire structure is zeroed.
Yes, all unspecified fields in a struct initialiser are set to 0.
Tim.
Re: [PATCH v3 5/5] xen/console: Traditional console timestamps including milliseconds
In reply to Andrew CooperQuoted 4 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
As for { 0 }, it is indeed special, but even with a copy of the C spec to hand, I cant see where it is exactly specified. The disassembly of
wallclock_time()does indeed confirm that the entire structure is zeroed.
In "Initialization", one of the subclauses says "If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration."
Jan