summaryrefslogtreecommitdiffstats
path: root/include/linux/rtc.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-13 20:56:58 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-13 20:56:58 -0500
commit2bcc673101268dc50e52b83226c5bbf38391e16d (patch)
tree0cdaf6affa8b05d436c2e8b80ff23e8c7f03a30a /include/linux/rtc.h
parent670310dfbae0eefe7318ff6a61e29e67a7a7bbce (diff)
parentb24591e2fcf852ad7ad2ccf745c8220bf378d312 (diff)
Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer updates from Thomas Gleixner: "Yet another big pile of changes: - More year 2038 work from Arnd slowly reaching the point where we need to think about the syscalls themself. - A new timer function which allows to conditionally (re)arm a timer only when it's either not running or the new expiry time is sooner than the armed expiry time. This allows to use a single timer for multiple timeout requirements w/o caring about the first expiry time at the call site. - A new NMI safe accessor to clock real time for the printk timestamp work. Can be used by tracing, perf as well if required. - A large number of timer setup conversions from Kees which got collected here because either maintainers requested so or they simply got ignored. As Kees pointed out already there are a few trivial merge conflicts and some redundant commits which was unavoidable due to the size of this conversion effort. - Avoid a redundant iteration in the timer wheel softirq processing. - Provide a mechanism to treat RTC implementations depending on their hardware properties, i.e. don't inflict the write at the 0.5 seconds boundary which originates from the PC CMOS RTC to all RTCs. No functional change as drivers need to be updated separately. - The usual small updates to core code clocksource drivers. Nothing really exciting" * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (111 commits) timers: Add a function to start/reduce a timer pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday() timer: Prepare to change all DEFINE_TIMER() callbacks netfilter: ipvs: Convert timers to use timer_setup() scsi: qla2xxx: Convert timers to use timer_setup() block/aoe: discover_timer: Convert timers to use timer_setup() ide: Convert timers to use timer_setup() drbd: Convert timers to use timer_setup() mailbox: Convert timers to use timer_setup() crypto: Convert timers to use timer_setup() drivers/pcmcia: omap1: Fix error in automated timer conversion ARM: footbridge: Fix typo in timer conversion drivers/sgi-xp: Convert timers to use timer_setup() drivers/pcmcia: Convert timers to use timer_setup() drivers/memstick: Convert timers to use timer_setup() drivers/macintosh: Convert timers to use timer_setup() hwrng/xgene-rng: Convert timers to use timer_setup() auxdisplay: Convert timers to use timer_setup() sparc/led: Convert timers to use timer_setup() mips: ip22/32: Convert timers to use timer_setup() ...
Diffstat (limited to 'include/linux/rtc.h')
-rw-r--r--include/linux/rtc.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f6d7ee98d93c..41319a2e409b 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -136,6 +136,14 @@ struct rtc_device {
136 /* Some hardware can't support UIE mode */ 136 /* Some hardware can't support UIE mode */
137 int uie_unsupported; 137 int uie_unsupported;
138 138
139 /* Number of nsec it takes to set the RTC clock. This influences when
140 * the set ops are called. An offset:
141 * - of 0.5 s will call RTC set for wall clock time 10.0 s at 9.5 s
142 * - of 1.5 s will call RTC set for wall clock time 10.0 s at 8.5 s
143 * - of -0.5 s will call RTC set for wall clock time 10.0 s at 10.5 s
144 */
145 long set_offset_nsec;
146
139 bool registered; 147 bool registered;
140 148
141 struct nvmem_config *nvmem_config; 149 struct nvmem_config *nvmem_config;
@@ -173,7 +181,7 @@ extern void devm_rtc_device_unregister(struct device *dev,
173 181
174extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm); 182extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
175extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm); 183extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
176extern int rtc_set_ntp_time(struct timespec64 now); 184extern int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec);
177int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm); 185int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm);
178extern int rtc_read_alarm(struct rtc_device *rtc, 186extern int rtc_read_alarm(struct rtc_device *rtc,
179 struct rtc_wkalrm *alrm); 187 struct rtc_wkalrm *alrm);
@@ -222,6 +230,39 @@ static inline bool is_leap_year(unsigned int year)
222 return (!(year % 4) && (year % 100)) || !(year % 400); 230 return (!(year % 4) && (year % 100)) || !(year % 400);
223} 231}
224 232
233/* Determine if we can call to driver to set the time. Drivers can only be
234 * called to set a second aligned time value, and the field set_offset_nsec
235 * specifies how far away from the second aligned time to call the driver.
236 *
237 * This also computes 'to_set' which is the time we are trying to set, and has
238 * a zero in tv_nsecs, such that:
239 * to_set - set_delay_nsec == now +/- FUZZ
240 *
241 */
242static inline bool rtc_tv_nsec_ok(s64 set_offset_nsec,
243 struct timespec64 *to_set,
244 const struct timespec64 *now)
245{
246 /* Allowed error in tv_nsec, arbitarily set to 5 jiffies in ns. */
247 const unsigned long TIME_SET_NSEC_FUZZ = TICK_NSEC * 5;
248 struct timespec64 delay = {.tv_sec = 0,
249 .tv_nsec = set_offset_nsec};
250
251 *to_set = timespec64_add(*now, delay);
252
253 if (to_set->tv_nsec < TIME_SET_NSEC_FUZZ) {
254 to_set->tv_nsec = 0;
255 return true;
256 }
257
258 if (to_set->tv_nsec > NSEC_PER_SEC - TIME_SET_NSEC_FUZZ) {
259 to_set->tv_sec++;
260 to_set->tv_nsec = 0;
261 return true;
262 }
263 return false;
264}
265
225#define rtc_register_device(device) \ 266#define rtc_register_device(device) \
226 __rtc_register_device(THIS_MODULE, device) 267 __rtc_register_device(THIS_MODULE, device)
227 268