Skip to content

Commit

Permalink
ptp: add gettimex64() to virtual clocks.
Browse files Browse the repository at this point in the history
If the physical clock has the gettimex64() function, provide a
gettimex64() wrapper in the virtual clock to enable more accurate
and stable synchronization.

This adds support for the PTP_SYS_OFFSET_EXTENDED ioctl.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Miroslav Lichvar authored and David S. Miller committed Feb 3, 2022
1 parent f77222d commit f0067eb
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion drivers/ptp/ptp_vclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ static int ptp_vclock_gettime(struct ptp_clock_info *ptp,
return 0;
}

static int ptp_vclock_gettimex(struct ptp_clock_info *ptp,
struct timespec64 *ts,
struct ptp_system_timestamp *sts)
{
struct ptp_vclock *vclock = info_to_vclock(ptp);
struct ptp_clock *pptp = vclock->pclock;
struct timespec64 pts;
unsigned long flags;
int err;
u64 ns;

err = pptp->info->gettimex64(pptp->info, &pts, sts);
if (err)
return err;

spin_lock_irqsave(&vclock->lock, flags);
ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts));
spin_unlock_irqrestore(&vclock->lock, flags);

*ts = ns_to_timespec64(ns);

return 0;
}

static int ptp_vclock_settime(struct ptp_clock_info *ptp,
const struct timespec64 *ts)
{
Expand Down Expand Up @@ -87,7 +111,6 @@ static const struct ptp_clock_info ptp_vclock_info = {
.max_adj = 500000000,
.adjfine = ptp_vclock_adjfine,
.adjtime = ptp_vclock_adjtime,
.gettime64 = ptp_vclock_gettime,
.settime64 = ptp_vclock_settime,
.do_aux_work = ptp_vclock_refresh,
};
Expand Down Expand Up @@ -123,6 +146,10 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock)

vclock->pclock = pclock;
vclock->info = ptp_vclock_info;
if (pclock->info->gettimex64)
vclock->info.gettimex64 = ptp_vclock_gettimex;
else
vclock->info.gettime64 = ptp_vclock_gettime;
vclock->cc = ptp_vclock_cc;

snprintf(vclock->info.name, PTP_CLOCK_NAME_LEN, "ptp%d_virt",
Expand Down

0 comments on commit f0067eb

Please sign in to comment.