177c79de0SHemant Agrawal.. SPDX-License-Identifier: BSD-3-Clause 277c79de0SHemant Agrawal Copyright 2018 The DPDK contributors 377c79de0SHemant Agrawal 46bdae907SThomas MonjalonDesign 56bdae907SThomas Monjalon====== 66bdae907SThomas Monjalon 7*5c9f84a8SBruce Richardson 86bdae907SThomas MonjalonEnvironment or Architecture-specific Sources 96bdae907SThomas Monjalon-------------------------------------------- 106bdae907SThomas Monjalon 11218c4e68SBruce RichardsonIn DPDK and DPDK applications, some code is specific to an architecture (i686, x86_64) or to an executive environment (freebsd or linux) and so on. 126bdae907SThomas MonjalonAs far as is possible, all such instances of architecture or env-specific code should be provided via standard APIs in the EAL. 136bdae907SThomas Monjalon 146bdae907SThomas MonjalonBy convention, a file is common if it is not located in a directory indicating that it is specific. 156bdae907SThomas MonjalonFor instance, a file located in a subdir of "x86_64" directory is specific to this architecture. 16218c4e68SBruce RichardsonA file located in a subdir of "linux" is specific to this execution environment. 176bdae907SThomas Monjalon 186bdae907SThomas Monjalon.. note:: 196bdae907SThomas Monjalon 206bdae907SThomas Monjalon Code in DPDK libraries and applications should be generic. 216bdae907SThomas Monjalon The correct location for architecture or executive environment specific code is in the EAL. 226bdae907SThomas Monjalon 236bdae907SThomas MonjalonWhen absolutely necessary, there are several ways to handle specific code: 246bdae907SThomas Monjalon 25532e4e48SCiara Power* Use a ``#ifdef`` with a build definition macro in the C code. 266bdae907SThomas Monjalon This can be done when the differences are small and they can be embedded in the same C file: 276bdae907SThomas Monjalon 2844622a72SJohn McNamara .. code-block:: c 296bdae907SThomas Monjalon 306bdae907SThomas Monjalon #ifdef RTE_ARCH_I686 316bdae907SThomas Monjalon toto(); 326bdae907SThomas Monjalon #else 336bdae907SThomas Monjalon titi(); 346bdae907SThomas Monjalon #endif 356bdae907SThomas Monjalon 36532e4e48SCiara Power* Use build definition macros and conditions in the Meson build file. This is done when the differences are more significant. 3744622a72SJohn McNamara In this case, the code is split into two separate files that are architecture or environment specific. 3844622a72SJohn McNamara This should only apply inside the EAL library. 396bdae907SThomas Monjalon 406bdae907SThomas MonjalonPer Architecture Sources 416bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~ 426bdae907SThomas Monjalon 43532e4e48SCiara PowerThe following macro options can be used: 446bdae907SThomas Monjalon 45532e4e48SCiara Power* ``RTE_ARCH`` is a string that contains the name of the architecture. 4629631ee5SMin Zhou* ``RTE_ARCH_I686``, ``RTE_ARCH_X86_64``, ``RTE_ARCH_X86_X32``, ``RTE_ARCH_PPC_64``, ``RTE_ARCH_RISCV``, ``RTE_ARCH_LOONGARCH``, ``RTE_ARCH_ARM``, ``RTE_ARCH_ARMv7`` or ``RTE_ARCH_ARM64`` are defined only if we are building for those architectures. 476bdae907SThomas Monjalon 486bdae907SThomas MonjalonPer Execution Environment Sources 496bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 506bdae907SThomas Monjalon 51532e4e48SCiara PowerThe following macro options can be used: 526bdae907SThomas Monjalon 53532e4e48SCiara Power* ``RTE_EXEC_ENV`` is a string that contains the name of the executive environment. 54532e4e48SCiara Power* ``RTE_EXEC_ENV_FREEBSD``, ``RTE_EXEC_ENV_LINUX`` or ``RTE_EXEC_ENV_WINDOWS`` are defined only if we are building for this execution environment. 556bdae907SThomas Monjalon 56d1342ea4SThomas MonjalonMbuf features 57d1342ea4SThomas Monjalon------------- 58d1342ea4SThomas Monjalon 59d1342ea4SThomas MonjalonThe ``rte_mbuf`` structure must be kept small (128 bytes). 60d1342ea4SThomas Monjalon 61d1342ea4SThomas MonjalonIn order to add new features without wasting buffer space for unused features, 62d1342ea4SThomas Monjalonsome fields and flags can be registered dynamically in a shared area. 63d1342ea4SThomas MonjalonThe "dynamic" mbuf area is the default choice for the new features. 64d1342ea4SThomas Monjalon 65d1342ea4SThomas MonjalonThe "dynamic" area is eating the remaining space in mbuf, 66d1342ea4SThomas Monjalonand some existing "static" fields may need to become "dynamic". 67d1342ea4SThomas Monjalon 68d1342ea4SThomas MonjalonAdding a new static field or flag must be an exception matching many criteria 69d1342ea4SThomas Monjalonlike (non exhaustive): wide usage, performance, size. 70d1342ea4SThomas Monjalon 71d1342ea4SThomas Monjalon 72*5c9f84a8SBruce RichardsonRuntime Information - Logging, Tracing and Telemetry 73*5c9f84a8SBruce Richardson---------------------------------------------------- 74*5c9f84a8SBruce Richardson 75*5c9f84a8SBruce RichardsonIt is often desirable to provide information to the end-user 76*5c9f84a8SBruce Richardsonas to what is happening to the application at runtime. 77*5c9f84a8SBruce RichardsonDPDK provides a number of built-in mechanisms to provide this introspection: 78*5c9f84a8SBruce Richardson 79*5c9f84a8SBruce Richardson* :ref:`Logging <dynamic_logging>` 80*5c9f84a8SBruce Richardson* :doc:`Tracing <../prog_guide/trace_lib>` 81*5c9f84a8SBruce Richardson* :doc:`Telemetry <../prog_guide/telemetry_lib>` 82*5c9f84a8SBruce Richardson 83*5c9f84a8SBruce RichardsonEach of these has its own strengths and suitabilities for use within DPDK components. 84*5c9f84a8SBruce Richardson 85*5c9f84a8SBruce RichardsonBelow are some guidelines for when each should be used: 86*5c9f84a8SBruce Richardson 87*5c9f84a8SBruce Richardson* For reporting error conditions, or other abnormal runtime issues, *logging* should be used. 88*5c9f84a8SBruce Richardson Depending on the severity of the issue, the appropriate log level, for example, 89*5c9f84a8SBruce Richardson ``ERROR``, ``WARNING`` or ``NOTICE``, should be used. 90*5c9f84a8SBruce Richardson 91*5c9f84a8SBruce Richardson.. note:: 92*5c9f84a8SBruce Richardson 93*5c9f84a8SBruce Richardson Drivers of all classes, including both bus and device drivers, 94*5c9f84a8SBruce Richardson should not output any log information if the hardware they support is not present. 95*5c9f84a8SBruce Richardson This is to avoid any changes in output for existing users when a new driver is added to DPDK. 96*5c9f84a8SBruce Richardson 97*5c9f84a8SBruce Richardson* For component initialization, or other cases where a path through the code 98*5c9f84a8SBruce Richardson is only likely to be taken once, 99*5c9f84a8SBruce Richardson either *logging* at ``DEBUG`` level or *tracing* may be used, or potentially both. 100*5c9f84a8SBruce Richardson In the latter case, tracing can provide basic information as to the code path taken, 101*5c9f84a8SBruce Richardson with debug-level logging providing additional details on internal state, 102*5c9f84a8SBruce Richardson not possible to emit via tracing. 103*5c9f84a8SBruce Richardson 104*5c9f84a8SBruce Richardson* For a component's data-path, where a path is to be taken multiple times within a short timeframe, 105*5c9f84a8SBruce Richardson *tracing* should be used. 106*5c9f84a8SBruce Richardson Since DPDK tracing uses `Common Trace Format <https://diamon.org/ctf/>`_ for its tracing logs, 107*5c9f84a8SBruce Richardson post-analysis can be done using a range of external tools. 108*5c9f84a8SBruce Richardson 109*5c9f84a8SBruce Richardson* For numerical or statistical data generated by a component, for example, per-packet statistics, 110*5c9f84a8SBruce Richardson *telemetry* should be used. 111*5c9f84a8SBruce Richardson 112*5c9f84a8SBruce Richardson* For any data where the data may need to be gathered at any point in the execution 113*5c9f84a8SBruce Richardson to help assess the state of the application component, 114*5c9f84a8SBruce Richardson for example, core configuration, device information, *telemetry* should be used. 115*5c9f84a8SBruce Richardson Telemetry callbacks should not modify any program state, but be "read-only". 116*5c9f84a8SBruce Richardson 117*5c9f84a8SBruce RichardsonMany libraries also include a ``rte_<libname>_dump()`` function as part of their API, 118*5c9f84a8SBruce Richardsonwriting verbose internal details to a given file-handle. 119*5c9f84a8SBruce RichardsonNew libraries are encouraged to provide such functions where it makes sense to do so, 120*5c9f84a8SBruce Richardsonas they provide an additional application-controlled mechanism 121*5c9f84a8SBruce Richardsonto get details of the internals of a DPDK component. 122*5c9f84a8SBruce Richardson 123*5c9f84a8SBruce Richardson 1246bdae907SThomas MonjalonLibrary Statistics 1256bdae907SThomas Monjalon------------------ 1266bdae907SThomas Monjalon 1276bdae907SThomas MonjalonDescription 1286bdae907SThomas Monjalon~~~~~~~~~~~ 1296bdae907SThomas Monjalon 1306bdae907SThomas MonjalonThis document describes the guidelines for DPDK library-level statistics counter 1316bdae907SThomas Monjalonsupport. This includes guidelines for turning library statistics on and off and 1326bdae907SThomas Monjalonrequirements for preventing ABI changes when implementing statistics. 1336bdae907SThomas Monjalon 1346bdae907SThomas Monjalon 1356bdae907SThomas MonjalonMechanism to allow the application to turn library statistics on and off 1366bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1376bdae907SThomas Monjalon 138532e4e48SCiara PowerHaving runtime support for enabling/disabling library statistics is recommended, 139532e4e48SCiara Poweras build-time options should be avoided. However, if build-time options are used, 140532e4e48SCiara Powerfor example as in the table library, the options can be set using c_args. 141532e4e48SCiara PowerWhen this flag is set, all the counters supported by current library are 1426bdae907SThomas Monjaloncollected for all the instances of every object type provided by the library. 1436bdae907SThomas MonjalonWhen this flag is cleared, none of the counters supported by the current library 1446bdae907SThomas Monjalonare collected for any instance of any object type provided by the library: 1456bdae907SThomas Monjalon 1466bdae907SThomas Monjalon 1476bdae907SThomas MonjalonPrevention of ABI changes due to library statistics support 1486bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1496bdae907SThomas Monjalon 1506bdae907SThomas MonjalonThe layout of data structures and prototype of functions that are part of the 1516bdae907SThomas Monjalonlibrary API should not be affected by whether the collection of statistics 1526bdae907SThomas Monjaloncounters is turned on or off for the current library. In practical terms, this 1536bdae907SThomas Monjalonmeans that space should always be allocated in the API data structures for 1546bdae907SThomas Monjalonstatistics counters and the statistics related API functions are always built 1556bdae907SThomas Monjaloninto the code, regardless of whether the statistics counter collection is turned 1566bdae907SThomas Monjalonon or off for the current library. 1576bdae907SThomas Monjalon 1586bdae907SThomas MonjalonWhen the collection of statistics counters for the current library is turned 1596bdae907SThomas Monjalonoff, the counters retrieved through the statistics related API functions should 1606bdae907SThomas Monjalonhave a default value of zero. 1616bdae907SThomas Monjalon 1626bdae907SThomas Monjalon 1636bdae907SThomas MonjalonMotivation to allow the application to turn library statistics on and off 1646bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1656bdae907SThomas Monjalon 1666bdae907SThomas MonjalonIt is highly recommended that each library provides statistics counters to allow 1676bdae907SThomas Monjalonan application to monitor the library-level run-time events. Typical counters 1686bdae907SThomas Monjalonare: number of packets received/dropped/transmitted, number of buffers 1696bdae907SThomas Monjalonallocated/freed, number of occurrences for specific events, etc. 1706bdae907SThomas Monjalon 1716bdae907SThomas MonjalonHowever, the resources consumed for library-level statistics counter collection 1726bdae907SThomas Monjalonhave to be spent out of the application budget and the counters collected by 1736bdae907SThomas Monjalonsome libraries might not be relevant to the current application. In order to 1746bdae907SThomas Monjalonavoid any unwanted waste of resources and/or performance impacts, the 1756bdae907SThomas Monjalonapplication should decide at build time whether the collection of library-level 1766bdae907SThomas Monjalonstatistics counters should be turned on or off for each library individually. 1776bdae907SThomas Monjalon 1786bdae907SThomas MonjalonLibrary-level statistics counters can be relevant or not for specific 1796bdae907SThomas Monjalonapplications: 1806bdae907SThomas Monjalon 1816bdae907SThomas Monjalon* For Application A, counters maintained by Library X are always relevant and 1826bdae907SThomas Monjalon the application needs to use them to implement certain features, such as traffic 1836bdae907SThomas Monjalon accounting, logging, application-level statistics, etc. In this case, 1846bdae907SThomas Monjalon the application requires that collection of statistics counters for Library X is 1856bdae907SThomas Monjalon always turned on. 1866bdae907SThomas Monjalon 1876bdae907SThomas Monjalon* For Application B, counters maintained by Library X are only useful during the 1886bdae907SThomas Monjalon application debug stage and are not relevant once debug phase is over. In this 1896bdae907SThomas Monjalon case, the application may decide to turn on the collection of Library X 1906bdae907SThomas Monjalon statistics counters during the debug phase and at a later stage turn them off. 1916bdae907SThomas Monjalon 1926bdae907SThomas Monjalon* For Application C, counters maintained by Library X are not relevant at all. 1936bdae907SThomas Monjalon It might be that the application maintains its own set of statistics counters 1946bdae907SThomas Monjalon that monitor a different set of run-time events (e.g. number of connection 1956bdae907SThomas Monjalon requests, number of active users, etc). It might also be that the application 1966bdae907SThomas Monjalon uses multiple libraries (Library X, Library Y, etc) and it is interested in the 1976bdae907SThomas Monjalon statistics counters of Library Y, but not in those of Library X. In this case, 1986bdae907SThomas Monjalon the application may decide to turn the collection of statistics counters off for 1996bdae907SThomas Monjalon Library X and on for Library Y. 2006bdae907SThomas Monjalon 2016bdae907SThomas MonjalonThe statistics collection consumes a certain amount of CPU resources (cycles, 2026bdae907SThomas Monjaloncache bandwidth, memory bandwidth, etc) that depends on: 2036bdae907SThomas Monjalon 2046bdae907SThomas Monjalon* Number of libraries used by the current application that have statistics 2056bdae907SThomas Monjalon counters collection turned on. 2066bdae907SThomas Monjalon 2076bdae907SThomas Monjalon* Number of statistics counters maintained by each library per object type 2086bdae907SThomas Monjalon instance (e.g. per port, table, pipeline, thread, etc). 2096bdae907SThomas Monjalon 2106bdae907SThomas Monjalon* Number of instances created for each object type supported by each library. 2116bdae907SThomas Monjalon 2126bdae907SThomas Monjalon* Complexity of the statistics logic collection for each counter: when only 2136bdae907SThomas Monjalon some occurrences of a specific event are valid, additional logic is typically 2146bdae907SThomas Monjalon needed to decide whether the current occurrence of the event should be counted 2156bdae907SThomas Monjalon or not. For example, in the event of packet reception, when only TCP packets 2166bdae907SThomas Monjalon with destination port within a certain range should be recorded, conditional 2176bdae907SThomas Monjalon branches are usually required. When processing a burst of packets that have been 2186bdae907SThomas Monjalon validated for header integrity, counting the number of bits set in a bitmask 2196bdae907SThomas Monjalon might be needed. 22019ffc161SWenzhuo Lu 22119ffc161SWenzhuo LuPF and VF Considerations 22219ffc161SWenzhuo Lu------------------------ 22319ffc161SWenzhuo Lu 22419ffc161SWenzhuo LuThe primary goal of DPDK is to provide a userspace dataplane. Managing VFs from 22519ffc161SWenzhuo Lua PF driver is a control plane feature and developers should generally rely on 22619ffc161SWenzhuo Luthe Linux Kernel for that. 22719ffc161SWenzhuo Lu 22819ffc161SWenzhuo LuDevelopers should work with the Linux Kernel community to get the required 22919ffc161SWenzhuo Lufunctionality upstream. PF functionality should only be added to DPDK for 23019ffc161SWenzhuo Lutesting and prototyping purposes while the kernel work is ongoing. It should 23119ffc161SWenzhuo Lualso be marked with an "EXPERIMENTAL" tag. If the functionality isn't 23219ffc161SWenzhuo Luupstreamable then a case can be made to maintain the PF functionality in DPDK 23319ffc161SWenzhuo Luwithout the EXPERIMENTAL tag. 234