xref: /dpdk/doc/guides/contributing/patches.rst (revision 8809f78c7dd9f33a44a4f89c58fc91ded34296ed)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright 2018 The DPDK contributors
3
4.. submitting_patches:
5
6Contributing Code to DPDK
7=========================
8
9This document outlines the guidelines for submitting code to DPDK.
10
11The DPDK development process is modeled (loosely) on the Linux Kernel development model so it is worth reading the
12Linux kernel guide on submitting patches:
13`How to Get Your Change Into the Linux Kernel <https://www.kernel.org/doc/html/latest/process/submitting-patches.html>`_.
14The rationale for many of the DPDK guidelines is explained in greater detail in the kernel guidelines.
15
16
17The DPDK Development Process
18----------------------------
19
20The DPDK development process has the following features:
21
22* The code is hosted in a public git repository.
23* There is a mailing list where developers submit patches.
24* There are maintainers for hierarchical components.
25* Patches are reviewed publicly on the mailing list.
26* Successfully reviewed patches are merged to the repository.
27* Patches should be sent to the target repository or sub-tree, see below.
28* All sub-repositories are merged into main repository for ``-rc1`` and ``-rc2`` versions of the release.
29* After the ``-rc2`` release all patches should target the main repository.
30
31The mailing list for DPDK development is `dev@dpdk.org <https://mails.dpdk.org/archives/dev/>`_.
32Contributors will need to `register for the mailing list <https://mails.dpdk.org/listinfo/dev>`_ in order to submit patches.
33It is also worth registering for the DPDK `Patchwork <https://patches.dpdk.org/project/dpdk/list/>`_
34
35If you are using the GitHub service, you can link your repository to
36the ``travis-ci.org`` build service.  When you push patches to your GitHub
37repository, the travis service will automatically build your changes.
38
39The development process requires some familiarity with the ``git`` version control system.
40Refer to the `Pro Git Book <http://www.git-scm.com/book/>`_ for further information.
41
42Source License
43--------------
44
45The DPDK uses the Open Source BSD-3-Clause license for the core libraries and
46drivers. The kernel components are GPL-2.0 licensed. DPDK uses single line
47reference to Unique License Identifiers in source files as defined by the Linux
48Foundation's `SPDX project <http://spdx.org/>`_.
49
50DPDK uses first line of the file to be SPDX tag. In case of *#!* scripts, SPDX
51tag can be placed in 2nd line of the file.
52
53For example, to label a file as subject to the BSD-3-Clause license,
54the following text would be used:
55
56``SPDX-License-Identifier: BSD-3-Clause``
57
58To label a file as dual-licensed with BSD-3-Clause and GPL-2.0 (e.g., for code
59that is shared between the kernel and userspace), the following text would be
60used:
61
62``SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)``
63
64Refer to ``licenses/README`` for more details.
65
66Maintainers and Sub-trees
67-------------------------
68
69The DPDK maintenance hierarchy is divided into a main repository ``dpdk`` and sub-repositories ``dpdk-next-*``.
70
71There are maintainers for the trees and for components within the tree.
72
73Trees and maintainers are listed in the ``MAINTAINERS`` file. For example::
74
75    Crypto Drivers
76    --------------
77    M: Some Name <some.name@email.com>
78    T: git://dpdk.org/next/dpdk-next-crypto
79
80    Intel AES-NI GCM PMD
81    M: Some One <some.one@email.com>
82    F: drivers/crypto/aesni_gcm/
83    F: doc/guides/cryptodevs/aesni_gcm.rst
84
85Where:
86
87* ``M`` is a tree or component maintainer.
88* ``T`` is a repository tree.
89* ``F`` is a maintained file or directory.
90
91Additional details are given in the ``MAINTAINERS`` file.
92
93The role of the component maintainers is to:
94
95* Review patches for the component or delegate the review.
96  The review should be done, ideally, within 1 week of submission to the mailing list.
97* Add an ``acked-by`` to patches, or patchsets, that are ready for committing to a tree.
98* Reply to questions asked about the component.
99
100Component maintainers can be added or removed by submitting a patch to the ``MAINTAINERS`` file.
101Maintainers should have demonstrated a reasonable level of contributions or reviews to the component area.
102The maintainer should be confirmed by an ``ack`` from an established contributor.
103There can be more than one component maintainer if desired.
104
105The role of the tree maintainers is to:
106
107* Maintain the overall quality of their tree.
108  This can entail additional review, compilation checks or other tests deemed necessary by the maintainer.
109* Commit patches that have been reviewed by component maintainers and/or other contributors.
110  The tree maintainer should determine if patches have been reviewed sufficiently.
111* Ensure that patches are reviewed in a timely manner.
112* Prepare the tree for integration.
113* Ensure that there is a designated back-up maintainer and coordinate a handover for periods where the
114  tree maintainer can't perform their role.
115
116Tree maintainers can be added or removed by submitting a patch to the ``MAINTAINERS`` file.
117The proposer should justify the need for a new sub-tree and should have demonstrated a sufficient level of contributions in the area or to a similar area.
118The maintainer should be confirmed by an ``ack`` from an existing tree maintainer.
119Disagreements on trees or maintainers can be brought to the Technical Board.
120
121The backup maintainer for the main tree should be selected
122from the existing sub-tree maintainers of the project.
123The backup maintainer for a sub-tree should be selected from among the component maintainers within that sub-tree.
124
125
126Getting the Source Code
127-----------------------
128
129The source code can be cloned using either of the following:
130
131main repository::
132
133    git clone git://dpdk.org/dpdk
134    git clone https://dpdk.org/git/dpdk
135
136sub-repositories (`list <https://git.dpdk.org/next>`_)::
137
138    git clone git://dpdk.org/next/dpdk-next-*
139    git clone https://dpdk.org/git/next/dpdk-next-*
140
141Make your Changes
142-----------------
143
144Make your planned changes in the cloned ``dpdk`` repo. Here are some guidelines and requirements:
145
146* Follow the :ref:`coding_style` guidelines.
147
148* If you add new files or directories you should add your name to the ``MAINTAINERS`` file.
149
150* Initial submission of new PMDs should be prepared against a corresponding repo.
151
152  * Thus, for example, initial submission of a new network PMD should be
153    prepared against dpdk-next-net repo.
154
155  * Likewise, initial submission of a new crypto or compression PMD should be
156    prepared against dpdk-next-crypto repo.
157
158  * For other PMDs and more info, refer to the ``MAINTAINERS`` file.
159
160* New external functions should be added to the local ``version.map`` file. See
161  the :doc:`ABI policy <abi_policy>` and :ref:`ABI versioning <abi_versioning>`
162  guides. New external functions should also be added in alphabetical order.
163
164* Important changes will require an addition to the release notes in ``doc/guides/rel_notes/``.
165  See the :ref:`Release Notes section of the Documentation Guidelines <doc_guidelines>` for details.
166
167* Test the compilation works with different targets, compilers and options, see :ref:`contrib_check_compilation`.
168
169* Don't break compilation between commits with forward dependencies in a patchset.
170  Each commit should compile on its own to allow for ``git bisect`` and continuous integration testing.
171
172* Add tests to the ``app/test`` unit test framework where possible.
173
174* Add documentation, if relevant, in the form of Doxygen comments or a User Guide in RST format.
175  See the :ref:`Documentation Guidelines <doc_guidelines>`.
176
177Once the changes have been made you should commit them to your local repo.
178
179For small changes, that do not require specific explanations, it is better to keep things together in the
180same patch.
181Larger changes that require different explanations should be separated into logical patches in a patchset.
182A good way of thinking about whether a patch should be split is to consider whether the change could be
183applied without dependencies as a backport.
184
185It is better to keep the related documentation changes in the same patch
186file as the code, rather than one big documentation patch at the end of a
187patchset. This makes it easier for future maintenance and development of the
188code.
189
190As a guide to how patches should be structured run ``git log`` on similar files.
191
192
193Commit Messages: Subject Line
194-----------------------------
195
196The first, summary, line of the git commit message becomes the subject line of the patch email.
197Here are some guidelines for the summary line:
198
199* The summary line must capture the area and the impact of the change.
200
201* The summary line should be around 50 characters.
202
203* The summary line should be lowercase apart from acronyms.
204
205* It should be prefixed with the component name (use git log to check existing components).
206  For example::
207
208     ixgbe: fix offload config option name
209
210     config: increase max queues per port
211
212* Use the imperative of the verb (like instructions to the code base).
213
214* Don't add a period/full stop to the subject line or you will end up two in the patch name: ``dpdk_description..patch``.
215
216The actual email subject line should be prefixed by ``[PATCH]`` and the version, if greater than v1,
217for example: ``PATCH v2``.
218The is generally added by ``git send-email`` or ``git format-patch``, see below.
219
220If you are submitting an RFC draft of a feature you can use ``[RFC]`` instead of ``[PATCH]``.
221An RFC patch doesn't have to be complete.
222It is intended as a way of getting early feedback.
223
224
225Commit Messages: Body
226---------------------
227
228Here are some guidelines for the body of a commit message:
229
230* The body of the message should describe the issue being fixed or the feature being added.
231  It is important to provide enough information to allow a reviewer to understand the purpose of the patch.
232
233* When the change is obvious the body can be blank, apart from the signoff.
234
235* The commit message must end with a ``Signed-off-by:`` line which is added using::
236
237      git commit --signoff # or -s
238
239  The purpose of the signoff is explained in the
240  `Developer's Certificate of Origin <https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1>`_
241  section of the Linux kernel guidelines.
242
243  .. Note::
244
245     All developers must ensure that they have read and understood the
246     Developer's Certificate of Origin section of the documentation prior
247     to applying the signoff and submitting a patch.
248
249* The signoff must be a real name and not an alias or nickname.
250  More than one signoff is allowed.
251
252* The text of the commit message should be wrapped at 72 characters.
253
254* When fixing a regression, it is required to reference the id of the commit
255  which introduced the bug, and put the original author of that commit on CC.
256  You can generate the required lines using the following git alias, which prints
257  the commit SHA and the author of the original code::
258
259     git config alias.fixline "log -1 --abbrev=12 --format='Fixes: %h (\"%s\")%nCc: %ae'"
260
261  The output of ``git fixline <SHA>`` must then be added to the commit message::
262
263     doc: fix some parameter description
264
265     Update the docs, fixing description of some parameter.
266
267     Fixes: abcdefgh1234 ("doc: add some parameter")
268     Cc: author@example.com
269
270     Signed-off-by: Alex Smith <alex.smith@example.com>
271
272* When fixing an error or warning it is useful to add the error message and instructions on how to reproduce it.
273
274* Use correct capitalization, punctuation and spelling.
275
276In addition to the ``Signed-off-by:`` name the commit messages can also have
277tags for who reported, suggested, tested and reviewed the patch being
278posted. Please refer to the `Tested, Acked and Reviewed by`_ section.
279
280Patch Fix Related Issues
281~~~~~~~~~~~~~~~~~~~~~~~~
282
283`Coverity <https://scan.coverity.com/projects/dpdk-data-plane-development-kit>`_
284is a tool for static code analysis.
285It is used as a cloud-based service used to scan the DPDK source code,
286and alert developers of any potential defects in the source code.
287When fixing an issue found by Coverity, the patch must contain a Coverity issue ID
288in the body of the commit message. For example::
289
290
291     doc: fix some parameter description
292
293     Update the docs, fixing description of some parameter.
294
295     Coverity issue: 12345
296     Fixes: abcdefgh1234 ("doc: add some parameter")
297     Cc: author@example.com
298
299     Signed-off-by: Alex Smith <alex.smith@example.com>
300
301
302`Bugzilla <https://bugs.dpdk.org>`_
303is a bug- or issue-tracking system.
304Bug-tracking systems allow individual or groups of developers
305effectively to keep track of outstanding problems with their product.
306When fixing an issue raised in Bugzilla, the patch must contain
307a Bugzilla issue ID in the body of the commit message.
308For example::
309
310    doc: fix some parameter description
311
312    Update the docs, fixing description of some parameter.
313
314    Bugzilla ID: 12345
315    Fixes: abcdefgh1234 ("doc: add some parameter")
316    Cc: author@example.com
317
318    Signed-off-by: Alex Smith <alex.smith@example.com>
319
320Patch for Stable Releases
321~~~~~~~~~~~~~~~~~~~~~~~~~
322
323All fix patches to the main branch that are candidates for backporting
324should also be CCed to the `stable@dpdk.org <https://mails.dpdk.org/listinfo/stable>`_
325mailing list.
326In the commit message body the Cc: stable@dpdk.org should be inserted as follows::
327
328     doc: fix some parameter description
329
330     Update the docs, fixing description of some parameter.
331
332     Fixes: abcdefgh1234 ("doc: add some parameter")
333     Cc: stable@dpdk.org
334
335     Signed-off-by: Alex Smith <alex.smith@example.com>
336
337For further information on stable contribution you can go to
338:doc:`Stable Contribution Guide <stable>`.
339
340Patch Dependencies
341~~~~~~~~~~~~~~~~~~
342
343Sometimes a patch or patchset can depend on another one.
344To help the maintainers and automation tasks, please document this dependency in commit log or cover letter
345with the following syntax:
346
347``Depends-on: series-NNNNN ("Title of the series")`` or ``Depends-on: patch-NNNNN ("Title of the patch")``
348
349Where ``NNNNN`` is patchwork ID for patch or series::
350
351     doc: fix some parameter description
352
353     Update the docs, fixing description of some parameter.
354
355     Signed-off-by: Alex Smith <alex.smith@example.com>
356     ---
357     Depends-on: series-10000 ("Title of the series")
358
359Creating Patches
360----------------
361
362It is possible to send patches directly from git but for new contributors it is recommended to generate the
363patches with ``git format-patch`` and then when everything looks okay, and the patches have been checked, to
364send them with ``git send-email``.
365
366Here are some examples of using ``git format-patch`` to generate patches:
367
368.. code-block:: console
369
370   # Generate a patch from the last commit.
371   git format-patch -1
372
373   # Generate a patch from the last 3 commits.
374   git format-patch -3
375
376   # Generate the patches in a directory.
377   git format-patch -3 -o ~/patch/
378
379   # Add a cover letter to explain a patchset.
380   git format-patch -3 -o ~/patch/ --cover-letter
381
382   # Add a prefix with a version number.
383   git format-patch -3 -o ~/patch/ -v 2
384
385
386Cover letters are useful for explaining a patchset and help to generate a logical threading to the patches.
387Smaller notes can be put inline in the patch after the ``---`` separator, for example::
388
389   Subject: [PATCH] fm10k/base: add FM10420 device ids
390
391   Add the device ID for Boulder Rapids and Atwood Channel to enable
392   drivers to support those devices.
393
394   Signed-off-by: Alex Smith <alex.smith@example.com>
395   ---
396
397   ADD NOTES HERE.
398
399    drivers/net/fm10k/base/fm10k_api.c  | 6 ++++++
400    drivers/net/fm10k/base/fm10k_type.h | 6 ++++++
401    2 files changed, 12 insertions(+)
402   ...
403
404Version 2 and later of a patchset should also include a short log of the changes so the reviewer knows what has changed.
405This can be added to the cover letter or the annotations.
406For example::
407
408   ---
409   v3:
410   * Fixed issued with version.map.
411
412   v2:
413   * Added i40e support.
414   * Renamed ethdev functions from rte_eth_ieee15888_*() to rte_eth_timesync_*()
415     since 802.1AS can be supported through the same interfaces.
416
417
418.. _contrib_checkpatch:
419
420Checking the Patches
421--------------------
422
423Patches should be checked for formatting and syntax issues using the ``checkpatches.sh`` script in the ``devtools``
424directory of the DPDK repo.
425This uses the Linux kernel development tool ``checkpatch.pl`` which  can be obtained by cloning, and periodically,
426updating the Linux kernel sources.
427
428The path to the original Linux script must be set in the environment variable ``DPDK_CHECKPATCH_PATH``.
429
430Spell checking of commonly misspelled words
431can be enabled by downloading the codespell dictionary::
432
433   https://raw.githubusercontent.com/codespell-project/codespell/master/codespell_lib/data/dictionary.txt
434
435The path to the downloaded ``dictionary.txt`` must be set
436in the environment variable ``DPDK_CHECKPATCH_CODESPELL``.
437
438Environment variables required by the development tools,
439are loaded from the following files, in order of preference::
440
441   .develconfig
442   ~/.config/dpdk/devel.config
443   /etc/dpdk/devel.config.
444
445Once the environment variable is set, the script can be run as follows::
446
447   devtools/checkpatches.sh ~/patch/
448
449The script usage is::
450
451   checkpatches.sh [-h] [-q] [-v] [-nX|-r range|patch1 [patch2] ...]
452
453Then the git logs should be checked using the ``check-git-log.sh`` script.
454
455The script usage is::
456
457   check-git-log.sh [-h] [-nX|-r range]
458
459For both of the above scripts, the -n option is used to specify a number of commits from HEAD,
460and the -r option allows the user specify a ``git log`` range.
461
462.. _contrib_check_compilation:
463
464Checking Compilation
465--------------------
466
467Compilation of patches is to be tested with ``devtools/test-meson-builds.sh`` script.
468
469The script internally checks for dependencies, then builds for several
470combinations of compilation configuration.
471By default, each build will be put in a subfolder of the current working directory.
472However, if it is preferred to place the builds in a different location,
473the environment variable ``DPDK_BUILD_TEST_DIR`` can be set to that desired location.
474For example, setting ``DPDK_BUILD_TEST_DIR=__builds`` will put all builds
475in a single subfolder called "__builds" created in the current directory.
476Setting ``DPDK_BUILD_TEST_DIR`` to an absolute directory path e.g. ``/tmp`` is also supported.
477
478
479.. _integrated_abi_check:
480
481Checking ABI compatibility
482--------------------------
483
484By default, ABI compatibility checks are disabled.
485
486To enable them, a reference version must be selected via the environment
487variable ``DPDK_ABI_REF_VERSION``.
488
489The ``devtools/test-meson-builds.sh`` script then build this reference version
490in a temporary directory and store the results in a subfolder of the current
491working directory.
492The environment variable ``DPDK_ABI_REF_DIR`` can be set so that the results go
493to a different location.
494
495
496Sending Patches
497---------------
498
499Patches should be sent to the mailing list using ``git send-email``.
500You can configure an external SMTP with something like the following::
501
502   [sendemail]
503       smtpuser = name@domain.com
504       smtpserver = smtp.domain.com
505       smtpserverport = 465
506       smtpencryption = ssl
507
508See the `Git send-email <https://git-scm.com/docs/git-send-email>`_ documentation for more details.
509
510The patches should be sent to ``dev@dpdk.org``.
511If the patches are a change to existing files then you should send them TO the maintainer(s) and CC ``dev@dpdk.org``.
512The appropriate maintainer can be found in the ``MAINTAINERS`` file::
513
514   git send-email --to maintainer@some.org --cc dev@dpdk.org 000*.patch
515
516Script ``get-maintainer.sh`` can be used to select maintainers automatically::
517
518  git send-email --to-cmd ./devtools/get-maintainer.sh --cc dev@dpdk.org 000*.patch
519
520New additions can be sent without a maintainer::
521
522   git send-email --to dev@dpdk.org 000*.patch
523
524You can test the emails by sending it to yourself or with the ``--dry-run`` option.
525
526If the patch is in relation to a previous email thread you can add it to the same thread using the Message ID::
527
528   git send-email --to dev@dpdk.org --in-reply-to <1234-foo@bar.com> 000*.patch
529
530The Message ID can be found in the raw text of emails or at the top of each Patchwork patch,
531`for example <https://patches.dpdk.org/patch/7646/>`_.
532Shallow threading (``--thread --no-chain-reply-to``) is preferred for a patch series.
533
534Once submitted your patches will appear on the mailing list and in Patchwork.
535
536Experienced committers may send patches directly with ``git send-email`` without the ``git format-patch`` step.
537The options ``--annotate`` and ``confirm = always`` are recommended for checking patches before sending.
538
539
540Backporting patches for Stable Releases
541~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
542
543Sometimes a maintainer or contributor wishes, or can be asked, to send a patch
544for a stable release rather than mainline.
545In this case the patch(es) should be sent to ``stable@dpdk.org``,
546not to ``dev@dpdk.org``.
547
548Given that there are multiple stable releases being maintained at the same time,
549please specify exactly which branch(es) the patch is for
550using ``git send-email --subject-prefix='PATCH 16.11' ...``
551and also optionally in the cover letter or in the annotation.
552
553
554The Review Process
555------------------
556
557Patches are reviewed by the community, relying on the experience and
558collaboration of the members to double-check each other's work. There are a
559number of ways to indicate that you have checked a patch on the mailing list.
560
561
562Tested, Acked and Reviewed by
563~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
564
565To indicate that you have interacted with a patch on the mailing list you
566should respond to the patch in an email with one of the following tags:
567
568 * Reviewed-by:
569 * Acked-by:
570 * Tested-by:
571 * Reported-by:
572 * Suggested-by:
573
574The tag should be on a separate line as follows::
575
576   tag-here: Name Surname <email@address.com>
577
578Each of these tags has a specific meaning. In general, the DPDK community
579follows the kernel usage of the tags. A short summary of the meanings of each
580tag is given here for reference:
581
582.. _statement: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#reviewer-s-statement-of-oversight
583
584``Reviewed-by:`` is a strong statement_ that the patch is an appropriate state
585for merging without any remaining serious technical issues. Reviews from
586community members who are known to understand the subject area and to perform
587thorough reviews will increase the likelihood of the patch getting merged.
588
589``Acked-by:`` is a record that the person named was not directly involved in
590the preparation of the patch but wishes to signify and record their acceptance
591and approval of it.
592
593``Tested-by:`` indicates that the patch has been successfully tested (in some
594environment) by the person named.
595
596``Reported-by:`` is used to acknowledge person who found or reported the bug.
597
598``Suggested-by:`` indicates that the patch idea was suggested by the named
599person.
600
601
602
603Steps to getting your patch merged
604~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
605
606The more work you put into the previous steps the easier it will be to get a
607patch accepted. The general cycle for patch review and acceptance is:
608
609#. Submit the patch.
610
611#. Check the automatic test reports in the coming hours.
612
613#. Wait for review comments. While you are waiting review some other patches.
614
615#. Fix the review comments and submit a ``v n+1`` patchset::
616
617      git format-patch -3 -v 2
618
619#. Update Patchwork to mark your previous patches as "Superseded".
620
621#. If the patch is deemed suitable for merging by the relevant maintainer(s) or other developers they will ``ack``
622   the patch with an email that includes something like::
623
624      Acked-by: Alex Smith <alex.smith@example.com>
625
626   **Note**: When acking patches please remove as much of the text of the patch email as possible.
627   It is generally best to delete everything after the ``Signed-off-by:`` line.
628
629#. Having the patch ``Reviewed-by:`` and/or ``Tested-by:`` will also help the patch to be accepted.
630
631#. If the patch isn't deemed suitable based on being out of scope or conflicting with existing functionality
632   it may receive a ``nack``.
633   In this case you will need to make a more convincing technical argument in favor of your patches.
634
635#. In addition a patch will not be accepted if it doesn't address comments from a previous version with fixes or
636   valid arguments.
637
638#. It is the responsibility of a maintainer to ensure that patches are reviewed and to provide an ``ack`` or
639   ``nack`` of those patches as appropriate.
640
641#. Once a patch has been acked by the relevant maintainer, reviewers may still comment on it for a further
642   two weeks. After that time, the patch should be merged into the relevant git tree for the next release.
643   Additional notes and restrictions:
644
645   * Patches should be acked by a maintainer at least two days before the release merge
646     deadline, in order to make that release.
647   * For patches acked with less than two weeks to go to the merge deadline, all additional
648     comments should be made no later than two days before the merge deadline.
649   * After the appropriate time for additional feedback has passed, if the patch has not yet
650     been merged to the relevant tree by the committer, it should be treated as though it had,
651     in that any additional changes needed to it must be addressed by a follow-on patch, rather
652     than rework of the original.
653   * Trivial patches may be merged sooner than described above at the tree committer's
654     discretion.
655