phc2sys: track ports

Add tracking of which ports have been added and to which clock they belong.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
master
Jiri Benc 2014-06-11 21:35:17 +02:00 committed by Richard Cochran
parent 90bbdbcfae
commit 506271acac
1 changed files with 51 additions and 0 deletions

View File

@ -75,6 +75,12 @@ struct clock {
struct clockcheck *sanity_check; struct clockcheck *sanity_check;
}; };
struct port {
LIST_ENTRY(port) list;
unsigned int number;
struct clock *clock;
};
struct node { struct node {
unsigned int stats_max_count; unsigned int stats_max_count;
int sanity_freq_limit; int sanity_freq_limit;
@ -89,6 +95,7 @@ struct node {
struct pmc *pmc; struct pmc *pmc;
int pmc_ds_requested; int pmc_ds_requested;
uint64_t pmc_last_update; uint64_t pmc_last_update;
LIST_HEAD(port_head, port) ports;
LIST_HEAD(clock_head, clock) clocks; LIST_HEAD(clock_head, clock) clocks;
struct clock *master; struct clock *master;
}; };
@ -206,6 +213,50 @@ static struct clock *clock_add(struct node *node, char *device)
return c; return c;
} }
static struct port *port_get(struct node *node, unsigned int number)
{
struct port *p;
LIST_FOREACH(p, &node->ports, list) {
if (p->number == number)
return p;
}
return NULL;
}
static struct port *port_add(struct node *node, unsigned int number,
char *device)
{
struct port *p;
struct clock *c = NULL, *tmp;
p = port_get(node, number);
if (p)
return p;
/* port is a new one, look whether we have the device already on
* a different port */
LIST_FOREACH(tmp, &node->clocks, list) {
if (!strcmp(tmp->device, device)) {
c = tmp;
break;
}
}
if (!c) {
c = clock_add(node, device);
if (!c)
return NULL;
}
p = malloc(sizeof(*p));
if (!p) {
pr_err("failed to allocate memory for a port");
return NULL;
}
p->number = number;
p->clock = c;
LIST_INSERT_HEAD(&node->ports, p, list);
return p;
}
static int read_phc(clockid_t clkid, clockid_t sysclk, int readings, static int read_phc(clockid_t clkid, clockid_t sysclk, int readings,
int64_t *offset, uint64_t *ts, int64_t *delay) int64_t *offset, uint64_t *ts, int64_t *delay)
{ {