Skip to content

Commit 56e9319

Browse files
yemj-odcferruhy
authored andcommitted
ethdev: add frequency adjustment API
This patch adds freq adjustment API for PTP high accuracy. Signed-off-by: Simei Su <[email protected]> Signed-off-by: Mingjin Ye <[email protected]> Reviewed-by: Ferruh Yigit <[email protected]>
1 parent 4206226 commit 56e9319

File tree

8 files changed

+87
-1
lines changed

8 files changed

+87
-1
lines changed

doc/guides/nics/features.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,12 @@ Supports IEEE1588/802.1AS timestamping.
677677

678678
* **[implements] eth_dev_ops**: ``timesync_enable``, ``timesync_disable``
679679
``timesync_read_rx_timestamp``, ``timesync_read_tx_timestamp``,
680-
``timesync_adjust_time``, ``timesync_read_time``, ``timesync_write_time``.
680+
``timesync_adjust_time``, ``timesync_adjust_freq``,
681+
``timesync_read_time``, ``timesync_write_time``.
681682
* **[related] API**: ``rte_eth_timesync_enable()``, ``rte_eth_timesync_disable()``,
682683
``rte_eth_timesync_read_rx_timestamp()``,
683684
``rte_eth_timesync_read_tx_timestamp``, ``rte_eth_timesync_adjust_time()``,
685+
``rte_eth_timesync_adjust_freq()``,
684686
``rte_eth_timesync_read_time()``, ``rte_eth_timesync_write_time()``.
685687

686688

doc/guides/rel_notes/release_24_11.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ New Features
196196
Applications should use ``RTE_EVENT_PORT_CFG_INDEPENDENT_ENQ`` to enable
197197
the feature if the capability ``RTE_EVENT_DEV_CAP_INDEPENDENT_ENQ`` exists.
198198

199+
* **Added Ethernet device clock frequency adjustment.**
200+
201+
Added new function ``rte_eth_timesync_adjust_freq`` to adjust the clock
202+
frequency for Ethernet devices.
203+
199204
* **Updated DLB2 event driver.**
200205

201206
* Added independent enqueue feature.

