84a5dab82f93f7d12cf591daf654cfa2e11a9d68
[deb_dpdk.git] / doc / guides / contributing / patches.rst
1 .. submitting_patches:
2
3 Contributing Code to DPDK
4 =========================
5
6 This document outlines the guidelines for submitting code to DPDK.
7
8 The DPDK development process is modelled (loosely) on the Linux Kernel development model so it is worth reading the
9 Linux kernel guide on submitting patches:
10 `How to Get Your Change Into the Linux Kernel <https://www.kernel.org/doc/html/latest/process/submitting-patches.html>`_.
11 The rationale for many of the DPDK guidelines is explained in greater detail in the kernel guidelines.
12
13
14 The DPDK Development Process
15 ----------------------------
16
17 The DPDK development process has the following features:
18
19 * The code is hosted in a public git repository.
20 * There is a mailing list where developers submit patches.
21 * There are maintainers for hierarchical components.
22 * Patches are reviewed publicly on the mailing list.
23 * Successfully reviewed patches are merged to the repository.
24 * Patches should be sent to the target repository or sub-tree, see below.
25 * All sub-repositories are merged into main repository for ``-rc1`` and ``-rc2`` versions of the release.
26 * After the ``-rc2`` release all patches should target the main repository.
27
28 The mailing list for DPDK development is `dev@dpdk.org <http://dpdk.org/ml/archives/dev/>`_.
29 Contributors will need to `register for the mailing list <http://dpdk.org/ml/listinfo/dev>`_ in order to submit patches.
30 It is also worth registering for the DPDK `Patchwork <http://dpdk.org/dev/patchwork/project/dpdk/list/>`_
31
32 The development process requires some familiarity with the ``git`` version control system.
33 Refer to the `Pro Git Book <http://www.git-scm.com/book/>`_ for further information.
34
35
36 Maintainers and Sub-trees
37 -------------------------
38
39 The DPDK maintenance hierarchy is divided into a main repository ``dpdk`` and sub-repositories ``dpdk-next-*``.
40
41 There are maintainers for the trees and for components within the tree.
42
43 Trees and maintainers are listed in the ``MAINTAINERS`` file. For example::
44
45     Crypto Drivers
46     --------------
47     M: Some Name <some.name@email.com>
48     B: Another Name <another.name@email.com>
49     T: git://dpdk.org/next/dpdk-next-crypto
50
51     Intel AES-NI GCM PMD
52     M: Some One <some.one@email.com>
53     F: drivers/crypto/aesni_gcm/
54     F: doc/guides/cryptodevs/aesni_gcm.rst
55
56 Where:
57
58 * ``M`` is a tree or component maintainer.
59 * ``B`` is a tree backup maintainer.
60 * ``T`` is a repository tree.
61 * ``F`` is a maintained file or directory.
62
63 Additional details are given in the ``MAINTAINERS`` file.
64
65 The role of the component maintainers is to:
66
67 * Review patches for the component or delegate the review.
68   The review should be done, ideally, within 1 week of submission to the mailing list.
69 * Add an ``acked-by`` to patches, or patchsets, that are ready for committing to a tree.
70 * Reply to questions asked about the component.
71
72 Component maintainers can be added or removed by submitting a patch to the ``MAINTAINERS`` file.
73 Maintainers should have demonstrated a reasonable level of contributions or reviews to the component area.
74 The maintainer should be confirmed by an ``ack`` from an established contributor.
75 There can be more than one component maintainer if desired.
76
77 The role of the tree maintainers is to:
78
79 * Maintain the overall quality of their tree.
80   This can entail additional review, compilation checks or other tests deemed necessary by the maintainer.
81 * Commit patches that have been reviewed by component maintainers and/or other contributors.
82   The tree maintainer should determine if patches have been reviewed sufficiently.
83 * Ensure that patches are reviewed in a timely manner.
84 * Prepare the tree for integration.
85 * Ensure that there is a designated back-up maintainer and coordinate a handover for periods where the
86   tree maintainer can't perform their role.
87
88 Tree maintainers can be added or removed by submitting a patch to the ``MAINTAINERS`` file.
89 The 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.
90 The maintainer should be confirmed by an ``ack`` from an existing tree maintainer.
91 Disagreements on trees or maintainers can be brought to the Technical Board.
92
93 The backup maintainer for the master tree should be selected from the existing sub-tree maintainers from the project.
94 The backup maintainer for a sub-tree should be selected from among the component maintainers within that sub-tree.
95
96
97 Getting the Source Code
98 -----------------------
99
100 The source code can be cloned using either of the following:
101
102 main repository::
103
104     git clone git://dpdk.org/dpdk
105     git clone http://dpdk.org/git/dpdk
106
107 sub-repositories (`list <http://dpdk.org/browse/next>`_)::
108
109     git clone git://dpdk.org/next/dpdk-next-*
110     git clone http://dpdk.org/git/next/dpdk-next-*
111
112 Make your Changes
113 -----------------
114
115 Make your planned changes in the cloned ``dpdk`` repo. Here are some guidelines and requirements:
116
117 * Follow the :ref:`coding_style` guidelines.
118
119 * If you add new files or directories you should add your name to the ``MAINTAINERS`` file.
120
121 * New external functions should be added to the local ``version.map`` file.
122   See the :doc:`Guidelines for ABI policy and versioning </contributing/versioning>`.
123   New external functions should also be added in alphabetical order.
124
125 * Important changes will require an addition to the release notes in ``doc/guides/rel_notes/``.
126   See the :ref:`Release Notes section of the Documentation Guidelines <doc_guidelines>` for details.
127
128 * Test the compilation works with different targets, compilers and options, see :ref:`contrib_check_compilation`.
129
130 * Don't break compilation between commits with forward dependencies in a patchset.
131   Each commit should compile on its own to allow for ``git bisect`` and continuous integration testing.
132
133 * Add tests to the the ``app/test`` unit test framework where possible.
134
135 * Add documentation, if relevant, in the form of Doxygen comments or a User Guide in RST format.
136   See the :ref:`Documentation Guidelines <doc_guidelines>`.
137
138 Once the changes have been made you should commit them to your local repo.
139
140 For small changes, that do not require specific explanations, it is better to keep things together in the
141 same patch.
142 Larger changes that require different explanations should be separated into logical patches in a patchset.
143 A good way of thinking about whether a patch should be split is to consider whether the change could be
144 applied without dependencies as a backport.
145
146 As a guide to how patches should be structured run ``git log`` on similar files.
147
148
149 Commit Messages: Subject Line
150 -----------------------------
151
152 The first, summary, line of the git commit message becomes the subject line of the patch email.
153 Here are some guidelines for the summary line:
154
155 * The summary line must capture the area and the impact of the change.
156
157 * The summary line should be around 50 characters.
158
159 * The summary line should be lowercase apart from acronyms.
160
161 * It should be prefixed with the component name (use git log to check existing components).
162   For example::
163
164      ixgbe: fix offload config option name
165
166      config: increase max queues per port
167
168 * Use the imperative of the verb (like instructions to the code base).
169
170 * Don't add a period/full stop to the subject line or you will end up two in the patch name: ``dpdk_description..patch``.
171
172 The actual email subject line should be prefixed by ``[PATCH]`` and the version, if greater than v1,
173 for example: ``PATCH v2``.
174 The is generally added by ``git send-email`` or ``git format-patch``, see below.
175
176 If you are submitting an RFC draft of a feature you can use ``[RFC]`` instead of ``[PATCH]``.
177 An RFC patch doesn't have to be complete.
178 It is intended as a way of getting early feedback.
179
180
181 Commit Messages: Body
182 ---------------------
183
184 Here are some guidelines for the body of a commit message:
185
186 * The body of the message should describe the issue being fixed or the feature being added.
187   It is important to provide enough information to allow a reviewer to understand the purpose of the patch.
188
189 * When the change is obvious the body can be blank, apart from the signoff.
190
191 * The commit message must end with a ``Signed-off-by:`` line which is added using::
192
193       git commit --signoff # or -s
194
195   The purpose of the signoff is explained in the
196   `Developer's Certificate of Origin <https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1>`_
197   section of the Linux kernel guidelines.
198
199   .. Note::
200
201      All developers must ensure that they have read and understood the
202      Developer's Certificate of Origin section of the documentation prior
203      to applying the signoff and submitting a patch.
204
205 * The signoff must be a real name and not an alias or nickname.
206   More than one signoff is allowed.
207
208 * The text of the commit message should be wrapped at 72 characters.
209
210 * When fixing a regression, it is a good idea to reference the id of the commit which introduced the bug.
211   You can generate the required text using the following git alias::
212
213      git config alias.fixline "log -1 --abbrev=12 --format='Fixes: %h (\"%s\")'"
214
215   The ``Fixes:`` line can then be added to the commit message::
216
217      doc: fix vhost sample parameter
218
219      Update the docs to reflect removed dev-index.
220
221      Fixes: 17b8320a3e11 ("vhost: remove index parameter")
222
223      Signed-off-by: Alex Smith <alex.smith@example.com>
224
225 * When fixing an error or warning it is useful to add the error message and instructions on how to reproduce it.
226
227 * Use correct capitalization, punctuation and spelling.
228
229 In addition to the ``Signed-off-by:`` name the commit messages can also have
230 tags for who reported, suggested, tested and reviewed the patch being
231 posted. Please refer to the `Tested, Acked and Reviewed by`_ section.
232
233
234 Creating Patches
235 ----------------
236
237 It is possible to send patches directly from git but for new contributors it is recommended to generate the
238 patches with ``git format-patch`` and then when everything looks okay, and the patches have been checked, to
239 send them with ``git send-email``.
240
241 Here are some examples of using ``git format-patch`` to generate patches:
242
243 .. code-block:: console
244
245    # Generate a patch from the last commit.
246    git format-patch -1
247
248    # Generate a patch from the last 3 commits.
249    git format-patch -3
250
251    # Generate the patches in a directory.
252    git format-patch -3 -o ~/patch/
253
254    # Add a cover letter to explain a patchset.
255    git format-patch -3 -o ~/patch/ --cover-letter
256
257    # Add a prefix with a version number.
258    git format-patch -3 -o ~/patch/ -v 2
259
260
261 Cover letters are useful for explaining a patchset and help to generate a logical threading to the patches.
262 Smaller notes can be put inline in the patch after the ``---`` separator, for example::
263
264    Subject: [PATCH] fm10k/base: add FM10420 device ids
265
266    Add the device ID for Boulder Rapids and Atwood Channel to enable
267    drivers to support those devices.
268
269    Signed-off-by: Alex Smith <alex.smith@example.com>
270    ---
271
272    ADD NOTES HERE.
273
274     drivers/net/fm10k/base/fm10k_api.c  | 6 ++++++
275     drivers/net/fm10k/base/fm10k_type.h | 6 ++++++
276     2 files changed, 12 insertions(+)
277    ...
278
279 Version 2 and later of a patchset should also include a short log of the changes so the reviewer knows what has changed.
280 This can be added to the cover letter or the annotations.
281 For example::
282
283    ---
284    v3:
285    * Fixed issued with version.map.
286
287    v2:
288    * Added i40e support.
289    * Renamed ethdev functions from rte_eth_ieee15888_*() to rte_eth_timesync_*()
290      since 802.1AS can be supported through the same interfaces.
291
292
293 .. _contrib_checkpatch:
294
295 Checking the Patches
296 --------------------
297
298 Patches should be checked for formatting and syntax issues using the ``checkpatches.sh`` script in the ``devtools``
299 directory of the DPDK repo.
300 This uses the Linux kernel development tool ``checkpatch.pl`` which  can be obtained by cloning, and periodically,
301 updating the Linux kernel sources.
302
303 The path to the original Linux script must be set in the environment variable ``DPDK_CHECKPATCH_PATH``.
304 This, and any other configuration variables required by the development tools, are loaded from the following
305 files, in order of preference::
306
307    .develconfig
308    ~/.config/dpdk/devel.config
309    /etc/dpdk/devel.config.
310
311 Once the environment variable the script can be run as follows::
312
313    devtools/checkpatches.sh ~/patch/
314
315 The script usage is::
316
317    checkpatches.sh [-h] [-q] [-v] [patch1 [patch2] ...]]"
318
319 Where:
320
321 * ``-h``: help, usage.
322 * ``-q``: quiet. Don't output anything for files without issues.
323 * ``-v``: verbose.
324 * ``patchX``: path to one or more patches.
325
326 Then the git logs should be checked using the ``check-git-log.sh`` script.
327
328 The script usage is::
329
330    check-git-log.sh [range]
331
332 Where the range is a ``git log`` option.
333
334
335 .. _contrib_check_compilation:
336
337 Checking Compilation
338 --------------------
339
340 Compilation of patches and changes should be tested using the the ``test-build.sh`` script in the ``devtools``
341 directory of the DPDK repo::
342
343   devtools/test-build.sh x86_64-native-linuxapp-gcc+next+shared
344
345 The script usage is::
346
347    test-build.sh [-h] [-jX] [-s] [config1 [config2] ...]]
348
349 Where:
350
351 * ``-h``: help, usage.
352 * ``-jX``: use X parallel jobs in "make".
353 * ``-s``: short test with only first config and without examples/doc.
354 * ``config``: default config name plus config switches delimited with a ``+`` sign.
355
356 Examples of configs are::
357
358    x86_64-native-linuxapp-gcc
359    x86_64-native-linuxapp-gcc+next+shared
360    x86_64-native-linuxapp-clang+shared
361
362 The builds can be modifies via the following environmental variables:
363
364 * ``DPDK_BUILD_TEST_CONFIGS`` (target1+option1+option2 target2)
365 * ``DPDK_DEP_CFLAGS``
366 * ``DPDK_DEP_LDFLAGS``
367 * ``DPDK_DEP_MOFED`` (y/[n])
368 * ``DPDK_DEP_PCAP`` (y/[n])
369 * ``DPDK_NOTIFY`` (notify-send)
370
371 These can be set from the command line or in the config files shown above in the :ref:`contrib_checkpatch`.
372
373 The recommended configurations and options to test compilation prior to submitting patches are::
374
375    x86_64-native-linuxapp-gcc+shared+next
376    x86_64-native-linuxapp-clang+shared
377    i686-native-linuxapp-gcc
378
379    export DPDK_DEP_ZLIB=y
380    export DPDK_DEP_PCAP=y
381    export DPDK_DEP_SSL=y
382
383
384 Sending Patches
385 ---------------
386
387 Patches should be sent to the mailing list using ``git send-email``.
388 You can configure an external SMTP with something like the following::
389
390    [sendemail]
391        smtpuser = name@domain.com
392        smtpserver = smtp.domain.com
393        smtpserverport = 465
394        smtpencryption = ssl
395
396 See the `Git send-email <https://git-scm.com/docs/git-send-email>`_ documentation for more details.
397
398 The patches should be sent to ``dev@dpdk.org``.
399 If the patches are a change to existing files then you should send them TO the maintainer(s) and CC ``dev@dpdk.org``.
400 The appropriate maintainer can be found in the ``MAINTAINERS`` file::
401
402    git send-email --to maintainer@some.org --cc dev@dpdk.org 000*.patch
403
404 New additions can be sent without a maintainer::
405
406    git send-email --to dev@dpdk.org 000*.patch
407
408 You can test the emails by sending it to yourself or with the ``--dry-run`` option.
409
410 If the patch is in relation to a previous email thread you can add it to the same thread using the Message ID::
411
412    git send-email --to dev@dpdk.org --in-reply-to <1234-foo@bar.com> 000*.patch
413
414 The Message ID can be found in the raw text of emails or at the top of each Patchwork patch,
415 `for example <http://dpdk.org/dev/patchwork/patch/7646/>`_.
416 Shallow threading (``--thread --no-chain-reply-to``) is preferred for a patch series.
417
418 Once submitted your patches will appear on the mailing list and in Patchwork.
419
420 Experienced committers may send patches directly with ``git send-email`` without the ``git format-patch`` step.
421 The options ``--annotate`` and ``confirm = always`` are recommended for checking patches before sending.
422
423
424 The Review Process
425 ------------------
426
427 Patches are reviewed by the community, relying on the experience and
428 collaboration of the members to double-check each other's work. There are a
429 number of ways to indicate that you have checked a patch on the mailing list.
430
431
432 Tested, Acked and Reviewed by
433 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434
435 To indicate that you have interacted with a patch on the mailing list you
436 should respond to the patch in an email with one of the following tags:
437
438  * Reviewed-by:
439  * Acked-by:
440  * Tested-by:
441  * Reported-by:
442  * Suggested-by:
443
444 The tag should be on a separate line as follows::
445
446    tag-here: Name Surname <email@address.com>
447
448 Each of these tags has a specific meaning. In general, the DPDK community
449 follows the kernel usage of the tags. A short summary of the meanings of each
450 tag is given here for reference:
451
452 .. _statement: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#reviewer-s-statement-of-oversight
453
454 ``Reviewed-by:`` is a strong statement_ that the patch is an appropriate state
455 for merging without any remaining serious technical issues. Reviews from
456 community members who are known to understand the subject area and to perform
457 thorough reviews will increase the likelihood of the patch getting merged.
458
459 ``Acked-by:`` is a record that the person named was not directly involved in
460 the preparation of the patch but wishes to signify and record their acceptance
461 and approval of it.
462
463 ``Tested-by:`` indicates that the patch has been successfully tested (in some
464 environment) by the person named.
465
466 ``Reported-by:`` is used to acknowledge person who found or reported the bug.
467
468 ``Suggested-by:`` indicates that the patch idea was suggested by the named
469 person.
470
471
472
473 Steps to getting your patch merged
474 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
475
476 The more work you put into the previous steps the easier it will be to get a
477 patch accepted. The general cycle for patch review and acceptance is:
478
479 #. Submit the patch.
480
481 #. Check the automatic test reports in the coming hours.
482
483 #. Wait for review comments. While you are waiting review some other patches.
484
485 #. Fix the review comments and submit a ``v n+1`` patchset::
486
487       git format-patch -3 -v 2
488
489 #. Update Patchwork to mark your previous patches as "Superseded".
490
491 #. If the patch is deemed suitable for merging by the relevant maintainer(s) or other developers they will ``ack``
492    the patch with an email that includes something like::
493
494       Acked-by: Alex Smith <alex.smith@example.com>
495
496    **Note**: When acking patches please remove as much of the text of the patch email as possible.
497    It is generally best to delete everything after the ``Signed-off-by:`` line.
498
499 #. Having the patch ``Reviewed-by:`` and/or ``Tested-by:`` will also help the patch to be accepted.
500
501 #. If the patch isn't deemed suitable based on being out of scope or conflicting with existing functionality
502    it may receive a ``nack``.
503    In this case you will need to make a more convincing technical argument in favor of your patches.
504
505 #. In addition a patch will not be accepted if it doesn't address comments from a previous version with fixes or
506    valid arguments.
507
508 #. It is the responsibility of a maintainer to ensure that patches are reviewed and to provide an ``ack`` or
509    ``nack`` of those patches as appropriate.
510
511 #. Once a patch has been acked by the relevant maintainer, reviewers may still comment on it for a further
512    two weeks. After that time, the patch should be merged into the relevant git tree for the next release.
513    Additional notes and restrictions:
514
515    * Patches should be acked by a maintainer at least two days before the release merge
516      deadline, in order to make that release.
517    * For patches acked with less than two weeks to go to the merge deadline, all additional
518      comments should be made no later than two days before the merge deadline.
519    * After the appropriate time for additional feedback has passed, if the patch has not yet
520      been merged to the relevant tree by the committer, it should be treated as though it had,
521      in that any additional changes needed to it must be addressed by a follow-on patch, rather
522      than rework of the original.
523    * Trivial patches may be merged sooner than described above at the tree committer's
524      discretion.