PHC support in ENA driver
Subsystems (4)
David Arinzon
maintainerv3 cover PHC support in ENA driver
Changes in v3:
- Resolve a compilation error
Changes in v2:
- CCd PTP maintainer
- Fixed style issues
- Fixed documentation warning
This patchset adds the support for PHC (PTP Hardware Clock) in the ENA driver. The documentation part of the patchset includes additional information, including statistics, utilization and invocation examples through the testptp utility.
David Arinzon (3):
net: ena: Add PHC support in the ENA driver
net: ena: PHC silent reset
net: ena: Add PHC documentation
.../device_drivers/ethernet/amazon/ena.rst | 78 ++++++ drivers/net/ethernet/amazon/Kconfig | 1 + drivers/net/ethernet/amazon/ena/Makefile | 2 +- .../net/ethernet/amazon/ena/ena_admin_defs.h | 63 ++++- drivers/net/ethernet/amazon/ena/ena_com.c | 247 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 83 ++++++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 102 ++++++-- drivers/net/ethernet/amazon/ena/ena_netdev.c | 28 +- drivers/net/ethernet/amazon/ena/ena_netdev.h | 4 + drivers/net/ethernet/amazon/ena/ena_phc.c | 230 ++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_phc.h | 37 +++ .../net/ethernet/amazon/ena/ena_regs_defs.h | 8 + 12 files changed, 859 insertions(+), 24 deletions(-) create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.h
Signature · 1 line
2.40.1
David Arinzon
maintainerPATCH v3 1/3 net: ena: Add PHC support in the ENA driver
The ENA driver will be extended to support the new PHC feature using ptp_clock interface [1]. this will provide timestamp reference for user space to allow measuring time offset between the PHC and the system clock in order to achieve nanosecond accuracy.
[1] - https://www.kernel.org/doc/html/latest/driver-api/ptp.html
--- drivers/net/ethernet/amazon/Kconfig | 1 + drivers/net/ethernet/amazon/ena/Makefile | 2 +- .../net/ethernet/amazon/ena/ena_admin_defs.h | 63 ++++- drivers/net/ethernet/amazon/ena/ena_com.c | 247 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 83 ++++++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 102 ++++++-- drivers/net/ethernet/amazon/ena/ena_netdev.c | 28 +- drivers/net/ethernet/amazon/ena/ena_netdev.h | 4 + drivers/net/ethernet/amazon/ena/ena_phc.c | 222 ++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_phc.h | 37 +++ .../net/ethernet/amazon/ena/ena_regs_defs.h | 8 + 11 files changed, 773 insertions(+), 24 deletions(-) create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.h
drivers/net/ethernet/amazon/Kconfig +1 -0
@@ -19,6 +19,7 @@ if NET_VENDOR_AMAZON config ENA_ETHERNET tristate "Elastic Network Adapter (ENA) support" depends on PCI_MSI && !CPU_BIG_ENDIAN + depends on PTP_1588_CLOCK_OPTIONAL select DIMLIB help This driver supports Elastic Network Adapter (ENA)"
drivers/net/ethernet/amazon/ena/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_ENA_ETHERNET) += ena.o -ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o +ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o ena_phc.o
drivers/net/ethernet/amazon/ena/ena_admin_defs.h +62 -1
111 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_com.c +247 -0
259 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_com.h +83 -0
107 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_ethtool.c +82 -20
191 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_netdev.c +26 -2
@@ -22,6 +22,8 @@#include "ena_pci_id_tbl.h" #include "ena_xdp.h" +#include "ena_phc.h" +MODULE_AUTHOR ("Amazon.com, Inc. or its affiliates" );MODULE_DESCRIPTION (DEVICE_NAME );MODULE_LICENSE ("GPL" );
@@ -2773,7 +2775,8 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pdENA_ADMIN_HOST_INFO_INTERRUPT_MODERATION_MASK |ENA_ADMIN_HOST_INFO_RX_BUF_MIRRORING_MASK |ENA_ADMIN_HOST_INFO_RSS_CONFIGURABLE_FUNCTION_KEY_MASK | -ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_MASK ; +ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_MASK | +ENA_ADMIN_HOST_INFO_PHC_MASK ; rc =ena_com_set_host_attributes (ena_dev);if (rc) {
@@ -3218,6 +3221,12 @@ static int ena_device_init(struct ena_adapter *adapter, struct pci_dev *pdev,if (unlikely (rc)) goto err_admin_init; + rc =ena_phc_init (adapter); +if (unlikely (rc && (rc != -EOPNOTSUPP ))) { +netdev_err (netdev,"Failed initiating PHC, error: %d\n" , rc); + goto err_admin_init; + } +return 0 ; err_admin_init:
@@ -3301,6 +3310,8 @@ static int ena_destroy_device(struct ena_adapter *adapter, bool graceful)ena_com_admin_destroy (ena_dev); +ena_phc_destroy (adapter); +ena_com_mmio_reg_read_request_destroy (ena_dev);/* return reset reason to default value */
@@ -3374,6 +3385,7 @@ err_device_destroy:ena_com_wait_for_abort_completion (ena_dev);ena_com_admin_destroy (ena_dev);ena_com_dev_reset (ena_dev,ENA_REGS_RESET_DRIVER_INVALID_STATE ); +ena_phc_destroy (adapter);ena_com_mmio_reg_read_request_destroy (ena_dev); err:clear_bit (ENA_FLAG_DEVICE_RUNNING , &adapter->flags);
@@ -3961,10 +3973,18 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_drvdata (pdev, adapter); + rc =ena_phc_alloc (adapter); +if (rc) { +netdev_err (netdev,"ena_phc_alloc failed\n" ); + goto err_netdev_destroy; + } + +ena_phc_enable (adapter, true); + rc =ena_com_allocate_customer_metrics_buffer (ena_dev);if (rc) {netdev_err (netdev,"ena_com_allocate_customer_metrics_buffer failed\n" ); - goto err_netdev_destroy; + goto err_free_phc; } rc =ena_map_llq_mem_bar (pdev, ena_dev, bars);
@@ -4101,6 +4121,8 @@ err_device_destroy:ena_com_admin_destroy (ena_dev); err_metrics_destroy:ena_com_delete_customer_metrics_buffer (ena_dev); +err_free_phc: +ena_phc_free (adapter); err_netdev_destroy:free_netdev (netdev); err_free_region:
@@ -4148,6 +4170,8 @@ static void __ena_shutoff(struct pci_dev *pdev, bool shutdown) adapter->reset_reason =ENA_REGS_RESET_SHUTDOWN ;ena_destroy_device (adapter, true); +ena_phc_free (adapter); +if (shutdown) {netif_device_detach (netdev);dev_close (netdev);
drivers/net/ethernet/amazon/ena/ena_netdev.h +4 -0
@@ -110,6 +110,8 @@#define ENA_MMIO_DISABLE_REG_READ BIT(0) +struct ena_phc_info ; +struct ena_irq {irq_handler_t handler;void *data;
@@ -348,6 +350,8 @@ struct ena_adapter {char name[ENA_NAME_MAX_LEN ]; +struct ena_phc_info *phc_info; +unsigned long flags;/* TX */ struct ena_ring tx_ring[ENA_MAX_NUM_IO_QUEUES ]
drivers/net/ethernet/amazon/ena/ena_phc.c new file +222 -0
222 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_phc.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* +* Copyright 2015-2022 Amazon.com, Inc. or its affiliates. All rights reserved. +*/ + +#ifndef ENA_PHC_H +#define ENA_PHC_H + +#include <linux/ptp_clock_kernel.h> + +struct ena_phc_info { +/* PTP hardware capabilities */ +struct ptp_clock_info clock_info; + +/* Registered PTP clock device */ +struct ptp_clock *clock; + +/* Adapter specific private data structure */ +struct ena_adapter *adapter; + +/* PHC lock */ +spinlock_t lock; + +/* Enabled by kernel */ +bool enabled; +}; + +void ena_phc_enable (struct ena_adapter *adapter,bool enable); +bool ena_phc_is_enabled (struct ena_adapter *adapter); +bool ena_phc_is_active (struct ena_adapter *adapter); +int ena_phc_get_index (struct ena_adapter *adapter); +int ena_phc_init (struct ena_adapter *adapter); +void ena_phc_destroy (struct ena_adapter *adapter); +int ena_phc_alloc (struct ena_adapter *adapter); +void ena_phc_free (struct ena_adapter *adapter); + +#endif /* ENA_PHC_H */
drivers/net/ethernet/amazon/ena/ena_regs_defs.h +8 -0
@@ -53,6 +53,11 @@ enum ena_regs_reset_reason_types {#define ENA_REGS_MMIO_RESP_HI_OFF 0x64#define ENA_REGS_RSS_IND_ENTRY_UPDATE_OFF 0x68 +/* phc_registers offsets */ + +/* 100 base */ +#define ENA_REGS_PHC_DB_OFF 0x100 +/* version register */ #define ENA_REGS_VERSION_MINOR_VERSION_MASK 0xff#define ENA_REGS_VERSION_MAJOR_VERSION_SHIFT 8
@@ -129,4 +134,7 @@ enum ena_regs_reset_reason_types {#define ENA_REGS_RSS_IND_ENTRY_UPDATE_CQ_IDX_SHIFT 16#define ENA_REGS_RSS_IND_ENTRY_UPDATE_CQ_IDX_MASK 0xffff0000 +/* phc_db_req_id register */ +#define ENA_REGS_PHC_DB_REQ_ID_MASK 0xffff +#endif /* _ENA_REGS_H_ */
Signature · 1 line
2.40.1
David Arinzon
maintainerPATCH v3 2/3 net: ena: PHC silent reset
In reply to David ArinzonEach PHC device kernel registration receives a unique kernel index, which is associated with a new PHC device file located at "/dev/ptp<index>".
This device file serves as an interface for obtaining PHC timestamps. Examples of tools that use "/dev/ptp" include testptp [1] and chrony [2].
A reset flow may occur in the ENA driver while PHC is active. During a reset, the driver will unregister and then re-register the PHC device with the kernel.
Under race conditions, particularly during heavy PHC loads, the driver’s reset flow might complete faster than the kernel’s PHC unregister/register process.
This can result in the PHC index being different from what it was prior to the reset, as the PHC index is selected using kernel ID allocation [3].
While driver rmmod/insmod are done by the user, a reset may occur at anytime, without the user awareness, consequently, the driver might receive a new PHC index after the reset, potentially compromising the user experience.
To prevent this issue, the PHC flow will detect the reset during PHC destruction and will skip the PHC unregister/register calls to preserve the kernel PHC index.
During the reset flow, any attempt to get a PHC timestamp will fail as expected, but the kernel PHC index will remain unchanged.
[1]: https://github.com/torvalds/linux/blob/v6.1/tools/testing/selftests/ptp/testptp.c
[2]: https://github.com/mlichvar/chrony
[3]: https://www.kernel.org/doc/html/latest/core-api/idr.html
--- drivers/net/ethernet/amazon/ena/ena_phc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_phc.c +9 -1
@@ -107,6 +107,10 @@ static int ena_phc_register(struct ena_adapter *adapter) phc_info = adapter->phc_info; clock_info = &phc_info->clock_info; +/* PHC may already be registered in case of a reset */ +if (ena_phc_is_active (adapter)) +return 0 ; + phc_info->adapter = adapter;spin_lock_init (&phc_info->lock);
@@ -133,7 +137,11 @@ static void ena_phc_unregister(struct ena_adapter *adapter) {struct ena_phc_info *phc_info = adapter->phc_info; -if (ena_phc_is_active (adapter)) { +/* During reset flow, PHC must stay registered +* to keep kernel's PHC index +*/ +if (ena_phc_is_active (adapter) && + !test_bit (ENA_FLAG_TRIGGER_RESET , &adapter->flags)) {ptp_clock_unregister (phc_info->clock); phc_info->clock =NULL ; }
Signature · 1 line
2.40.1
David Arinzon
maintainerPATCH v3 3/3 net: ena: Add PHC documentation
In reply to David ArinzonProvide the relevant information and guidelines
about the feature support in the ENA driver.
--- .../device_drivers/ethernet/amazon/ena.rst | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+)
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +78 -0
@@ -56,6 +56,7 @@ ena_netdev.[ch] Main Linux kernel driver. ena_ethtool.c ethtool callbacks. ena_xdp.[ch] XDP files ena_pci_id_tbl.h Supported device IDs. +ena_phc.[ch] PTP hardware clock infrastructure (see `PHC`_ for more info) ================= ====================================================== Management Interface:
@@ -221,6 +222,83 @@ descriptor it was received on would be recycled. When a packet smaller than RX copybreak bytes is received, it is copied into a new memory buffer and the RX descriptor is returned to HW. +.. _`PHC`: + +PTP Hardware Clock (PHC) +======================== +.. _`ptp-userspace-api`: https://docs.kernel.org/driver-api/ptp.html#ptp-hardware-clock-user-space-api +.. _`testptp`: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/ptp/testptp.c + +ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond accuracy. + +**PHC support** + +PHC depends on the PTP module, which needs to be either loaded as a module or compiled into the kernel. + +Verify if the PTP module is present: + +.. code-block:: shell + + grep -w '^CONFIG_PTP_1588_CLOCK=[ym]' /boot/config-`uname -r` + +- If no output is provided, the ENA driver cannot be loaded with PHC support. + +- ``CONFIG_PTP_1588_CLOCK=y``: the PTP module is already compiled and loaded inside the kernel binary file. + +- ``CONFIG_PTP_1588_CLOCK=m``: the PTP module needs to be loaded prior to loading the ENA driver: + +Load PTP module: + +.. code-block:: shell + + sudo modprobe ptp + +All available PTP clock sources can be tracked here: + +.. code-block:: shell + + ls /sys/class/ptp + +PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface> + +**PHC timestamp** + +To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example using `testptp`_: + +.. code-block:: shell + + testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware Clock:/ {print $NF}') -k 1 + +PHC get time requests should be within reasonable bounds, +avoid excessive utilization to ensure optimal performance and efficiency. +The ENA device restricts the frequency of PHC get time requests to a maximum +of 125 requests per second. If this limit is surpassed, the get time request +will fail, leading to an increment in the phc_err statistic. + +**PHC statistics** + +PHC can be monitored using :code:`ethtool -S` counters: + +================= ====================================================== +**phc_cnt** Number of successful retrieved timestamps (below expire timeout). +**phc_exp** Number of expired retrieved timestamps (above expire timeout). +**phc_skp** Number of skipped get time attempts (during block period). +**phc_err** Number of failed get time attempts (entering into block state). +================= ====================================================== + +PHC timeouts: + +================= ====================================================== +**expire** Max time for a valid timestamp retrieval, passing this threshold will fail + the get time request and block new requests until block timeout. +**block** Blocking period starts once get time request expires or fails, all get time + requests during block period will be skipped. +================= ====================================================== + Statistics ==========
Signature · 1 line
2.40.1
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Documentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller · line 291
Quoted 6 lines · On Sun, 3 Nov 2024 13:31:39 +0200 David Arinzon wrote:
+================= ======================================================
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +5
-0+**phc_cnt** Number of successful retrieved timestamps (below expire timeout). +**phc_exp** Number of expired retrieved timestamps (above expire timeout). +**phc_skp** Number of skipped get time attempts (during block period). +**phc_err** Number of failed get time attempts (entering into block state). +================= ======================================================
I seem to recall we had an unpleasant conversation about using standard stats recently. Please tell me where you looked to check if Linux has standard stats for packet timestamping. We need to add the right info there.
Signature · 1 line
pw-bot: cr
Arinzon, David
maintainerRE: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Quoted 10 lines
Quoted 1 line
+=================
======================================================
Quoted 1 line
+**phc_cnt** Number of successful retrieved timestamps (below
expire timeout).
Quoted 1 line
+**phc_exp** Number of expired retrieved timestamps (above
expire timeout).
Quoted 1 line
+**phc_skp** Number of skipped get time attempts (during block
period).
Quoted 1 line
+**phc_err** Number of failed get time attempts (entering into block
state).
Quoted 8 lines
Quoted 1 line
+=================
======================================================
I seem to recall we had an unpleasant conversation about using standard stats recently. Please tell me where you looked to check if Linux has standard stats for packet timestamping. We need to add the right info there. --
pw-bot: cr
Hi Jakub,
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not for TX/RX packet timestamping.
We reviewed similar drivers that support HW timestamping via gettime64 and gettimex64 APIs,
and we couldn't identify any that capture or report statistics related to reading a HW timestamp.
Let us know if further details would be helpful.
Re: RE: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Quoted 19 lines · David
Quoted 10 lines
Quoted 1 line
+=================
======================================================
Quoted 1 line
+**phc_cnt** Number of successful retrieved timestamps (below
expire timeout).
Quoted 1 line
+**phc_exp** Number of expired retrieved timestamps (above
expire timeout).
Quoted 1 line
+**phc_skp** Number of skipped get time attempts (during block
period).
Quoted 1 line
+**phc_err** Number of failed get time attempts (entering into block
state).
Quoted 8 lines
Quoted 1 line
+=================
======================================================
I seem to recall we had an unpleasant conversation about using standard stats recently. Please tell me where you looked to check if Linux has standard stats for packet timestamping. We need to add the right info there. --
pw-bot: cr
Quoted 7 lines
Hi Jakub,
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not for TX/RX packet timestamping.
We reviewed similar drivers that support HW timestamping viagettime64andgettimex64APIs,
and we couldn't identify any that capture or report statistics related to reading a HW timestamp.
Let us know if further details would be helpful.
David, did you consider Rahul's recent timestamping stats API? 0e9c127729be ("ethtool: add interface to read Tx hardware timestamping statistics")
Arinzon, David
maintainerRE: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
+=================
======================================================
Quoted 1 line
+**phc_cnt** Number of successful retrieved timestamps (below
expire timeout).
Quoted 1 line
+**phc_exp** Number of expired retrieved timestamps (above
expire timeout).
Quoted 1 line
+**phc_skp** Number of skipped get time attempts (during block
period).
Quoted 1 line
+**phc_err** Number of failed get time attempts (entering into
block
Quoted 7 lines
Quoted 7 lines
state).
Quoted 1 line
+=================
======================================================
I seem to recall we had an unpleasant conversation about using standard stats recently. Please tell me where you looked to check if Linux has standard stats for packet timestamping. We need to add the
right info there.
Quoted 7 lines
Quoted 2 lines
--
pw-bot: crHi Jakub,
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not
for TX/RX packet timestamping.
Quoted 8 lines
Quoted 2 lines
We reviewed similar drivers that support HW timestamping via
gettime64andgettimex64APIs, and we couldn't identify any thatcapture or report statistics related to reading a HW timestamp.
Quoted 1 line
Let us know if further details would be helpful.
David, did you consider Rahul's recent timestamping stats API?
0e9c127729be("ethtool: add interface to read Tx hardware timestamping statistics")
Hi Gal,
We've looked into the get_ts_stats ethtool hook, and it refers to TX HW packet timestamping and not HW timestamp which is retrieved through gettime64 and gettimex64.
Re: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Quoted 31 lines · David
Quoted 31 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
+=================
======================================================
Quoted 1 line
+**phc_cnt** Number of successful retrieved timestamps (below
expire timeout).
Quoted 1 line
+**phc_exp** Number of expired retrieved timestamps (above
expire timeout).
Quoted 1 line
+**phc_skp** Number of skipped get time attempts (during block
period).
Quoted 1 line
+**phc_err** Number of failed get time attempts (entering into
block
Quoted 7 lines
Quoted 7 lines
state).
Quoted 1 line
+=================
======================================================
I seem to recall we had an unpleasant conversation about using standard stats recently. Please tell me where you looked to check if Linux has standard stats for packet timestamping. We need to add the
right info there.
Quoted 7 lines
Quoted 2 lines
--
pw-bot: crHi Jakub,
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not
for TX/RX packet timestamping.
Quoted 2 lines
We reviewed similar drivers that support HW timestamping via
gettime64andgettimex64APIs, and we couldn't identify any thatcapture or report statistics related to reading a HW timestamp.
Quoted 1 line
Let us know if further details would be helpful.
Quoted 8 lines
Quoted 3 lines
David, did you consider Rahul's recent timestamping stats API?
0e9c127729be("ethtool: add interface to read Tx hardware timestamping statistics")Hi Gal,
We've looked into the
get_ts_statsethtool hook, and it refers to TX HW packet timestamping and not HW timestamp which is retrieved throughgettime64andgettimex64.
Hi folks,
I think everyone might be on the same page now, but I wanted to provide some clarifications just in case.
The use case that the TX HW timestamping statistics covers
┌─────────────────────────────────────┐
│ │
│ │
│ ┌──────┤
│ NIC hw │ │ Packets out
│ │ PF ├────────────────────────────────────────────────►
│ │ │
│ └───┬──┤
│ │ │
│ │ │
│ │ │
│ ┌────┘ │
│ │ │
└─────────────────────────────┼───────┘
│Hw timestamp information per packet
┌─────────────────────────────┼───────┐
│ │ │
│ ┌─────▼────┐ │
│ │ cmsg │ │
│ │ │ │
│ │ queue │ │
│ │ │ │
│ └──────────┘ │
│ │
│ │
│ Linux Kernel Stack │
│ │
│ │
│ │
└─────────────────────────────────────┘We are collecting statistics on every packet being sent out the wire. The use case being described here
┌──────────────────────────────────┐
│ │
│ │
│ ┌───────┤
│ NIC hw │ │
│ │ PF │
│ ┌───────────────────┐ │ │
│ │ │ └───────┤
│ │ PHC │ │
│ │ │ │
│ │ │ │
│ │ (just a clock dev)│ │
│ └─────────┬─────────┘ │
│ │ │
└──────────────┼───────────────────┘
│ Query device's clock for current time
┌──────────────┼───────────────────┐ ┌─────────────────────────────────┐
│ │ │ │ │
│ │ │ │ │
│ ┌──────────┼─────────────┐ │ │ │
│ │ │ │ │ │ ┌───────────────────────┐ │
│ │ │ │ │ │ │ │ │
│ │ ▼ ───┼─────┼──────┼────┼──────────► │ │
│ │ │ │ │ │ │ │
│ │ .gettimex64 callback │ │ │ │ clock_gettime syscall│ │
│ └────────────────────────┘ │ │ └───────────────────────┘ │
│ │ │ │
│ Linux Kernel Stack │ │ Userspace │
│ │ │ │
└──────────────────────────────────┘ └─────────────────────────────────┘The model above is about getting the time from the NIC hardware in the userspace application (which has not involvement with TX/RX traffic).
I do think the phc-to-host related statistics are on the niche side of things. The following drivers are error free in their gettimex64 paths.
* AMD pesando/ionic
* Broadcom Tigon3
* Intel ixgbe
* Intel igc
* NVIDIA mlxsw
* NVIDIA mlx5_core
The above drivers would definitely not benefit from having "phc (nic)"-to-host related statistics being presented here. I am more in favor of making these statistics specific to amazon's ENA driver since I think most drivers do not have a complex . Also, what value is there in the count of phc-to-host successful/failed operations versus just keeping track of the errors in userspace for whoever is calling clock_gettime. I am somewhat ok with these counters, but I honestly cannot imagine any practical use to this especially since they are not related to anything over-the-wire. So the errors in userspace would be enough of an indicator of whether there is excessive utilization of the requests and the counters seem redundant to that (at least to me). Feel free to share how you feel these counters would be helpful beyond handling the return codes through clock_gettime. I might just be missing something.
Hope this helps.
Signature · 3 lines
Thanks, Rahul Rameshbabu
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Quoted 10 lines · On Tue, 05 Nov 2024 18:02:57 -0800 Rahul Rameshbabu wrote:
I do think the phc-to-host related statistics are on the niche side of things. The following drivers are error free in their gettimex64 paths.
* AMD pesando/ionic
* Broadcom Tigon3
* Intel ixgbe
* Intel igc
* NVIDIA mlxsw
* NVIDIAmlx5_core
Quoted 14 lines
The above drivers would definitely not benefit from having "phc (nic)"-to-host related statistics being presented here. I am more in favor of making these statistics specific to amazon's ENA driver since I think most drivers do not have a complex . Also, what value is there in the count of phc-to-host successful/failed operations versus just keeping track of the errors in userspace for whoever is calling
clock_gettime. I am somewhat ok with these counters, but I honestly cannot imagine any practical use to this especially since they are not related to anything over-the-wire. So the errors in userspace would be enough of an indicator of whether there is excessive utilization of the requests and the counters seem redundant to that (at least to me). Feel free to share how you feel these counters would be helpful beyond handling the return codes throughclock_gettime. I might just be missing something.
Agreed, thanks a lot for the analysis. I misread the code. I looked at ena_com_phc_get() last night and incorrectly assumed it's way to complex to be called from gettimex64 :S
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
In reply to Arinzon, DavidQuoted 3 lines · David
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not for TX/RX packet timestamping.
Oh, so you're saying you can only read the clock from the device? The word timestamp means time associated with an event.
In the doc you talk about:
Documentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller · line 266
Quoted 5 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +5
-0+PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface>
which is for packet timestamping
also:
Quoted 2 lines
ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond accuracy.
You probably want to double check the definitions of accuracy and resolution.
We recently merged an Amazon PTP clock driver from David Woodhouse, see commit 20503272422693. If you're not timestamping packets why not use that driver?
Arinzon, David
maintainerRE: [PATCH v3 net-next 3/3] net: ena: Add PHC documentation
Thank you Rahul for the detailed explanations
Hi Jakub,
Quoted 7 lines
Quoted 3 lines
Just wanted to clarify that this feature and the associated documentation are specifically intended for reading a HW timestamp, not for TX/RX packet timestamping.
Oh, so you're saying you can only read the clock from the device? The word timestamp means time associated with an event.
Based on the documentation of gettimex64 API
The ts parameter holds the PHC timestamp.
We are using the same terminology
https://elixir.bootlin.com/linux/v6.11.6/source/include/linux/ptp_clock_kernel.h#L97
* @gettimex64: Reads the current time from the hardware clock and optionally * also the system clock. * parameter ts: Holds the PHC timestamp. * parameter sts: If not NULL, it holds a pair of timestamps from * the system clock. The first reading is made right before * reading the lowest bits of the PHC timestamp and the second * reading immediately follows that.
Quoted 10 lines
In the doc you talk about:
Documentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller · line 266
Quoted 5 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +5
-0+PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface>which is for packet timestamping
ethtool -T shows all timestamping capabilities, which indeed include packet timestamping but also the PTP Hardware Clock (PHC) index If the value is none, it means that there's no PHC support This is done by implementing the get_ts_info hook, which is part of this patchset.
https://elixir.bootlin.com/linux/v6.11.6/source/include/linux/ethtool.h#L720
Quoted 8 lines
also:
Quoted 2 lines
ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond accuracy.
You probably want to double check the definitions of accuracy and resolution.
Thank you, will be changed in the next patchset
Quoted 3 lines
We recently merged an Amazon PTP clock driver from David Woodhouse, see commit 20503272422693. If you're not timestamping packets why not use that driver?
The AMZNC10C vmclock device driver is intended to be used in systems where there's an hypervisor. The PHC driver in this patchset is intended for virtual and non-virtual (metal) instances in AWS. The AMZNC10C might not be available in the future on the same instances where PHC is available.