Signed-off-by: Dimitrios Katsaros <[email protected]>
---
clock.c | 11 +++++------
makefile | 4 ++--
phc.c | 16 ++++------------
phc.h | 7 -------
phc2sys.c | 3 ++-
5 files changed, 13 insertions(+), 28 deletions(-)
diff --git a/clock.c b/clock.c
index 56bc79b..ec3f0fd 100644
--- a/clock.c
+++ b/clock.c
@@ -43,6 +43,7 @@
#include "tsproc.h"
#include "uds.h"
#include "util.h"
+#include "posixclock.h"
#define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer
*/
#define POW2_41 ((double)(1ULL << 41))
@@ -265,9 +266,7 @@ void clock_destroy(struct clock *c)
}
port_close(c->uds_port);
free(c->pollfd);
- if (c->clkid != CLOCK_REALTIME) {
- phc_close(c->clkid);
- }
+ posix_clock_close(c->clkid);
servo_destroy(c->servo);
tsproc_destroy(c->tsproc);
stats_destroy(c->stats.offset);
@@ -1607,7 +1606,7 @@ int clock_switch_phc(struct clock *c, int phc_index)
max_adj = phc_max_adj(clkid);
if (!max_adj) {
pr_err("Switching PHC, clock is not adjustable");
- phc_close(clkid);
+ posix_clock_close(clkid);
return -1;
}
fadj = (int) clockadj_get_freq(clkid);
@@ -1615,10 +1614,10 @@ int clock_switch_phc(struct clock *c, int phc_index)
servo = servo_create(c->config, c->servo_type, -fadj, max_adj, 0);
if (!servo) {
pr_err("Switching PHC, failed to create clock servo");
- phc_close(clkid);
+ posix_clock_close(clkid);
return -1;
}
- phc_close(c->clkid);
+ posix_clock_close(c->clkid);
servo_destroy(c->servo);
c->clkid = clkid;
c->servo = servo;
diff --git a/makefile b/makefile
index dc3bf7b..a6da8b4 100644
--- a/makefile
+++ b/makefile
@@ -63,11 +63,11 @@ pmc: config.o hash.o msg.o pmc.o pmc_common.o print.o raw.o
sk.o tlv.o \
phc2sys: clockadj.o clockcheck.o config.o hash.o linreg.o msg.o ntpshm.o \
nullf.o phc.o phc2sys.o pi.o pmc_common.o print.o raw.o servo.o sk.o stats.o \
- sysoff.o tlv.o transport.o udp.o udp6.o uds.o util.o version.o
+ sysoff.o tlv.o transport.o udp.o udp6.o uds.o util.o version.o posixclock.o
hwstamp_ctl: hwstamp_ctl.o version.o
-phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
+phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
posixclock.o\
snmp4lptp: config.o hash.o msg.o pmc_common.o print.o raw.o sk.o \
snmp4lptp.o tlv.o transport.o udp.o udp6.o uds.o util.o
diff --git a/phc.c b/phc.c
index 40fa6a1..257832a 100644
--- a/phc.c
+++ b/phc.c
@@ -25,6 +25,7 @@
#include <linux/ptp_clock.h>
+#include "posixclock.h"
#include "phc.h"
/*
@@ -42,29 +43,20 @@ clockid_t phc_open(char *phc)
{
clockid_t clkid;
struct ptp_clock_caps caps;
- int fd = open(phc, O_RDWR);
- if (fd < 0)
+ clkid = posix_clock_open(phc);
+ if (clkid == CLOCK_INVALID)
return CLOCK_INVALID;
- clkid = FD_TO_CLOCKID(fd);
/* check if clkid is valid */
if (phc_get_caps(clkid, &caps)) {
- close(fd);
+ posix_clock_close(clkid);
return CLOCK_INVALID;
}
return clkid;
}
-void phc_close(clockid_t clkid)
-{
- if (clkid == CLOCK_INVALID)
- return;
-
- close(CLOCKID_TO_FD(clkid));
-}
-
static int phc_get_caps(clockid_t clkid, struct ptp_clock_caps *caps)
{
int fd = CLOCKID_TO_FD(clkid), err;
diff --git a/phc.h b/phc.h
index 154e35e..efec495 100644
--- a/phc.h
+++ b/phc.h
@@ -30,13 +30,6 @@
*/
clockid_t phc_open(char *phc);
-/**
- * Closes a PTP hardware clock device.
- *
- * @param clkid A clock ID obtained using phc_open().
- */
-void phc_close(clockid_t clkid);
-
/**
* Query the maximum frequency adjustment of a PTP hardware clock device.
*
diff --git a/phc2sys.c b/phc2sys.c
index 15f8d75..693371f 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -56,6 +56,7 @@
#include "uds.h"
#include "util.h"
#include "version.h"
+#include "posixclock.h"
#define KP 0.7
#define KI 0.3
@@ -376,7 +377,7 @@ static void clock_reinit(struct node *node, struct clock
*clock, int new_state)
if (clkid == CLOCK_INVALID)
return;
- phc_close(clock->clkid);
+ posix_clock_close(clock->clkid);
clock->clkid = clkid;
clock->phc_index = phc_index;
--
2.17.1
_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel