Skip to content

Commit

Permalink
examples/ptp: replace terms master and slave
Browse files Browse the repository at this point in the history
Remove one of the few remaining uses of master/slave.

The IEEE 1588 standard has been updated to remove the use
of master-slave terminology. Change the sample to Use the terms
recommended by IEEE 1588g-2022 amendment.

  In place of the term “master”, use the term “timeTransmitter”.
  In place of the term “slave”, use the term “timeReceiver”.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
  • Loading branch information
shemminger authored and tmonjalo committed Nov 13, 2024
1 parent c5df7a3 commit b8d1d60
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
7 changes: 4 additions & 3 deletions doc/guides/nics/bnxt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,11 @@ Time Synchronization
~~~~~~~~~~~~~~~~~~~~

System operators may run a PTP (Precision Time Protocol) client application to
synchronize the time on the NIC (and optionally, on the system) to a PTP master.
synchronize the time on the NIC (and optionally, on the system) to a PTP time transmitter.

The BNXT PMD supports a PTP client application to communicate with a PTP master
clock using DPDK IEEE1588 APIs. Note that the PTP client application needs to
The BNXT PMD supports a PTP client application to communicate with a PTP time transmitter
using DPDK IEEE1588 APIs.
Note that the PTP client application needs to
run on PF and vector mode needs to be disabled.

.. code-block:: console
Expand Down
4 changes: 2 additions & 2 deletions doc/guides/sample_app_ug/img/ptpclient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/guides/sample_app_ug/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ examples are highlighted below.
* :doc:`Precision Time Protocol (PTP) client<ptpclient>`: The PTP
client is another minimal implementation of a real world application.
In this case the application is a PTP client that communicates with a PTP
master clock to synchronize time on a Network Interface Card (NIC) using the
time transmitter to synchronize time on a Network Interface Card (NIC) using the
IEEE1588 protocol.

* :doc:`Quality of Service (QoS) Scheduler<qos_scheduler>`: The QoS
Expand Down
31 changes: 16 additions & 15 deletions doc/guides/sample_app_ug/ptpclient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PTP Client Sample Application
=============================

The PTP (Precision Time Protocol) client sample application is a simple
example of using the DPDK IEEE1588 API to communicate with a PTP master clock
example of using the DPDK IEEE1588 API to communicate with a PTP time transmitter
to synchronize the time on the NIC and, optionally, on the Linux system.

Note, PTP is a time syncing protocol and cannot be used within DPDK as a
Expand All @@ -21,10 +21,10 @@ The PTP sample application is intended as a simple reference implementation of
a PTP client using the DPDK IEEE1588 API.
In order to keep the application simple the following assumptions are made:

* The first discovered master is the main for the session.
* The first discovered time transmitter is the main for the session.
* Only L2 PTP packets are supported.
* Only the PTP v2 protocol is supported.
* Only the slave clock is implemented.
* Only the time receiver clock is implemented.


How the Application Works
Expand All @@ -38,12 +38,12 @@ How the Application Works

The PTP synchronization in the sample application works as follows:

* Master sends *Sync* message - the slave saves it as T2.
* Master sends *Follow Up* message and sends time of T1.
* Slave sends *Delay Request* frame to PTP Master and stores T3.
* Master sends *Delay Response* T4 time which is time of received T3.
* Time transmitter sends *Sync* message - the time receiver saves it as T2.
* Time transmitter sends *Follow Up* message and sends time of T1.
* Time receiver sends *Delay Request* frame to PTP time transmitter and stores T3.
* Time transmitter sends *Delay Response* T4 time which is time of received T3.

The adjustment for slave can be represented as:
The adjustment for time receiver can be represented as:

adj = -[(T2-T1)-(T4 - T3)]/2

Expand Down Expand Up @@ -77,15 +77,15 @@ Refer to *DPDK Getting Started Guide* for general information on running
applications and the Environment Abstraction Layer (EAL) options.

* ``-p portmask``: Hexadecimal portmask.
* ``-T 0``: Update only the PTP slave clock.
* ``-T 1``: Update the PTP slave clock and synchronize the Linux Kernel to the PTP clock.
* ``-T 0``: Update only the PTP time receiver clock.
* ``-T 1``: Update the PTP time receiver clock and synchronize the Linux Kernel to the PTP clock.
* ``-c 0``: Not used clock servo controller.
* ``-c 1``: The clock servo PI controller is used and the log will print information
about "master offset".
about time transmitter offset.
Note that the PMD needs to support the ``rte_eth_timesync_adjust_freq()`` API
to enable the servo controller.

