15 minutes timer is added for pm cycle.

Signed-off-by: Anders Selhammer <anders.selham...@est.tech>
---
 clock.c | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/clock.c b/clock.c
index ee5f855..7e92958 100644
--- a/clock.c
+++ b/clock.c
@@ -125,6 +125,7 @@ struct clock {
        LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
        /* performance monitoring */
        int performance_monitoring;
+       int pm_fd;
        struct pm_clock_stats pm_stats_record;
 };
 
@@ -144,6 +145,16 @@ int clock_performance_monitoring(struct clock *c)
        return c->performance_monitoring;
 }
 
+static int clock_set_pm_tmo(struct clock *c)
+{
+       return set_tmo_lin(c->pm_fd, PM_15M_TIMER);
+}
+
+static int clock_clr_tmo(int fd)
+{
+       return set_tmo_lin(fd, 0);
+}
+
 static void clock_set_pmtime(struct clock *c)
 {
        struct timespec now;
@@ -291,6 +302,8 @@ void clock_destroy(struct clock *c)
                clock_remove_port(c, p);
        }
        port_close(c->uds_port);
+       clock_clr_tmo(c->pm_fd);
+       close(c->pm_fd);
        free(c->pollfd);
        if (c->clkid != CLOCK_REALTIME) {
                phc_close(c->clkid);
@@ -1124,6 +1137,11 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
                return NULL;
        }
 
+       c->pm_fd = timerfd_create(CLOCK_MONOTONIC, 0);
+       if (c->pm_fd < 0) {
+               pr_err("timerfd_create failed: %m");
+               return NULL;
+       }
        if (pm_create_clock_stats(&c->pm_stats_record)) {
                pr_err("failed to create pm clock stats");
                return NULL;
@@ -1153,6 +1171,7 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
        port_dispatch(c->uds_port, EV_INITIALIZE, 0);
 
        if (c->performance_monitoring) {
+               clock_set_pm_tmo(c);
                clock_set_pmtime(c);
        }
 
@@ -1220,9 +1239,10 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports)
 {
        struct pollfd *new_pollfd;
 
-       /* Need to allocate one whole extra block of fds for UDS. */
+       /* Need to allocate one extra fd for pm and one whole extra block
+        * of fds for UDS. */
        new_pollfd = realloc(c->pollfd,
-                            (new_nports + 1) * N_CLOCK_PFD *
+                            (1 + (new_nports + 1) * N_CLOCK_PFD) *
                             sizeof(struct pollfd));
        if (!new_pollfd) {
                return -1;
@@ -1231,7 +1251,7 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports)
        return 0;
 }
 
-static void clock_fill_pollfd(struct pollfd *dest, struct port *p)
+static void clock_fill_port_pollfd(struct pollfd *dest, struct port *p)
 {
        struct fdarray *fda;
        int i;
@@ -1245,6 +1265,12 @@ static void clock_fill_pollfd(struct pollfd *dest, 
struct port *p)
        dest[i].events = POLLIN|POLLPRI;
 }
 
+static void clock_fill_pm_pollfd(struct pollfd *dest, struct clock *c)
+{
+       dest[0].fd = c->pm_fd;
+       dest[0].events = POLLIN|POLLPRI;
+}
+
 static void clock_check_pollfd(struct clock *c)
 {
        struct port *p;
@@ -1254,10 +1280,12 @@ static void clock_check_pollfd(struct clock *c)
                return;
        }
        LIST_FOREACH(p, &c->ports, list) {
-               clock_fill_pollfd(dest, p);
+               clock_fill_port_pollfd(dest, p);
                dest += N_CLOCK_PFD;
        }
-       clock_fill_pollfd(dest, c->uds_port);
+       clock_fill_port_pollfd(dest, c->uds_port);
+       dest += N_CLOCK_PFD;
+       clock_fill_pm_pollfd(dest, c);
        c->pollfd_valid = 1;
 }
 
@@ -1486,7 +1514,7 @@ int clock_poll(struct clock *c)
        struct port *p;
 
        clock_check_pollfd(c);
-       cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1);
+       cnt = poll(c->pollfd, 1 + (c->nports + 1) * N_CLOCK_PFD, -1);
        if (cnt < 0) {
                if (EINTR == errno) {
                        return 0;
@@ -1543,6 +1571,12 @@ int clock_poll(struct clock *c)
                        }
                }
        }
+       cur += N_CLOCK_PFD;
+
+       /* Check the pm timer. */
+       if (cur[0].revents & (POLLIN|POLLPRI)) {
+               ;
+       }
 
        if (c->sde) {
                handle_state_decision_event(c);
-- 
1.8.3.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to