Skip to content

Commit

Permalink
- Added QNX support:
Browse files Browse the repository at this point in the history
  - clean build on QNX 6.5 out of the box  
  - adjfreq emulation using native ClockAdjust
  - binding to CPU cores
  - Experimental (but yield best results):
    * interpolated getTime attached to IRQ0
    * RX/TX timestamps in software on send or receive,
      bypassing pcap or socket timestampint
- implemented unicast negotiation port mask:
  when a node sends signaling and other messages
  from a different port number, mask is ORed onto it
- UDP checksums disabled on Linux by default:
  enables interop with TCs that don't correct checksums
- added options to accept timing from any GMs when
  using negotiation: allows a mix of signaling and
  non-signaling GMs
- support for systems without getopt_long (like QNX)
- adjfreq-like behaviour on systems with adjtime only:
  properly scaled adjtime() pulled into PI servo
  (vastly improved sync on systems like OpenBSD and OSX),
  support for drift file for those systems
- critical: added minimum POSIX timer interval to prevent from
  timers firing to quickly for the process to handle,
  resulting in 100% CPU and endless signal queue
- improved processing of unicast destination, domain
  and local preference lists
- CPU affinity setting moved to a separate function
- fixed incorrect PTP_UNICAST flag setting for multicast
- fixed missing management or signalling message acceptance
  condition (clockid==clockid, portid=0xffff): ISPCS 2015 plugfest
- signaling.c: fixed order of grant processing for PTP messages
  (ann,syn,fup,dresp,pdelayresp) instead of numeric loop,
  to assist with interop where transmission request order
  makes a difference to the master
- signaling.c: do not reset known clock ID when changing GMs,
  to allow to keep accepting announce from other masters
- signaling.c: update unicast index when transport address
  match only: fix for cache misses for non-best masters
  • Loading branch information
wowczarek committed Oct 12, 2015
1 parent 675c818 commit 1f0baae
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 229 deletions.
41 changes: 40 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2013-09-22 Wojciech Owczarek <wojciech@owczarek.co.uk>
2013-10-12 Wojciech Owczarek <wojciech@owczarek.co.uk>

* 2.3.1.1 minor / bugfix release

Expand All @@ -21,6 +21,45 @@
- added Sequence ID to statistics log
- Solaris build fixes - linking lnsl and lsocket when
building without SNMP support
- critical: added minimum POSIX timer interval to prevent from
timers firing to quickly for the process to handle,
resulting in 100% CPU and endless signal queue
- improved processing of unicast destination, domain
and local preference lists
- CPU affinity setting moved to a separate function
- fixed incorrect PTP_UNICAST flag setting for multicast
- fixed missing management or signalling message acceptance
condition (clockid==clockid, portid=0xffff): ISPCS 2015 plugfest
- signaling.c: fixed order of grant processing for PTP messages
(ann,syn,fup,dresp,pdelayresp) instead of numeric loop,
to assist with interop where transmission request order
makes a difference to the master
- signaling.c: do not reset known clock ID when changing GMs,
to allow to keep accepting announce from other masters
- signaling.c: update unicast index when transport address
match only: fix for cache misses for non-best masters

* New features since 2.3.1:

- unicast port number mask to assist with nodes
using different port IDs for negotiation
- option to accept any GM when unicast negotiation
is enabled
- UDP checksums disabled on Linux by default:
enables interop with TCs that don't correct checksums
- Added QNX support:
- clean build on QNX 6.5 out of the box
- adjfreq emulation using native ClockAdjust
- binding to CPU cores
- Experimental (but yield best results):
* interpolated getTime attached to IRQ0
* RX/TX timestamps in software on send or receive,
bypassing pcap or socket timestampint
- support for systems without getopt_long (like QNX)
- adjfreq-like behaviour on systems with adjtime only:
properly scaled adjtime() pulled into PI servo
(vastly improved sync on systems like OpenBSD and OSX),
support for drift file for those systems

2013-06-10 Wojciech Owczarek <wojciech@owczarek.co.uk>

Expand Down
24 changes: 21 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ AC_SEARCH_LIBS([gethostbyname], [nsl])
# Checks for header files.
AC_HEADER_STDC

AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h net/ethernet.h netinet/in.h netinet/in_systm.h netinet/ether.h sys/uio.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/sockio.h ifaddrs.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h linux/rtc.h sys/timex.h])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h net/ethernet.h netinet/in.h netinet/in_systm.h netinet/ether.h sys/uio.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/sockio.h ifaddrs.h sys/time.h syslog.h unistd.h glob.h sched.h utmp.h utmpx.h unix.h linux/rtc.h sys/timex.h getopt.h])

AC_CHECK_HEADERS([endian.h machine/endian.h sys/isa_defs.h])

Expand Down Expand Up @@ -174,6 +174,11 @@ m4_version_prereq(2.60,[
)

# Check for tick in the timex structure
AC_CHECK_MEMBERS([struct utmp.ut_time], [], [], [
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif
])
AC_CHECK_MEMBERS([struct timex.tick], [], [], [[#include <sys/timex.h>]])
AC_CHECK_MEMBERS([struct timex.tai], [], [], [[#include <sys/timex.h>]])
AC_CHECK_MEMBERS([struct ntptimeval.tai], [], [],
Expand Down Expand Up @@ -206,15 +211,28 @@ AC_CHECK_MEMBERS([struct ether_addr.octet], [], [],
#endif
])

# Checks for library functions.
# Checks for library functions
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([clock_gettime dup2 ftruncate gethostbyname2 gettimeofday inet_ntoa memset pow select socket strchr strdup strerror strtol glob pututline utmpxname updwtmpx setutent endutent signal ntp_gettime])
AC_CHECK_FUNCS([clock_gettime dup2 ftruncate gethostbyname2 gettimeofday inet_ntoa memset pow select socket strchr strdup strerror strtol glob pututline utmpxname updwtmpx setutent endutent signal ntp_gettime getopt_long])

if test -n "$GCC"; then
AC_MSG_CHECKING(if GCC -fstack-protector is usable)
OLDCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fstack-protector"
AC_TRY_LINK(,,[
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
CFLAGS="$OLDCFLAGS"
])
fi


AC_MSG_NOTICE([************************************************************])
AC_MSG_NOTICE([* PTPD BUILD FLAG AND LIBRARY DEPENDENCY CHECKS START HERE *])
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lib_LTLIBRARIES = $(LIBPTPD2_LIBS_LA)
sbin_PROGRAMS = ptpd2
man_MANS = ptpd2.8 ptpd2.conf.5

AM_CFLAGS = $(SNMP_CFLAGS) $(PCAP_CFLAGS) -Wall -fexceptions -fstack-protector
AM_CFLAGS = $(SNMP_CFLAGS) $(PCAP_CFLAGS) -Wall -fexceptions
AM_CPPFLAGS = $(SNMP_CPPFLAGS) $(PCAP_CPPFLAGS)
AM_LDFLAGS = $(SNMP_LIBS) $(PCAP_LIBS)

Expand Down
4 changes: 3 additions & 1 deletion src/bmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ bmcStateDecision(MsgHeader *header, MsgAnnounce *announce, UInteger8 localPrefer
s1(header,announce,ptpClock, rtOpts);
if(rtOpts->unicastNegotiation) {
ptpClock->parentGrants = findUnicastGrants(&ptpClock->parentPortIdentity, 0,
ptpClock->unicastGrants, ptpClock->unicastGrantIndex, ptpClock->unicastDestinationCount ,
ptpClock->unicastGrants, &ptpClock->grantIndex, ptpClock->unicastDestinationCount ,
FALSE);
}
if (newBM) {
Expand Down Expand Up @@ -658,6 +658,7 @@ bmcStateDecision(MsgHeader *header, MsgAnnounce *announce, UInteger8 localPrefer
} else if (comp > 0) {
s1(header,announce,ptpClock, rtOpts);
if (newBM) {
ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
displayPortIdentity(&header->sourcePortIdentity,
"New best master selected:");
ptpClock->counters.masterChanges++;
Expand All @@ -679,6 +680,7 @@ bmcStateDecision(MsgHeader *header, MsgAnnounce *announce, UInteger8 localPrefer
"New best master selected:");
ptpClock->counters.masterChanges++;
if(ptpClock->portState == PTP_SLAVE)
ptpClock->masterAddr = ptpClock->netPath.lastSourceAddr;
displayStatus(ptpClock, "State: ");
if(rtOpts->calibrationDelay) {
ptpClock->isCalibrated = FALSE;
Expand Down
27 changes: 27 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,31 @@ enum {
ACKNOWLEDGE
};

/* Enterprise Profile TLV definitions */

#define IETF_OUI 0x000005
#define IETF_PROFILE 0x01

/* phase adjustment units */

enum {

PHASEADJ_UNKNOWN = 0x00,
PHASEADJ_S = 0x01, /* seconds */
PHASEADJ_MS = 0x03, /* milliseconds */
PHASEADJ_US = 0x06, /* microsecondas*/
PHASEADJ_NS = 0x09, /* nanoseconds */
PHASEADJ_PS = 0x12, /* picoseconds */
PHASEADJ_FS = 0x15, /* femtoseconds */

/* coming soon to a GM near you */

PHASEADJ_AS = 0x18, /* attoseconds (haha) */
PHASEADJ_ZS = 0x21, /* zeptoseconds (schwiiing!) */
PHASEADJ_YS = 0x24 /* yoctoseconds (I AM GOD) */

};

/**
* \brief flagField1 bit position values (Table 20 in the spec)
*/
Expand Down Expand Up @@ -328,6 +353,8 @@ enum {
PTP_MAX_MESSAGE
};

#define PTP_MESSAGETYPE_COUNT 10

/* communication technology */
enum {
PTP_ETHER, PTP_DEFAULT
Expand Down
21 changes: 19 additions & 2 deletions src/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ struct UnicastGrantTable {
TimeInternal lastSyncTimestamp; /* last Sync message timestamp sent */
};

/* Unicast index holder: data + port mask */
typedef struct {
UnicastGrantTable* data[UNICAST_MAX_DESTINATIONS];
UInteger16 portMask;
} UnicastGrantIndex;

/* Unicast destination configuration: Address, domain, preference, last Sync timestamp sent */
typedef struct {
Integer32 transportAddress; /* destination address */
Expand All @@ -677,6 +683,8 @@ typedef struct {
TimeInternal lastSyncTimestamp; /* last Sync timestamp sent */
} UnicastDestination;



typedef struct {
Integer32 transportAddress;
} SyncDestEntry;
Expand Down Expand Up @@ -766,7 +774,7 @@ typedef struct {
/* unicast grant table - our own grants or our slaves' grants or grants to peers */
UnicastGrantTable unicastGrants[UNICAST_MAX_DESTINATIONS];
/* our trivial index table to speed up lookups */
UnicastGrantTable* unicastGrantIndex[UNICAST_MAX_DESTINATIONS];
UnicastGrantIndex grantIndex;
/* current parent from the above table */
UnicastGrantTable *parentGrants;
/* previous parent's grants when changing parents: if not null, this is what should be canceled */
Expand Down Expand Up @@ -1040,7 +1048,7 @@ typedef struct {

int ttl;
int dscpValue;
#if (defined(linux) && defined(HAVE_SCHED_H)) || defined(HAVE_SYS_CPUSET_H)
#if (defined(linux) && defined(HAVE_SCHED_H)) || defined(HAVE_SYS_CPUSET_H) || defined (__QNXNTO__)
int cpuNumber;
#endif /* linux && HAVE_SCHED_H || HAVE_SYS_CPUSET_H*/

Expand Down Expand Up @@ -1102,6 +1110,8 @@ typedef struct {
int ipMode; /* IP transmission mode */
Boolean dot2AS; /* 801.2AS support -> transportSpecific field */

Boolean disableUdpChecksums; /* disable UDP checksum validation where supported */

/* list of unicast destinations for use with unicast with or without signaling */
char unicastDestinations[MAXHOSTNAMELEN * UNICAST_MAX_DESTINATIONS];
char unicastDomains[MAXHOSTNAMELEN * UNICAST_MAX_DESTINATIONS];
Expand All @@ -1116,6 +1126,13 @@ typedef struct {
Boolean unicastNegotiation; /* Enable unicast negotiation support */
Boolean unicastNegotiationListening; /* Master: Reply to signaling messages when in LISTENING */
Boolean disableBMCA; /* used to achieve master-only for unicast */
Boolean unicastAcceptAny; /* Slave: accept messages from all GMs, regardless of grants */
/*
* port mask to apply to portNumber when using negotiation:
* treats different port numbers as the same port ID for clocks which
* transmit signaling using one port ID, and rest of messages with another
*/
UInteger16 unicastPortMask; /* port mask to apply to portNumber when using negotiation */

#ifdef RUNTIME_DEBUG
int debug_level;
Expand Down
15 changes: 13 additions & 2 deletions src/dep/constants_dep.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/* platform dependent */

#if !defined(linux) && !defined(__NetBSD__) && !defined(__FreeBSD__) && \
!defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__sun)
!defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__sun) && !defined(__QNXNTO__)
#error PTPD hasn't been ported to this OS - should be possible \
if it's POSIX compatible, if you succeed, report it to ptpd-devel@sourceforge.net
#endif
Expand All @@ -34,7 +34,7 @@ if it's POSIX compatible, if you succeed, report it to ptpd-devel@sourceforge.ne
#define octet ether_addr_octet
#endif /* linux */

#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun)
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun) || defined(__QNXNTO__)
# include <sys/types.h>
# include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
Expand All @@ -57,6 +57,17 @@ if it's POSIX compatible, if you succeed, report it to ptpd-devel@sourceforge.ne
# define IFACE_NAME_LENGTH IF_NAMESIZE
# define NET_ADDRESS_LENGTH INET_ADDRSTRLEN

#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif /* HAVE_SYS_PARAM_H */

#ifdef __QNXNTO__
#include <sys/neutrino.h>
#include <sys/syspage.h>
#define BSD_INTERFACE_FUNCTIONS
#endif /* __QNXNTO __ */


#if !defined(ETHER_ADDR_LEN) && defined(ETHERADDRL)
# define ETHER_ADDR_LEN ETHERADDRL
#endif /* ETHER_ADDR_LEN && ETHERADDRL */
Expand Down
Loading

0 comments on commit 1f0baae

Please sign in to comment.