Skip to content

Commit a6d9638

Browse files
committed
Merge tag 'ktime-get-clock-ts64-for-ptp' into timers/ptp
Pull the base implementation of ktime_get_clock_ts64() for PTP, which contains a temporary CLOCK_AUX* workaround. That was created to allow integration of depending changes into the networking tree. The workaround is going to be removed in a subsequent change in the timekeeping tree. Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2 parents 7b95663 + 5b605db commit a6d9638

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

include/linux/timekeeping.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern void ktime_get_ts64(struct timespec64 *ts);
4444
extern void ktime_get_real_ts64(struct timespec64 *tv);
4545
extern void ktime_get_coarse_ts64(struct timespec64 *ts);
4646
extern void ktime_get_coarse_real_ts64(struct timespec64 *ts);
47+
extern void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts);
4748

4849
/* Multigrain timestamp interfaces */
4950
extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts);
@@ -356,4 +357,13 @@ void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock,
356357
extern int update_persistent_clock64(struct timespec64 now);
357358
#endif
358359

360+
/* Temporary workaround to avoid merge dependencies and cross tree messes */
361+
#ifndef CLOCK_AUX
362+
#define CLOCK_AUX MAX_CLOCKS
363+
#define MAX_AUX_CLOCKS 8
364+
#define CLOCK_AUX_LAST (CLOCK_AUX + MAX_AUX_CLOCKS - 1)
365+
366+
static inline bool ktime_get_aux_ts64(clockid_t id, struct timespec64 *kt) { return false; }
367+
#endif
368+
359369
#endif

kernel/time/timekeeping.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,40 @@ void ktime_get_raw_ts64(struct timespec64 *ts)
16401640
}
16411641
EXPORT_SYMBOL(ktime_get_raw_ts64);
16421642

1643+
/**
1644+
* ktime_get_clock_ts64 - Returns time of a clock in a timespec
1645+
* @id: POSIX clock ID of the clock to read
1646+
* @ts: Pointer to the timespec64 to be set
1647+
*
1648+
* The timestamp is invalidated (@ts->sec is set to -1) if the
1649+
* clock @id is not available.
1650+
*/
1651+
void ktime_get_clock_ts64(clockid_t id, struct timespec64 *ts)
1652+
{
1653+
/* Invalidate time stamp */
1654+
ts->tv_sec = -1;
1655+
ts->tv_nsec = 0;
1656+
1657+
switch (id) {
1658+
case CLOCK_REALTIME:
1659+
ktime_get_real_ts64(ts);
1660+
return;
1661+
case CLOCK_MONOTONIC:
1662+
ktime_get_ts64(ts);
1663+
return;
1664+
case CLOCK_MONOTONIC_RAW:
1665+
ktime_get_raw_ts64(ts);
1666+
return;
1667+
case CLOCK_AUX ... CLOCK_AUX_LAST:
1668+
if (IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS))
1669+
ktime_get_aux_ts64(id, ts);
1670+
return;
1671+
default:
1672+
WARN_ON_ONCE(1);
1673+
}
1674+
}
1675+
EXPORT_SYMBOL_GPL(ktime_get_clock_ts64);
1676+
16431677
/**
16441678
* timekeeping_valid_for_hres - Check if timekeeping is suitable for hres
16451679
*/

0 commit comments

Comments
 (0)