Also, by adding ``-T 1`` and ``-c 1``, the ``master offset`` value printed in the log
Also, by adding ``-T 1`` and ``-c 1``, the time transmitter offset value printed in the log
will slowly converge and eventually stabilise at the nanosecond level.
The synchronisation accuracy is much higher compared to not using a servo controller.

Expand Down Expand Up @@ -193,7 +193,7 @@ The forwarding loop can be interrupted and the application closed using
PTP parsing
~~~~~~~~~~~

The ``parse_ptp_frames()`` function processes PTP packets, implementing slave
The ``parse_ptp_frames()`` function processes PTP packets, implementing time receiver
PTP IEEE1588 L2 functionality.

.. literalinclude:: ../../../examples/ptpclient/ptpclient.c
Expand All @@ -202,11 +202,12 @@ PTP IEEE1588 L2 functionality.
:end-before: >8 End of function processes PTP packets.

There are 3 types of packets on the RX path which we must parse to create a minimal
implementation of the PTP slave client:
implementation of the PTP time receiver client:

* SYNC packet.
* FOLLOW UP packet
* DELAY RESPONSE packet.

When we parse the *FOLLOW UP* packet we also create and send a *DELAY_REQUEST* packet.
Also when we parse the *DELAY RESPONSE* packet, and all conditions are met we adjust the PTP slave clock.
Also when we parse the *DELAY RESPONSE* packet, and all conditions are met
we adjust the PTP time receiver clock.
60 changes: 30 additions & 30 deletions examples/ptpclient/ptpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ struct ptp_message {
} __rte_packed;
};

struct ptpv2_data_slave_ordinary {
struct ptpv2_time_receiver_ordinary {
struct rte_mbuf *m;
struct timespec tstamp1;
struct timespec tstamp2;
struct timespec tstamp3;
struct timespec tstamp4;
struct clock_id client_clock_id;
struct clock_id master_clock_id;
struct clock_id transmitter_clock_id;
struct timeval new_adj;
int64_t delta;
uint16_t portid;
Expand All @@ -169,7 +169,7 @@ struct ptpv2_data_slave_ordinary {
struct pi_servo *servo;
};

static struct ptpv2_data_slave_ordinary ptp_data;
static struct ptpv2_time_receiver_ordinary ptp_data;

static inline uint64_t timespec64_to_ns(const struct timespec *ts)
{
Expand Down Expand Up @@ -311,39 +311,39 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool)
}

static void
print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data)
print_clock_info(struct ptpv2_time_receiver_ordinary *ptp_data)
{
int64_t nsec;
struct timespec net_time, sys_time;

printf("Master Clock id: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
ptp_data->master_clock_id.id[0],
ptp_data->master_clock_id.id[1],
ptp_data->master_clock_id.id[2],
ptp_data->master_clock_id.id[3],
ptp_data->master_clock_id.id[4],
ptp_data->master_clock_id.id[5],
ptp_data->master_clock_id.id[6],
ptp_data->master_clock_id.id[7]);

printf("\nT2 - Slave Clock. %lds %ldns",
printf("time transmitter clock id: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
ptp_data->transmitter_clock_id.id[0],
ptp_data->transmitter_clock_id.id[1],
ptp_data->transmitter_clock_id.id[2],
ptp_data->transmitter_clock_id.id[3],
ptp_data->transmitter_clock_id.id[4],
ptp_data->transmitter_clock_id.id[5],
ptp_data->transmitter_clock_id.id[6],
ptp_data->transmitter_clock_id.id[7]);

printf("\nT2 - time receiver clock. %lds %ldns",
(ptp_data->tstamp2.tv_sec),
(ptp_data->tstamp2.tv_nsec));

printf("\nT1 - Master Clock. %lds %ldns ",
printf("\nT1 - time transmitter clock. %lds %ldns ",
ptp_data->tstamp1.tv_sec,
(ptp_data->tstamp1.tv_nsec));

printf("\nT3 - Slave Clock. %lds %ldns",
printf("\nT3 - time receiver clock. %lds %ldns",
ptp_data->tstamp3.tv_sec,
(ptp_data->tstamp3.tv_nsec));

printf("\nT4 - Master Clock. %lds %ldns\n",
printf("\nT4 - time transmitter clock. %lds %ldns\n",
ptp_data->tstamp4.tv_sec,
(ptp_data->tstamp4.tv_nsec));

if (mode == MODE_NONE) {
printf("\nDelta between master and slave clocks:%"PRId64"ns\n",
printf("\nDelta between transmitter and receiver clocks:%"PRId64"ns\n",
ptp_data->delta);

clock_gettime(CLOCK_REALTIME, &sys_time);
Expand Down Expand Up @@ -374,7 +374,7 @@ print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data)

if (mode == MODE_PI) {
printf("path delay: %"PRId64"ns\n", ptp_data->path_delay);
printf("master offset: %"PRId64"ns\n", ptp_data->master_offset);
printf("time transmitter offset: %"PRId64"ns\n", ptp_data->master_offset);
}

printf("[Ctrl+C to quit]\n");
Expand All @@ -384,7 +384,7 @@ print_clock_info(struct ptpv2_data_slave_ordinary *ptp_data)
}

static int64_t
delta_eval(struct ptpv2_data_slave_ordinary *ptp_data)
delta_eval(struct ptpv2_time_receiver_ordinary *ptp_data)
{
int64_t delta;
uint64_t t1 = 0;
Expand All @@ -406,7 +406,7 @@ delta_eval(struct ptpv2_data_slave_ordinary *ptp_data)
* Parse the PTP SYNC message.
*/
static void
parse_sync(struct ptpv2_data_slave_ordinary *ptp_data, uint16_t rx_tstamp_idx)
parse_sync(struct ptpv2_time_receiver_ordinary *ptp_data, uint16_t rx_tstamp_idx)
{
struct ptp_header *ptp_hdr;

Expand All @@ -415,7 +415,7 @@ parse_sync(struct ptpv2_data_slave_ordinary *ptp_data, uint16_t rx_tstamp_idx)
ptp_data->seqID_SYNC = rte_be_to_cpu_16(ptp_hdr->seq_id);

if (ptp_data->ptpset == 0) {
rte_memcpy(&ptp_data->master_clock_id,
rte_memcpy(&ptp_data->transmitter_clock_id,
&ptp_hdr->source_port_id.clock_id,
sizeof(struct clock_id));
ptp_data->ptpset = 1;
Expand All @@ -436,7 +436,7 @@ parse_sync(struct ptpv2_data_slave_ordinary *ptp_data, uint16_t rx_tstamp_idx)
* Parse the PTP FOLLOWUP message and send DELAY_REQ to the main clock.
*/
static void
parse_fup(struct ptpv2_data_slave_ordinary *ptp_data)
parse_fup(struct ptpv2_time_receiver_ordinary *ptp_data)
{
struct rte_ether_hdr *eth_hdr;
struct rte_ether_addr eth_addr;
Expand All @@ -455,7 +455,7 @@ parse_fup(struct ptpv2_data_slave_ordinary *ptp_data)
eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
ptp_hdr = rte_pktmbuf_mtod_offset(m, struct ptp_header *,
sizeof(struct rte_ether_hdr));
if (memcmp(&ptp_data->master_clock_id,
if (memcmp(&ptp_data->transmitter_clock_id,
&ptp_hdr->source_port_id.clock_id,
sizeof(struct clock_id)) != 0)
return;
Expand Down Expand Up @@ -583,7 +583,7 @@ update_kernel_time(void)
}

static void
clock_path_delay(struct ptpv2_data_slave_ordinary *ptp_data)
clock_path_delay(struct ptpv2_time_receiver_ordinary *ptp_data)
{
uint64_t t1_ns, t2_ns, t3_ns, t4_ns;
int64_t pd, diff;
Expand Down Expand Up @@ -692,7 +692,7 @@ pi_sample(struct pi_servo *s, int64_t offset, double local_ts,
}

static void
ptp_adjust_servo(struct ptpv2_data_slave_ordinary *ptp_data)
ptp_adjust_servo(struct ptpv2_time_receiver_ordinary *ptp_data)
{
uint64_t t1_ns, t2_ns;
double adj_freq;
Expand Down Expand Up @@ -729,7 +729,7 @@ ptp_adjust_servo(struct ptpv2_data_slave_ordinary *ptp_data)
* Parse the DELAY_RESP message.
*/
static void
parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data)
parse_drsp(struct ptpv2_time_receiver_ordinary *ptp_data)
{
struct rte_mbuf *m = ptp_data->m;
struct ptp_message *ptp_msg;
Expand Down Expand Up @@ -772,7 +772,7 @@ parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data)
}
}

/* This function processes PTP packets, implementing slave PTP IEEE1588 L2
/* This function processes PTP packets, implementing time receiver PTP IEEE1588 L2
* functionality.
*/

Expand Down Expand Up @@ -1007,7 +1007,7 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
/* >8 End of initialization of EAL. */

memset(&ptp_data, '\0', sizeof(struct ptpv2_data_slave_ordinary));
memset(&ptp_data, 0, sizeof(struct ptpv2_time_receiver_ordinary));

/* Parse specific arguments. 8< */
argc -= ret;
Expand Down

0 comments on commit b8d1d60

Please sign in to comment.