doc: add patch dependency syntax to contributing guide
[dpdk.git] / doc / guides / contributing / design.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright 2018 The DPDK contributors
3
4 Design
5 ======
6
7 Environment or Architecture-specific Sources
8 --------------------------------------------
9
10 In DPDK and DPDK applications, some code is specific to an architecture (i686, x86_64) or to an executive environment (freebsd or linux) and so on.
11 As far as is possible, all such instances of architecture or env-specific code should be provided via standard APIs in the EAL.
12
13 By convention, a file is common if it is not located in a directory indicating that it is specific.
14 For instance, a file located in a subdir of "x86_64" directory is specific to this architecture.
15 A file located in a subdir of "linux" is specific to this execution environment.
16
17 .. note::
18
19    Code in DPDK libraries and applications should be generic.
20    The correct location for architecture or executive environment specific code is in the EAL.
21
22 When absolutely necessary, there are several ways to handle specific code:
23
24 * Use a ``#ifdef`` with the CONFIG option in the C code.
25   This can be done when the differences are small and they can be embedded in the same C file:
26
27   .. code-block:: c
28
29      #ifdef RTE_ARCH_I686
30      toto();
31      #else
32      titi();
33      #endif
34
35 * Use the CONFIG option in the Makefile. This is done when the differences are more significant.
36   In this case, the code is split into two separate files that are architecture or environment specific.
37   This should only apply inside the EAL library.
38
39 .. note::
40
41    As in the linux kernel, the ``CONFIG_`` prefix is not used in C code.
42    This is only needed in Makefiles or shell scripts.
43
44 Per Architecture Sources
45 ~~~~~~~~~~~~~~~~~~~~~~~~
46
47 The following config options can be used:
48
49 * ``CONFIG_RTE_ARCH`` is a string that contains the name of the architecture.
50 * ``CONFIG_RTE_ARCH_I686``, ``CONFIG_RTE_ARCH_X86_64``, ``CONFIG_RTE_ARCH_X86_64_32`` or ``CONFIG_RTE_ARCH_PPC_64`` are defined only if we are building for those architectures.
51
52 Per Execution Environment Sources
53 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
55 The following config options can be used:
56
57 * ``CONFIG_RTE_EXEC_ENV`` is a string that contains the name of the executive environment.
58 * ``CONFIG_RTE_EXEC_ENV_FREEBSD`` or ``CONFIG_RTE_EXEC_ENV_LINUX`` are defined only if we are building for this execution environment.
59
60 Mbuf features
61 -------------
62
63 The ``rte_mbuf`` structure must be kept small (128 bytes).
64
65 In order to add new features without wasting buffer space for unused features,
66 some fields and flags can be registered dynamically in a shared area.
67 The "dynamic" mbuf area is the default choice for the new features.
68
69 The "dynamic" area is eating the remaining space in mbuf,
70 and some existing "static" fields may need to become "dynamic".
71
72 Adding a new static field or flag must be an exception matching many criteria
73 like (non exhaustive): wide usage, performance, size.
74
75
76 Library Statistics
77 ------------------
78
79 Description
80 ~~~~~~~~~~~
81
82 This document describes the guidelines for DPDK library-level statistics counter
83 support. This includes guidelines for turning library statistics on and off and
84 requirements for preventing ABI changes when implementing statistics.
85
86
87 Mechanism to allow the application to turn library statistics on and off
88 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90 Each library that maintains statistics counters should provide a single build
91 time flag that decides whether the statistics counter collection is enabled or
92 not. This flag should be exposed as a variable within the DPDK configuration
93 file. When this flag is set, all the counters supported by current library are
94 collected for all the instances of every object type provided by the library.
95 When this flag is cleared, none of the counters supported by the current library
96 are collected for any instance of any object type provided by the library:
97
98 .. code-block:: console
99
100    # DPDK file config/common_linux, config/common_freebsd, etc.
101    CONFIG_RTE_<LIBRARY_NAME>_STATS_COLLECT=y/n
102
103 The default value for this DPDK configuration file variable (either "yes" or
104 "no") is decided by each library.
105
106
107 Prevention of ABI changes due to library statistics support
108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109
110 The layout of data structures and prototype of functions that are part of the
111 library API should not be affected by whether the collection of statistics
112 counters is turned on or off for the current library. In practical terms, this
113 means that space should always be allocated in the API data structures for
114 statistics counters and the statistics related API functions are always built
115 into the code, regardless of whether the statistics counter collection is turned
116 on or off for the current library.
117
118 When the collection of statistics counters for the current library is turned
119 off, the counters retrieved through the statistics related API functions should
120 have a default value of zero.
121
122
123 Motivation to allow the application to turn library statistics on and off
124 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125
126 It is highly recommended that each library provides statistics counters to allow
127 an application to monitor the library-level run-time events. Typical counters
128 are: number of packets received/dropped/transmitted, number of buffers
129 allocated/freed, number of occurrences for specific events, etc.
130
131 However, the resources consumed for library-level statistics counter collection
132 have to be spent out of the application budget and the counters collected by
133 some libraries might not be relevant to the current application. In order to
134 avoid any unwanted waste of resources and/or performance impacts, the
135 application should decide at build time whether the collection of library-level
136 statistics counters should be turned on or off for each library individually.
137
138 Library-level statistics counters can be relevant or not for specific
139 applications:
140
141 * For Application A, counters maintained by Library X are always relevant and
142   the application needs to use them to implement certain features, such as traffic
143   accounting, logging, application-level statistics, etc. In this case,
144   the application requires that collection of statistics counters for Library X is
145   always turned on.
146
147 * For Application B, counters maintained by Library X are only useful during the
148   application debug stage and are not relevant once debug phase is over. In this
149   case, the application may decide to turn on the collection of Library X
150   statistics counters during the debug phase and at a later stage turn them off.
151
152 * For Application C, counters maintained by Library X are not relevant at all.
153   It might be that the application maintains its own set of statistics counters
154   that monitor a different set of run-time events (e.g. number of connection
155   requests, number of active users, etc). It might also be that the application
156   uses multiple libraries (Library X, Library Y, etc) and it is interested in the
157   statistics counters of Library Y, but not in those of Library X. In this case,
158   the application may decide to turn the collection of statistics counters off for
159   Library X and on for Library Y.
160
161 The statistics collection consumes a certain amount of CPU resources (cycles,
162 cache bandwidth, memory bandwidth, etc) that depends on:
163
164 * Number of libraries used by the current application that have statistics
165   counters collection turned on.
166
167 * Number of statistics counters maintained by each library per object type
168   instance (e.g. per port, table, pipeline, thread, etc).
169
170 * Number of instances created for each object type supported by each library.
171
172 * Complexity of the statistics logic collection for each counter: when only
173   some occurrences of a specific event are valid, additional logic is typically
174   needed to decide whether the current occurrence of the event should be counted
175   or not. For example, in the event of packet reception, when only TCP packets
176   with destination port within a certain range should be recorded, conditional
177   branches are usually required. When processing a burst of packets that have been
178   validated for header integrity, counting the number of bits set in a bitmask
179   might be needed.
180
181 PF and VF Considerations
182 ------------------------
183
184 The primary goal of DPDK is to provide a userspace dataplane. Managing VFs from
185 a PF driver is a control plane feature and developers should generally rely on
186 the Linux Kernel for that.
187
188 Developers should work with the Linux Kernel community to get the required
189 functionality upstream. PF functionality should only be added to DPDK for
190 testing and prototyping purposes while the kernel work is ongoing. It should
191 also be marked with an "EXPERIMENTAL" tag. If the functionality isn't
192 upstreamable then a case can be made to maintain the PF functionality in DPDK
193 without the EXPERIMENTAL tag.