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