introduce time managment in xtf
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 30 lines · Paul Semel
this file is introduce to be able to implement an inter domain communication protocol over xenstore. For synchronization purpose, we do really want to be able to "control" time
common/time.c:since_boot_timegets the time in nanoseconds from the moment the VM has bootedSigned-off-by Paul Semel <[email protected]>---
Notes:
v4:
- moved rdtsc toarch/x86/include/arch/lib.h
- added ardtsc_orderedimplementation to serialize rdtsc
- simplifiedsince_boot_timefunction
- still need to have Andrew'sscale_deltaversionarch/x86/include/arch/lib.h | 18 ++++++++++ build/files.mk | 1 + common/time.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 24 ++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 common/time.c create mode 100644 include/xtf/time.harch/x86/include/arch/lib.h +0
-0
arch/x86/include/arch/lib.h line 9
Quoted 4 lines
arch/x86/include/arch/lib.h +1
-0@@ -6,6 +6,7 @@#include <xen/arch-x86/xen.h> #include <arch/desc.h> #include <arch/msr.h> +#include <arch/barrier.h>
This include list is sorted alphabetically.
Quoted 13 lines
arch/x86/include/arch/lib.h +6
-0static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,@@ -374,6 +375,23 @@ static inline void write_xcr0(uint64_t xcr0)xsetbv (0 , xcr0); } +static inline uint64_t rdtsc (void ) +{ +uint32_t lo, hi; + + asmvolatile ("rdtsc" :"=a" (lo),"=d" (hi)); +
arch/x86/include/arch/lib.h static inline void write_xcr0(uint64_t xcr0) · line 393
Quoted 10 lines
arch/x86/include/arch/lib.h +10
-0+return ((uint64_t )hi <<32 ) | lo; +} + +static inline uint64_t rdtsc_ordered (void ) +{ +rmb (); +mb (); + +return rdtsc (); +}
I would likely just add a single function like:
static inline uint64_t rdtsc_ordered(void)
{
uint32_t lo, hi;
asm volatile("lfence; mfence; rdtsc" : "=a" (lo), "=d" (hi));
return ((uint64_t)hi << 32) | lo;
}Because there's no external caller of rdtsc, but I will leave that to Andrew to decide. In any case this should work fine.
Quoted 22 lines
arch/x86/include/arch/lib.h +1
-0+#endif /* XTF_X86_LIB_H */ /* build/files.mk +1
-0@@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o obj-perarch += $(ROOT)/common/report.o obj-perarch += $(ROOT)/common/setup.o obj-perarch += $(ROOT)/common/xenbus.o +obj-perarch += $(ROOT)/common/time.o obj-perenv += $(ROOT)/arch/x86/decode.o obj-perenv += $(ROOT)/arch/x86/desc.ocommon/time.c new file +0
-0
common/time.c line 3
Quoted 3 lines
common/time.c new file +3
-0@@ -0,0 +1,81 @@ +#include <xtf/types.h> +#include <xtf/traps.h> +#include <xtf/time.h>
Alphabetic order please.
common/time.c line 8
Quoted 5 lines
common/time.c new file +5
-0+#include <arch/barrier.h> +#include <arch/lib.h> + +/* This function was taken from mini-os source code */ +/* It returns ((delta << shift) * mul_frac) >> 32 */
Comment has wrong style, please check CODING_STYLE.
Quoted 13 lines
common/time.c new file +13
-0+static inline uint64_t scale_delta (uint64_t delta,uint32_t mul_frac,int shift) +{ +uint64_t product; +#ifdef __i386__ +uint32_t tmp1, tmp2; +#endif + +if ( shift <0 ) + delta >>= -shift; +else + delta <<= shift; + +#ifdef __i386__
common/time.c line 31
Quoted 10 lines
common/time.c new file +10
-0+ __asm__ ( +"mul %5 ; " +"mov %4,%%eax ; " +"mov %%edx,%4 ; " +"mul %5 ; " +"add %4,%%eax ; " +"xor %5,%5 ; " +"adc %5,%%edx ; " + :"=A" (product),"=r" (tmp1),"=r" (tmp2) + :"a" ((uint32_t )delta),"1" ((uint32_t )(delta >>32 )),"2" (mul_frac) );
This line is too long.
common/time.c line 35
Quoted 4 lines
common/time.c new file +4
-0+#else + __asm__ ( +"mul %%rdx ; shrd $32,%%rdx,%%rax" + :"=a" (product) :"0" (delta),"d" ((uint64_t )mul_frac) );
Not sure whether you need to add a ': "d"' clobber here, since the d register is used but it's not in the list of output operands.
Quoted 14 lines
common/time.c new file +14
-0+#endif + +return product; +} + + +uint64_t since_boot_time (void ) +{ +uint32_t ver1, ver2; +uint64_t tsc_timestamp, system_time, tsc; +uint32_t tsc_to_system_mul; +int8_t tsc_shift; + + do
common/time.c line 59
Quoted 10 lines
common/time.c new file +10
-0+ { + ver1 =ACCESS_ONCE (shared_info.vcpu_info[0 ].time.version); +smp_rmb (); + + system_time = shared_info.vcpu_info[0 ].time.system_time; + tsc_timestamp = shared_info.vcpu_info[0 ].time.tsc_timestamp; + tsc_to_system_mul = shared_info.vcpu_info[0 ].time.tsc_to_system_mul; + tsc_shift = shared_info.vcpu_info[0 ].time.tsc_shift; + tsc =rdtsc_ordered (); +smp_rmb ();
I don't think you need the barrier here if you use rdtsc_ordered, but I would like confirmation from someone else.
Quoted 29 lines
common/time.c new file +21
-0+ + ver2 =ACCESS_ONCE (shared_info.vcpu_info[0 ].time.version); + }while ( ver2 &1 || ver1 != ver2 ); + + + system_time +=scale_delta (tsc - tsc_timestamp, + tsc_to_system_mul, + tsc_shift); + +return system_time; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ include/xtf/time.h new file +2
-0@@ -0,0 +1,24 @@ +/** +* @file include/xtf/time.h
include/xtf/time.h line 12
Quoted 10 lines
include/xtf/time.h new file +10
-0+* +* Time management +*/ +#ifndef XTF_TIME_H +# define XTF_TIME_H + +#include <xtf/types.h> + +/* Time from boot in nanoseconds */ +uint64_t since_boot_time (void );
since_boot_time looks like a weird name, I would probably name this hypervisor_uptime or system_time, but I'm not specially thrilled anyway.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 72 lines · Roger Pau Monné
Quoted 30 lines
this file is introduce to be able to implement an inter domain communication protocol over xenstore. For synchronization purpose, we do really want to be able to "control" time
common/time.c:since_boot_timegets the time in nanoseconds from the moment the VM has bootedSigned-off-by Paul Semel <[email protected]>---
Notes:
v4:
- moved rdtsc toarch/x86/include/arch/lib.h
- added ardtsc_orderedimplementation to serialize rdtsc
- simplifiedsince_boot_timefunction
- still need to have Andrew'sscale_deltaversionarch/x86/include/arch/lib.h | 18 ++++++++++ build/files.mk | 1 + common/time.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 24 ++++++++++++++ 4 files changed, 124 insertions(+)create mode 100644
common/time.c
create mode 100644include/xtf/time.harch/x86/include/arch/lib.h +0
-0arch/x86/include/arch/lib.h line 9
Quoted 4 lines
arch/x86/include/arch/lib.h +1
-0@@ -6,6 +6,7 @@#include <xen/arch-x86/xen.h> #include <arch/desc.h> #include <arch/msr.h> +#include <arch/barrier.h> This include list is sorted alphabetically.
Quoted 13 lines
arch/x86/include/arch/lib.h +6
-0static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx,@@ -374,6 +375,23 @@ static inline void write_xcr0(uint64_t xcr0)xsetbv (0 , xcr0); } +static inline uint64_t rdtsc (void ) +{ +uint32_t lo, hi; + + asmvolatile ("rdtsc" :"=a" (lo),"=d" (hi)); +arch/x86/include/arch/lib.h static inline void write_xcr0(uint64_t xcr0) · line 393
Quoted 10 lines
arch/x86/include/arch/lib.h +10
-0+return ((uint64_t )hi <<32 ) | lo; +} + +static inline uint64_t rdtsc_ordered (void ) +{ +rmb (); +mb (); + +return rdtsc (); +}I would likely just add a single function like:
static inline
uint64_trdtsc_ordered(void){ uint32_t lo, hi; asm volatile("lfence; mfence; rdtsc" : "=a" (lo), "=d" (hi)); return ((uint64_t)hi << 32) | lo; }
Quoted 3 lines
Because there's no external caller of rdtsc, but I will leave that to Andrew to decide. In any case this should work fine.
I think you're right for this one. What do you think about it @Andrew ?
Quoted 67 lines
Quoted 22 lines
arch/x86/include/arch/lib.h +1
-0+#endif /* XTF_X86_LIB_H */ /* build/files.mk +1
-0@@ -16,6 +16,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o obj-perarch += $(ROOT)/common/report.o obj-perarch += $(ROOT)/common/setup.o obj-perarch += $(ROOT)/common/xenbus.o +obj-perarch += $(ROOT)/common/time.o obj-perenv += $(ROOT)/arch/x86/decode.o obj-perenv += $(ROOT)/arch/x86/desc.ocommon/time.c new file +0
-0common/time.c line 3
Quoted 3 lines
common/time.c new file +3
-0@@ -0,0 +1,81 @@ +#include <xtf/types.h> +#include <xtf/traps.h> +#include <xtf/time.h> Alphabetic order please.
common/time.c line 8
Quoted 5 lines
common/time.c new file +5
-0+#include <arch/barrier.h> +#include <arch/lib.h> + +/* This function was taken from mini-os source code */ +/* It returns ((delta << shift) * mul_frac) >> 32 */ Comment has wrong style, please check
CODING_STYLE.Quoted 13 lines
common/time.c new file +13
-0+static inline uint64_t scale_delta (uint64_t delta,uint32_t mul_frac,int shift) +{ +uint64_t product; +#ifdef __i386__ +uint32_t tmp1, tmp2; +#endif + +if ( shift <0 ) + delta >>= -shift; +else + delta <<= shift; + +#ifdef __i386__common/time.c line 31
Quoted 10 lines
common/time.c new file +10
-0+ __asm__ ( +"mul %5 ; " +"mov %4,%%eax ; " +"mov %%edx,%4 ; " +"mul %5 ; " +"add %4,%%eax ; " +"xor %5,%5 ; " +"adc %5,%%edx ; " + :"=A" (product),"=r" (tmp1),"=r" (tmp2) + :"a" ((uint32_t )delta),"1" ((uint32_t )(delta >>32 )),"2" (mul_frac) );This line is too long.
common/time.c line 35
Quoted 4 lines
common/time.c new file +4
-0+#else + __asm__ ( +"mul %%rdx ; shrd $32,%%rdx,%%rax" + :"=a" (product) :"0" (delta),"d" ((uint64_t )mul_frac) );
Quoted 8 lines
Not sure whether you need to add a ': "d"' clobber here, since the d register is used but it's not in the list of output operands.
common/time.c line 40
Quoted 5 lines
common/time.c new file +5
-0+#endif + +return product; +} +
Actually, I'm not sure that I have to make that much changes to this function, as @Andrew wanted to use another version of it as far as I recall.
Quoted 58 lines
Quoted 9 lines
common/time.c new file +9
-0+ +uint64_t since_boot_time (void ) +{ +uint32_t ver1, ver2; +uint64_t tsc_timestamp, system_time, tsc; +uint32_t tsc_to_system_mul; +int8_t tsc_shift; + + docommon/time.c line 59
Quoted 10 lines
common/time.c new file +10
-0+ { + ver1 =ACCESS_ONCE (shared_info.vcpu_info[0 ].time.version); +smp_rmb (); + + system_time = shared_info.vcpu_info[0 ].time.system_time; + tsc_timestamp = shared_info.vcpu_info[0 ].time.tsc_timestamp; + tsc_to_system_mul = shared_info.vcpu_info[0 ].time.tsc_to_system_mul; + tsc_shift = shared_info.vcpu_info[0 ].time.tsc_shift; + tsc =rdtsc_ordered (); +smp_rmb ();I don't think you need the barrier here if you use
rdtsc_ordered, but I would like confirmation from someone else.Quoted 35 lines
common/time.c new file +21
-0+ + ver2 =ACCESS_ONCE (shared_info.vcpu_info[0 ].time.version); + }while ( ver2 &1 || ver1 != ver2 ); + + + system_time +=scale_delta (tsc - tsc_timestamp, + tsc_to_system_mul, + tsc_shift); + +return system_time; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ include/xtf/time.h new file +8
-0@@ -0,0 +1,24 @@ +/** +* @file include/xtf/time.h +* +* Time management +*/ +#ifndef XTF_TIME_H +# define XTF_TIME_H +
Quoted 8 lines
include/xtf/time.h line 12
Quoted 4 lines
include/xtf/time.h new file +4
-0+#include <xtf/types.h> + +/* Time from boot in nanoseconds */ +uint64_t since_boot_time (void );
since_boot_timelooks like a weird name, I would probably name thishypervisor_uptimeorsystem_time, but I'm not specially thrilled anyway.
Sure. since_boot_time was really awful..
Thanks,
Signature · 6 lines
Paul Semel _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 35 lines · Paul Semel
Quoted 34 lines · Roger Pau Monné
Quoted 13 lines
(quoted diff) +13
-0+static inline uint64_t scale_delta(uint64_t delta, uint32_t mul_frac, int shift) +{ + uint64_t product; +#ifdef __i386__ + uint32_t tmp1, tmp2; +#endif + + if ( shift < 0 ) + delta >>= -shift; + else + delta <<= shift; + +#ifdef __i386__Review
Quoted 10 lines
(quoted diff) +10
-0+ __asm__ ( + "mul %5 ; " + "mov %4,%%eax ; " + "mov %%edx,%4 ; " + "mul %5 ; " + "add %4,%%eax ; " + "xor %5,%5 ; " + "adc %5,%%edx ; " + : "=A" (product), "=r" (tmp1), "=r" (tmp2) + : "a" ((uint32_t)delta), "1" ((uint32_t)(delta >> 32)), "2" (mul_frac) );This line is too long.
Review
Quoted 4 lines
(quoted diff) +4
-0+#else + __asm__ ( + "mul %%rdx ; shrd $32,%%rdx,%%rax" + : "=a" (product) : "0" (delta), "d" ((uint64_t)mul_frac) );Not sure whether you need to add a ': "d"' clobber here, since the d register is used but it's not in the list of output operands.
Quoted 8 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+#endif + + return product; +} +Actually, I'm not sure that I have to make that much changes to this function, as @Andrew wanted to use another version of it as far as I recall.
IMO if there are known issues with this function they need to be sorted out before committing.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 2/7] add current_time function to time manager
Quoted 18 lines · Paul Semel
this function returns the "epoch" time
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 39 +++++++++++++++++++++++++++++++++++++++ include/xtf/time.h | 5 +++++ 2 files changed, 44 insertions(+)common/time.c +0
-0
common/time.c line 7
Quoted 4 lines
common/time.c +1
-0@@ -4,6 +4,7 @@#include <arch/barrier.h> #include <arch/lib.h> +#include <arch/div.h>
Sorting
Quoted 4 lines
common/time.c +0
-0/* This function was taken from mini-os source code */ /* It returns ((delta << shift) * mul_frac) >> 32 */
common/time.c uint64_t since_boot_time(void) · line 80
Quoted 10 lines
common/time.c +7
-0@@ -70,6 +71,44 @@ uint64_t since_boot_time(void)return system_time; } +static void get_time_info (uint64_t *boot_time,uint64_t *sec,uint32_t *nsec) +{ +uint32_t ver1, ver2; + do { + ver1 = ACCESS_ONCE(shared_info.wc_version); + smp_rmb(); + *boot_time = since_boot_time();
Why are you reading the uptime in the middle of the loop? You can read this out of the loop, or in a different function.
common/time.c uint64_t since_boot_time(void) · line 86
Quoted 6 lines
common/time.c +6
-0+#if defined(__i386__) + *sec = (uint64_t )ACCESS_ONCE (shared_info.wc_sec); +#else + *sec = ((uint64_t )ACCESS_ONCE (shared_info.wc_sec_hi) <<32 ) + |ACCESS_ONCE (shared_info.wc_sec); +#endif
I think this should be:
*sec = shared_info.wc_sec;
#ifdef __i386__
*sec |= shared_info.arch.wc_sec_hi << 32;
#else
*sec |= shared_info.wc_sec_hi << 32;
#endif
common/time.c uint64_t since_boot_time(void) · line 90
Quoted 4 lines
common/time.c +4
-0+ *nsec = (uint64_t )ACCESS_ONCE (shared_info.wc_nsec); +smp_rmb (); + ver2 =ACCESS_ONCE (shared_info.wc_version); +smp_rmb ();
This AFAICT this has the same issues as the code used in patch 1 to access the vcpu_time_info data.
You only need the ACCESS_ONCE in order to read ver2, the rest can be dropped.
common/time.c uint64_t since_boot_time(void) · line 101
Quoted 11 lines
common/time.c +11
-0+ }while ( (ver1 &1 ) !=0 && ver1 != ver2 ); +} + +/* This function return the epoch time (number of seconds elapsed +* since Juanary 1, 1970) */ +uint64_t current_time (void ) +{ +uint32_t nsec; +uint64_t boot_time, sec; + +get_time_info (&boot_time, &sec, &nsec);
I think it would make more sense to:
1. Call since_boot_time hypervisor_uptime.
2. Call get_time_info hypervisor_wallclock.
In order to get the current time here you call both functions and then add the result, like you do below.
common/time.c uint64_t since_boot_time(void) · line 107
Quoted 6 lines
common/time.c +6
-0+ +#if defined(__i386__) +divmod64 (&boot_time,SEC_TO_NSEC (1 )); +#else + boot_time /=SEC_TO_NSEC (1 ); +#endif
Please use devmod64 unconditionally.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 3/7] add gettimeofday function to time managment
Quoted 18 lines · Paul Semel
this function acts as the POSIX gettimeofday function
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 30 ++++++++++++++++++++++++++++++ include/xtf/time.h | 8 ++++++++ 2 files changed, 38 insertions(+)common/time.c +0
-0
common/time.c line 4
Quoted 4 lines
common/time.c +1
-0@@ -1,6 +1,7 @@#include <xtf/types.h> #include <xtf/traps.h> #include <xtf/time.h> +#include <xen/errno.h>
Sorting.
Quoted 13 lines
common/time.c +6
-0#include <arch/barrier.h> #include <arch/lib.h> @@ -109,6 +110,35 @@ uint64_t current_time(void)return sec + boot_time; } +/* The POSIX gettimeofday syscall normally takes a second argument, which is +* the timezone (struct timezone). However, it sould be NULL because linux +* doesn't use it anymore. So we need for us to add it in this function +*/ +int gettimeofday (struct timeval *tp,void *restrict tzp) +{
common/time.c uint64_t current_time(void) · line 128
Quoted 10 lines
common/time.c +10
-0+uint64_t boot_time, sec; +uint32_t mod, nsec; + +if ( tzp !=NULL ) +return -EOPNOTSUPP ; + +if ( tp ==NULL ) +return -EINVAL ; + +get_time_info (&boot_time, &sec, &nsec);
Why are you using get_time_info here? Shouldn't you use the current_time function introduced in the previous patch?
Or else I don't see the need to introduce current_time in the previous patch.
common/time.c uint64_t current_time(void) · line 134
Quoted 6 lines
common/time.c +6
-0+#if defined(__i386__) + mod =divmod64 (&boot_time,SEC_TO_NSEC (1 )); +#else + mod = boot_time %SEC_TO_NSEC (1 ); + boot_time /=SEC_TO_NSEC (1 ); +#endif
Please use divmod64 unconditionally.
Quoted 14 lines
common/time.c +6
-0+ + tp->sec = sec + boot_time; + tp->nsec = nsec + mod; +return 0 ; +} +/* * Local variables: * mode: C include/xtf/time.h +0
-0
include/xtf/time.h line 16
Quoted 9 lines
include/xtf/time.h +6
-0@@ -8,6 +8,12 @@#include <xtf/types.h> +struct timeval { +uint64_t sec; +uint64_t nsec; +}; + +
Extra newline.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 3/7] add gettimeofday function to time managment
Hi !
Thanks a lot for reviewing !
Quoted 53 lines · Roger Pau Monné
Quoted 18 lines · Paul Semel
this function acts as the POSIX gettimeofday function
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 30 ++++++++++++++++++++++++++++++ include/xtf/time.h | 8 ++++++++ 2 files changed, 38 insertions(+)common/time.c +0
-0common/time.c line 4
Quoted 4 lines
common/time.c +1
-0@@ -1,6 +1,7 @@#include <xtf/types.h> #include <xtf/traps.h> #include <xtf/time.h> +#include <xen/errno.h> Sorting.
Quoted 13 lines
common/time.c +6
-0#include <arch/barrier.h> #include <arch/lib.h> @@ -109,6 +110,35 @@ uint64_t current_time(void)return sec + boot_time; } +/* The POSIX gettimeofday syscall normally takes a second argument, which is +* the timezone (struct timezone). However, it sould be NULL because linux +* doesn't use it anymore. So we need for us to add it in this function +*/ +int gettimeofday (struct timeval *tp,void *restrict tzp) +{common/time.c uint64_t current_time(void) · line 128
Quoted 10 lines
common/time.c +10
-0+uint64_t boot_time, sec; +uint32_t mod, nsec; + +if ( tzp !=NULL ) +return -EOPNOTSUPP ; + +if ( tp ==NULL ) +return -EINVAL ; + +get_time_info (&boot_time, &sec, &nsec);Why are you using
get_time_infohere? Shouldn't you use thecurrent_timefunction introduced in the previous patch?
Quoted 3 lines
Or else I don't see the need to introduce
current_timein the previous patch.
Actually, I can't use *only* the current_time function here, because I won't be able to get the nanoseconds if so.
Anyway, in the last patch, I am using current_time function for the NOW() macro, which I think is really helpful.
Do you think I should drop all of those ?
Quoted 26 lines
common/time.c uint64_t current_time(void) · line 134
Quoted 6 lines
common/time.c +6
-0+#if defined(__i386__) + mod =divmod64 (&boot_time,SEC_TO_NSEC (1 )); +#else + mod = boot_time %SEC_TO_NSEC (1 ); + boot_time /=SEC_TO_NSEC (1 ); +#endif Please use divmod64 unconditionally.
Quoted 17 lines
common/time.c +6
-0+ + tp->sec = sec + boot_time; + tp->nsec = nsec + mod; +return 0 ; +} +/* * Local variables: * mode: C include/xtf/time.h +0
-0@@ -8,6 +8,12 @@#include <xtf/types.h>
Quoted 8 lines
include/xtf/time.h line 16
Quoted 6 lines
include/xtf/time.h +6
-0+struct timeval { +uint64_t sec; +uint64_t nsec; +}; + +Extra newline.
Thanks,
Signature · 6 lines
Paul _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 3/7] add gettimeofday function to time managment
Quoted 60 lines · Paul Semel
Hi !
Thanks a lot for reviewing !
Quoted 51 lines · Roger Pau Monné
Quoted 18 lines · Paul Semel
this function acts as the POSIX gettimeofday function
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 30 ++++++++++++++++++++++++++++++ include/xtf/time.h | 8 ++++++++ 2 files changed, 38 insertions(+)common/time.c +0
-0common/time.c line 4
Quoted 4 lines
common/time.c +1
-0@@ -1,6 +1,7 @@#include <xtf/types.h> #include <xtf/traps.h> #include <xtf/time.h> +#include <xen/errno.h> Sorting.
Quoted 11 lines
common/time.c +6
-0#include <arch/barrier.h> #include <arch/lib.h> @@ -109,6 +110,35 @@ uint64_t current_time(void)return sec + boot_time; } +/* The POSIX gettimeofday syscall normally takes a second argument, which is +* the timezone (struct timezone). However, it sould be NULL because linux +* doesn't use it anymore. So we need for us to add it in this function +*/ +int gettimeofday (struct timeval *tp,void *restrict tzp) +{common/time.c uint64_t current_time(void) · line 127
Quoted 10 lines
common/time.c +10
-0+uint64_t boot_time, sec; +uint32_t mod, nsec; + +if ( tzp !=NULL ) +return -EOPNOTSUPP ; + +if ( tp ==NULL ) +return -EINVAL ; + +get_time_info (&boot_time, &sec, &nsec);Why are you using
get_time_infohere? Shouldn't you use thecurrent_timefunction introduced in the previous patch?Quoted 3 lines
Or else I don't see the need to introduce
current_timein the previous patch.
Quoted 7 lines
Actually, I can't use *only* the
current_timefunction here, because I won't be able to get the nanoseconds if so.Anyway, in the last patch, I am using
current_timefunction for theNOW()macro, which I think is really helpful.Do you think I should drop all of those ?
Without having any users of those functions it's hard to tell which ones we should keep and which ones should be removed.
IMO, I would keep gettimeofday in order to get the current time.
Then I would also keep the m/u/sleep functions and add a small selftest in test/selftest/main.c that makes use of those functions, for example something as simple as:
s = gettimeofday
msleep(1)
if ( s + 1ms < gettimeofday )
xtf_failure("Fail: error in time keeping functions\n")
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 4/7] add nspin_sleep function to time manager
Quoted 20 lines · Paul Semel
this function spin sleeps for t nanoseconds
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)common/time.c +0
-0@@ -139,6 +139,18 @@ int gettimeofday(struct timeval *tp, void *restrict tzp)return 0 ; }
common/time.c int gettimeofday(struct timeval *tp, void *restrict tzp) · line 151
Quoted 10 lines
common/time.c +10
-0+static inline void nspin_sleep (uint64_t t) +{ +uint64_t curr =since_boot_time (); +uint64_t end = curr + t; + +if ( end < curr ) +panic ("end value overflows counter\n" ); + +while (since_boot_time () < end ) + asmvolatile ("pause" );
You likely want to add a pause helper to arch/x86/include/arch/lib.h in order to avoid open-coding the asm instruction in common code.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 5/7] add spin_sleep function to time manager
Quoted 1 line · Paul Semel
this function uses
nspin_sleepto spin sleep for t seconds
IMO you can squash this into the previous patch.
Quoted 15 lines
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 6 ++++++ 1 file changed, 6 insertions(+)common/time.c +0
-0
common/time.c static inline void nspin_sleep(uint64_t t) · line 156
Quoted 6 lines
common/time.c +3
-0@@ -151,6 +151,12 @@ static inline void nspin_sleep(uint64_t t) asmvolatile ("pause" ); } +static inline void spin_sleep (uint64_t t) +{ +uint64_t nsec =SEC_TO_NSEC (t);
Newline.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 6/7] add mspin_sleep function to time manager
Quoted 18 lines · Paul Semel
this function uses
mspin_sleepto spin sleep for t millisecondsSigned-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 6 ++++++ include/xtf/time.h | 1 + 2 files changed, 7 insertions(+)common/time.c +0
-0
common/time.c static inline void spin_sleep(uint64_t t) · line 162
Quoted 6 lines
common/time.c +3
-0@@ -157,6 +157,12 @@ static inline void spin_sleep(uint64_t t)nspin_sleep (nsec); } +static inline void mspin_sleep (uint64_t t) +{ +uint64_t nsec =MSEC_TO_NSEC (t);
Newline.
And IMO can be squashed into the previous patch.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v4 7/7] add sleep, msleep and NOW() macros to time manager
Quoted 19 lines · Paul Semel
those are helpful macro to use the time manager correctly
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 10 ++++++++++ include/xtf/time.h | 12 ++++++++++++ 2 files changed, 22 insertions(+)common/time.c +0
-0@@ -163,6 +163,16 @@ static inline void mspin_sleep(uint64_t t)nspin_sleep (nsec);
common/time.c static inline void mspin_sleep(uint64_t t) · line 173
Quoted 10 lines
common/time.c +8
-0} +void sleep (uint64_t t) +{ +spin_sleep (t); +} + +void msleep (uint64_t t) +{ +mspin_sleep (t);
Why can you just call mspin_sleep msleep directly?
The same applies to spin_sleep.
Also I was expecting to see some kind of test appear at the end of the series. You are basically adding a bunch of dead code, since there's no user of any of the newly introduced functions.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 7/7] add sleep, msleep and NOW() macros to time manager
Quoted 32 lines · Roger Pau Monné
Quoted 19 lines
those are helpful macro to use the time manager correctly
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 10 ++++++++++ include/xtf/time.h | 12 ++++++++++++ 2 files changed, 22 insertions(+)common/time.c +0
-0@@ -163,6 +163,16 @@ static inline void mspin_sleep(uint64_t t)nspin_sleep (nsec);common/time.c static inline void mspin_sleep(uint64_t t) · line 173
Quoted 10 lines
common/time.c +8
-0} +void sleep (uint64_t t) +{ +spin_sleep (t); +} + +void msleep (uint64_t t) +{ +mspin_sleep (t);Why can you just call
mspin_sleepmsleep directly?
Quoted 5 lines
The same applies to
spin_sleep.Also I was expecting to see some kind of test appear at the end of the series. You are basically adding a bunch of dead code, since there's no user of any of the newly introduced functions.
Actually, I won't be able to add a real XSA test using this feature. Anyway, I do think that having the sleep functions will be really useful in the future. Anyway, I was thinking about adding a test that is calling the gettimeofday function or something similar.
What do you think about it ?
Signature · 6 lines
Paul Semel _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v4 7/7] add sleep, msleep and NOW() macros to time manager
Quoted 38 lines · Paul Semel
Quoted 31 lines · Roger Pau Monné
Quoted 18 lines
those are helpful macro to use the time manager correctly
Signed-off-by Paul Semel <[email protected]>---
Notes:
v4:
- new patch versioncommon/time.c | 10 ++++++++++ include/xtf/time.h | 12 ++++++++++++ 2 files changed, 22 insertions(+)common/time.c +0
-0common/time.c static inline void mspin_sleep(uint64_t t) · line 172
Quoted 10 lines
common/time.c +8
-0@@ -163,6 +163,16 @@ static inline void mspin_sleep(uint64_t t)nspin_sleep (nsec); } +void sleep (uint64_t t) +{ +spin_sleep (t); +} + +void msleep (uint64_t t) +{ +mspin_sleep (t);Why can you just call
mspin_sleepmsleep directly?Quoted 5 lines
The same applies to
spin_sleep.Also I was expecting to see some kind of test appear at the end of the series. You are basically adding a bunch of dead code, since there's no user of any of the newly introduced functions.
Quoted 7 lines
Actually, I won't be able to add a real XSA test using this feature. Anyway, I do think that having the sleep functions will be really useful in the future.
Anyway, I was thinking about adding a test that is calling the gettimeofday function or something similar.What do you think about it ?
Yes, see my last reply to 3/7.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel