History

ptp: add ability to configure duty cycle for periodic output

There are external event timestampers (PHCs with support for PTP_EXTTS_REQUEST) that timestamp both event edges. When those edges are very close (such as in the case of a short pulse), there is a chance that the collected timestamp might be of the rising, or of the falling edge, we never know. There are also PHCs capable of generating periodic output with a configurable duty cycle. This is good news, because we can space the rising and falling edge out enough in time, that the risks to overrun the 1-entry timestamp FIFO of the extts PHC are lower (example: the perout PHC can be configured for a period of 1 second, and an "on" time of 0.5 seconds, resulting in a duty cycle of 50%). A flag is introduced for signaling that an on time is present in the perout request structure, for preserving compatibility. Logically speaking, the duty cycle cannot exceed 100% and the PTP core checks for this. PHC drivers that don't support this flag emit a periodic output of an unspecified duty cycle, same as before. The duty cycle is encoded as an "on" time, similar to the "start" and "period" times, and reuses the reserved space while preserving overall binary layout. Pahole reported before: struct ptp_perout_request { struct ptp_clock_time start; /* 0 16 */ struct ptp_clock_time period; /* 16 16 */ unsigned int index; /* 32 4 */ unsigned int flags; /* 36 4 */ unsigned int rsv[4]; /* 40 16 */ /* size: 56, cachelines: 1, members: 5 */ /* last cacheline: 56 bytes */ }; And now: struct ptp_perout_request { struct ptp_clock_time start; /* 0 16 */ struct ptp_clock_time period; /* 16 16 */ unsigned int index; /* 32 4 */ unsigned int flags; /* 36 4 */ union { struct ptp_clock_time on; /* 40 16 */ unsigned int rsv[4]; /* 40 16 */ }; /* 40 16 */ /* size: 56, cachelines: 1, members: 5 */ /* last cacheline: 56 bytes */ };

Vladimir Oltean committed 6 years ago

Commit f65b71a1 parent eba75c52 files · +41 −9Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/ptp_clock.h+14−3
@@ -53,12 +53,14 @@ · 52 unmodified lines
5353 /*
5454 * Bits of the ptp_perout_request.flags field:
5555 */
56−#define PTP_PEROUT_ONE_SHOT (1<<0)
56+#define PTP_PEROUT_ONE_SHOT (1<<0)
57+#define PTP_PEROUT_DUTY_CYCLE (1<<1)
5758
5859 /*
5960 * flag fields valid for the new PTP_PEROUT_REQUEST2 ioctl.
6061 */
61−#define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT)
62+#define PTP_PEROUT_VALID_FLAGS (PTP_PEROUT_ONE_SHOT | \
63+ PTP_PEROUT_DUTY_CYCLE)
6264
6365 /*
6466 * No flags are valid for the original PTP_PEROUT_REQUEST ioctl
@@ -105,7 +107,16 @@ struct ptp_perout_request { · 40 unmodified lines
105107 struct ptp_clock_time period; /* Desired period, zero means disable. */
106108 unsigned int index; /* Which channel to configure. */
107109 unsigned int flags;
108− unsigned int rsv[4]; /* Reserved for future use. */
110+ union {
111+ /*
112+ * The "on" time of the signal.
113+ * Must be lower than the period.
114+ * Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set.
115+ */
116+ struct ptp_clock_time on;
117+ /* Reserved for future use. */
118+ unsigned int rsv[4];
119+ };
109120 };
110121
111122 #define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */