3 DPDK Documentation Guidelines
4 =============================
6 This document outlines the guidelines for writing the DPDK Guides and API documentation in RST and Doxygen format.
8 It also explains the structure of the DPDK documentation and shows how to build the Html and PDF versions of the documents.
11 Structure of the Documentation
12 ------------------------------
14 The DPDK source code repository contains input files to build the API documentation and User Guides.
16 The main directories that contain files related to documentation are shown below::
40 The API documentation is built from `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`_ comments in the header files.
41 These files are mainly in the ``lib/librte_*`` directories although some of the Poll Mode Drivers in ``drivers/net``
42 are also documented with Doxygen.
44 The configuration files that are used to control the Doxygen output are in the ``doc/api`` directory.
46 The user guides such as *The Programmers Guide* and the *FreeBSD* and *Linux Getting Started* Guides are generated
47 from RST markup text files using the `Sphinx <http://sphinx-doc.org/index.html>`_ Documentation Generator.
49 These files are included in the ``doc/guides/`` directory.
50 The output is controlled by the ``doc/guides/conf.py`` file.
53 Role of the Documentation
54 -------------------------
56 The following items outline the roles of the different parts of the documentation and when they need to be updated or
57 added to by the developer.
61 The Release Notes document which features have been added in the current and previous releases of DPDK and highlight
63 The Releases Notes also contain notifications of features that will change ABI compatibility in the next major release.
65 Developers should include updates to the Release Notes with patch sets that relate to any of the following sections:
68 * Resolved Issues (see below)
72 * Shared Library Versions
74 Resolved Issues should only include issues from previous releases that have been resolved in the current release.
75 Issues that are introduced and then fixed within a release cycle do not have to be included here.
77 Refer to the Release Notes from the previous DPDK release for the correct format of each section.
80 * **API documentation**
82 The API documentation explains how to use the public DPDK functions.
83 The `API index page <http://dpdk.org/doc/api/>`_ shows the generated API documentation with related groups of functions.
85 The API documentation should be updated via Doxygen comments when new functions are added.
87 * **Getting Started Guides**
89 The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes.
91 A Getting Started Guide should be added when DPDK is ported to a new OS.
93 * **The Programmers Guide**
95 The Programmers Guide explains how the API components of DPDK such as the EAL, Memzone, Rings and the Hash Library work.
96 It also explains how some higher level functionality such as Packet Distributor, Packet Framework and KNI work.
97 It also shows the build system and explains how to add applications.
99 The Programmers Guide should be expanded when new functionality is added to DPDK.
103 The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``.
105 The app guides should be updated if functionality is changed or added.
107 * **Sample App Guides**
109 The sample app guides document the DPDK example applications in the examples directory.
110 Generally they demonstrate a major feature such as L2 or L3 Forwarding, Multi Process or Power Management.
111 They explain the purpose of the sample application, how to run it and step through some of the code to explain the
114 A new sample application should be accompanied by a new sample app guide.
115 The guide for the Skeleton Forwarding app is a good starting reference.
117 * **Network Interface Controller Drivers**
119 The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements,
120 configuration and initialization.
122 New documentation should be added for new Poll Mode Drivers.
126 The guideline documents record community process, expectations and design directions.
128 They can be extended, amended or discussed by submitting a patch and getting community approval.
131 Building the Documentation
132 --------------------------
138 The following dependencies must be installed to build the documentation:
142 * Sphinx (also called python-sphinx).
144 * TexLive (at least TexLive-core and the extra Latex support).
148 `Doxygen`_ generates documentation from commented source code.
149 It can be installed as follows:
151 .. code-block:: console
154 sudo apt-get -y install doxygen
157 sudo dnf -y install doxygen
159 `Sphinx`_ is a Python documentation tool for converting RST files to Html or to PDF (via LaTeX).
160 For full support with figure and table captioning the latest version of Sphinx can be installed as follows:
162 .. code-block:: console
165 sudo apt-get -y install python-pip
166 sudo pip install --upgrade sphinx
167 sudo pip install --upgrade sphinx_rtd_theme
170 sudo dnf -y install python-pip
171 sudo pip install --upgrade sphinx
172 sudo pip install --upgrade sphinx_rtd_theme
174 For further information on getting started with Sphinx see the `Sphinx Tutorial <http://sphinx-doc.org/tutorial.html>`_.
178 To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later.
181 `Inkscape`_ is a vector based graphics program which is used to create SVG images and also to convert SVG images to PDF images.
182 It can be installed as follows:
184 .. code-block:: console
187 sudo apt-get -y install inkscape
190 sudo dnf -y install inkscape
192 `TexLive <http://www.tug.org/texlive/>`_ is an installation package for Tex/LaTeX.
193 It is used to generate the PDF versions of the documentation.
194 The main required packages can be installed as follows:
196 .. code-block:: console
199 sudo apt-get -y install texlive-latex-extra
201 # Red Hat/Fedora, selective install.
202 sudo dnf -y install texlive-collection-latexextra
208 The documentation is built using the standard DPDK build system.
209 Some examples are shown below:
211 * Generate all the documentation targets::
215 * Generate the Doxygen API documentation in Html::
219 * Generate the guides documentation in Html::
223 * Generate the guides documentation in Pdf::
227 The output of these commands is generated in the ``build`` directory::
240 Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation.
242 The documentation output files can be removed as follows::
250 Here are some guidelines in relation to the style of the documentation:
252 * Document the obvious as well as the obscure since it won't always be obvious to the reader.
253 For example an instruction like "Set up 64 2MB Hugepages" is better when followed by a sample commandline or a link to
254 the appropriate section of the documentation.
256 * Use American English spellings throughout.
257 This can be checked using the ``aspell`` utility::
259 aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst
265 The RST (reStructuredText) format is a plain text markup format that can be converted to Html, PDF or other formats.
266 It is most closely associated with Python but it can be used to document any language.
267 It is used in DPDK to document everything apart from the API.
269 The Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a
270 good place to learn the minimal set of syntax required to format a document.
272 The official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the
273 RST format and also examples of how to use it.
274 However, for most developers the RST Primer is a better resource.
276 The most common guidelines for writing RST text are detailed in the
277 `Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines.
278 The additional guidelines below reiterate or expand upon those guidelines.
284 * Lines in sentences should be less than 80 characters and wrapped at
285 words. Multiple sentences which are not separated by a blank line are joined
286 automatically into paragraphs.
288 * Lines in literal blocks **must** be less than 80 characters since
289 they are not wrapped by the document formatters and can exceed the page width
292 Long literal command lines can be shown wrapped with backslashes. For
295 testpmd -l 2-3 -n 4 \
296 --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \
297 -- -i --txqflags=0x0 --enable-hw-vlan --enable-lro \
298 --enable-rx-cksum --txq=2 --rxq=2 --rxd=1024 --txd=1024
304 * Standard RST indentation is 3 spaces.
305 Code can be indented 4 spaces, especially if it is copied from source files.
308 Convert tabs in embedded code to 4 or 8 spaces.
310 * No trailing whitespace.
312 * Add 2 blank lines before each section header.
314 * Add 1 blank line after each section header.
316 * Add 1 blank line between each line of a list.
322 * Section headers should use the following underline formats::
340 * Level 4 headings should be used sparingly.
342 * The underlines should match the length of the text.
344 * In general, the heading should be less than 80 characters, for conciseness.
348 * Add 2 blank lines before each section header.
350 * Add 1 blank line after each section header.
356 * Bullet lists should be formatted with a leading ``*`` as follows::
360 * Item two is a long line that is wrapped and then indented to match
361 the start of the previous line.
363 * One space character between the bullet and the text is preferred.
365 * Numbered lists can be formatted with a leading number but the preference is to use ``#.`` which will give automatic numbering.
366 This is more convenient when adding or removing items::
370 #. Item two is a long line that is wrapped and then indented to match
371 the start of the previous line.
375 * Definition lists can be written with or without a bullet::
379 Some text about item one.
383 Some text about item two.
385 * All lists, and sub-lists, must be separated from the preceding text by a blank line.
386 This is a syntax requirement.
388 * All list items should be separated by a blank line for readability.
391 Code and Literal block sections
392 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394 * Inline text that is required to be rendered with a fixed width font should be enclosed in backquotes like this:
395 \`\`text\`\`, so that it appears like this: ``text``.
397 * Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this::
399 Here is some fixed width text::
401 0x0001 0x0001 0x00FF 0x00FF
403 * It is also possible to specify an encoding for a literal block using the ``.. code-block::`` directive so that syntax
404 highlighting can be applied.
405 Examples of supported highlighting are::
407 .. code-block:: console
409 .. code-block:: python
413 That can be applied as follows::
421 printf("Hello World\n");
426 Which would be rendered as:
434 printf("Hello World\n");
440 * The default encoding for a literal block using the simplified ``::``
441 directive is ``none``.
443 * Lines in literal blocks must be less than 80 characters since they can exceed the page width when converted to PDF documentation.
444 For long literal lines that exceed that limit try to wrap the text at sensible locations.
445 For example a long command line could be documented like this and still work if copied directly from the docs::
447 build/app/testpmd -l 0-2 -n3 --vdev=net_pcap0,iface=eth0 \
448 --vdev=net_pcap1,iface=eth1 \
449 -- -i --nb-cores=2 --nb-ports=2 \
450 --total-num-mbufs=2048
452 * Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters.
458 * All images should be in SVG scalar graphics format.
459 They should be true SVG XML files and should not include binary formats embedded in a SVG wrapper.
461 * The DPDK documentation contains some legacy images in PNG format.
462 These will be converted to SVG in time.
464 * `Inkscape <http://inkscape.org>`_ is the recommended graphics editor for creating the images.
465 Use some of the older images in ``doc/guides/prog_guide/img/`` as a template, for example ``mbuf1.svg``
466 or ``ring-enqueue1.svg``.
468 * The SVG images should include a copyright notice, as an XML comment.
470 * Images in the documentation should be formatted as follows:
472 * The image should be preceded by a label in the format ``.. _figure_XXXX:`` with a leading underscore and
473 where ``XXXX`` is a unique descriptive name.
475 * Images should be included using the ``.. figure::`` directive and the file type should be set to ``*`` (not ``.svg``).
476 This allows the format of the image to be changed if required, without updating the documentation.
478 * Images must have a caption as part of the ``.. figure::`` directive.
480 * Here is an example of the previous three guidelines::
484 .. figure:: img/mempool.*
486 A mempool in memory with its associated ring.
490 * Images can then be linked to using the ``:numref:`` directive::
492 The mempool layout is shown in :numref:`figure_mempool`.
494 This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`.
496 **Note**: The ``:numref:`` directive requires Sphinx 1.3.1 or later.
497 With earlier versions it will still be rendered as a link but won't have an automatically generated number.
499 * The caption of the image can be generated, with a link, using the ``:ref:`` directive::
501 :ref:`figure_mempool`
503 This would be rendered as: *A mempool in memory with its associated ring.*
508 * RST tables should be used sparingly.
509 They are hard to format and to edit, they are often rendered incorrectly in PDF format, and the same information
510 can usually be shown just as clearly with a definition or bullet list.
512 * Tables in the documentation should be formatted as follows:
514 * The table should be preceded by a label in the format ``.. _table_XXXX:`` with a leading underscore and where
515 ``XXXX`` is a unique descriptive name.
517 * Tables should be included using the ``.. table::`` directive and must have a caption.
519 * Here is an example of the previous two guidelines::
523 .. table:: Sample configuration for QOS pipes.
525 +----------+----------+----------+
526 | Header 1 | Header 2 | Header 3 |
528 +==========+==========+==========+
529 | Text | Text | Text |
530 +----------+----------+----------+
532 +----------+----------+----------+
534 * Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images.
537 The QOS configuration is shown in :numref:`table_qos_pipes`.
539 * Tables should not include merged cells since they are not supported by the PDF renderer.
547 * Links to external websites can be plain URLs.
548 The following is rendered as http://dpdk.org::
552 * They can contain alternative text.
553 The following is rendered as `Check out DPDK <http://dpdk.org>`_::
555 `Check out DPDK <http://dpdk.org>`_
557 * An internal link can be generated by placing labels in the document with the format ``.. _label_name``.
559 * The following links to the top of this section: :ref:`links`::
566 * The following links to the top of this section: :ref:`links`:
570 The label must have a leading underscore but the reference to it must omit it.
571 This is a frequent cause of errors and warnings.
573 * The use of a label is preferred since it works across files and will still work if the header text changes.
576 .. _doxygen_guidelines:
581 The DPDK API is documented using Doxygen comment annotations in the header files.
582 Doxygen is a very powerful tool, it is extremely configurable and with a little effort can be used to create expressive documents.
583 See the `Doxygen website <http://www.stack.nl/~dimitri/doxygen/>`_ for full details on how to use it.
585 The following are some guidelines for use of Doxygen in the DPDK API documentation:
587 * New libraries that are documented with Doxygen should be added to the Doxygen configuration file: ``doc/api/doxy-api.conf``.
588 It is only required to add the directory that contains the files.
589 It isn't necessary to explicitly name each file since the configuration matches all ``rte_*.h`` files in the directory.
591 * Use proper capitalization and punctuation in the Doxygen comments since they will become sentences in the documentation.
592 This in particular applies to single line comments, which is the case the is most often forgotten.
594 * Use ``@`` style Doxygen commands instead of ``\`` style commands.
596 * Add a general description of each library at the head of the main header files:
604 * A memory pool is an allocator of fixed-size object. It is
605 * identified by its name, and uses a ring to store free objects.
609 * Document the purpose of a function, the parameters used and the return
615 * Attach a new Ethernet device specified by arguments.
618 * A pointer to a strings array describing the new device
619 * to be attached. The strings should be a pci address like
620 * `0000:01:00.0` or **virtual** device name like `net_pcap0`.
622 * A pointer to a port identifier actually attached.
625 * 0 on success and port_id is filled, negative on error.
627 int rte_eth_dev_attach(const char *devargs, uint8_t *port_id);
629 * Doxygen supports Markdown style syntax such as bold, italics, fixed width text and lists.
630 For example the second line in the ``devargs`` parameter in the previous example will be rendered as:
632 The strings should be a pci address like ``0000:01:00.0`` or **virtual** device name like ``net_pcap0``.
634 * Use ``-`` instead of ``*`` for lists within the Doxygen comment since the latter can get confused with the comment delimiter.
636 * Add an empty line between the function description, the ``@params`` and ``@return`` for readability.
638 * Place the ``@params`` description on separate line and indent it by 2 spaces.
639 (It would be better to use no indentation since this is more common and also because checkpatch complains about leading
640 whitespace in comments.
641 However this is the convention used in the existing DPDK code.)
643 * Documented functions can be linked to simply by adding ``()`` to the function name:
648 * The functions exported by the application Ethernet API to setup
649 * a device designated by its port identifier must be invoked in
650 * the following order:
651 * - rte_eth_dev_configure()
652 * - rte_eth_tx_queue_setup()
653 * - rte_eth_rx_queue_setup()
654 * - rte_eth_dev_start()
657 In the API documentation the functions will be rendered as links, see the
658 `online section of the rte_ethdev.h docs <http://dpdk.org/doc/api/rte__ethdev_8h.html>`_ that contains the above text.
660 * The ``@see`` keyword can be used to create a *see also* link to another file or library.
661 This directive should be placed on one line at the bottom of the documentation section.
668 * Some text that references mempools.
673 * Doxygen supports two types of comments for documenting variables, constants and members: prefix and postfix:
677 /** This is a prefix comment. */
678 #define RTE_FOO_ERROR 0x023.
680 #define RTE_BAR_ERROR 0x024. /**< This is a postfix comment. */
682 * Postfix comments are preferred for struct members and constants if they can be documented in the same way:
686 struct rte_eth_stats {
687 uint64_t ipackets; /**< Total number of received packets. */
688 uint64_t opackets; /**< Total number of transmitted packets.*/
689 uint64_t ibytes; /**< Total number of received bytes. */
690 uint64_t obytes; /**< Total number of transmitted bytes. */
691 uint64_t imissed; /**< Total of RX missed packets. */
692 uint64_t ibadcrc; /**< Total of RX packets with CRC error. */
693 uint64_t ibadlen; /**< Total of RX packets with bad length. */
696 Note: postfix comments should be aligned with spaces not tabs in accordance
697 with the :ref:`coding_style`.
699 * If a single comment type can't be used, due to line length limitations then
700 prefix comments should be preferred.
701 For example this section of the code contains prefix comments, postfix comments on the same line and postfix
702 comments on a separate line:
706 /** Number of elements in the elt_pa array. */
707 uint32_t pg_num __rte_cache_aligned;
708 uint32_t pg_shift; /**< LOG2 of the physical pages. */
709 uintptr_t pg_mask; /**< Physical page mask value. */
710 uintptr_t elt_va_start;
711 /**< Virtual address of the first mempool object. */
712 uintptr_t elt_va_end;
713 /**< Virtual address of the <size + 1> mempool object. */
714 phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
715 /**< Array of physical page addresses for the mempool buffer. */
717 This doesn't have an effect on the rendered documentation but it is confusing for the developer reading the code.
718 It this case it would be clearer to use prefix comments throughout:
722 /** Number of elements in the elt_pa array. */
723 uint32_t pg_num __rte_cache_aligned;
724 /** LOG2 of the physical pages. */
726 /** Physical page mask value. */
728 /** Virtual address of the first mempool object. */
729 uintptr_t elt_va_start;
730 /** Virtual address of the <size + 1> mempool object. */
731 uintptr_t elt_va_end;
732 /** Array of physical page addresses for the mempool buffer. */
733 phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
735 * Check for Doxygen warnings in new code by checking the API documentation build::
737 make doc-api-html >/dev/null
739 * Read the rendered section of the documentation that you have added for correctness, clarity and consistency
740 with the surrounding text.