phc2sys: move phc loop to its own function.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2013-01-14 17:09:13 +01:00 committed by Richard Cochran
parent 627bc0fdf7
commit 2d4b2f1640
1 changed files with 21 additions and 13 deletions

View File

@ -227,6 +227,25 @@ static int do_sysoff_loop(struct clock *clock, clockid_t src,
return err; return err;
} }
static int do_phc_loop(struct clock *clock, clockid_t src,
int rate, int n_readings, int sync_offset)
{
uint64_t ts;
int64_t offset;
clock->source_label = "phc";
while (1) {
usleep(1000000 / rate);
if (!read_phc(src, clock->clkid, n_readings, &offset, &ts)) {
continue;
}
offset -= sync_offset * NS_PER_SEC;
update_clock(clock, offset, ts);
}
return 0;
}
static void usage(char *progname) static void usage(char *progname)
{ {
fprintf(stderr, fprintf(stderr,
@ -251,8 +270,6 @@ int main(int argc, char *argv[])
{ {
char *device = NULL, *progname, *ethdev = NULL; char *device = NULL, *progname, *ethdev = NULL;
clockid_t src = CLOCK_INVALID; clockid_t src = CLOCK_INVALID;
uint64_t phc_ts;
int64_t phc_offset;
int c, phc_readings = 5, phc_rate = 1, sync_offset = 0; int c, phc_readings = 5, phc_rate = 1, sync_offset = 0;
struct clock dst_clock = { struct clock dst_clock = {
.clkid = CLOCK_REALTIME, .clkid = CLOCK_REALTIME,
@ -346,15 +363,6 @@ int main(int argc, char *argv[])
return do_sysoff_loop(&dst_clock, src, phc_rate, return do_sysoff_loop(&dst_clock, src, phc_rate,
phc_readings, sync_offset); phc_readings, sync_offset);
dst_clock.source_label = "phc"; return do_phc_loop(&dst_clock, src, phc_rate,
phc_readings, sync_offset);
while (1) {
usleep(1000000 / phc_rate);
if (!read_phc(src, dst_clock.clkid, phc_readings, &phc_offset, &phc_ts)) {
continue;
}
phc_offset -= sync_offset * NS_PER_SEC;
update_clock(&dst_clock, phc_offset, phc_ts);
}
return 0;
} }