LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-02-2019, 11:07 AM   #1
h1uke
LQ Newbie
 
Registered: Dec 2019
Posts: 2

Rep: Reputation: Disabled
system clock runs faster in 64-bit kernel


Recently we upgraded our legacy device to a newer, 64-bit kernel (4.1.3 --> 5.0.12) and found that the TSC-based system clock runs faster under a 64-bit OS.
It is an embedded Intel Atom box(4 x E3800), no external NTP service available.
The 64-bit OS system clock is gaining approximately 2 seconds per hour compared to a 32-bit one, which is not acceptable.

Different TSC calibration methods used in two different kernels, and the results are also different (see below).

Does this look familiar to anyone? Just wanted to ask before diving into the source code.

Thanks.

Code:
---- dmesg | grep -i TSC ----------

64-bit kernel 5.0.12 :

[    0.000000] tsc: Detected 1915.900 MHz processor
[    0.150872] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x373bb0d4809, max_idle_ns: 881590714052 ns
[    0.156020] TSC deadline timer enabled
[    0.677033] clocksource: Switched to clocksource tsc-early
[    2.249153] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x373bb0d4809, max_idle_ns: 881590714052 ns
[    2.249187] clocksource: Switched to clocksource tsc
---------------------------------

32-bit kernel 4.1.3 :

TSC runs at 1913600 KHz
tsc: Detected 1913.600 MHz processor
TSC deadline timer enabled
tsc: Refined TSC clocksource calibration: 1916.670 MHz
clocksource tsc: mask: 0xffffffffffffffff max_cycles: 0x37415f43c80, max_idle_ns: 881590514357 ns
---------------------------------
 
Old 12-07-2019, 01:05 AM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
hi h1uke!


I'm certainly not sure, but just a couple thoughts offhand.

1) I thought there is a 3820 CPU that is 64-bit, don't know about the 3800.
2) Although there appear to be identical "mask" values shown, I do have to wonder if the 64-bit OS is expecting a 64-bit CPU and so is doing calculations with, in some sense, 64-bit accuracy, while the 32-bit OS is expecting 32-bit accuracy. I wonder if that results in the slight difference in the other values.

Last edited by rigor; 12-07-2019 at 01:06 AM.
 
Old 12-16-2019, 06:56 AM   #3
h1uke
LQ Newbie
 
Registered: Dec 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
here's the update:

- there's nothing to do with the 64-bit vs the 32-bit kernel. The real cause for a problem is a [surprisingly] different implementation of "arch/x86/kernel/tsc.c" in 5.0.12 vs 4.1.3 kernel source tree as it found on kernel.org.

- the TSC frequencies calculated by two implementations above are slightly different: 1916.670 MHz in v4.1.3 vs 1915.9 MHz in v5.0.12 _on_the_same_box_. Simply calculations show that this will cause the system clock in v5.0.12 to run faster gaining ~ 400usec every second, which results in approximately 33 minutes per day.

- we were able to confirm the above numbers by measuring/averaging the number of microsecond cycles ( using gettimeofday() ) between two consecutive 1-second pulses of the onboard DS3231 RTC chip -- our system clock advances by ~ 100385 microseconds per second tick provided by an independent chip which is very accurate

- a quick and dirty workaround is used for now: we extended the system startup script with a call to adjtimex which modifies the kernel time constants according to our needs.
A convenient calculator of adjtimex parameters can be found here

P.S. rigor: besides this is irrelevant ... the CPU we use is Intel Atom E3845, which contains four cores belonging to E3800 family
 
Old 01-11-2020, 09:56 AM   #4
ordealbyfire83
Member
 
Registered: Oct 2006
Location: Leiden, Netherlands
Distribution: LFS, Ubuntu Hardy
Posts: 302

Rep: Reputation: 89
As a workaround, can you change the clock source? I think something like "cat /sys/devices/system/clocksource/clocksource0/available_clocksource" should show what other clock sources can be used. You can change it at boot time using the clocksource= kernel parameter or echo that to the current_clocksource entry in the same directory.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why system clock runs faster than hardware clock? DavidLiu Linux - Software 2 01-23-2011 07:38 AM
System clock correct, hardware clock wrong karlovac Linux - General 5 01-16-2009 07:19 PM
Failed to set system clock to hardware clock jrtayloriv Linux - Newbie 2 09-25-2008 07:06 AM
system clock,hardware clock varunbihani Linux - Newbie 2 07-23-2005 09:04 AM
system clock vs. CMOS clock dtamajka Linux - General 7 12-11-2003 05:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration