* [patch V2 43/64] x86: kvm: Use ktime_get_boot_ns()
[not found] <20140716205018.175419210@linutronix.de>
@ 2014-07-16 21:04 ` Thomas Gleixner
2014-07-17 10:58 ` Paolo Bonzini
2014-07-16 21:04 ` [patch V2 44/64] x86: kvm: Make kvm_get_time_and_clockread() nanoseconds based Thomas Gleixner
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2014-07-16 21:04 UTC (permalink / raw)
To: LKML; +Cc: John Stultz, Peter Zijlstra, Gleb Natapov, kvm
[-- Attachment #1: x86-kvm-use-ktime.patch --]
[-- Type: text/plain, Size: 712 bytes --]
Use the new nanoseconds based interface and get rid of the timespec
conversion dance.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: kvm@vger.kernel.org
---
arch/x86/kvm/x86.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
Index: tip/arch/x86/kvm/x86.c
===================================================================
--- tip.orig/arch/x86/kvm/x86.c
+++ tip/arch/x86/kvm/x86.c
@@ -1109,11 +1109,7 @@ static void kvm_get_time_scale(uint32_t
static inline u64 get_kernel_ns(void)
{
- struct timespec ts;
-
- ktime_get_ts(&ts);
- monotonic_to_bootbased(&ts);
- return timespec_to_ns(&ts);
+ return ktime_get_boot_ns();
}
#ifdef CONFIG_X86_64
^ permalink raw reply [flat|nested] 4+ messages in thread
* [patch V2 44/64] x86: kvm: Make kvm_get_time_and_clockread() nanoseconds based
[not found] <20140716205018.175419210@linutronix.de>
2014-07-16 21:04 ` [patch V2 43/64] x86: kvm: Use ktime_get_boot_ns() Thomas Gleixner
@ 2014-07-16 21:04 ` Thomas Gleixner
2014-07-17 10:58 ` Paolo Bonzini
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2014-07-16 21:04 UTC (permalink / raw)
To: LKML; +Cc: John Stultz, Peter Zijlstra, Gleb Natapov, kvm
[-- Attachment #1: x86-kvm-use-ktime-based.patch --]
[-- Type: text/plain, Size: 3091 bytes --]
Convert the relevant base data right away to nanoseconds instead of
doing the conversion on every readout. Reduces text size by 160 bytes.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: kvm@vger.kernel.org
---
arch/x86/kvm/x86.c | 44 ++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)
Index: tip/arch/x86/kvm/x86.c
===================================================================
--- tip.orig/arch/x86/kvm/x86.c
+++ tip/arch/x86/kvm/x86.c
@@ -984,9 +984,8 @@ struct pvclock_gtod_data {
u32 shift;
} clock;
- /* open coded 'struct timespec' */
- u64 monotonic_time_snsec;
- time_t monotonic_time_sec;
+ u64 boot_ns;
+ u64 nsec_base;
};
static struct pvclock_gtod_data pvclock_gtod_data;
@@ -994,6 +993,9 @@ static struct pvclock_gtod_data pvclock_
static void update_pvclock_gtod(struct timekeeper *tk)
{
struct pvclock_gtod_data *vdata = &pvclock_gtod_data;
+ u64 boot_ns;
+
+ boot_ns = ktime_to_ns(ktime_add(tk->base_mono, tk->offs_boot));
write_seqcount_begin(&vdata->seq);
@@ -1004,17 +1006,8 @@ static void update_pvclock_gtod(struct t
vdata->clock.mult = tk->mult;
vdata->clock.shift = tk->shift;
- vdata->monotonic_time_sec = tk->xtime_sec
- + tk->wall_to_monotonic.tv_sec;
- vdata->monotonic_time_snsec = tk->xtime_nsec
- + (tk->wall_to_monotonic.tv_nsec
- << tk->shift);
- while (vdata->monotonic_time_snsec >=
- (((u64)NSEC_PER_SEC) << tk->shift)) {
- vdata->monotonic_time_snsec -=
- ((u64)NSEC_PER_SEC) << tk->shift;
- vdata->monotonic_time_sec++;
- }
+ vdata->boot_ns = boot_ns;
+ vdata->nsec_base = tk->xtime_nsec;
write_seqcount_end(&vdata->seq);
}
@@ -1371,23 +1364,22 @@ static inline u64 vgettsc(cycle_t *cycle
return v * gtod->clock.mult;
}
-static int do_monotonic(struct timespec *ts, cycle_t *cycle_now)
+static int do_monotonic_boot(s64 *t, cycle_t *cycle_now)
{
+ struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
unsigned long seq;
- u64 ns;
int mode;
- struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
+ u64 ns;
- ts->tv_nsec = 0;
do {
seq = read_seqcount_begin(>od->seq);
mode = gtod->clock.vclock_mode;
- ts->tv_sec = gtod->monotonic_time_sec;
- ns = gtod->monotonic_time_snsec;
+ ns = gtod->nsec_base;
ns += vgettsc(cycle_now);
ns >>= gtod->clock.shift;
+ ns += gtod->boot_ns;
} while (unlikely(read_seqcount_retry(>od->seq, seq)));
- timespec_add_ns(ts, ns);
+ *t = ns;
return mode;
}
@@ -1395,19 +1387,11 @@ static int do_monotonic(struct timespec
/* returns true if host is using tsc clocksource */
static bool kvm_get_time_and_clockread(s64 *kernel_ns, cycle_t *cycle_now)
{
- struct timespec ts;
-
/* checked again under seqlock below */
if (pvclock_gtod_data.clock.vclock_mode != VCLOCK_TSC)
return false;
- if (do_monotonic(&ts, cycle_now) != VCLOCK_TSC)
- return false;
-
- monotonic_to_bootbased(&ts);
- *kernel_ns = timespec_to_ns(&ts);
-
- return true;
+ return do_monotonic_boot(kernel_ns, cycle_now) == VCLOCK_TSC;
}
#endif
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch V2 43/64] x86: kvm: Use ktime_get_boot_ns()
2014-07-16 21:04 ` [patch V2 43/64] x86: kvm: Use ktime_get_boot_ns() Thomas Gleixner
@ 2014-07-17 10:58 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-17 10:58 UTC (permalink / raw)
To: Thomas Gleixner, LKML; +Cc: John Stultz, Peter Zijlstra, Gleb Natapov, kvm
Il 16/07/2014 23:04, Thomas Gleixner ha scritto:
> Use the new nanoseconds based interface and get rid of the timespec
> conversion dance.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Gleb Natapov <gleb@kernel.org>
> Cc: kvm@vger.kernel.org
> ---
> arch/x86/kvm/x86.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> Index: tip/arch/x86/kvm/x86.c
> ===================================================================
> --- tip.orig/arch/x86/kvm/x86.c
> +++ tip/arch/x86/kvm/x86.c
> @@ -1109,11 +1109,7 @@ static void kvm_get_time_scale(uint32_t
>
> static inline u64 get_kernel_ns(void)
> {
> - struct timespec ts;
> -
> - ktime_get_ts(&ts);
> - monotonic_to_bootbased(&ts);
> - return timespec_to_ns(&ts);
> + return ktime_get_boot_ns();
> }
>
> #ifdef CONFIG_X86_64
>
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
I will remove get_kernel_ns if you don't do that for me...
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch V2 44/64] x86: kvm: Make kvm_get_time_and_clockread() nanoseconds based
2014-07-16 21:04 ` [patch V2 44/64] x86: kvm: Make kvm_get_time_and_clockread() nanoseconds based Thomas Gleixner
@ 2014-07-17 10:58 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-17 10:58 UTC (permalink / raw)
To: Thomas Gleixner, LKML; +Cc: John Stultz, Peter Zijlstra, Gleb Natapov, kvm
Il 16/07/2014 23:04, Thomas Gleixner ha scritto:
> Convert the relevant base data right away to nanoseconds instead of
> doing the conversion on every readout. Reduces text size by 160 bytes.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Gleb Natapov <gleb@kernel.org>
> Cc: kvm@vger.kernel.org
> ---
> arch/x86/kvm/x86.c | 44 ++++++++++++++------------------------------
> 1 file changed, 14 insertions(+), 30 deletions(-)
>
> Index: tip/arch/x86/kvm/x86.c
> ===================================================================
> --- tip.orig/arch/x86/kvm/x86.c
> +++ tip/arch/x86/kvm/x86.c
> @@ -984,9 +984,8 @@ struct pvclock_gtod_data {
> u32 shift;
> } clock;
>
> - /* open coded 'struct timespec' */
> - u64 monotonic_time_snsec;
> - time_t monotonic_time_sec;
> + u64 boot_ns;
> + u64 nsec_base;
> };
>
> static struct pvclock_gtod_data pvclock_gtod_data;
> @@ -994,6 +993,9 @@ static struct pvclock_gtod_data pvclock_
> static void update_pvclock_gtod(struct timekeeper *tk)
> {
> struct pvclock_gtod_data *vdata = &pvclock_gtod_data;
> + u64 boot_ns;
> +
> + boot_ns = ktime_to_ns(ktime_add(tk->base_mono, tk->offs_boot));
>
> write_seqcount_begin(&vdata->seq);
>
> @@ -1004,17 +1006,8 @@ static void update_pvclock_gtod(struct t
> vdata->clock.mult = tk->mult;
> vdata->clock.shift = tk->shift;
>
> - vdata->monotonic_time_sec = tk->xtime_sec
> - + tk->wall_to_monotonic.tv_sec;
> - vdata->monotonic_time_snsec = tk->xtime_nsec
> - + (tk->wall_to_monotonic.tv_nsec
> - << tk->shift);
> - while (vdata->monotonic_time_snsec >=
> - (((u64)NSEC_PER_SEC) << tk->shift)) {
> - vdata->monotonic_time_snsec -=
> - ((u64)NSEC_PER_SEC) << tk->shift;
> - vdata->monotonic_time_sec++;
> - }
> + vdata->boot_ns = boot_ns;
> + vdata->nsec_base = tk->xtime_nsec;
>
> write_seqcount_end(&vdata->seq);
> }
> @@ -1371,23 +1364,22 @@ static inline u64 vgettsc(cycle_t *cycle
> return v * gtod->clock.mult;
> }
>
> -static int do_monotonic(struct timespec *ts, cycle_t *cycle_now)
> +static int do_monotonic_boot(s64 *t, cycle_t *cycle_now)
> {
> + struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
> unsigned long seq;
> - u64 ns;
> int mode;
> - struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
> + u64 ns;
>
> - ts->tv_nsec = 0;
> do {
> seq = read_seqcount_begin(>od->seq);
> mode = gtod->clock.vclock_mode;
> - ts->tv_sec = gtod->monotonic_time_sec;
> - ns = gtod->monotonic_time_snsec;
> + ns = gtod->nsec_base;
> ns += vgettsc(cycle_now);
> ns >>= gtod->clock.shift;
> + ns += gtod->boot_ns;
> } while (unlikely(read_seqcount_retry(>od->seq, seq)));
> - timespec_add_ns(ts, ns);
> + *t = ns;
>
> return mode;
> }
> @@ -1395,19 +1387,11 @@ static int do_monotonic(struct timespec
> /* returns true if host is using tsc clocksource */
> static bool kvm_get_time_and_clockread(s64 *kernel_ns, cycle_t *cycle_now)
> {
> - struct timespec ts;
> -
> /* checked again under seqlock below */
> if (pvclock_gtod_data.clock.vclock_mode != VCLOCK_TSC)
> return false;
>
> - if (do_monotonic(&ts, cycle_now) != VCLOCK_TSC)
> - return false;
> -
> - monotonic_to_bootbased(&ts);
> - *kernel_ns = timespec_to_ns(&ts);
> -
> - return true;
> + return do_monotonic_boot(kernel_ns, cycle_now) == VCLOCK_TSC;
> }
> #endif
>
>
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-17 11:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20140716205018.175419210@linutronix.de>
2014-07-16 21:04 ` [patch V2 43/64] x86: kvm: Use ktime_get_boot_ns() Thomas Gleixner
2014-07-17 10:58 ` Paolo Bonzini
2014-07-16 21:04 ` [patch V2 44/64] x86: kvm: Make kvm_get_time_and_clockread() nanoseconds based Thomas Gleixner
2014-07-17 10:58 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox