<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/time/timekeeping.c, branch v6.12</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.12</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.12'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2024-09-10T11:50:40Z</updated>
<entry>
<title>ntp: Make sure RTC is synchronized when time goes backwards</title>
<updated>2024-09-10T11:50:40Z</updated>
<author>
<name>Benjamin ROBIN</name>
<email>dev@benjarobin.fr</email>
</author>
<published>2024-09-08T14:08:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=35b603f8a78b0bd51566db277c4f7b56b3ff6bac'/>
<id>urn:sha1:35b603f8a78b0bd51566db277c4f7b56b3ff6bac</id>
<content type='text'>
sync_hw_clock() is normally called every 11 minutes when time is
synchronized. This issue is that this periodic timer uses the REALTIME
clock, so when time moves backwards (the NTP server jumps into the past),
the timer expires late.

If the timer expires late, which can be days later, the RTC will no longer
be updated, which is an issue if the device is abruptly powered OFF during
this period. When the device will restart (when powered ON), it will have
the date prior to the ADJ_SETOFFSET call.

A normal NTP server should not jump in the past like that, but it is
possible... Another way of reproducing this issue is to use phc2sys to
synchronize the REALTIME clock with, for example, an IRIG timecode with
the source always starting at the same date (not synchronized).

Also, if the time jump in the future by less than 11 minutes, the RTC may
not be updated immediately (minor issue). Consider the following scenario:
 - Time is synchronized, and sync_hw_clock() was just called (the timer
   expires in 11 minutes).
 - A time jump is realized in the future by a couple of minutes.
 - The time is synchronized again.
 - Users may expect that RTC to be updated as soon as possible, and not
   after 11 minutes (for the same reason, if a power loss occurs in this
   period).

Cancel periodic timer on any time jump (ADJ_SETOFFSET) greater than or
equal to 1s. The timer will be relaunched at the end of do_adjtimex() if
NTP is still considered synced. Otherwise the timer will be relaunched
later when NTP is synced. This way, when the time is synchronized again,
the RTC is updated after less than 2 seconds.

Signed-off-by: Benjamin ROBIN &lt;dev@benjarobin.fr&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/all/20240908140836.203911-1-dev@benjarobin.fr

</content>
</entry>
<entry>
<title>timekeeping: Fix bogus clock_was_set() invocation in do_adjtimex()</title>
<updated>2024-08-05T14:14:14Z</updated>
<author>
<name>Thomas Gleixner</name>
<email>tglx@linutronix.de</email>
</author>
<published>2024-08-03T15:07:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5916be8a53de6401871bdd953f6c60237b47d6d3'/>
<id>urn:sha1:5916be8a53de6401871bdd953f6c60237b47d6d3</id>
<content type='text'>
The addition of the bases argument to clock_was_set() fixed up all call
sites correctly except for do_adjtimex(). This uses CLOCK_REALTIME
instead of CLOCK_SET_WALL as argument. CLOCK_REALTIME is 0.

As a result the effect of that clock_was_set() notification is incomplete
and might result in timers expiring late because the hrtimer code does
not re-evaluate the affected clock bases.

Use CLOCK_SET_WALL instead of CLOCK_REALTIME to tell the hrtimers code
which clock bases need to be re-evaluated.

Fixes: 17a1b8826b45 ("hrtimer: Add bases argument to clock_was_set()")
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/877ccx7igo.ffs@tglx

</content>
</entry>
<entry>
<title>timekeeping: Add missing kernel-doc function comments</title>
<updated>2024-06-23T17:57:30Z</updated>
<author>
<name>Yang Li</name>
<email>yang.lee@linux.alibaba.com</email>
</author>
<published>2024-06-07T09:06:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e1b6a78b58aa859c66a32cfaeb121df87631d4ed'/>
<id>urn:sha1:e1b6a78b58aa859c66a32cfaeb121df87631d4ed</id>
<content type='text'>
Fixup the incomplete kernel-doc style comments for do_adjtimex() and
hardpps() by documenting the function parameters.

Reported-by: Abaci Robot &lt;abaci@linux.alibaba.com&gt;
Signed-off-by: Yang Li &lt;yang.lee@linux.alibaba.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240607090656.104883-1-yang.lee@linux.alibaba.com
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9301
</content>
</entry>
<entry>
<title>timekeeping: Add function to convert realtime to base clock</title>
<updated>2024-06-03T09:18:51Z</updated>
<author>
<name>Lakshmi Sowjanya D</name>
<email>lakshmi.sowjanya.d@intel.com</email>
</author>
<published>2024-05-13T10:38:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=02ecee07ca30f76f2a0f1381661a688b8e501ab0'/>
<id>urn:sha1:02ecee07ca30f76f2a0f1381661a688b8e501ab0</id>
<content type='text'>
PPS (Pulse Per Second) generates a hardware pulse every second based on
CLOCK_REALTIME. This works fine when the pulse is generated in software
from a hrtimer callback function.

For hardware which generates the pulse by programming a timer it is
required to convert CLOCK_REALTIME to the underlying hardware clock.

The X86 Timed IO device is based on the Always Running Timer (ART), which
is the base clock of the TSC, which is usually the system clocksource on
X86.

The core code already has functionality to convert base clock timestamps to
system clocksource timestamps, but there is no support for converting the
other way around.

Provide the required functionality to support such devices in a generic
way to avoid code duplication in drivers:

  1) ktime_real_to_base_clock() to convert a CLOCK_REALTIME timestamp to a
     base clock timestamp

  2) timekeeping_clocksource_has_base() to allow drivers to validate that
     the system clocksource is based on a particular clocksource ID.

[ tglx: Simplify timekeeping_clocksource_has_base() and add missing READ_ONCE() ]

Co-developed-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Co-developed-by: Christopher S. Hall &lt;christopher.s.hall@intel.com&gt;
Signed-off-by: Christopher S. Hall &lt;christopher.s.hall@intel.com&gt;
Signed-off-by: Lakshmi Sowjanya D &lt;lakshmi.sowjanya.d@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240513103813.5666-10-lakshmi.sowjanya.d@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Provide infrastructure for converting to/from a base clock</title>
<updated>2024-06-03T09:18:50Z</updated>
<author>
<name>Lakshmi Sowjanya D</name>
<email>lakshmi.sowjanya.d@intel.com</email>
</author>
<published>2024-05-13T10:38:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6b2e29977518ec13ef3022f234ff8f3014c243da'/>
<id>urn:sha1:6b2e29977518ec13ef3022f234ff8f3014c243da</id>
<content type='text'>
Hardware time stamps like provided by PTP clock implementations are based
on a clock which feeds both the PCIe device and the system clock. For
further processing the underlying hardwarre clock timestamp must be
converted to the system clock.

Right now this requires drivers to invoke an architecture specific
conversion function, e.g. to convert the ART (Always Running Timer)
timestamp to a TSC timestamp.

As the system clock is aware of the underlying base clock, this can be
moved to the core code by providing a base clock property for the system
clock which contains the conversion factors and assigning a clocksource ID
to the base clock.

Add the required data structures and the conversion infrastructure in the
core code to prepare for converting X86 and the related PTP drivers over.

[ tglx: Added a missing READ_ONCE(). Massaged change log ]

Co-developed-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Co-developed-by: Christopher S. Hall &lt;christopher.s.hall@intel.com&gt;
Signed-off-by: Christopher S. Hall &lt;christopher.s.hall@intel.com&gt;
Signed-off-by: Lakshmi Sowjanya D &lt;lakshmi.sowjanya.d@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240513103813.5666-2-lakshmi.sowjanya.d@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Let timekeeping_cycles_to_ns() handle both under and overflow</title>
<updated>2024-04-08T13:03:08Z</updated>
<author>
<name>Adrian Hunter</name>
<email>adrian.hunter@intel.com</email>
</author>
<published>2024-03-25T06:40:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=135225a363ae67bc90bde7a2cbbe1ea0f152ba22'/>
<id>urn:sha1:135225a363ae67bc90bde7a2cbbe1ea0f152ba22</id>
<content type='text'>
For the case !CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE, forego overflow
protection in the range (mask &lt;&lt; 1) &lt; delta &lt;= mask, and interpret it
always as an inconsistency between CPU clock values. That allows
slightly neater code, and it is on a slow path so has no effect on
performance.

