Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-08 Thread Richard Cochran
On Wed, Nov 07, 2018 at 04:40:50PM +0100, Dimitrios Katsaros wrote:
> I was instead checking for the clock_gettime syscall. Would that be an
> acceptable solution?

We should check for clock_adjtime() as well.

Thanks,
Richard


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-07 Thread Dimitrios Katsaros
Ah and one more clarification,

Because my device is reprisented using the POSIX interface, i do not
support the
phc_get_caps option. if I were to use the -p option to pass any clock, I
would have to
change this to something more basic, like I was doing in the posix_open
function, where
I was instead checking for the clock_gettime syscall. Would that be an
acceptable solution?

Regards,

Dimitrios

On Wed, Nov 7, 2018 at 4:07 PM Richard Cochran 
wrote:

> On Wed, Nov 07, 2018 at 03:16:22PM +0100, Dimitrios Katsaros wrote:
> > However, there is one issue for this setup to work correctly: fd clock
> > support is limited. The kernel does provide the ability to implement your
> > own POSIX clocks, but the daemons providing ptp clock support do not have
> > the ability to synchronize any system based POSIX clock, just the
> standard,
> > predefined clocks.
>
> The ptp4l program already has a command line option to specify the
> PHC.  Currently this is required to match the PHC associated with the
> network interface.  A minor change is needed to allow a different
> clock.
>
> So why not simply use the '-p' option?
>
> Initially, before we had the ethtool interfaces, this was needed to
> specify the PHC, but today the option is useless.
>
> We can change the code to relax the restrictions on the passed
> character device node path.
>
> Thanks,
> Richard
>
>
___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-07 Thread Dimitrios Katsaros
Thanks for the quick reply,

I was more afraid that changing the phc to not be expected to be in the
pattern /dev/ptp%
and to remove the phc_get_caps check would find more resistance. I can make
a new patch
with your suggestion and get back to you.

Thanks!

Dimitrios

On Wed, Nov 7, 2018 at 4:07 PM Richard Cochran 
wrote:

> On Wed, Nov 07, 2018 at 03:16:22PM +0100, Dimitrios Katsaros wrote:
> > However, there is one issue for this setup to work correctly: fd clock
> > support is limited. The kernel does provide the ability to implement your
> > own POSIX clocks, but the daemons providing ptp clock support do not have
> > the ability to synchronize any system based POSIX clock, just the
> standard,
> > predefined clocks.
>
> The ptp4l program already has a command line option to specify the
> PHC.  Currently this is required to match the PHC associated with the
> network interface.  A minor change is needed to allow a different
> clock.
>
> So why not simply use the '-p' option?
>
> Initially, before we had the ethtool interfaces, this was needed to
> specify the PHC, but today the option is useless.
>
> We can change the code to relax the restrictions on the passed
> character device node path.
>
> Thanks,
> Richard
>
>
___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-07 Thread Richard Cochran
On Wed, Nov 07, 2018 at 03:16:22PM +0100, Dimitrios Katsaros wrote:
> However, there is one issue for this setup to work correctly: fd clock
> support is limited. The kernel does provide the ability to implement your
> own POSIX clocks, but the daemons providing ptp clock support do not have
> the ability to synchronize any system based POSIX clock, just the standard,
> predefined clocks.

The ptp4l program already has a command line option to specify the
PHC.  Currently this is required to match the PHC associated with the
network interface.  A minor change is needed to allow a different
clock.

So why not simply use the '-p' option?

Initially, before we had the ethtool interfaces, this was needed to
specify the PHC, but today the option is useless.

We can change the code to relax the restrictions on the passed
character device node path.

Thanks,
Richard



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-07 Thread Dimitrios Katsaros
Hello,

I was not very descriptive with the patches, sorry about that.

I am working on a set of devices where I wish to expose custom system
clocks. Because we will be using different technologies for different
hardware setups, the goal is to develop custom clock drivers using the
POSIX interface provided by the kernel. This provides the advantage that
the components comprising the final product can be broken down into
distinct pieces that could be interchanged based on the requirements of the
system. Also, there are added advantages with having your own clock driver,
e.g. custom IOCTLS.

However, there is one issue for this setup to work correctly: fd clock
support is limited. The kernel does provide the ability to implement your
own POSIX clocks, but the daemons providing ptp clock support do not have
the ability to synchronize any system based POSIX clock, just the standard,
predefined clocks.

Thus I created this patch series. The first patch just implements basic
POSIX clock operations (open, close). The second patch integrates the clock
operations into the existing phc clock operations and the final patch adds
an additional -d parameter, where you can specify a clock device when
running in software clock mode, e.g. -d /dev/custom_clock0.

I am open to suggestions or any constructive criticism on the idea. Sorry
if I am being a bit vague but I can't get into too much detail :)

Regards,

Dimitrios

On Mon, Nov 5, 2018 at 4:06 PM Richard Cochran 
wrote:

> On Mon, Nov 05, 2018 at 12:00:40PM +0100, Dimitrios Katsaros wrote:
> > This patch adds dedicated logic for opening and closing posix clocks.
> > We will need this for adding logic to ptp4l for using clocks that
> > may not be ptp clocks.
>
> Tell us about the use case, please.
>
> Thanks,
> Richard
>
___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-05 Thread Richard Cochran
On Mon, Nov 05, 2018 at 12:00:40PM +0100, Dimitrios Katsaros wrote:
> This patch adds dedicated logic for opening and closing posix clocks.
> We will need this for adding logic to ptp4l for using clocks that
> may not be ptp clocks.

Tell us about the use case, please.

Thanks,
Richard


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 1/3] Implement POSIX interface for opening device clocks

2018-11-05 Thread Dimitrios Katsaros
This patch adds dedicated logic for opening and closing posix clocks.
We will need this for adding logic to ptp4l for using clocks that
may not be ptp clocks.

Signed-off-by: Dimitrios Katsaros 
---
 makefile |  2 +-
 missing.h| 10 +-
 posixclock.c | 51 +++
 posixclock.h | 37 +
 4 files changed, 98 insertions(+), 2 deletions(-)
 create mode 100644 posixclock.c
 create mode 100644 posixclock.h

diff --git a/makefile b/makefile
index d09a4a9..dc3bf7b 100644
--- a/makefile
+++ b/makefile
@@ -28,7 +28,7 @@ e2e_tc.o fault.o filter.o fsm.o hash.o linreg.o mave.o 
mmedian.o msg.o ntpshm.o
 nullf.o phc.o pi.o port.o port_signaling.o pqueue.o print.o ptp4l.o p2p_tc.o \
 raw.o rtnl.o servo.o sk.o stats.o tc.o telecom.o tlv.o transport.o tsproc.o \
 udp.o udp6.o uds.o unicast_client.o unicast_fsm.o unicast_service.o util.o \
-version.o
+version.o posixclock.o
 
 OBJECTS= $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o 
pmc_common.o \
  sysoff.o timemaster.o
diff --git a/missing.h b/missing.h
index 2f7adb9..8eb89db 100644
--- a/missing.h
+++ b/missing.h
@@ -44,10 +44,18 @@
 #define CLOCK_INVALID -1
 #endif
 
+#ifndef CPUCLOCK_PERTHREAD_MASK
+#define CPUCLOCK_PERTHREAD_MASK 4
+#endif
+
+#ifndef CPUCLOCK_CLOCK_MASK
+#define CPUCLOCK_CLOCK_MASK3
+#endif
+
 #define CLOCKFD 3
 #define FD_TO_CLOCKID(fd)  ((clockid_t) unsigned int) ~fd) << 3) | 
CLOCKFD))
 #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
-
+#define CLOCKFD_MASK   (CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
 #ifndef HAVE_ONESTEP_SYNC
 enum _missing_hwtstamp_tx_types {
HWTSTAMP_TX_ONESTEP_SYNC = 2,
diff --git a/posixclock.c b/posixclock.c
new file mode 100644
index 000..9861aec
--- /dev/null
+++ b/posixclock.c
@@ -0,0 +1,51 @@
+/**
+ * @file posixclock.c
+ * @note Copyright (C) 2018 Dimitrios Katsaros 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include 
+#include "missing.h"
+
+#include "posixclock.h"
+
+clockid_t posix_clock_open(const char *device_path)
+{
+   clockid_t clkid;
+   struct timespec ts;
+   int fd;
+
+   if (!device_path)
+   return CLOCK_INVALID;
+   fd = open(device_path, O_RDWR);
+   if (fd < 0)
+   return CLOCK_INVALID;
+
+   clkid = FD_TO_CLOCKID(fd);
+   /* did we actually open a clock? */
+   if (clock_gettime(clkid, )) {
+   close(fd);
+   return CLOCK_INVALID;
+   }
+   return clkid;
+}
+
+void posix_clock_close(clockid_t clkid)
+{
+   if ((clkid < 0) && (clkid & CLOCKFD_MASK) != CLOCKFD)
+   return;
+
+   close(CLOCKID_TO_FD(clkid));
+}
diff --git a/posixclock.h b/posixclock.h
new file mode 100644
index 000..11db38f
--- /dev/null
+++ b/posixclock.h
@@ -0,0 +1,37 @@
+/**
+ * @file posixclock.h
+ * @brief Wraps clock character device functionality.
+ * @note Copyright (C) 2018 Dimitrios Katsaros 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef HAVE_POSIX_CLOCK_H
+#define HAVE_POSIX_CLOCK_H
+
+#include 
+
+/**
+ * Tries to open a posix clock device using the passed device path
+ * @param devpath The clock device path.
+ */
+clockid_t posix_clock_open(const char *device_path);
+
+/**
+ * Closes a posix clock. It checks that the clock id passed is a valid clock fd
+ * @param clkid The clock identifier.
+ */
+void posix_clock_close(clockid_t clkid);
+
+#endif
-- 
2.17.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net