xref: /dpdk/doc/guides/contributing/documentation.rst (revision 7f9326423a045f7346a459280dc98fed4afd6811)
177c79de0SHemant Agrawal..  SPDX-License-Identifier: BSD-3-Clause
277c79de0SHemant Agrawal    Copyright 2018 The DPDK contributors
377c79de0SHemant Agrawal
458abf6e7SJohn McNamara.. _doc_guidelines:
56bdae907SThomas Monjalon
66bdae907SThomas MonjalonDPDK Documentation Guidelines
76bdae907SThomas Monjalon=============================
86bdae907SThomas Monjalon
96bdae907SThomas MonjalonThis document outlines the guidelines for writing the DPDK Guides and API documentation in RST and Doxygen format.
106bdae907SThomas Monjalon
11428eaeb8SThomas MonjalonIt also explains the structure of the DPDK documentation and how to build it.
126bdae907SThomas Monjalon
136bdae907SThomas Monjalon
146bdae907SThomas MonjalonStructure of the Documentation
156bdae907SThomas Monjalon------------------------------
166bdae907SThomas Monjalon
176bdae907SThomas MonjalonThe DPDK source code repository contains input files to build the API documentation and User Guides.
186bdae907SThomas Monjalon
196bdae907SThomas MonjalonThe main directories that contain files related to documentation are shown below::
206bdae907SThomas Monjalon
216bdae907SThomas Monjalon   lib
2299a2dd95SBruce Richardson   |-- acl
2399a2dd95SBruce Richardson   |-- cfgfile
2499a2dd95SBruce Richardson   |-- cmdline
2599a2dd95SBruce Richardson   |-- eal
266bdae907SThomas Monjalon   |   |-- ...
276bdae907SThomas Monjalon   ...
286bdae907SThomas Monjalon   doc
296bdae907SThomas Monjalon   |-- api
306bdae907SThomas Monjalon   +-- guides
316bdae907SThomas Monjalon       |-- freebsd_gsg
326bdae907SThomas Monjalon       |-- linux_gsg
336bdae907SThomas Monjalon       |-- prog_guide
346bdae907SThomas Monjalon       |-- sample_app_ug
356bdae907SThomas Monjalon       |-- guidelines
366bdae907SThomas Monjalon       |-- testpmd_app_ug
376bdae907SThomas Monjalon       |-- rel_notes
386bdae907SThomas Monjalon       |-- nics
396bdae907SThomas Monjalon       |-- ...
406bdae907SThomas Monjalon
416bdae907SThomas Monjalon
42047b663aSDekel PeledThe API documentation is built from `Doxygen <http://www.doxygen.nl>`_ comments in the header files.
4399a2dd95SBruce RichardsonThese files are mainly in the ``lib/*`` directories although some of the Poll Mode Drivers in ``drivers/net``
446bdae907SThomas Monjalonare also documented with Doxygen.
456bdae907SThomas Monjalon
466bdae907SThomas MonjalonThe configuration files that are used to control the Doxygen output are in the ``doc/api`` directory.
476bdae907SThomas Monjalon
486bdae907SThomas MonjalonThe user guides such as *The Programmers Guide* and the *FreeBSD* and *Linux Getting Started* Guides are generated
49047b663aSDekel Peledfrom RST markup text files using the `Sphinx <http://sphinx-doc.org>`_ Documentation Generator.
506bdae907SThomas Monjalon
516bdae907SThomas MonjalonThese files are included in the ``doc/guides/`` directory.
526bdae907SThomas MonjalonThe output is controlled by the ``doc/guides/conf.py`` file.
536bdae907SThomas Monjalon
546bdae907SThomas Monjalon
556bdae907SThomas MonjalonRole of the Documentation
566bdae907SThomas Monjalon-------------------------
576bdae907SThomas Monjalon
586bdae907SThomas MonjalonThe following items outline the roles of the different parts of the documentation and when they need to be updated or
596bdae907SThomas Monjalonadded to by the developer.
606bdae907SThomas Monjalon
616bdae907SThomas Monjalon* **Release Notes**
626bdae907SThomas Monjalon
636bdae907SThomas Monjalon  The Release Notes document which features have been added in the current and previous releases of DPDK and highlight
646bdae907SThomas Monjalon  any known issues.
65e85373edSThomas Monjalon  The Releases Notes also contain notifications of features that will change ABI compatibility in the next release.
666bdae907SThomas Monjalon
67c36a82f0SJohn McNamara  Developers should include updates to the Release Notes with patch sets that relate to any of the following sections:
68c36a82f0SJohn McNamara
69c36a82f0SJohn McNamara  * New Features
70c36a82f0SJohn McNamara  * Resolved Issues (see below)
71c36a82f0SJohn McNamara  * Known Issues
72c36a82f0SJohn McNamara  * API Changes
73c36a82f0SJohn McNamara  * ABI Changes
74c36a82f0SJohn McNamara  * Shared Library Versions
75c36a82f0SJohn McNamara
76c36a82f0SJohn McNamara  Resolved Issues should only include issues from previous releases that have been resolved in the current release.
77c36a82f0SJohn McNamara  Issues that are introduced and then fixed within a release cycle do not have to be included here.
78c36a82f0SJohn McNamara
79c36a82f0SJohn McNamara  Refer to the Release Notes from the previous DPDK release for the correct format of each section.
80c36a82f0SJohn McNamara
816bdae907SThomas Monjalon
826bdae907SThomas Monjalon* **API documentation**
836bdae907SThomas Monjalon
846bdae907SThomas Monjalon  The API documentation explains how to use the public DPDK functions.
853d4b2afbSDavid Marchand  The `API index page <https://doc.dpdk.org/api/>`_ shows the generated API documentation with related groups of functions.
866bdae907SThomas Monjalon
876bdae907SThomas Monjalon  The API documentation should be updated via Doxygen comments when new functions are added.
886bdae907SThomas Monjalon
896bdae907SThomas Monjalon* **Getting Started Guides**
906bdae907SThomas Monjalon
916bdae907SThomas Monjalon  The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes.
926bdae907SThomas Monjalon
936bdae907SThomas Monjalon  A Getting Started Guide should be added when DPDK is ported to a new OS.
946bdae907SThomas Monjalon
956bdae907SThomas Monjalon* **The Programmers Guide**
966bdae907SThomas Monjalon
976bdae907SThomas Monjalon  The Programmers Guide explains how the API components of DPDK such as the EAL, Memzone, Rings and the Hash Library work.
98f78c100bSStephen Hemminger  It also describes some of the higher level functionality such as Packet Distributor and Packet Framework.
996bdae907SThomas Monjalon  It also shows the build system and explains how to add applications.
1006bdae907SThomas Monjalon
1016bdae907SThomas Monjalon  The Programmers Guide should be expanded when new functionality is added to DPDK.
1026bdae907SThomas Monjalon
1036bdae907SThomas Monjalon* **App Guides**
1046bdae907SThomas Monjalon
1056bdae907SThomas Monjalon  The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``.
1066bdae907SThomas Monjalon
1076bdae907SThomas Monjalon  The app guides should be updated if functionality is changed or added.
1086bdae907SThomas Monjalon
1096bdae907SThomas Monjalon* **Sample App Guides**
1106bdae907SThomas Monjalon
1116bdae907SThomas Monjalon  The sample app guides document the DPDK example applications in the examples directory.
1126bdae907SThomas Monjalon  Generally they demonstrate a major feature such as L2 or L3 Forwarding, Multi Process or Power Management.
1136bdae907SThomas Monjalon  They explain the purpose of the sample application, how to run it and step through some of the code to explain the
1146bdae907SThomas Monjalon  major functionality.
1156bdae907SThomas Monjalon
1166bdae907SThomas Monjalon  A new sample application should be accompanied by a new sample app guide.
1176bdae907SThomas Monjalon  The guide for the Skeleton Forwarding app is a good starting reference.
1186bdae907SThomas Monjalon
1196bdae907SThomas Monjalon* **Network Interface Controller Drivers**
1206bdae907SThomas Monjalon
1216bdae907SThomas Monjalon  The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements,
1226bdae907SThomas Monjalon  configuration and initialization.
1236bdae907SThomas Monjalon
1246bdae907SThomas Monjalon  New documentation should be added for new Poll Mode Drivers.
1256bdae907SThomas Monjalon
1266bdae907SThomas Monjalon* **Guidelines**
1276bdae907SThomas Monjalon
1286bdae907SThomas Monjalon  The guideline documents record community process, expectations and design directions.
1296bdae907SThomas Monjalon
1306bdae907SThomas Monjalon  They can be extended, amended or discussed by submitting a patch and getting community approval.
1316bdae907SThomas Monjalon
1326bdae907SThomas Monjalon
1336bdae907SThomas MonjalonBuilding the Documentation
1346bdae907SThomas Monjalon--------------------------
1356bdae907SThomas Monjalon
136*7f932642SJuraj Linkeš.. _doc_dependencies:
137*7f932642SJuraj Linkeš
1386bdae907SThomas MonjalonDependencies
1396bdae907SThomas Monjalon~~~~~~~~~~~~
1406bdae907SThomas Monjalon
1416bdae907SThomas MonjalonThe following dependencies must be installed to build the documentation:
1426bdae907SThomas Monjalon
1436bdae907SThomas Monjalon* Doxygen.
1446bdae907SThomas Monjalon* Sphinx (also called python-sphinx).
1456bdae907SThomas Monjalon
1466bdae907SThomas Monjalon`Doxygen`_ generates documentation from commented source code.
1476bdae907SThomas MonjalonIt can be installed as follows:
1486bdae907SThomas Monjalon
1496bdae907SThomas Monjalon.. code-block:: console
1506bdae907SThomas Monjalon
1516bdae907SThomas Monjalon   # Ubuntu/Debian.
1526bdae907SThomas Monjalon   sudo apt-get -y install doxygen
1536bdae907SThomas Monjalon
1546bdae907SThomas Monjalon   # Red Hat/Fedora.
1554b677a3bSJohn McNamara   sudo dnf     -y install doxygen
1566bdae907SThomas Monjalon
157428eaeb8SThomas Monjalon`Sphinx`_ is a Python documentation tool for converting RST files to HTML.
158bc00fecfSJohn McNamaraFor full support with figure and table captioning the latest version of Sphinx can be installed as follows:
1596bdae907SThomas Monjalon
1606bdae907SThomas Monjalon.. code-block:: console
1616bdae907SThomas Monjalon
1626bdae907SThomas Monjalon   # Ubuntu/Debian.
163b1df4163SRobin Jarry   sudo apt-get -y install python3-sphinx python3-sphinx-rtd-theme
1646bdae907SThomas Monjalon
1656bdae907SThomas Monjalon   # Red Hat/Fedora.
166b1df4163SRobin Jarry   sudo dnf     -y install python3-sphinx python3-sphinx_rtd_theme
1676bdae907SThomas Monjalon
168047b663aSDekel PeledFor further information on getting started with Sphinx see the
169047b663aSDekel Peled`Sphinx Getting Started <http://www.sphinx-doc.org/en/master/usage/quickstart.html>`_.
1706bdae907SThomas Monjalon
1716bdae907SThomas Monjalon.. Note::
1726bdae907SThomas Monjalon
1736bdae907SThomas Monjalon   To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later.
1746bdae907SThomas Monjalon
1756bdae907SThomas Monjalon
1766bdae907SThomas MonjalonBuild commands
1776bdae907SThomas Monjalon~~~~~~~~~~~~~~
1786bdae907SThomas Monjalon
1796bdae907SThomas MonjalonThe documentation is built using the standard DPDK build system.
1806bdae907SThomas Monjalon
181532e4e48SCiara PowerTo build the documentation::
1826bdae907SThomas Monjalon
183532e4e48SCiara Power   ninja -C build doc
1846bdae907SThomas Monjalon
185532e4e48SCiara PowerSee :doc:`../linux_gsg/build_dpdk` for more detail on compiling DPDK with meson.
1866bdae907SThomas Monjalon
187c56185fcSBruce RichardsonThe output is generated in the directory ``build/doc/``, with:
188c56185fcSBruce Richardson
189c56185fcSBruce Richardson* HTML versions of the guide docs, e.g. Getting Started Guides, Programmers Guide, in ``build/doc/guides/html``
190c56185fcSBruce Richardson* HTML version of the API documentation in ``build/doc/api/html``
191c56185fcSBruce Richardson* Man-page version of the API documentation in ``build/doc/api/man``.
192c56185fcSBruce Richardson  If not installing DPDK system-wise, these pages can be accessed by adding this directory to the ``MANPATH`` environment variable.
193c56185fcSBruce Richardson  For example:
194c56185fcSBruce Richardson
195c56185fcSBruce Richardson.. code-block:: console
196c56185fcSBruce Richardson
197c56185fcSBruce Richardson   export MANPATH=:/path/to/build/doc/api/man
1986bdae907SThomas Monjalon
1996bdae907SThomas Monjalon.. Note::
2006bdae907SThomas Monjalon
2016bdae907SThomas Monjalon   Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation.
2026bdae907SThomas Monjalon
2036bdae907SThomas Monjalon
2046bdae907SThomas MonjalonDocument Guidelines
2056bdae907SThomas Monjalon-------------------
2066bdae907SThomas Monjalon
2076bdae907SThomas MonjalonHere are some guidelines in relation to the style of the documentation:
2086bdae907SThomas Monjalon
2096bdae907SThomas Monjalon* Document the obvious as well as the obscure since it won't always be obvious to the reader.
2106bdae907SThomas Monjalon  For example an instruction like "Set up 64 2MB Hugepages" is better when followed by a sample commandline or a link to
2116bdae907SThomas Monjalon  the appropriate section of the documentation.
2126bdae907SThomas Monjalon
2136bdae907SThomas Monjalon* Use American English spellings throughout.
2146bdae907SThomas Monjalon  This can be checked using the ``aspell`` utility::
2156bdae907SThomas Monjalon
2166bdae907SThomas Monjalon       aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst
2176bdae907SThomas Monjalon
2186bdae907SThomas Monjalon
2196bdae907SThomas MonjalonRST Guidelines
2206bdae907SThomas Monjalon--------------
2216bdae907SThomas Monjalon
222428eaeb8SThomas MonjalonThe RST (reStructuredText) format is a plain text markup format
223428eaeb8SThomas Monjalonthat can be converted to HTML or other formats.
2246bdae907SThomas MonjalonIt is most closely associated with Python but it can be used to document any language.
2256bdae907SThomas MonjalonIt is used in DPDK to document everything apart from the API.
2266bdae907SThomas Monjalon
2276bdae907SThomas MonjalonThe Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a
2286bdae907SThomas Monjalongood place to learn the minimal set of syntax required to format a document.
2296bdae907SThomas Monjalon
2306bdae907SThomas MonjalonThe official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the
2316bdae907SThomas MonjalonRST format and also examples of how to use it.
2326bdae907SThomas MonjalonHowever, for most developers the RST Primer is a better resource.
2336bdae907SThomas Monjalon
2346bdae907SThomas MonjalonThe most common guidelines for writing RST text are detailed in the
2356bdae907SThomas Monjalon`Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines.
2366bdae907SThomas MonjalonThe additional guidelines below reiterate or expand upon those guidelines.
2376bdae907SThomas Monjalon
2386bdae907SThomas Monjalon
239da78bca7SBruce RichardsonLine Length and Wrapping
240da78bca7SBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~
2416bdae907SThomas Monjalon
242da78bca7SBruce Richardson* Documentation lines should be less than 100 characters.
243da78bca7SBruce Richardson
244da78bca7SBruce Richardson* Each sentence should start on a new line.
245da78bca7SBruce Richardson  Multiple sentences, which are not separated by a blank line,
246da78bca7SBruce Richardson  are joined automatically into paragraphs.
247da78bca7SBruce Richardson
248da78bca7SBruce Richardson* Wrap sentences at punctuation points, for example, at a comma.
249da78bca7SBruce Richardson  If no punctuation, put the newline at a logical point in the sentence,
250da78bca7SBruce Richardson  for example, at the end of a clause before an "and" or "but".
2516bdae907SThomas Monjalon
252428eaeb8SThomas Monjalon* Lines in literal blocks should be less than 80 characters
253428eaeb8SThomas Monjalon  since they are not wrapped by the document formatters.
2546bdae907SThomas Monjalon
25524c7008fSJohn McNamara  Long literal command lines can be shown wrapped with backslashes. For
25624c7008fSJohn McNamara  example::
2576bdae907SThomas Monjalon
258532e4e48SCiara Power     dpdk-testpmd -l 2-3 -n 4 \
25924c7008fSJohn McNamara             --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \
26071ac6399STiwei Bie             -- -i --tx-offloads=0x0000002c --enable-lro --txq=2 --rxq=2 \
26171ac6399STiwei Bie             --txd=1024 --rxd=1024
2626bdae907SThomas Monjalon
2636bdae907SThomas Monjalon
2646bdae907SThomas MonjalonWhitespace
2656bdae907SThomas Monjalon~~~~~~~~~~
2666bdae907SThomas Monjalon
2676bdae907SThomas Monjalon* Standard RST indentation is 3 spaces.
2686bdae907SThomas Monjalon  Code can be indented 4 spaces, especially if it is copied from source files.
2696bdae907SThomas Monjalon
2706bdae907SThomas Monjalon* No tabs.
2716bdae907SThomas Monjalon  Convert tabs in embedded code to 4 or 8 spaces.
2726bdae907SThomas Monjalon
2736bdae907SThomas Monjalon* No trailing whitespace.
2746bdae907SThomas Monjalon
2756bdae907SThomas Monjalon* Add 2 blank lines before each section header.
2766bdae907SThomas Monjalon
2776bdae907SThomas Monjalon* Add 1 blank line after each section header.
2786bdae907SThomas Monjalon
2796bdae907SThomas Monjalon* Add 1 blank line between each line of a list.
2806bdae907SThomas Monjalon
2816bdae907SThomas Monjalon
2826bdae907SThomas MonjalonSection Headers
2836bdae907SThomas Monjalon~~~~~~~~~~~~~~~
2846bdae907SThomas Monjalon
285a56d1d55SYong Wang* Section headers should use the following underline formats::
2866bdae907SThomas Monjalon
2876bdae907SThomas Monjalon   Level 1 Heading
2886bdae907SThomas Monjalon   ===============
2896bdae907SThomas Monjalon
2906bdae907SThomas Monjalon
2916bdae907SThomas Monjalon   Level 2 Heading
2926bdae907SThomas Monjalon   ---------------
2936bdae907SThomas Monjalon
2946bdae907SThomas Monjalon
2956bdae907SThomas Monjalon   Level 3 Heading
2966bdae907SThomas Monjalon   ~~~~~~~~~~~~~~~
2976bdae907SThomas Monjalon
2986bdae907SThomas Monjalon
2996bdae907SThomas Monjalon   Level 4 Heading
3006bdae907SThomas Monjalon   ^^^^^^^^^^^^^^^
3016bdae907SThomas Monjalon
3026bdae907SThomas Monjalon
3036bdae907SThomas Monjalon* Level 4 headings should be used sparingly.
3046bdae907SThomas Monjalon
3056bdae907SThomas Monjalon* The underlines should match the length of the text.
3066bdae907SThomas Monjalon
3076bdae907SThomas Monjalon* In general, the heading should be less than 80 characters, for conciseness.
3086bdae907SThomas Monjalon
3096bdae907SThomas Monjalon* As noted above:
3106bdae907SThomas Monjalon
3116bdae907SThomas Monjalon   * Add 2 blank lines before each section header.
3126bdae907SThomas Monjalon
3136bdae907SThomas Monjalon   * Add 1 blank line after each section header.
3146bdae907SThomas Monjalon
3156bdae907SThomas Monjalon
3166bdae907SThomas MonjalonLists
3176bdae907SThomas Monjalon~~~~~
3186bdae907SThomas Monjalon
3196bdae907SThomas Monjalon* Bullet lists should be formatted with a leading ``*`` as follows::
3206bdae907SThomas Monjalon
3216bdae907SThomas Monjalon     * Item one.
3226bdae907SThomas Monjalon
3236bdae907SThomas Monjalon     * Item two is a long line that is wrapped and then indented to match
3246bdae907SThomas Monjalon       the start of the previous line.
3256bdae907SThomas Monjalon
3266bdae907SThomas Monjalon     * One space character between the bullet and the text is preferred.
3276bdae907SThomas Monjalon
3286bdae907SThomas Monjalon* Numbered lists can be formatted with a leading number but the preference is to use ``#.`` which will give automatic numbering.
3296bdae907SThomas Monjalon  This is more convenient when adding or removing items::
3306bdae907SThomas Monjalon
3316bdae907SThomas Monjalon     #. Item one.
3326bdae907SThomas Monjalon
3336bdae907SThomas Monjalon     #. Item two is a long line that is wrapped and then indented to match
3346bdae907SThomas Monjalon        the start of the previous line.
3356bdae907SThomas Monjalon
336bc474e72SYong Wang     #. Item three.
337bc474e72SYong Wang
3386bdae907SThomas Monjalon* Definition lists can be written with or without a bullet::
3396bdae907SThomas Monjalon
3406bdae907SThomas Monjalon     * Item one.
3416bdae907SThomas Monjalon
3426bdae907SThomas Monjalon       Some text about item one.
3436bdae907SThomas Monjalon
3446bdae907SThomas Monjalon     * Item two.
3456bdae907SThomas Monjalon
3466bdae907SThomas Monjalon       Some text about item two.
3476bdae907SThomas Monjalon
3486bdae907SThomas Monjalon* All lists, and sub-lists, must be separated from the preceding text by a blank line.
3496bdae907SThomas Monjalon  This is a syntax requirement.
3506bdae907SThomas Monjalon
3516bdae907SThomas Monjalon* All list items should be separated by a blank line for readability.
3526bdae907SThomas Monjalon
3536bdae907SThomas Monjalon
3546bdae907SThomas MonjalonCode and Literal block sections
3556bdae907SThomas Monjalon~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3566bdae907SThomas Monjalon
3576bdae907SThomas Monjalon* Inline text that is required to be rendered with a fixed width font should be enclosed in backquotes like this:
3586bdae907SThomas Monjalon  \`\`text\`\`, so that it appears like this: ``text``.
3596bdae907SThomas Monjalon
3606bdae907SThomas Monjalon* Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this::
3616bdae907SThomas Monjalon
3626bdae907SThomas Monjalon     Here is some fixed width text::
3636bdae907SThomas Monjalon
3646bdae907SThomas Monjalon        0x0001 0x0001 0x00FF 0x00FF
3656bdae907SThomas Monjalon
3666bdae907SThomas Monjalon* It is also possible to specify an encoding for a literal block using the ``.. code-block::`` directive so that syntax
3676bdae907SThomas Monjalon  highlighting can be applied.
3686bdae907SThomas Monjalon  Examples of supported highlighting are::
3696bdae907SThomas Monjalon
3706bdae907SThomas Monjalon     .. code-block:: console
3716bdae907SThomas Monjalon     .. code-block:: c
3726bdae907SThomas Monjalon     .. code-block:: python
3736bdae907SThomas Monjalon     .. code-block:: diff
3746bdae907SThomas Monjalon     .. code-block:: none
3756bdae907SThomas Monjalon
3766bdae907SThomas Monjalon  That can be applied as follows::
3776bdae907SThomas Monjalon
3786bdae907SThomas Monjalon      .. code-block:: c
3796bdae907SThomas Monjalon
3806bdae907SThomas Monjalon         #include<stdio.h>
3816bdae907SThomas Monjalon
3826bdae907SThomas Monjalon         int main() {
3836bdae907SThomas Monjalon
3846bdae907SThomas Monjalon            printf("Hello World\n");
3856bdae907SThomas Monjalon
3866bdae907SThomas Monjalon            return 0;
3876bdae907SThomas Monjalon         }
3886bdae907SThomas Monjalon
3896bdae907SThomas Monjalon  Which would be rendered as:
3906bdae907SThomas Monjalon
3916bdae907SThomas Monjalon  .. code-block:: c
3926bdae907SThomas Monjalon
3936bdae907SThomas Monjalon      #include<stdio.h>
3946bdae907SThomas Monjalon
3956bdae907SThomas Monjalon      int main() {
3966bdae907SThomas Monjalon
3976bdae907SThomas Monjalon         printf("Hello World\n");
3986bdae907SThomas Monjalon
3996bdae907SThomas Monjalon         return 0;
4006bdae907SThomas Monjalon      }
4016bdae907SThomas Monjalon
402413c75c3SConor Walsh* Code snippets can also be included directly from the code using the ``literalinclude`` block.
403413c75c3SConor Walsh  Using this block instead of a code block will ensure that the code snippets
404413c75c3SConor Walsh  shown in the documentation are always up to date with the code.
405413c75c3SConor Walsh
406413c75c3SConor Walsh  The following will include a snippet from the skeleton sample app::
407413c75c3SConor Walsh
408413c75c3SConor Walsh      .. literalinclude:: ../../../examples/skeleton/basicfwd.c
409413c75c3SConor Walsh         :language: c
410413c75c3SConor Walsh         :start-after: Display the port MAC address.
411413c75c3SConor Walsh         :end-before: Enable RX in promiscuous mode for the Ethernet device.
412413c75c3SConor Walsh         :dedent: 1
413413c75c3SConor Walsh
414413c75c3SConor Walsh  This would be rendered as:
415413c75c3SConor Walsh
416413c75c3SConor Walsh  .. literalinclude:: ../../../examples/skeleton/basicfwd.c
417413c75c3SConor Walsh     :language: c
418413c75c3SConor Walsh     :start-after: Display the port MAC address.
419413c75c3SConor Walsh     :end-before: Enable RX in promiscuous mode for the Ethernet device.
420413c75c3SConor Walsh     :dedent: 1
421413c75c3SConor Walsh
422413c75c3SConor Walsh  Specifying ``:language:`` will enable syntax highlighting for the specified language.
423413c75c3SConor Walsh  ``:dedent:`` is used in this example to remove 1 leading tab from each line of the snippet.
424413c75c3SConor Walsh
425413c75c3SConor Walsh* ``start-after`` and ``end-before`` can use any text within a given file,
426413c75c3SConor Walsh  however it may be difficult to find unique text within your code to mark the
427413c75c3SConor Walsh  start and end of your snippets. In these cases, it is recommended to include
428413c75c3SConor Walsh  explicit tags in your code to denote these locations for documentation purposes.
429413c75c3SConor Walsh  The accepted format for these comments is:
430413c75c3SConor Walsh
431413c75c3SConor Walsh     * Before the code snippet, create a new comment which is a sentence explaining
432413c75c3SConor Walsh       what the code snippet contains. The comment is terminated with a scissors ``8<``.
433413c75c3SConor Walsh     * After the code snippet, create another new comment which starts with a
434413c75c3SConor Walsh       scissors ``>8``, then ``End of`` and the first comment repeated.
435413c75c3SConor Walsh     * The scissors should be orientated as shown to make it clear what code is being snipped.
436413c75c3SConor Walsh
437413c75c3SConor Walsh  This can be done as follows:
438413c75c3SConor Walsh
439413c75c3SConor Walsh  .. code-block:: c
440413c75c3SConor Walsh
441413c75c3SConor Walsh    /* Example feature being documented. 8< */
442413c75c3SConor Walsh    foo(bar);
443413c75c3SConor Walsh    /* >8 End of example feature being documented. */
444413c75c3SConor Walsh
445413c75c3SConor Walsh  ``foo(bar);`` could then be included in the docs using::
446413c75c3SConor Walsh
447413c75c3SConor Walsh      .. literalinclude:: ../../../examples/sample_app/main.c
448413c75c3SConor Walsh         :language: c
449413c75c3SConor Walsh         :start-after: Example feature being documented. 8<
450413c75c3SConor Walsh         :end-before: >8 End of example feature being documented.
451413c75c3SConor Walsh
452413c75c3SConor Walsh  If a multiline comment is needed before the snippet,
453413c75c3SConor Walsh  then the last line of the multiline comment should be in the same format as
454413c75c3SConor Walsh  the first comment shown in the example.
455413c75c3SConor Walsh
456413c75c3SConor Walsh* More information about the ``literalinclude`` block can be found within the
457413c75c3SConor Walsh  `Sphinx Documentation <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html?highlight=literalinclude#directive-literalinclude>`_.
4586bdae907SThomas Monjalon
4596bdae907SThomas Monjalon* The default encoding for a literal block using the simplified ``::``
4606bdae907SThomas Monjalon  directive is ``none``.
4616bdae907SThomas Monjalon
462428eaeb8SThomas Monjalon* Lines in literal blocks should be less than 80 characters.
463428eaeb8SThomas Monjalon  For long literal lines, try to wrap the text at sensible locations.
4646bdae907SThomas Monjalon  For example a long command line could be documented like this and still work if copied directly from the docs::
4656bdae907SThomas Monjalon
466532e4e48SCiara Power     ./<build_dir>/app/dpdk-testpmd -l 0-2 -n3 --vdev=net_pcap0,iface=eth0    \
46758c82067SThomas Monjalon                               --vdev=net_pcap1,iface=eth1     \
4686bdae907SThomas Monjalon                               -- -i --nb-cores=2 --nb-ports=2 \
4696bdae907SThomas Monjalon                                  --total-num-mbufs=2048
4706bdae907SThomas Monjalon
4716bdae907SThomas Monjalon* Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters.
4726bdae907SThomas Monjalon
4736bdae907SThomas Monjalon
4746bdae907SThomas MonjalonImages
4756bdae907SThomas Monjalon~~~~~~
4766bdae907SThomas Monjalon
4776bdae907SThomas Monjalon* All images should be in SVG scalar graphics format.
4786bdae907SThomas Monjalon  They should be true SVG XML files and should not include binary formats embedded in a SVG wrapper.
4796bdae907SThomas Monjalon
4806bdae907SThomas Monjalon* The DPDK documentation contains some legacy images in PNG format.
4816bdae907SThomas Monjalon  These will be converted to SVG in time.
4826bdae907SThomas Monjalon
48388284dccSJohn McNamara* `Inkscape <http://inkscape.org>`_ is the recommended graphics editor for creating the images.
4846bdae907SThomas Monjalon  Use some of the older images in ``doc/guides/prog_guide/img/`` as a template, for example ``mbuf1.svg``
485bc474e72SYong Wang  or ``ring-enqueue1.svg``.
4866bdae907SThomas Monjalon
4876bdae907SThomas Monjalon* The SVG images should include a copyright notice, as an XML comment.
4886bdae907SThomas Monjalon
4896bdae907SThomas Monjalon* Images in the documentation should be formatted as follows:
4906bdae907SThomas Monjalon
4916bdae907SThomas Monjalon   * The image should be preceded by a label in the format ``.. _figure_XXXX:`` with a leading underscore and
4926bdae907SThomas Monjalon     where ``XXXX`` is a unique descriptive name.
4936bdae907SThomas Monjalon
4946bdae907SThomas Monjalon   * Images should be included using the ``.. figure::`` directive and the file type should be set to ``*`` (not ``.svg``).
4956bdae907SThomas Monjalon     This allows the format of the image to be changed if required, without updating the documentation.
4966bdae907SThomas Monjalon
4976bdae907SThomas Monjalon   * Images must have a caption as part of the ``.. figure::`` directive.
4986bdae907SThomas Monjalon
4996bdae907SThomas Monjalon* Here is an example of the previous three guidelines::
5006bdae907SThomas Monjalon
5016bdae907SThomas Monjalon     .. _figure_mempool:
5026bdae907SThomas Monjalon
5036bdae907SThomas Monjalon     .. figure:: img/mempool.*
5046bdae907SThomas Monjalon
5056bdae907SThomas Monjalon        A mempool in memory with its associated ring.
5066bdae907SThomas Monjalon
5076bdae907SThomas Monjalon.. _mock_label:
5086bdae907SThomas Monjalon
5096bdae907SThomas Monjalon* Images can then be linked to using the ``:numref:`` directive::
5106bdae907SThomas Monjalon
5116bdae907SThomas Monjalon     The mempool layout is shown in :numref:`figure_mempool`.
5126bdae907SThomas Monjalon
5136bdae907SThomas Monjalon  This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`.
5146bdae907SThomas Monjalon
5156bdae907SThomas Monjalon  **Note**: The ``:numref:`` directive requires Sphinx 1.3.1 or later.
5166bdae907SThomas Monjalon  With earlier versions it will still be rendered as a link but won't have an automatically generated number.
5176bdae907SThomas Monjalon
5186bdae907SThomas Monjalon* The caption of the image can be generated, with a link, using the ``:ref:`` directive::
5196bdae907SThomas Monjalon
5206bdae907SThomas Monjalon     :ref:`figure_mempool`
5216bdae907SThomas Monjalon
5226bdae907SThomas Monjalon  This would be rendered as: *A mempool in memory with its associated ring.*
5236bdae907SThomas Monjalon
5246bdae907SThomas MonjalonTables
5256bdae907SThomas Monjalon~~~~~~
5266bdae907SThomas Monjalon
5276bdae907SThomas Monjalon* RST tables should be used sparingly.
528428eaeb8SThomas Monjalon  They are hard to format and to edit, and the same information
5296bdae907SThomas Monjalon  can usually be shown just as clearly with a definition or bullet list.
5306bdae907SThomas Monjalon
5316bdae907SThomas Monjalon* Tables in the documentation should be formatted as follows:
5326bdae907SThomas Monjalon
5336bdae907SThomas Monjalon   * The table should be preceded by a label in the format ``.. _table_XXXX:`` with a leading underscore and where
5346bdae907SThomas Monjalon     ``XXXX`` is a unique descriptive name.
5356bdae907SThomas Monjalon
5366bdae907SThomas Monjalon   * Tables should be included using the ``.. table::`` directive and must have a caption.
5376bdae907SThomas Monjalon
5386bdae907SThomas Monjalon* Here is an example of the previous two guidelines::
5396bdae907SThomas Monjalon
5406bdae907SThomas Monjalon     .. _table_qos_pipes:
5416bdae907SThomas Monjalon
5426bdae907SThomas Monjalon     .. table:: Sample configuration for QOS pipes.
5436bdae907SThomas Monjalon
5446bdae907SThomas Monjalon        +----------+----------+----------+
5456bdae907SThomas Monjalon        | Header 1 | Header 2 | Header 3 |
5466bdae907SThomas Monjalon        |          |          |          |
5476bdae907SThomas Monjalon        +==========+==========+==========+
5486bdae907SThomas Monjalon        | Text     | Text     | Text     |
5496bdae907SThomas Monjalon        +----------+----------+----------+
5506bdae907SThomas Monjalon        | ...      | ...      | ...      |
5516bdae907SThomas Monjalon        +----------+----------+----------+
5526bdae907SThomas Monjalon
5536bdae907SThomas Monjalon* Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images.
5546bdae907SThomas Monjalon  For example::
5556bdae907SThomas Monjalon
5566bdae907SThomas Monjalon     The QOS configuration is shown in :numref:`table_qos_pipes`.
5576bdae907SThomas Monjalon
5586bdae907SThomas Monjalon
5596bdae907SThomas Monjalon.. _links:
5606bdae907SThomas Monjalon
5616bdae907SThomas MonjalonHyperlinks
5626bdae907SThomas Monjalon~~~~~~~~~~
5636bdae907SThomas Monjalon
5646bdae907SThomas Monjalon* Links to external websites can be plain URLs.
5653d4b2afbSDavid Marchand  The following is rendered as https://dpdk.org::
5666bdae907SThomas Monjalon
5673d4b2afbSDavid Marchand     https://dpdk.org
5686bdae907SThomas Monjalon
5696bdae907SThomas Monjalon* They can contain alternative text.
5703d4b2afbSDavid Marchand  The following is rendered as `Check out DPDK <https://dpdk.org>`_::
5716bdae907SThomas Monjalon
5723d4b2afbSDavid Marchand     `Check out DPDK <https://dpdk.org>`_
5736bdae907SThomas Monjalon
5746bdae907SThomas Monjalon* An internal link can be generated by placing labels in the document with the format ``.. _label_name``.
5756bdae907SThomas Monjalon
5766bdae907SThomas Monjalon* The following links to the top of this section: :ref:`links`::
5776bdae907SThomas Monjalon
5786bdae907SThomas Monjalon     .. _links:
5796bdae907SThomas Monjalon
5806bdae907SThomas Monjalon     Hyperlinks
5816bdae907SThomas Monjalon     ~~~~~~~~~~
5826bdae907SThomas Monjalon
5836bdae907SThomas Monjalon     * The following links to the top of this section: :ref:`links`:
5846bdae907SThomas Monjalon
5856bdae907SThomas Monjalon.. Note::
5866bdae907SThomas Monjalon
5876bdae907SThomas Monjalon   The label must have a leading underscore but the reference to it must omit it.
5886bdae907SThomas Monjalon   This is a frequent cause of errors and warnings.
5896bdae907SThomas Monjalon
5906bdae907SThomas Monjalon* The use of a label is preferred since it works across files and will still work if the header text changes.
5916bdae907SThomas Monjalon
5926bdae907SThomas Monjalon
5936bdae907SThomas Monjalon.. _doxygen_guidelines:
5946bdae907SThomas Monjalon
5956bdae907SThomas MonjalonDoxygen Guidelines
5966bdae907SThomas Monjalon------------------
5976bdae907SThomas Monjalon
5986bdae907SThomas MonjalonThe DPDK API is documented using Doxygen comment annotations in the header files.
5996bdae907SThomas MonjalonDoxygen is a very powerful tool, it is extremely configurable and with a little effort can be used to create expressive documents.
600047b663aSDekel PeledSee the `Doxygen website <http://www.doxygen.nl>`_ for full details on how to use it.
6016bdae907SThomas Monjalon
6026bdae907SThomas MonjalonThe following are some guidelines for use of Doxygen in the DPDK API documentation:
6036bdae907SThomas Monjalon
6046bdae907SThomas Monjalon* New libraries that are documented with Doxygen should be added to the Doxygen configuration file: ``doc/api/doxy-api.conf``.
6056bdae907SThomas Monjalon  It is only required to add the directory that contains the files.
6066bdae907SThomas Monjalon  It isn't necessary to explicitly name each file since the configuration matches all ``rte_*.h`` files in the directory.
6076bdae907SThomas Monjalon
6086bdae907SThomas Monjalon* Use proper capitalization and punctuation in the Doxygen comments since they will become sentences in the documentation.
6096bdae907SThomas Monjalon  This in particular applies to single line comments, which is the case the is most often forgotten.
6106bdae907SThomas Monjalon
6116bdae907SThomas Monjalon* Use ``@`` style Doxygen commands instead of ``\`` style commands.
6126bdae907SThomas Monjalon
6136bdae907SThomas Monjalon* Add a general description of each library at the head of the main header files:
6146bdae907SThomas Monjalon
6156bdae907SThomas Monjalon  .. code-block:: c
6166bdae907SThomas Monjalon
6176bdae907SThomas Monjalon      /**
6186bdae907SThomas Monjalon       * @file
6196bdae907SThomas Monjalon       * RTE Mempool.
6206bdae907SThomas Monjalon       *
6216bdae907SThomas Monjalon       * A memory pool is an allocator of fixed-size object. It is
6226bdae907SThomas Monjalon       * identified by its name, and uses a ring to store free objects.
6236bdae907SThomas Monjalon       * ...
6246bdae907SThomas Monjalon       */
6256bdae907SThomas Monjalon
6266bdae907SThomas Monjalon* Document the purpose of a function, the parameters used and the return
6276bdae907SThomas Monjalon  value:
6286bdae907SThomas Monjalon
6296bdae907SThomas Monjalon  .. code-block:: c
6306bdae907SThomas Monjalon
6316bdae907SThomas Monjalon     /**
6325f63d635SThomas Monjalon      * Try to take the lock.
6336bdae907SThomas Monjalon      *
6345f63d635SThomas Monjalon      * @param sl
6355f63d635SThomas Monjalon      *   A pointer to the spinlock.
6366bdae907SThomas Monjalon      * @return
6375f63d635SThomas Monjalon      *   1 if the lock is successfully taken; 0 otherwise.
6386bdae907SThomas Monjalon      */
6395f63d635SThomas Monjalon     int rte_spinlock_trylock(rte_spinlock_t *sl);
6406bdae907SThomas Monjalon
6416bdae907SThomas Monjalon* Doxygen supports Markdown style syntax such as bold, italics, fixed width text and lists.
6426bdae907SThomas Monjalon  For example the second line in the ``devargs`` parameter in the previous example will be rendered as:
6436bdae907SThomas Monjalon
6445fc07e3eSThomas Monjalon     The strings should be a pci address like ``0000:01:00.0`` or **virtual** device name like ``net_pcap0``.
6456bdae907SThomas Monjalon
6466bdae907SThomas Monjalon* Use ``-`` instead of ``*`` for lists within the Doxygen comment since the latter can get confused with the comment delimiter.
6476bdae907SThomas Monjalon
6486bdae907SThomas Monjalon* Add an empty line between the function description, the ``@params`` and ``@return`` for readability.
6496bdae907SThomas Monjalon
6506bdae907SThomas Monjalon* Place the ``@params`` description on separate line and indent it by 2 spaces.
6516bdae907SThomas Monjalon  (It would be better to use no indentation since this is more common and also because checkpatch complains about leading
6526bdae907SThomas Monjalon  whitespace in comments.
6536bdae907SThomas Monjalon  However this is the convention used in the existing DPDK code.)
6546bdae907SThomas Monjalon
6556bdae907SThomas Monjalon* Documented functions can be linked to simply by adding ``()`` to the function name:
6566bdae907SThomas Monjalon
6576bdae907SThomas Monjalon  .. code-block:: c
6586bdae907SThomas Monjalon
6596bdae907SThomas Monjalon      /**
6606bdae907SThomas Monjalon       * The functions exported by the application Ethernet API to setup
6616bdae907SThomas Monjalon       * a device designated by its port identifier must be invoked in
6626bdae907SThomas Monjalon       * the following order:
6636bdae907SThomas Monjalon       *     - rte_eth_dev_configure()
6646bdae907SThomas Monjalon       *     - rte_eth_tx_queue_setup()
6656bdae907SThomas Monjalon       *     - rte_eth_rx_queue_setup()
6666bdae907SThomas Monjalon       *     - rte_eth_dev_start()
6676bdae907SThomas Monjalon       */
6686bdae907SThomas Monjalon
6696bdae907SThomas Monjalon  In the API documentation the functions will be rendered as links, see the
6703d4b2afbSDavid Marchand  `online section of the rte_ethdev.h docs <https://doc.dpdk.org/api/rte__ethdev_8h.html>`_ that contains the above text.
6716bdae907SThomas Monjalon
6726bdae907SThomas Monjalon* The ``@see`` keyword can be used to create a *see also* link to another file or library.
6736bdae907SThomas Monjalon  This directive should be placed on one line at the bottom of the documentation section.
6746bdae907SThomas Monjalon
6756bdae907SThomas Monjalon  .. code-block:: c
6766bdae907SThomas Monjalon
6776bdae907SThomas Monjalon     /**
6786bdae907SThomas Monjalon      * ...
6796bdae907SThomas Monjalon      *
6806bdae907SThomas Monjalon      * Some text that references mempools.
6816bdae907SThomas Monjalon      *
6826bdae907SThomas Monjalon      * @see eal_memzone.c
6836bdae907SThomas Monjalon      */
6846bdae907SThomas Monjalon
6856bdae907SThomas Monjalon* Doxygen supports two types of comments for documenting variables, constants and members: prefix and postfix:
6866bdae907SThomas Monjalon
6876bdae907SThomas Monjalon  .. code-block:: c
6886bdae907SThomas Monjalon
6896bdae907SThomas Monjalon     /** This is a prefix comment. */
6906bdae907SThomas Monjalon     #define RTE_FOO_ERROR  0x023.
6916bdae907SThomas Monjalon
6926bdae907SThomas Monjalon     #define RTE_BAR_ERROR  0x024. /**< This is a postfix comment. */
6936bdae907SThomas Monjalon
6946bdae907SThomas Monjalon* Postfix comments are preferred for struct members and constants if they can be documented in the same way:
6956bdae907SThomas Monjalon
6966bdae907SThomas Monjalon  .. code-block:: c
6976bdae907SThomas Monjalon
6986bdae907SThomas Monjalon     struct rte_eth_stats {
6996bdae907SThomas Monjalon         uint64_t ipackets; /**< Total number of received packets. */
7006bdae907SThomas Monjalon         uint64_t opackets; /**< Total number of transmitted packets.*/
7016bdae907SThomas Monjalon         uint64_t ibytes;   /**< Total number of received bytes. */
7026bdae907SThomas Monjalon         uint64_t obytes;   /**< Total number of transmitted bytes. */
7036bdae907SThomas Monjalon         uint64_t imissed;  /**< Total of RX missed packets. */
7046bdae907SThomas Monjalon         uint64_t ibadcrc;  /**< Total of RX packets with CRC error. */
7056bdae907SThomas Monjalon         uint64_t ibadlen;  /**< Total of RX packets with bad length. */
7066bdae907SThomas Monjalon     }
7076bdae907SThomas Monjalon
7086bdae907SThomas Monjalon  Note: postfix comments should be aligned with spaces not tabs in accordance
7096bdae907SThomas Monjalon  with the :ref:`coding_style`.
7106bdae907SThomas Monjalon
7116bdae907SThomas Monjalon* If a single comment type can't be used, due to line length limitations then
7126bdae907SThomas Monjalon  prefix comments should be preferred.
7136bdae907SThomas Monjalon  For example this section of the code contains prefix comments, postfix comments on the same line and postfix
7146bdae907SThomas Monjalon  comments on a separate line:
7156bdae907SThomas Monjalon
7166bdae907SThomas Monjalon  .. code-block:: c
7176bdae907SThomas Monjalon
7186bdae907SThomas Monjalon     /** Number of elements in the elt_pa array. */
719e9fd1ebfSTyler Retzlaff     alignas(RTE_CACHE_LINE_SIZE) uint32_t    pg_num;
7206bdae907SThomas Monjalon     uint32_t    pg_shift;     /**< LOG2 of the physical pages. */
7216bdae907SThomas Monjalon     uintptr_t   pg_mask;      /**< Physical page mask value. */
7226bdae907SThomas Monjalon     uintptr_t   elt_va_start;
7236bdae907SThomas Monjalon     /**< Virtual address of the first mempool object. */
7246bdae907SThomas Monjalon     uintptr_t   elt_va_end;
7256bdae907SThomas Monjalon     /**< Virtual address of the <size + 1> mempool object. */
726fb11ae88SAndrew Rybchenko     phys_addr_t elt_pa[1];
7276bdae907SThomas Monjalon     /**< Array of physical page addresses for the mempool buffer. */
7286bdae907SThomas Monjalon
7296bdae907SThomas Monjalon  This doesn't have an effect on the rendered documentation but it is confusing for the developer reading the code.
7306bdae907SThomas Monjalon  It this case it would be clearer to use prefix comments throughout:
7316bdae907SThomas Monjalon
7326bdae907SThomas Monjalon  .. code-block:: c
7336bdae907SThomas Monjalon
7346bdae907SThomas Monjalon     /** Number of elements in the elt_pa array. */
735e9fd1ebfSTyler Retzlaff     alignas(RTE_CACHE_LINE_SIZE) uint32_t    pg_num;
7366bdae907SThomas Monjalon     /** LOG2 of the physical pages. */
7376bdae907SThomas Monjalon     uint32_t    pg_shift;
7386bdae907SThomas Monjalon     /** Physical page mask value. */
7396bdae907SThomas Monjalon     uintptr_t   pg_mask;
7406bdae907SThomas Monjalon     /** Virtual address of the first mempool object. */
7416bdae907SThomas Monjalon     uintptr_t   elt_va_start;
7426bdae907SThomas Monjalon     /** Virtual address of the <size + 1> mempool object. */
7436bdae907SThomas Monjalon     uintptr_t   elt_va_end;
7446bdae907SThomas Monjalon     /** Array of physical page addresses for the mempool buffer. */
745fb11ae88SAndrew Rybchenko     phys_addr_t elt_pa[1];
7466bdae907SThomas Monjalon
7476bdae907SThomas Monjalon* Read the rendered section of the documentation that you have added for correctness, clarity and consistency
7486bdae907SThomas Monjalon  with the surrounding text.
749