lib/ethdev/ethdev_driver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ typedef int (*eth_timesync_read_tx_timestamp_t)(struct rte_eth_dev *dev,
751751
/** @internal Function used to adjust the device clock. */
752752
typedef int (*eth_timesync_adjust_time)(struct rte_eth_dev *dev, int64_t);
753753

754+
/** @internal Function used to adjust the clock frequency. */
755+
typedef int (*eth_timesync_adjust_freq)(struct rte_eth_dev *dev, int64_t);
756+
754757
/** @internal Function used to get time from the device clock. */
755758
typedef int (*eth_timesync_read_time)(struct rte_eth_dev *dev,
756759
struct timespec *timestamp);
@@ -1511,6 +1514,8 @@ struct eth_dev_ops {
15111514
eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
15121515
/** Adjust the device clock */
15131516
eth_timesync_adjust_time timesync_adjust_time;
1517+
/** Adjust the clock frequency */
1518+
eth_timesync_adjust_freq timesync_adjust_freq;
15141519
/** Get the device clock time */
15151520
eth_timesync_read_time timesync_read_time;
15161521
/** Set the device clock time */

lib/ethdev/ethdev_trace.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,15 @@ RTE_TRACE_POINT_FP(
21852185
rte_trace_point_emit_int(ret);
21862186
)
21872187

2188+
/* Called in loop in examples/ptpclient */
2189+
RTE_TRACE_POINT_FP(
2190+
rte_eth_trace_timesync_adjust_freq,
2191+
RTE_TRACE_POINT_ARGS(uint16_t port_id, int64_t ppm, int ret),
2192+
rte_trace_point_emit_u16(port_id);
2193+
rte_trace_point_emit_i64(ppm);
2194+
rte_trace_point_emit_int(ret);
2195+
)
2196+
21882197
/* Called in loop in app/test-flow-perf */
21892198
RTE_TRACE_POINT_FP(
21902199
rte_flow_trace_create,

lib/ethdev/ethdev_trace_points.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_timesync_read_tx_timestamp,
415415
RTE_TRACE_POINT_REGISTER(rte_eth_trace_timesync_adjust_time,
416416
lib.ethdev.timesync_adjust_time)
417417

418+
RTE_TRACE_POINT_REGISTER(rte_eth_trace_timesync_adjust_freq,
419+
lib.ethdev.timesync_adjust_freq)
420+
418421
RTE_TRACE_POINT_REGISTER(rte_eth_trace_timesync_read_time,
419422
lib.ethdev.timesync_read_time)
420423

lib/ethdev/rte_ethdev.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6397,6 +6397,24 @@ rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
63976397
return ret;
63986398
}
63996399

6400+
int
6401+
rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm)
6402+
{
6403+
struct rte_eth_dev *dev;
6404+
int ret;
6405+
6406+
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6407+
dev = &rte_eth_devices[port_id];
6408+
6409+
if (*dev->dev_ops->timesync_adjust_freq == NULL)
6410+
return -ENOTSUP;
6411+
ret = eth_err(port_id, (*dev->dev_ops->timesync_adjust_freq)(dev, ppm));
6412+
6413+
rte_eth_trace_timesync_adjust_freq(port_id, ppm, ret);
6414+
6415+
return ret;
6416+
}
6417+
64006418
int
64016419
rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
64026420
{

lib/ethdev/rte_ethdev.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,6 +5405,49 @@ int rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
54055405
*/
54065406
int rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta);
54075407

5408+
/**
5409+
* Adjust the clock frequency on an Ethernet device.
5410+
*
5411+
* Adjusts the base frequency by a specified percentage of ppm (parts per
5412+
* million). This is usually used in conjunction with other Ethdev timesync
5413+
* functions to synchronize the device time using the IEEE1588/802.1AS
5414+
* protocol.
5415+
*
5416+
* The clock is subject to frequency deviation and rate of change drift due to
5417+
* the environment. The upper layer APP calculates the frequency compensation
5418+
* value of the slave clock relative to the master clock via a servo algorithm
5419+
* and adjusts the device clock frequency via "rte_eth_timesync_adjust_freq()".
5420+
* Commonly used servo algorithms are pi/linreg/ntpshm, for implementation
5421+
* see: https://github.com/nxp-archive/openil_linuxptp.git.
5422+
*
5423+
* The adjustment value obtained by the servo algorithm is usually in
5424+
* ppb (parts per billion). For consistency with the kernel driver .adjfine,
5425+
* the tuning values are in ppm. Note that 1 ppb is approximately 65.536 scaled
5426+
* ppm, see Linux kernel upstream commit 1060707e3809 (‘ptp: introduce helpers
5427+
* to adjust by scaled parts per million’).
5428+
*
5429+
* In addition, the device reference frequency is usually also the stepping
5430+
* threshold for the servo algorithm, and the frequency up and down adjustment
5431+
* range is limited by the device. The device clock frequency should be
5432+
* adjusted with "rte_eth_timesync_adjust_freq()" every time the clock is
5433+
* synchronised. Also use ‘rte_eth_timesync_adjust_time()’ to update the device
5434+
* clock only if the absolute value of the master/slave clock offset is greater than
5435+
* or equal to the step threshold.
5436+
*
5437+
* @param port_id
5438+
* The port identifier of the Ethernet device.
5439+
* @param ppm
5440+
* Parts per million with 16-bit fractional field
5441+
*
5442+
* @return
5443+
* - 0: Success.
5444+
* - -ENODEV: The port ID is invalid.
5445+
* - -EIO: if device is removed.
5446+
* - -ENOTSUP: The function is not supported by the Ethernet driver.
5447+
*/
5448+
__rte_experimental
5449+
int rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm);
5450+
54085451
/**
54095452
* Read the time from the timesync clock on an Ethernet device.
54105453
*

lib/ethdev/version.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ EXPERIMENTAL {
334334
rte_eth_speed_lanes_get;
335335
rte_eth_speed_lanes_get_capability;
336336
rte_eth_speed_lanes_set;
337+
rte_eth_timesync_adjust_freq;
337338
rte_flow_async_create_by_index_with_pattern;
338339
};
339340

0 commit comments

Comments
 (0)