1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright 2018 The DPDK contributors 3 4.. _doc_guidelines: 5 6DPDK Documentation Guidelines 7============================= 8 9This document outlines the guidelines for writing the DPDK Guides and API documentation in RST and Doxygen format. 10 11It also explains the structure of the DPDK documentation and shows how to build the Html and PDF versions of the documents. 12 13 14Structure of the Documentation 15------------------------------ 16 17The DPDK source code repository contains input files to build the API documentation and User Guides. 18 19The main directories that contain files related to documentation are shown below:: 20 21 lib 22 |-- librte_acl 23 |-- librte_cfgfile 24 |-- librte_cmdline 25 |-- librte_compat 26 |-- librte_eal 27 | |-- ... 28 ... 29 doc 30 |-- api 31 +-- guides 32 |-- freebsd_gsg 33 |-- linux_gsg 34 |-- prog_guide 35 |-- sample_app_ug 36 |-- guidelines 37 |-- testpmd_app_ug 38 |-- rel_notes 39 |-- nics 40 |-- ... 41 42 43The API documentation is built from `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`_ comments in the header files. 44These files are mainly in the ``lib/librte_*`` directories although some of the Poll Mode Drivers in ``drivers/net`` 45are also documented with Doxygen. 46 47The configuration files that are used to control the Doxygen output are in the ``doc/api`` directory. 48 49The user guides such as *The Programmers Guide* and the *FreeBSD* and *Linux Getting Started* Guides are generated 50from RST markup text files using the `Sphinx <http://sphinx-doc.org/index.html>`_ Documentation Generator. 51 52These files are included in the ``doc/guides/`` directory. 53The output is controlled by the ``doc/guides/conf.py`` file. 54 55 56Role of the Documentation 57------------------------- 58 59The following items outline the roles of the different parts of the documentation and when they need to be updated or 60added to by the developer. 61 62* **Release Notes** 63 64 The Release Notes document which features have been added in the current and previous releases of DPDK and highlight 65 any known issues. 66 The Releases Notes also contain notifications of features that will change ABI compatibility in the next major release. 67 68 Developers should include updates to the Release Notes with patch sets that relate to any of the following sections: 69 70 * New Features 71 * Resolved Issues (see below) 72 * Known Issues 73 * API Changes 74 * ABI Changes 75 * Shared Library Versions 76 77 Resolved Issues should only include issues from previous releases that have been resolved in the current release. 78 Issues that are introduced and then fixed within a release cycle do not have to be included here. 79 80 Refer to the Release Notes from the previous DPDK release for the correct format of each section. 81 82 83* **API documentation** 84 85 The API documentation explains how to use the public DPDK functions. 86 The `API index page <http://dpdk.org/doc/api/>`_ shows the generated API documentation with related groups of functions. 87 88 The API documentation should be updated via Doxygen comments when new functions are added. 89 90* **Getting Started Guides** 91 92 The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes. 93 94 A Getting Started Guide should be added when DPDK is ported to a new OS. 95 96* **The Programmers Guide** 97 98 The Programmers Guide explains how the API components of DPDK such as the EAL, Memzone, Rings and the Hash Library work. 99 It also explains how some higher level functionality such as Packet Distributor, Packet Framework and KNI work. 100 It also shows the build system and explains how to add applications. 101 102 The Programmers Guide should be expanded when new functionality is added to DPDK. 103 104* **App Guides** 105 106 The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``. 107 108 The app guides should be updated if functionality is changed or added. 109 110* **Sample App Guides** 111 112 The sample app guides document the DPDK example applications in the examples directory. 113 Generally they demonstrate a major feature such as L2 or L3 Forwarding, Multi Process or Power Management. 114 They explain the purpose of the sample application, how to run it and step through some of the code to explain the 115 major functionality. 116 117 A new sample application should be accompanied by a new sample app guide. 118 The guide for the Skeleton Forwarding app is a good starting reference. 119 120* **Network Interface Controller Drivers** 121 122 The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements, 123 configuration and initialization. 124 125 New documentation should be added for new Poll Mode Drivers. 126 127* **Guidelines** 128 129 The guideline documents record community process, expectations and design directions. 130 131 They can be extended, amended or discussed by submitting a patch and getting community approval. 132 133 134Building the Documentation 135-------------------------- 136 137Dependencies 138~~~~~~~~~~~~ 139 140 141The following dependencies must be installed to build the documentation: 142 143* Doxygen. 144 145* Sphinx (also called python-sphinx). 146 147* TexLive (at least TexLive-core and the extra Latex support). 148 149* Inkscape. 150 151`Doxygen`_ generates documentation from commented source code. 152It can be installed as follows: 153 154.. code-block:: console 155 156 # Ubuntu/Debian. 157 sudo apt-get -y install doxygen 158 159 # Red Hat/Fedora. 160 sudo dnf -y install doxygen 161 162`Sphinx`_ is a Python documentation tool for converting RST files to Html or to PDF (via LaTeX). 163For full support with figure and table captioning the latest version of Sphinx can be installed as follows: 164 165.. code-block:: console 166 167 # Ubuntu/Debian. 168 sudo apt-get -y install python-pip 169 sudo pip install --upgrade sphinx 170 sudo pip install --upgrade sphinx_rtd_theme 171 172 # Red Hat/Fedora. 173 sudo dnf -y install python-pip 174 sudo pip install --upgrade sphinx 175 sudo pip install --upgrade sphinx_rtd_theme 176 177For further information on getting started with Sphinx see the `Sphinx Tutorial <http://sphinx-doc.org/tutorial.html>`_. 178 179.. Note:: 180 181 To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later. 182 183 184`Inkscape`_ is a vector based graphics program which is used to create SVG images and also to convert SVG images to PDF images. 185It can be installed as follows: 186 187.. code-block:: console 188 189 # Ubuntu/Debian. 190 sudo apt-get -y install inkscape 191 192 # Red Hat/Fedora. 193 sudo dnf -y install inkscape 194 195`TexLive <http://www.tug.org/texlive/>`_ is an installation package for Tex/LaTeX. 196It is used to generate the PDF versions of the documentation. 197The main required packages can be installed as follows: 198 199.. code-block:: console 200 201 # Ubuntu/Debian. 202 sudo apt-get -y install texlive-latex-extra 203 204 # Red Hat/Fedora, selective install. 205 sudo dnf -y install texlive-collection-latexextra 206 207 208Build commands 209~~~~~~~~~~~~~~ 210 211The documentation is built using the standard DPDK build system. 212Some examples are shown below: 213 214* Generate all the documentation targets:: 215 216 make doc 217 218* Generate the Doxygen API documentation in Html:: 219 220 make doc-api-html 221 222* Generate the guides documentation in Html:: 223 224 make doc-guides-html 225 226* Generate the guides documentation in Pdf:: 227 228 make doc-guides-pdf 229 230The output of these commands is generated in the ``build`` directory:: 231 232 build/doc 233 |-- html 234 | |-- api 235 | +-- guides 236 | 237 +-- pdf 238 +-- guides 239 240 241.. Note:: 242 243 Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation. 244 245The documentation output files can be removed as follows:: 246 247 make doc-clean 248 249 250Document Guidelines 251------------------- 252 253Here are some guidelines in relation to the style of the documentation: 254 255* Document the obvious as well as the obscure since it won't always be obvious to the reader. 256 For example an instruction like "Set up 64 2MB Hugepages" is better when followed by a sample commandline or a link to 257 the appropriate section of the documentation. 258 259* Use American English spellings throughout. 260 This can be checked using the ``aspell`` utility:: 261 262 aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst 263 264 265RST Guidelines 266-------------- 267 268The RST (reStructuredText) format is a plain text markup format that can be converted to Html, PDF or other formats. 269It is most closely associated with Python but it can be used to document any language. 270It is used in DPDK to document everything apart from the API. 271 272The Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a 273good place to learn the minimal set of syntax required to format a document. 274 275The official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the 276RST format and also examples of how to use it. 277However, for most developers the RST Primer is a better resource. 278 279The most common guidelines for writing RST text are detailed in the 280`Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines. 281The additional guidelines below reiterate or expand upon those guidelines. 282 283 284Line Length 285~~~~~~~~~~~ 286 287* Lines in sentences should be less than 80 characters and wrapped at 288 words. Multiple sentences which are not separated by a blank line are joined 289 automatically into paragraphs. 290 291* Lines in literal blocks **must** be less than 80 characters since 292 they are not wrapped by the document formatters and can exceed the page width 293 in PDF documents. 294 295 Long literal command lines can be shown wrapped with backslashes. For 296 example:: 297 298 testpmd -l 2-3 -n 4 \ 299 --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \ 300 -- -i --tx-offloads=0x0000002c --enable-lro --txq=2 --rxq=2 \ 301 --txd=1024 --rxd=1024 302 303 304Whitespace 305~~~~~~~~~~ 306 307* Standard RST indentation is 3 spaces. 308 Code can be indented 4 spaces, especially if it is copied from source files. 309 310* No tabs. 311 Convert tabs in embedded code to 4 or 8 spaces. 312 313* No trailing whitespace. 314 315* Add 2 blank lines before each section header. 316 317* Add 1 blank line after each section header. 318 319* Add 1 blank line between each line of a list. 320 321 322Section Headers 323~~~~~~~~~~~~~~~ 324 325* Section headers should use the following underline formats:: 326 327 Level 1 Heading 328 =============== 329 330 331 Level 2 Heading 332 --------------- 333 334 335 Level 3 Heading 336 ~~~~~~~~~~~~~~~ 337 338 339 Level 4 Heading 340 ^^^^^^^^^^^^^^^ 341 342 343* Level 4 headings should be used sparingly. 344 345* The underlines should match the length of the text. 346 347* In general, the heading should be less than 80 characters, for conciseness. 348 349* As noted above: 350 351 * Add 2 blank lines before each section header. 352 353 * Add 1 blank line after each section header. 354 355 356Lists 357~~~~~ 358 359* Bullet lists should be formatted with a leading ``*`` as follows:: 360 361 * Item one. 362 363 * Item two is a long line that is wrapped and then indented to match 364 the start of the previous line. 365 366 * One space character between the bullet and the text is preferred. 367 368* Numbered lists can be formatted with a leading number but the preference is to use ``#.`` which will give automatic numbering. 369 This is more convenient when adding or removing items:: 370 371 #. Item one. 372 373 #. Item two is a long line that is wrapped and then indented to match 374 the start of the previous line. 375 376 #. Item three. 377 378* Definition lists can be written with or without a bullet:: 379 380 * Item one. 381 382 Some text about item one. 383 384 * Item two. 385 386 Some text about item two. 387 388* All lists, and sub-lists, must be separated from the preceding text by a blank line. 389 This is a syntax requirement. 390 391* All list items should be separated by a blank line for readability. 392 393 394Code and Literal block sections 395~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 396 397* Inline text that is required to be rendered with a fixed width font should be enclosed in backquotes like this: 398 \`\`text\`\`, so that it appears like this: ``text``. 399 400* Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this:: 401 402 Here is some fixed width text:: 403 404 0x0001 0x0001 0x00FF 0x00FF 405 406* It is also possible to specify an encoding for a literal block using the ``.. code-block::`` directive so that syntax 407 highlighting can be applied. 408 Examples of supported highlighting are:: 409 410 .. code-block:: console 411 .. code-block:: c 412 .. code-block:: python 413 .. code-block:: diff 414 .. code-block:: none 415 416 That can be applied as follows:: 417 418 .. code-block:: c 419 420 #include<stdio.h> 421 422 int main() { 423 424 printf("Hello World\n"); 425 426 return 0; 427 } 428 429 Which would be rendered as: 430 431 .. code-block:: c 432 433 #include<stdio.h> 434 435 int main() { 436 437 printf("Hello World\n"); 438 439 return 0; 440 } 441 442 443* The default encoding for a literal block using the simplified ``::`` 444 directive is ``none``. 445 446* Lines in literal blocks must be less than 80 characters since they can exceed the page width when converted to PDF documentation. 447 For long literal lines that exceed that limit try to wrap the text at sensible locations. 448 For example a long command line could be documented like this and still work if copied directly from the docs:: 449 450 build/app/testpmd -l 0-2 -n3 --vdev=net_pcap0,iface=eth0 \ 451 --vdev=net_pcap1,iface=eth1 \ 452 -- -i --nb-cores=2 --nb-ports=2 \ 453 --total-num-mbufs=2048 454 455* Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters. 456 457 458Images 459~~~~~~ 460 461* All images should be in SVG scalar graphics format. 462 They should be true SVG XML files and should not include binary formats embedded in a SVG wrapper. 463 464* The DPDK documentation contains some legacy images in PNG format. 465 These will be converted to SVG in time. 466 467* `Inkscape <http://inkscape.org>`_ is the recommended graphics editor for creating the images. 468 Use some of the older images in ``doc/guides/prog_guide/img/`` as a template, for example ``mbuf1.svg`` 469 or ``ring-enqueue1.svg``. 470 471* The SVG images should include a copyright notice, as an XML comment. 472 473* Images in the documentation should be formatted as follows: 474 475 * The image should be preceded by a label in the format ``.. _figure_XXXX:`` with a leading underscore and 476 where ``XXXX`` is a unique descriptive name. 477 478 * Images should be included using the ``.. figure::`` directive and the file type should be set to ``*`` (not ``.svg``). 479 This allows the format of the image to be changed if required, without updating the documentation. 480 481 * Images must have a caption as part of the ``.. figure::`` directive. 482 483* Here is an example of the previous three guidelines:: 484 485 .. _figure_mempool: 486 487 .. figure:: img/mempool.* 488 489 A mempool in memory with its associated ring. 490 491.. _mock_label: 492 493* Images can then be linked to using the ``:numref:`` directive:: 494 495 The mempool layout is shown in :numref:`figure_mempool`. 496 497 This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`. 498 499 **Note**: The ``:numref:`` directive requires Sphinx 1.3.1 or later. 500 With earlier versions it will still be rendered as a link but won't have an automatically generated number. 501 502* The caption of the image can be generated, with a link, using the ``:ref:`` directive:: 503 504 :ref:`figure_mempool` 505 506 This would be rendered as: *A mempool in memory with its associated ring.* 507 508Tables 509~~~~~~ 510 511* RST tables should be used sparingly. 512 They are hard to format and to edit, they are often rendered incorrectly in PDF format, and the same information 513 can usually be shown just as clearly with a definition or bullet list. 514 515* Tables in the documentation should be formatted as follows: 516 517 * The table should be preceded by a label in the format ``.. _table_XXXX:`` with a leading underscore and where 518 ``XXXX`` is a unique descriptive name. 519 520 * Tables should be included using the ``.. table::`` directive and must have a caption. 521 522* Here is an example of the previous two guidelines:: 523 524 .. _table_qos_pipes: 525 526 .. table:: Sample configuration for QOS pipes. 527 528 +----------+----------+----------+ 529 | Header 1 | Header 2 | Header 3 | 530 | | | | 531 +==========+==========+==========+ 532 | Text | Text | Text | 533 +----------+----------+----------+ 534 | ... | ... | ... | 535 +----------+----------+----------+ 536 537* Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images. 538 For example:: 539 540 The QOS configuration is shown in :numref:`table_qos_pipes`. 541 542* Tables should not include merged cells since they are not supported by the PDF renderer. 543 544 545.. _links: 546 547Hyperlinks 548~~~~~~~~~~ 549 550* Links to external websites can be plain URLs. 551 The following is rendered as http://dpdk.org:: 552 553 http://dpdk.org 554 555* They can contain alternative text. 556 The following is rendered as `Check out DPDK <http://dpdk.org>`_:: 557 558 `Check out DPDK <http://dpdk.org>`_ 559 560* An internal link can be generated by placing labels in the document with the format ``.. _label_name``. 561 562* The following links to the top of this section: :ref:`links`:: 563 564 .. _links: 565 566 Hyperlinks 567 ~~~~~~~~~~ 568 569 * The following links to the top of this section: :ref:`links`: 570 571.. Note:: 572 573 The label must have a leading underscore but the reference to it must omit it. 574 This is a frequent cause of errors and warnings. 575 576* The use of a label is preferred since it works across files and will still work if the header text changes. 577 578 579.. _doxygen_guidelines: 580 581Doxygen Guidelines 582------------------ 583 584The DPDK API is documented using Doxygen comment annotations in the header files. 585Doxygen is a very powerful tool, it is extremely configurable and with a little effort can be used to create expressive documents. 586See the `Doxygen website <http://www.stack.nl/~dimitri/doxygen/>`_ for full details on how to use it. 587 588The following are some guidelines for use of Doxygen in the DPDK API documentation: 589 590* New libraries that are documented with Doxygen should be added to the Doxygen configuration file: ``doc/api/doxy-api.conf``. 591 It is only required to add the directory that contains the files. 592 It isn't necessary to explicitly name each file since the configuration matches all ``rte_*.h`` files in the directory. 593 594* Use proper capitalization and punctuation in the Doxygen comments since they will become sentences in the documentation. 595 This in particular applies to single line comments, which is the case the is most often forgotten. 596 597* Use ``@`` style Doxygen commands instead of ``\`` style commands. 598 599* Add a general description of each library at the head of the main header files: 600 601 .. code-block:: c 602 603 /** 604 * @file 605 * RTE Mempool. 606 * 607 * A memory pool is an allocator of fixed-size object. It is 608 * identified by its name, and uses a ring to store free objects. 609 * ... 610 */ 611 612* Document the purpose of a function, the parameters used and the return 613 value: 614 615 .. code-block:: c 616 617 /** 618 * Attach a new Ethernet device specified by arguments. 619 * 620 * @param devargs 621 * A pointer to a strings array describing the new device 622 * to be attached. The strings should be a pci address like 623 * `0000:01:00.0` or **virtual** device name like `net_pcap0`. 624 * @param port_id 625 * A pointer to a port identifier actually attached. 626 * 627 * @return 628 * 0 on success and port_id is filled, negative on error. 629 */ 630 int rte_eth_dev_attach(const char *devargs, uint8_t *port_id); 631 632* Doxygen supports Markdown style syntax such as bold, italics, fixed width text and lists. 633 For example the second line in the ``devargs`` parameter in the previous example will be rendered as: 634 635 The strings should be a pci address like ``0000:01:00.0`` or **virtual** device name like ``net_pcap0``. 636 637* Use ``-`` instead of ``*`` for lists within the Doxygen comment since the latter can get confused with the comment delimiter. 638 639* Add an empty line between the function description, the ``@params`` and ``@return`` for readability. 640 641* Place the ``@params`` description on separate line and indent it by 2 spaces. 642 (It would be better to use no indentation since this is more common and also because checkpatch complains about leading 643 whitespace in comments. 644 However this is the convention used in the existing DPDK code.) 645 646* Documented functions can be linked to simply by adding ``()`` to the function name: 647 648 .. code-block:: c 649 650 /** 651 * The functions exported by the application Ethernet API to setup 652 * a device designated by its port identifier must be invoked in 653 * the following order: 654 * - rte_eth_dev_configure() 655 * - rte_eth_tx_queue_setup() 656 * - rte_eth_rx_queue_setup() 657 * - rte_eth_dev_start() 658 */ 659 660 In the API documentation the functions will be rendered as links, see the 661 `online section of the rte_ethdev.h docs <http://dpdk.org/doc/api/rte__ethdev_8h.html>`_ that contains the above text. 662 663* The ``@see`` keyword can be used to create a *see also* link to another file or library. 664 This directive should be placed on one line at the bottom of the documentation section. 665 666 .. code-block:: c 667 668 /** 669 * ... 670 * 671 * Some text that references mempools. 672 * 673 * @see eal_memzone.c 674 */ 675 676* Doxygen supports two types of comments for documenting variables, constants and members: prefix and postfix: 677 678 .. code-block:: c 679 680 /** This is a prefix comment. */ 681 #define RTE_FOO_ERROR 0x023. 682 683 #define RTE_BAR_ERROR 0x024. /**< This is a postfix comment. */ 684 685* Postfix comments are preferred for struct members and constants if they can be documented in the same way: 686 687 .. code-block:: c 688 689 struct rte_eth_stats { 690 uint64_t ipackets; /**< Total number of received packets. */ 691 uint64_t opackets; /**< Total number of transmitted packets.*/ 692 uint64_t ibytes; /**< Total number of received bytes. */ 693 uint64_t obytes; /**< Total number of transmitted bytes. */ 694 uint64_t imissed; /**< Total of RX missed packets. */ 695 uint64_t ibadcrc; /**< Total of RX packets with CRC error. */ 696 uint64_t ibadlen; /**< Total of RX packets with bad length. */ 697 } 698 699 Note: postfix comments should be aligned with spaces not tabs in accordance 700 with the :ref:`coding_style`. 701 702* If a single comment type can't be used, due to line length limitations then 703 prefix comments should be preferred. 704 For example this section of the code contains prefix comments, postfix comments on the same line and postfix 705 comments on a separate line: 706 707 .. code-block:: c 708 709 /** Number of elements in the elt_pa array. */ 710 uint32_t pg_num __rte_cache_aligned; 711 uint32_t pg_shift; /**< LOG2 of the physical pages. */ 712 uintptr_t pg_mask; /**< Physical page mask value. */ 713 uintptr_t elt_va_start; 714 /**< Virtual address of the first mempool object. */ 715 uintptr_t elt_va_end; 716 /**< Virtual address of the <size + 1> mempool object. */ 717 phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT]; 718 /**< Array of physical page addresses for the mempool buffer. */ 719 720 This doesn't have an effect on the rendered documentation but it is confusing for the developer reading the code. 721 It this case it would be clearer to use prefix comments throughout: 722 723 .. code-block:: c 724 725 /** Number of elements in the elt_pa array. */ 726 uint32_t pg_num __rte_cache_aligned; 727 /** LOG2 of the physical pages. */ 728 uint32_t pg_shift; 729 /** Physical page mask value. */ 730 uintptr_t pg_mask; 731 /** Virtual address of the first mempool object. */ 732 uintptr_t elt_va_start; 733 /** Virtual address of the <size + 1> mempool object. */ 734 uintptr_t elt_va_end; 735 /** Array of physical page addresses for the mempool buffer. */ 736 phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT]; 737 738* Check for Doxygen warnings in new code by checking the API documentation build:: 739 740 make doc-api-html >/dev/null 741 742* Read the rendered section of the documentation that you have added for correctness, clarity and consistency 743 with the surrounding text. 744