* Re: [PATCH v15 23/26] sched: early boot clock [not found] ` <20180719205545.16512-24-pasha.tatashin@oracle.com> @ 2018-11-06 5:42 ` Dominique Martinet [not found] ` <20181106054212.GA31768@nautica> 1 sibling, 0 replies; 4+ messages in thread From: Dominique Martinet @ 2018-11-06 5:42 UTC (permalink / raw) To: Pavel Tatashin Cc: gnomes, feng.tang, kvm, peterz, heiko.carstens, qemu-devel, virtualization, steven.sistare, hpa, boris.ostrovsky, prarit, linux-s390, x86, linux, daniel.m.jordan, mingo, pmladek, john.stultz, tglx, jgross, douly.fnst, sboyd, linux-kernel, schwidefsky, pbonzini (added various kvm/virtualization lists in Cc as well as qemu as I don't know who's "wrong" here) Pavel Tatashin wrote on Thu, Jul 19, 2018: > Allow sched_clock() to be used before schec_clock_init() is called. > This provides with a way to get early boot timestamps on machines with > unstable clocks. This isn't something I understand, but bisect tells me this patch (landed as 857baa87b64 ("sched/clock: Enable sched clock early")) makes a VM running with kvmclock take a step in uptime/printk timer early in boot sequence as illustrated below. The step seems to be related to the amount of time the host was suspended while qemu was running before the reboot. $ dmesg ... [ 0.000000] SMBIOS 2.8 present. [ 0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20180724_192412-buildhw-07.phx2.fedoraproject.org-1.fc29 04/01/2014 [ 0.000000] Hypervisor detected: KVM [ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00 [283120.529821] kvm-clock: cpu 0, msr 321a8001, primary cpu clock [283120.529822] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns [283120.529824] tsc: Detected 2592.000 MHz processor ... (The VM is x86_64 on x86_64, I can provide my .config on request but don't think it's related) It's rather annoying for me as I often reboot VMs and rely on the 'uptime' command to check if I did just reboot or not as I have the attention span of a goldfish; I'd rather not have to find something else to check if I did just reboot or not. Note that if the qemu process is restarted, there is no offset anymore. I unfortunately just did that so cannot say with confidence (putting my laptop to sleep for 30s only led to a 2s offset and I do not want to wait longer right now), but it looks like the clock is still mostly correct after reboot after disabling my VM's ntp client. Will infirm that tomorrow if I was wrong. Happy to try to help fixing this in any way, as written above the quote I'm not even actually sure who is wrong here. Thanks! (As a side, mostly unrelated note, insert swearing here about cf7a63ef4 not compiling earlier in this serie; some variable declaration got removed before their use. Was fixed in the next patch but I didn't notice the kernel didn't fully rebuild and wasted time in my bisect heading the wrong way...) > Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com> > --- > init/main.c | 2 +- > kernel/sched/clock.c | 20 +++++++++++++++++++- > 2 files changed, 20 insertions(+), 2 deletions(-) > > diff --git a/init/main.c b/init/main.c > index 162d931c9511..ff0a24170b95 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -642,7 +642,6 @@ asmlinkage __visible void __init start_kernel(void) > softirq_init(); > timekeeping_init(); > time_init(); > - sched_clock_init(); > printk_safe_init(); > perf_event_init(); > profile_init(); > @@ -697,6 +696,7 @@ asmlinkage __visible void __init start_kernel(void) > acpi_early_init(); > if (late_time_init) > late_time_init(); > + sched_clock_init(); > calibrate_delay(); > pid_idr_init(); > anon_vma_init(); > diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c > index 0e9dbb2d9aea..422cd63f8f17 100644 > --- a/kernel/sched/clock.c > +++ b/kernel/sched/clock.c > @@ -202,7 +202,25 @@ static void __sched_clock_gtod_offset(void) > > void __init sched_clock_init(void) > { > + unsigned long flags; > + > + /* > + * Set __gtod_offset such that once we mark sched_clock_running, > + * sched_clock_tick() continues where sched_clock() left off. > + * > + * Even if TSC is buggered, we're still UP at this point so it > + * can't really be out of sync. > + */ > + local_irq_save(flags); > + __sched_clock_gtod_offset(); > + local_irq_restore(flags); > + > sched_clock_running = 1; > + > + /* Now that sched_clock_running is set adjust scd */ > + local_irq_save(flags); > + sched_clock_tick(); > + local_irq_restore(flags); > } > /* > * We run this as late_initcall() such that it runs after all built-in drivers, > @@ -356,7 +374,7 @@ u64 sched_clock_cpu(int cpu) > return sched_clock() + __sched_clock_offset; > > if (unlikely(!sched_clock_running)) > - return 0ull; > + return sched_clock(); > > preempt_disable_notrace(); > scd = cpu_sdc(cpu); -- Dominique Martinet | Asmadeus ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <20181106054212.GA31768@nautica>]
[parent not found: <95c3920e-bf80-0c7e-7854-01a1c3189c23@oracle.com>]
[parent not found: <20190102202032.GA1034@eldamar.local>]
[parent not found: <CA+CK2bC70pnL0Wimb0xt99J4nNfi8W3zuUHgAk-jsPuOP9jpHA@mail.gmail.com>]
* Re: [PATCH v15 23/26] sched: early boot clock [not found] ` <CA+CK2bC70pnL0Wimb0xt99J4nNfi8W3zuUHgAk-jsPuOP9jpHA@mail.gmail.com> @ 2019-01-03 23:43 ` Dominique Martinet [not found] ` <CA+CK2bDj1f=VpT+k-e8kSSaoLJ3W9-JPPq9udFdDwd6ijXi28g@mail.gmail.com> 0 siblings, 1 reply; 4+ messages in thread From: Dominique Martinet @ 2019-01-03 23:43 UTC (permalink / raw) To: Pavel Tatashin Cc: gnomes, feng.tang, kvm, pmladek, Peter Zijlstra, heiko.carstens, qemu-devel, virtualization, Steven Sistare, hpa, boris.ostrovsky, prarit, linux-s390, x86, linux, Daniel Jordan, mingo, Pavel Tatashin, john.stultz, Thomas Gleixner, Salvatore Bonaccorso, jgross, douly.fnst, sboyd, LKML, schwidefsky, pbonzini [-- Attachment #1: Type: text/plain, Size: 1574 bytes --] Pavel Tatashin wrote on Thu, Jan 03, 2019: > Could you please send the config file and qemu arguments that were > used to reproduce this problem. Running qemu by hand, nothing fancy e.g. this works: # qemu-system-x86_64 -m 1G -smp 4 -drive file=/root/kvm-wrapper/disks/f2.img,if=virtio -serial mon:stdio --enable-kvm -cpu Haswell -device virtio-rng-pci -nographic (used a specific cpu just in case but normally runnning with cpu host on a skylake machine; can probably go older) qemu is fedora 29 blend as is: $ qemu-system-x86_64 --version QEMU emulator version 3.0.0 (qemu-3.0.0-3.fc29) Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers compressed .config attached to the mail, this can likely be trimmed down some as well but that takes more time for me.. I didn't rebuild the kernel so not 100% sure (comes from /proc/config.gz) but it should work on a 4.20-rc2 kernel as written in the first few lines; 857baa87b64 I referred to in another mail was merged in 4.19-rc1 so anything past that is probably OK to reproduce... Re-checked today with these exact options (fresh VM start; then suspend laptop for a bit, then reboot VM): [ 0.000000] Hypervisor detected: KVM [ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00 [ 2477.907447] kvm-clock: cpu 0, msr 153a4001, primary cpu clock [ 2477.907448] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns [ 2477.907450] tsc: Detected 2592.000 MHz processor As offered previously, happy to help in any way. Thanks, -- Dominique [-- Attachment #2: config.xz --] [-- Type: application/octet-stream, Size: 19476 bytes --] [-- Attachment #3: Type: text/plain, Size: 183 bytes --] _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <CA+CK2bDj1f=VpT+k-e8kSSaoLJ3W9-JPPq9udFdDwd6ijXi28g@mail.gmail.com>]
* Re: [PATCH v15 23/26] sched: early boot clock [not found] ` <CA+CK2bDj1f=VpT+k-e8kSSaoLJ3W9-JPPq9udFdDwd6ijXi28g@mail.gmail.com> @ 2019-01-07 23:48 ` Dominique Martinet [not found] ` <20190107234839.GA15269@nautica> 1 sibling, 0 replies; 4+ messages in thread From: Dominique Martinet @ 2019-01-07 23:48 UTC (permalink / raw) To: Pavel Tatashin Cc: gnomes, feng.tang, kvm, Petr Mladek, Peter Zijlstra, heiko.carstens, qemu-devel, virtualization, Steven Sistare, hpa, boris.ostrovsky, prarit, linux-s390, x86, linux, Daniel Jordan, mingo, Pavel Tatashin, John Stultz, Thomas Gleixner, Salvatore Bonaccorso, jgross, douly.fnst, sboyd, LKML, schwidefsky, pbonzini Pavel Tatashin wrote on Mon, Jan 07, 2019: > I could not reproduce the problem. Did you suspend to memory between > wake ups? Does this time jump happen every time, even if your laptop > sleeps for a minute? I'm not sure I understand "suspend to memory between the wake ups". The full sequence is: - start a VM (just in case, I let it boot till the end) - suspend to memory (aka systemctl suspend) the host - after resuming the host, soft reboot the VM (login through serial/ssh/whatever and reboot or in the qemu console 'system_reset') I've just slept exactly one minute and reproduced again with the fedora stock kernel now (4.19.13-300.fc29.x86_64) in the VM. Interestingly I'm not getting the same offset between multiple reboots now despite not suspending again; but if I don't suspend I cannot seem to get it to give an offset at all (only tried for a few minutes; this might not be true) ; OTOH I pushed my luck further and even with a five seconds sleep I'm getting a noticeable offset on first VM reboot after resume: [ 0.000000] Hypervisor detected: KVM [ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00 [ 179.362163] kvm-clock: cpu 0, msr 13c01001, primary cpu clock [ 179.362163] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns Honestly not sure what more information I could give, I'll try on some other hardware than my laptop (if I can get a server to resume after suspend through ipmi or wake on lan); but I don't have anything I could install ubuntu on to try their qemu's version... although I really don't want to believe that's the difference... Thanks, -- Dominique ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <20190107234839.GA15269@nautica>]
[parent not found: <CA+CK2bD3kbcNvkVf2kiKQYs+srcw7BdWngqt_wM7Z-QsBJyH6w@mail.gmail.com>]
* Re: [PATCH v15 23/26] sched: early boot clock [not found] ` <CA+CK2bD3kbcNvkVf2kiKQYs+srcw7BdWngqt_wM7Z-QsBJyH6w@mail.gmail.com> @ 2019-01-08 1:09 ` Dominique Martinet 0 siblings, 0 replies; 4+ messages in thread From: Dominique Martinet @ 2019-01-08 1:09 UTC (permalink / raw) To: Pavel Tatashin Cc: gnomes, feng.tang, kvm, Petr Mladek, Peter Zijlstra, heiko.carstens, qemu-devel, virtualization, Steven Sistare, hpa, boris.ostrovsky, prarit, linux-s390, x86, linux, Daniel Jordan, mingo, Pavel Tatashin, John Stultz, Thomas Gleixner, Salvatore Bonaccorso, jgross, douly.fnst, sboyd, LKML, schwidefsky, pbonzini Pavel Tatashin wrote on Mon, Jan 07, 2019: > I did exactly the same sequence on Kaby Lake CPU and could not > reproduce it. What is your host CPU? skylake consumer laptop CPU: Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz I don't have any kaby lake around; I have access to older servers though... -- Dominique ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-01-08 1:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20180719205545.16512-1-pasha.tatashin@oracle.com>
[not found] ` <20180719205545.16512-24-pasha.tatashin@oracle.com>
2018-11-06 5:42 ` [PATCH v15 23/26] sched: early boot clock Dominique Martinet
[not found] ` <20181106054212.GA31768@nautica>
[not found] ` <95c3920e-bf80-0c7e-7854-01a1c3189c23@oracle.com>
[not found] ` <20190102202032.GA1034@eldamar.local>
[not found] ` <CA+CK2bC70pnL0Wimb0xt99J4nNfi8W3zuUHgAk-jsPuOP9jpHA@mail.gmail.com>
2019-01-03 23:43 ` Dominique Martinet
[not found] ` <CA+CK2bDj1f=VpT+k-e8kSSaoLJ3W9-JPPq9udFdDwd6ijXi28g@mail.gmail.com>
2019-01-07 23:48 ` Dominique Martinet
[not found] ` <20190107234839.GA15269@nautica>
[not found] ` <CA+CK2bD3kbcNvkVf2kiKQYs+srcw7BdWngqt_wM7Z-QsBJyH6w@mail.gmail.com>
2019-01-08 1:09 ` Dominique Martinet
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox