doc: add documentation guidelines
[dpdk.git] / doc / guides / guidelines / 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 update the Release Notes to add a short description of new or updated features.
67   Developers should also update the Release Notes to add ABI announcements if necessary,
68   (see :doc:`/guidelines/versioning` for details).
69
70 * **API documentation**
71
72   The API documentation explains how to use the public DPDK functions.
73   The `API index page <http://dpdk.org/doc/api/>`_ shows the generated API documentation with related groups of functions.
74
75   The API documentation should be updated via Doxygen comments when new functions are added.
76
77 * **Getting Started Guides**
78
79   The Getting Started Guides show how to install and configure DPDK and how to run DPDK based applications on different OSes.
80
81   A Getting Started Guide should be added when DPDK is ported to a new OS.
82
83 * **The Programmers Guide**
84
85   The Programmers Guide explains how the API components of DPDK such as the EAL, Memzone, Rings and the Hash Library work.
86   It also explains how some higher level functionality such as Packet Distributor, Packet Framework and KNI work.
87   It also shows the build system and explains how to add applications.
88
89   The Programmers Guide should be expanded when new functionality is added to DPDK.
90
91 * **App Guides**
92
93   The app guides document the DPDK applications in the ``app`` directory such as ``testpmd``.
94
95   The app guides should be updated if functionality is changed or added.
96
97 * **Sample App Guides**
98
99   The sample app guides document the DPDK example applications in the examples directory.
100   Generally they demonstrate a major feature such as L2 or L3 Forwarding, Multi Process or Power Management.
101   They explain the purpose of the sample application, how to run it and step through some of the code to explain the
102   major functionality.
103
104   A new sample application should be accompanied by a new sample app guide.
105   The guide for the Skeleton Forwarding app is a good starting reference.
106
107 * **Network Interface Controller Drivers**
108
109   The NIC Drivers document explains the features of the individual Poll Mode Drivers, such as software requirements,
110   configuration and initialization.
111
112   New documentation should be added for new Poll Mode Drivers.
113
114 * **Guidelines**
115
116   The guideline documents record community process, expectations and design directions.
117
118   They can be extended, amended or discussed by submitting a patch and getting community approval.
119
120
121 Building the Documentation
122 --------------------------
123
124 Dependencies
125 ~~~~~~~~~~~~
126
127
128 The following dependencies must be installed to build the documentation:
129
130 * Doxygen.
131
132 * Sphinx (also called python-sphinx).
133
134 * TexLive (at least TexLive-core, extra Latex support and extra fonts).
135
136 * Inkscape.
137
138 `Doxygen`_ generates documentation from commented source code.
139 It can be installed as follows:
140
141 .. code-block:: console
142
143    # Ubuntu/Debian.
144    sudo apt-get -y install doxygen
145
146    # Red Hat/Fedora.
147    sudo yum     -y install doxygen
148
149 `Sphinx`_ is a Python documentation tool for converting RST files to Html or to PDF (via LaTeX).
150 It can be installed as follows:
151
152 .. code-block:: console
153
154    # Ubuntu/Debian.
155    sudo apt-get -y install python-sphinx
156
157    # Red Hat/Fedora.
158    sudo yum     -y install python-sphinx
159
160    # Or, on any system with Python installed.
161    sudo easy_install -U sphinx
162
163 For further information on getting started with Sphinx see the `Sphinx Tutorial <http://sphinx-doc.org/tutorial.html>`_.
164
165 .. Note::
166
167    To get full support for Figure and Table numbering it is best to install Sphinx 1.3.1 or later.
168
169
170 `Inkscape`_ is a vector based graphics program which is used to create SVG images and also to convert SVG images to PDF images.
171 It can be installed as follows:
172
173 .. code-block:: console
174
175    # Ubuntu/Debian.
176    sudo apt-get -y install inkscape
177
178    # Red Hat/Fedora.
179    sudo yum     -y install inkscape
180
181 `TexLive <http://www.tug.org/texlive/>`_ is an installation package for Tex/LaTeX.
182 It is used to generate the PDF versions of the documentation.
183 The main required packages can be installed as follows:
184
185 .. code-block:: console
186
187    # Ubuntu/Debian.
188    sudo apt-get -y install texlive-latex-extra texlive-fonts-extra \
189                            texlive-fonts-recommended
190
191
192    # Red Hat/Fedora, selective install.
193    sudo yum     -y install texlive-collection-latexextra \
194                            texlive-collection-fontsextra
195
196
197 Build commands
198 ~~~~~~~~~~~~~~
199
200 The documentation is built using the standard DPDK build system.
201 Some examples are shown below:
202
203 * Generate all the documentation targets::
204
205      make doc
206
207 * Generate the Doxygen API documentation in Html::
208
209      make doc-api-html
210
211 * Generate the guides documentation in Html::
212
213      make doc-guides-html
214
215 * Generate the guides documentation in Pdf::
216
217      make doc-guides-pdf
218
219 The output of these commands is generated in the ``build`` directory::
220
221    build/doc
222          |-- html
223          |   |-- api
224          |   +-- guides
225          |
226          +-- pdf
227              +-- guides
228
229
230 .. Note::
231
232    Make sure to fix any Sphinx or Doxygen warnings when adding or updating documentation.
233
234 The documentation output files can be removed as follows::
235
236    make doc-clean
237
238
239 Document Guidelines
240 -------------------
241
242 Here are some guidelines in relation to the style of the documentation:
243
244 * Document the obvious as well as the obscure since it won't always be obvious to the reader.
245   For example an instruction like "Set up 64 2MB Hugepages" is better when followed by a sample commandline or a link to
246   the appropriate section of the documentation.
247
248 * Use American English spellings throughout.
249   This can be checked using the ``aspell`` utility::
250
251        aspell --lang=en_US --check doc/guides/sample_app_ug/mydoc.rst
252
253
254 RST Guidelines
255 --------------
256
257 The RST (reStructuredText) format is a plain text markup format that can be converted to Html, PDF or other formats.
258 It is most closely associated with Python but it can be used to document any language.
259 It is used in DPDK to document everything apart from the API.
260
261 The Sphinx documentation contains a very useful `RST Primer <http://sphinx-doc.org/rest.html#rst-primer>`_ which is a
262 good place to learn the minimal set of syntax required to format a document.
263
264 The official `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ website contains the specification for the
265 RST format and also examples of how to use it.
266 However, for most developers the RST Primer is a better resource.
267
268 The most common guidelines for writing RST text are detailed in the
269 `Documenting Python <https://docs.python.org/devguide/documenting.html>`_ guidelines.
270 The additional guidelines below reiterate or expand upon those guidelines.
271
272
273 Line Length
274 ~~~~~~~~~~~
275
276 * The recommended style for the DPDK documentation is to put sentences on separate lines.
277   This allows for easier reviewing of patches.
278   Multiple sentences which are not separated by a blank line are joined automatically into paragraphs, for example::
279
280      Here is an example sentence.
281      Long sentences over the limit shown below can be wrapped onto
282      a new line.
283      These three sentences will be joined into the same paragraph.
284
285      This is a new paragraph, since it is separated from the
286      previous paragraph by a blank line.
287
288   This would be rendered as follows:
289
290      *Here is an example sentence.
291      Long sentences over the limit shown below can be wrapped onto
292      a new line.
293      These three sentences will be joined into the same paragraph.*
294
295      *This is a new paragraph, since it is separated from the
296      previous paragraph by a blank line.*
297
298
299 * Long sentences should be wrapped at 120 characters +/- 10 characters. They should be wrapped at words.
300
301 * Lines in literal blocks must by less than 80 characters since they aren't wrapped by the document formatters
302   and can exceed the page width in PDF documents.
303
304
305 Whitespace
306 ~~~~~~~~~~
307
308 * Standard RST indentation is 3 spaces.
309   Code can be indented 4 spaces, especially if it is copied from source files.
310
311 * No tabs.
312   Convert tabs in embedded code to 4 or 8 spaces.
313
314 * No trailing whitespace.
315
316 * Add 2 blank lines before each section header.
317
318 * Add 1 blank line after each section header.
319
320 * Add 1 blank line between each line of a list.
321
322
323 Section Headers
324 ~~~~~~~~~~~~~~~
325
326 * Section headers should use the use the following underline formats::
327
328    Level 1 Heading
329    ===============
330
331
332    Level 2 Heading
333    ---------------
334
335
336    Level 3 Heading
337    ~~~~~~~~~~~~~~~
338
339
340    Level 4 Heading
341    ^^^^^^^^^^^^^^^
342
343
344 * Level 4 headings should be used sparingly.
345
346 * The underlines should match the length of the text.
347
348 * In general, the heading should be less than 80 characters, for conciseness.
349
350 * As noted above:
351
352    * Add 2 blank lines before each section header.
353
354    * Add 1 blank line after each section header.
355
356
357 Lists
358 ~~~~~
359
360 * Bullet lists should be formatted with a leading ``*`` as follows::
361
362      * Item one.
363
364      * Item two is a long line that is wrapped and then indented to match
365        the start of the previous line.
366
367      * One space character between the bullet and the text is preferred.
368
369 * Numbered lists can be formatted with a leading number but the preference is to use ``#.`` which will give automatic numbering.
370   This is more convenient when adding or removing items::
371
372      #. Item one.
373
374      #. Item two is a long line that is wrapped and then indented
375         to match the start of the e first line.
376
377      #. Item two is a long line that is wrapped and then indented to match
378         the start of the previous line.
379
380 * Definition lists can be written with or without a bullet::
381
382      * Item one.
383
384        Some text about item one.
385
386      * Item two.
387
388        Some text about item two.
389
390 * All lists, and sub-lists, must be separated from the preceding text by a blank line.
391   This is a syntax requirement.
392
393 * All list items should be separated by a blank line for readability.
394
395
396 Code and Literal block sections
397 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
398
399 * Inline text that is required to be rendered with a fixed width font should be enclosed in backquotes like this:
400   \`\`text\`\`, so that it appears like this: ``text``.
401
402 * Fixed width, literal blocks of texts should be indented at least 3 spaces and prefixed with ``::`` like this::
403
404      Here is some fixed width text::
405
406         0x0001 0x0001 0x00FF 0x00FF
407
408 * It is also possible to specify an encoding for a literal block using the ``.. code-block::`` directive so that syntax
409   highlighting can be applied.
410   Examples of supported highlighting are::
411
412      .. code-block:: console
413      .. code-block:: c
414      .. code-block:: python
415      .. code-block:: diff
416      .. code-block:: none
417
418   That can be applied as follows::
419
420       .. code-block:: c
421
422          #include<stdio.h>
423
424          int main() {
425
426             printf("Hello World\n");
427
428             return 0;
429          }
430
431   Which would be rendered as:
432
433   .. code-block:: c
434
435       #include<stdio.h>
436
437       int main() {
438
439          printf("Hello World\n");
440
441          return 0;
442       }
443
444
445 * The default encoding for a literal block using the simplified ``::``
446   directive is ``none``.
447
448 * Lines in literal blocks must be less than 80 characters since they can exceed the page width when converted to PDF documentation.
449   For long literal lines that exceed that limit try to wrap the text at sensible locations.
450   For example a long command line could be documented like this and still work if copied directly from the docs::
451
452      build/app/testpmd -c7 -n3 --vdev=eth_pcap0,iface=eth0     \
453                                --vdev=eth_pcap1,iface=eth1     \
454                                -- -i --nb-cores=2 --nb-ports=2 \
455                                   --total-num-mbufs=2048
456
457 * Long lines that cannot be wrapped, such as application output, should be truncated to be less than 80 characters.
458
459
460 Images
461 ~~~~~~
462
463 * All images should be in SVG scalar graphics format.
464   They should be true SVG XML files and should not include binary formats embedded in a SVG wrapper.
465
466 * The DPDK documentation contains some legacy images in PNG format.
467   These will be converted to SVG in time.
468
469 * `Inkscape <inkscape.org>`_ is the recommended graphics editor for creating the images.
470   Use some of the older images in ``doc/guides/prog_guide/img/`` as a template, for example ``mbuf1.svg``
471   or ``ring-enqueue.svg``.
472
473 * The SVG images should include a copyright notice, as an XML comment.
474
475 * Images in the documentation should be formatted as follows:
476
477    * The image should be preceded by a label in the format ``.. _figure_XXXX:`` with a leading underscore and
478      where ``XXXX`` is a unique descriptive name.
479
480    * Images should be included using the ``.. figure::`` directive and the file type should be set to ``*`` (not ``.svg``).
481      This allows the format of the image to be changed if required, without updating the documentation.
482
483    * Images must have a caption as part of the ``.. figure::`` directive.
484
485 * Here is an example of the previous three guidelines::
486
487      .. _figure_mempool:
488
489      .. figure:: img/mempool.*
490
491         A mempool in memory with its associated ring.
492
493 .. _mock_label:
494
495 * Images can then be linked to using the ``:numref:`` directive::
496
497      The mempool layout is shown in :numref:`figure_mempool`.
498
499   This would be rendered as: *The mempool layout is shown in* :ref:`Fig 6.3 <mock_label>`.
500
501   **Note**: The ``:numref:`` directive requires Sphinx 1.3.1 or later.
502   With earlier versions it will still be rendered as a link but won't have an automatically generated number.
503
504 * The caption of the image can be generated, with a link, using the ``:ref:`` directive::
505
506      :ref:`figure_mempool`
507
508   This would be rendered as: *A mempool in memory with its associated ring.*
509
510 Tables
511 ~~~~~~
512
513 * RST tables should be used sparingly.
514   They are hard to format and to edit, they are often rendered incorrectly in PDF format, and the same information
515   can usually be shown just as clearly with a definition or bullet list.
516
517 * Tables in the documentation should be formatted as follows:
518
519    * The table should be preceded by a label in the format ``.. _table_XXXX:`` with a leading underscore and where
520      ``XXXX`` is a unique descriptive name.
521
522    * Tables should be included using the ``.. table::`` directive and must have a caption.
523
524 * Here is an example of the previous two guidelines::
525
526      .. _table_qos_pipes:
527
528      .. table:: Sample configuration for QOS pipes.
529
530         +----------+----------+----------+
531         | Header 1 | Header 2 | Header 3 |
532         |          |          |          |
533         +==========+==========+==========+
534         | Text     | Text     | Text     |
535         +----------+----------+----------+
536         | ...      | ...      | ...      |
537         +----------+----------+----------+
538
539 * Tables can be linked to using the ``:numref:`` and ``:ref:`` directives, as shown in the previous section for images.
540   For example::
541
542      The QOS configuration is shown in :numref:`table_qos_pipes`.
543
544 * Tables should not include merged cells since they are not supported by the PDF renderer.
545
546
547 .. _links:
548
549 Hyperlinks
550 ~~~~~~~~~~
551
552 * Links to external websites can be plain URLs.
553   The following is rendered as http://dpdk.org::
554
555      http://dpdk.org
556
557 * They can contain alternative text.
558   The following is rendered as `Check out DPDK <http://dpdk.org>`_::
559
560      `Check out DPDK <http://dpdk.org>`_
561
562 * An internal link can be generated by placing labels in the document with the format ``.. _label_name``.
563
564 * The following links to the top of this section: :ref:`links`::
565
566      .. _links:
567
568      Hyperlinks
569      ~~~~~~~~~~
570
571      * The following links to the top of this section: :ref:`links`:
572
573 .. Note::
574
575    The label must have a leading underscore but the reference to it must omit it.
576    This is a frequent cause of errors and warnings.
577
578 * The use of a label is preferred since it works across files and will still work if the header text changes.
579