xref: /dpdk/doc/guides/contributing/documentation.rst (revision 3998e2a07220844d3f3c17f76a781ced3efe0de0)
1.. _doc_guidelines:
2
3DPDK Documentation Guidelines
4=============================
5
6This document outlines the guidelines for writing the DPDK Guides and API documentation in RST and Doxygen format.
7
8It also explains the structure of the DPDK documentation and shows how to build the Html and PDF versions of the documents.
9
10
11Structure of the Documentation
12------------------------------
13
14The DPDK source code repository contains input files to build the API documentation and User Guides.
15
16The main directories that contain files related to documentation are shown below::
17
18   lib
19   |-- librte_acl
20   |-- librte_cfgfile
21   |-- librte_cmdline
22   |-- librte_compat
23   |-- librte_eal
24   |   |-- ...
25   ...
26   doc
27   |-- api
28   +-- guides
29       |-- freebsd_gsg
30       |-- linux_gsg
31       |-- prog_guide
32       |-- sample_app_ug
33       |-- guidelines
34       |-- testpmd_app_ug
35       |-- rel_notes
36       |-- nics
37       |-- ...
38
39
40The API documentation is built from `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`_ comments in the header files.
41These files are mainly in the ``lib/librte_*`` directories although some of the Poll Mode Drivers in ``drivers/net``
42are also documented with Doxygen.
43
44The configuration files that are used to control the Doxygen output are in the ``doc/api`` directory.
45
46The user guides such as *The Programmers Guide* and the *FreeBSD* and *Linux Getting Started* Guides are generated
47from RST markup text files using the `Sphinx <http://sphinx-doc.org/index.html>`_ Documentation Generator.
48
49These files are included in the ``doc/guides/`` directory.
50The output is controlled by the ``doc/guides/conf.py`` file.
51
52
53Role of the Documentation
54-------------------------
55
56The following items outline the roles of the different parts of the documentation and when they need to be updated or
57added to by the developer.
58
59* **Release Notes**
60
61  The Release Notes document which features have been added in the current and previous releases of DPDK and highlight
62  any known issues.
63  The Releases Notes also contain notifications of features that will change ABI compatibility in the next major release.
64
65  Developers should include updates to the Release Notes with patch sets that relate to any of the following sections:
66
67  * New Features
68  * Resolved Issues (see below)
69  * Known Issues
70  * API Changes
71  * ABI Changes
72  * Shared Library Versions
73
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.
76
77  Refer to the Release Notes from the previous DPDK release for the correct format of each section.
78
79
80* **API documentation**
81
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.
84
85  The API documentation should be updated via Doxygen comments when new functions are added.
86
87* **Getting Started Guides**
88
89  The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes.
90
91  A Getting Started Guide should be added when DPDK is ported to a new OS.
92
93* **The Programmers Guide**
94
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.
98
99  The Programmers Guide should be expanded when new functionality is added to DPDK.
100
101* **App Guides**
102
103  The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``.
104
105  The app guides should be updated if functionality is changed or added.
106
107* **Sample App Guides**
108
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
112  major functionality.
113
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.
116
117* **Network Interface Controller Drivers**
118
119  The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements,
120  configuration and initialization.
121
122  New documentation should be added for new Poll Mode Drivers.
123
124* **Guidelines**
125
126  The guideline documents record community process, expectations and design directions.
127
128  They can be extended, amended or discussed by submitting a patch and getting community approval.
129
130
131Building the Documentation
132--------------------------
133
134Dependencies
135~~~~~~~~~~~~
136
137
138The following dependencies must be installed to build the documentation:
139
140* Doxygen.
141
142* Sphinx (also called python-sphinx).
143
144* TexLive (at least TexLive-core and the extra Latex support).
145
146* Inkscape.
147
148`Doxygen`_ generates documentation from commented source code.
149It can be installed as follows:
150
151.. code-block:: console
152
153   # Ubuntu/Debian.
154   sudo apt-get -y install doxygen
155
156   # Red Hat/Fedora.
157   sudo dnf     -y install doxygen
158
159`Sphinx`_ is a Python documentation tool for converting RST files to Html or to PDF (via LaTeX).
160For full support with figure and table captioning the latest version of Sphinx can be installed as follows:
161
162.. code-block:: console
163
164   # Ubuntu/Debian.
165   sudo apt-get -y install python-pip
166   sudo pip install --upgrade sphinx
167   sudo pip install --upgrade sphinx_rtd_theme
168
169   # Red Hat/Fedora.
170   sudo dnf     -y install python-pip
171   sudo pip install --upgrade sphinx
172   sudo pip install --upgrade sphinx_rtd_theme
173
174For further information on getting started with Sphinx see the `Sphinx Tutorial <http://sphinx-doc.org/tutorial.html>`_.
175
176.. Note::
177
178   To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later.
179
180
181`Inkscape`_ is a vector based graphics program which is used to create SVG images and also to convert SVG images to PDF images.
182It can be installed as follows:
183
184.. code-block:: console
185
186   # Ubuntu/Debian.
187   sudo apt-get -y install inkscape
188
189   # Red Hat/Fedora.
190   sudo dnf     -y install inkscape
191
192`TexLive <http://www.tug.org/texlive/>`_ is an installation package for Tex/LaTeX.
193It is used to generate the PDF versions of the documentation.
194The main required packages can be installed as follows:
195
196.. code-block:: console
197
198   # Ubuntu/Debian.
199   sudo apt-get -y install texlive-latex-extra
200
201   # Red Hat/Fedora, selective install.
202   sudo dnf     -y install texlive-collection-latexextra
203
204
205Build commands
206~~~~~~~~~~~~~~
207
208The documentation is built using the standard DPDK build system.
209Some examples are shown below:
210
211* Generate all the documentation targets::
212
213     make doc
214
215* Generate the Doxygen API documentation in Html::
216
217     make doc-api-html
218
219* Generate the guides documentation in Html::
220
221     make doc-guides-html
222
223* Generate the guides documentation in Pdf::
224
225     make doc-guides-pdf
226
227The output of these commands is generated in the ``build`` directory::
228
229   build/doc
230         |-- html
231         |   |-- api
232         |   +-- guides
233         |
234         +-- pdf
235             +-- guides
236
237
238.. Note::
239
240   Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation.
241
242The documentation output files can be removed as follows::
243
244   make doc-clean
245
246
247Document Guidelines
248-------------------
249
250Here are some guidelines in relation to the style of the documentation:
251
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.
255
256* Use American English spellings throughout.
257  This can be checked using the ``aspell`` utility::
258
259       aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst
260
261
262RST Guidelines
263--------------
264
265The RST (reStructuredText) format is a plain text markup format that can be converted to Html, PDF or other formats.
266It is most closely associated with Python but it can be used to document any language.
267It is used in DPDK to document everything apart from the API.
268
269The Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a
270good place to learn the minimal set of syntax required to format a document.
271
272The official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the
273RST format and also examples of how to use it.
274However, for most developers the RST Primer is a better resource.
275
276The most common guidelines for writing RST text are detailed in the
277`Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines.
278The additional guidelines below reiterate or expand upon those guidelines.
279
280
281Line Length
282~~~~~~~~~~~
283
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.
287
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
290  in PDF documents.
291
292  Long literal command lines can be shown wrapped with backslashes. For
293  example::
294
295     testpmd -l 2-3 -n 4 \
296             --vdev=virtio_user0,path=/dev/vhost-net,queues=2,queue_size=1024 \
297             -- -i --txqflags=0x0 --disable-hw-vlan --enable-lro \
298             --enable-rx-cksum --txq=2 --rxq=2 --rxd=1024  --txd=1024
299
300
301Whitespace
302~~~~~~~~~~
303
304* Standard RST indentation is 3 spaces.
305  Code can be indented 4 spaces, especially if it is copied from source files.
306
307* No tabs.
308  Convert tabs in embedded code to 4 or 8 spaces.
309
310* No trailing whitespace.
311
312* Add 2 blank lines before each section header.
313
314* Add 1 blank line after each section header.
315
316* Add 1 blank line between each line of a list.
317
318
319Section Headers
320~~~~~~~~~~~~~~~
321
322* Section headers should use the following underline formats::
323
324   Level 1 Heading
325   ===============
326
327
328   Level 2 Heading
329   ---------------
330
331
332   Level 3 Heading
333   ~~~~~~~~~~~~~~~
334
335
336   Level 4 Heading
337   ^^^^^^^^^^^^^^^
338
339
340* Level 4 headings should be used sparingly.
341
342* The underlines should match the length of the text.
343
344* In general, the heading should be less than 80 characters, for conciseness.
345
346* As noted above:
347
348   * Add 2 blank lines before each section header.
349
350   * Add 1 blank line after each section header.
351
352
353Lists
354~~~~~
355
356* Bullet lists should be formatted with a leading ``*`` as follows::
357
358     * Item one.
359
360     * Item two is a long line that is wrapped and then indented to match
361       the start of the previous line.
362
363     * One space character between the bullet and the text is preferred.
364
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::
367
368     #. Item one.
369
370     #. Item two is a long line that is wrapped and then indented to match
371        the start of the previous line.
372
373     #. Item three.
374
375* Definition lists can be written with or without a bullet::
376
377     * Item one.
378
379       Some text about item one.
380
381     * Item two.
382
383       Some text about item two.
384
385* All lists, and sub-lists, must be separated from the preceding text by a blank line.
386  This is a syntax requirement.
387
388* All list items should be separated by a blank line for readability.
389
390
391Code and Literal block sections
392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393
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``.
396
397* Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this::
398
399     Here is some fixed width text::
400
401        0x0001 0x0001 0x00FF 0x00FF
402
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::
406
407     .. code-block:: console
408     .. code-block:: c
409     .. code-block:: python
410     .. code-block:: diff
411     .. code-block:: none
412
413  That can be applied as follows::
414
415      .. code-block:: c
416
417         #include<stdio.h>
418
419         int main() {
420
421            printf("Hello World\n");
422
423            return 0;
424         }
425
426  Which would be rendered as:
427
428  .. code-block:: c
429
430      #include<stdio.h>
431
432      int main() {
433
434         printf("Hello World\n");
435
436         return 0;
437      }
438
439
440* The default encoding for a literal block using the simplified ``::``
441  directive is ``none``.
442
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::
446
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
451
452* Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters.
453
454
455Images
456~~~~~~
457
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.
460
461* The DPDK documentation contains some legacy images in PNG format.
462  These will be converted to SVG in time.
463
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``.
467
468* The SVG images should include a copyright notice, as an XML comment.
469
470* Images in the documentation should be formatted as follows:
471
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.
474
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.
477
478   * Images must have a caption as part of the ``.. figure::`` directive.
479
480* Here is an example of the previous three guidelines::
481
482     .. _figure_mempool:
483
484     .. figure:: img/mempool.*
485
486        A mempool in memory with its associated ring.
487
488.. _mock_label:
489
490* Images can then be linked to using the ``:numref:`` directive::
491
492     The mempool layout is shown in :numref:`figure_mempool`.
493
494  This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`.
495
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.
498
499* The caption of the image can be generated, with a link, using the ``:ref:`` directive::
500
501     :ref:`figure_mempool`
502
503  This would be rendered as: *A mempool in memory with its associated ring.*
504
505Tables
506~~~~~~
507
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.
511
512* Tables in the documentation should be formatted as follows:
513
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.
516
517   * Tables should be included using the ``.. table::`` directive and must have a caption.
518
519* Here is an example of the previous two guidelines::
520
521     .. _table_qos_pipes:
522
523     .. table:: Sample configuration for QOS pipes.
524
525        +----------+----------+----------+
526        | Header 1 | Header 2 | Header 3 |
527        |          |          |          |
528        +==========+==========+==========+
529        | Text     | Text     | Text     |
530        +----------+----------+----------+
531        | ...      | ...      | ...      |
532        +----------+----------+----------+
533
534* Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images.
535  For example::
536
537     The QOS configuration is shown in :numref:`table_qos_pipes`.
538
539* Tables should not include merged cells since they are not supported by the PDF renderer.
540
541
542.. _links:
543
544Hyperlinks
545~~~~~~~~~~
546
547* Links to external websites can be plain URLs.
548  The following is rendered as http://dpdk.org::
549
550     http://dpdk.org
551
552* They can contain alternative text.
553  The following is rendered as `Check out DPDK <http://dpdk.org>`_::
554
555     `Check out DPDK <http://dpdk.org>`_
556
557* An internal link can be generated by placing labels in the document with the format ``.. _label_name``.
558
559* The following links to the top of this section: :ref:`links`::
560
561     .. _links:
562
563     Hyperlinks
564     ~~~~~~~~~~
565
566     * The following links to the top of this section: :ref:`links`:
567
568.. Note::
569
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.
572
573* The use of a label is preferred since it works across files and will still work if the header text changes.
574
575
576.. _doxygen_guidelines:
577
578Doxygen Guidelines
579------------------
580
581The DPDK API is documented using Doxygen comment annotations in the header files.
582Doxygen is a very powerful tool, it is extremely configurable and with a little effort can be used to create expressive documents.
583See the `Doxygen website <http://www.stack.nl/~dimitri/doxygen/>`_ for full details on how to use it.
584
585The following are some guidelines for use of Doxygen in the DPDK API documentation:
586
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.
590
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.
593
594* Use ``@`` style Doxygen commands instead of ``\`` style commands.
595
596* Add a general description of each library at the head of the main header files:
597
598  .. code-block:: c
599
600      /**
601       * @file
602       * RTE Mempool.
603       *
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.
606       * ...
607       */
608
609* Document the purpose of a function, the parameters used and the return
610  value:
611
612  .. code-block:: c
613
614     /**
615      * Attach a new Ethernet device specified by arguments.
616      *
617      * @param devargs
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`.
621      * @param port_id
622      *  A pointer to a port identifier actually attached.
623      *
624      * @return
625      *  0 on success and port_id is filled, negative on error.
626      */
627     int rte_eth_dev_attach(const char *devargs, uint8_t *port_id);
628
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:
631
632     The strings should be a pci address like ``0000:01:00.0`` or **virtual** device name like ``net_pcap0``.
633
634* Use ``-`` instead of ``*`` for lists within the Doxygen comment since the latter can get confused with the comment delimiter.
635
636* Add an empty line between the function description, the ``@params`` and ``@return`` for readability.
637
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.)
642
643* Documented functions can be linked to simply by adding ``()`` to the function name:
644
645  .. code-block:: c
646
647      /**
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()
655       */
656
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.
659
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.
662
663  .. code-block:: c
664
665     /**
666      * ...
667      *
668      * Some text that references mempools.
669      *
670      * @see eal_memzone.c
671      */
672
673* Doxygen supports two types of comments for documenting variables, constants and members: prefix and postfix:
674
675  .. code-block:: c
676
677     /** This is a prefix comment. */
678     #define RTE_FOO_ERROR  0x023.
679
680     #define RTE_BAR_ERROR  0x024. /**< This is a postfix comment. */
681
682* Postfix comments are preferred for struct members and constants if they can be documented in the same way:
683
684  .. code-block:: c
685
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. */
694     }
695
696  Note: postfix comments should be aligned with spaces not tabs in accordance
697  with the :ref:`coding_style`.
698
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:
703
704  .. code-block:: c
705
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. */
716
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:
719
720  .. code-block:: c
721
722     /** Number of elements in the elt_pa array. */
723     uint32_t    pg_num __rte_cache_aligned;
724     /** LOG2 of the physical pages. */
725     uint32_t    pg_shift;
726     /** Physical page mask value. */
727     uintptr_t   pg_mask;
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];
734
735* Check for Doxygen warnings in new code by checking the API documentation build::
736
737     make doc-api-html >/dev/null
738
739* Read the rendered section of the documentation that you have added for correctness, clarity and consistency
740  with the surrounding text.
741