Suggested-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Adrian Hunter &lt;adrian.hunter@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240325064023.2997-19-adrian.hunter@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Make delta calculation overflow safe</title>
<updated>2024-04-08T13:03:08Z</updated>
<author>
<name>Adrian Hunter</name>
<email>adrian.hunter@intel.com</email>
</author>
<published>2024-03-25T06:40:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fcf190c369149c3b04539797cedf28741eb14164'/>
<id>urn:sha1:fcf190c369149c3b04539797cedf28741eb14164</id>
<content type='text'>
Kernel timekeeping is designed to keep the change in cycles (since the last
timer interrupt) below max_cycles, which prevents multiplication overflow
when converting cycles to nanoseconds. However, if timer interrupts stop,
the calculation will eventually overflow.

Add protection against that. In timekeeping_cycles_to_ns() calculation,
check against max_cycles, falling back to a slower higher precision
calculation. In timekeeping_forward_now(), process delta in chunks of at
most max_cycles.

Suggested-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Adrian Hunter &lt;adrian.hunter@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240325064023.2997-18-adrian.hunter@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Prepare timekeeping_cycles_to_ns() for overflow safety</title>
<updated>2024-04-08T13:03:08Z</updated>
<author>
<name>Adrian Hunter</name>
<email>adrian.hunter@intel.com</email>
</author>
<published>2024-03-25T06:40:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e809a80aa0bcf802f99407c23fd6be6fd4eb250a'/>
<id>urn:sha1:e809a80aa0bcf802f99407c23fd6be6fd4eb250a</id>
<content type='text'>
Open code clocksource_delta() in timekeeping_cycles_to_ns() so that
overflow safety can be added efficiently.

Suggested-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Adrian Hunter &lt;adrian.hunter@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240325064023.2997-17-adrian.hunter@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Fold in timekeeping_delta_to_ns()</title>
<updated>2024-04-08T13:03:08Z</updated>
<author>
<name>Adrian Hunter</name>
<email>adrian.hunter@intel.com</email>
</author>
<published>2024-03-25T06:40:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3094c6db1cba0bbca6ea19c777762c26fee747d7'/>
<id>urn:sha1:3094c6db1cba0bbca6ea19c777762c26fee747d7</id>
<content type='text'>
timekeeping_delta_to_ns() is now called only from
timekeeping_cycles_to_ns(), and it is not useful otherwise.

Simplify the code by folding it into timekeeping_cycles_to_ns().

No functional change.

Suggested-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Adrian Hunter &lt;adrian.hunter@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240325064023.2997-16-adrian.hunter@intel.com

</content>
</entry>
<entry>
<title>timekeeping: Consolidate timekeeping helpers</title>
<updated>2024-04-08T13:03:08Z</updated>
<author>
<name>Adrian Hunter</name>
<email>adrian.hunter@intel.com</email>
</author>
<published>2024-03-25T06:40:18Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e84f43e34faf85816587f80594541ec978449d6e'/>
<id>urn:sha1:e84f43e34faf85816587f80594541ec978449d6e</id>
<content type='text'>
Consolidate timekeeping helpers, making use of timekeeping_cycles_to_ns()
in preference to directly using timekeeping_delta_to_ns().

No functional change.

Suggested-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Adrian Hunter &lt;adrian.hunter@intel.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lore.kernel.org/r/20240325064023.2997-15-adrian.hunter@intel.com

</content>
</entry>
</feed>
