diff options
-rw-r--r-- | Documentation/00-INDEX | 3 | ||||
-rw-r--r-- | Documentation/development-process/1.Intro | 274 | ||||
-rw-r--r-- | Documentation/development-process/2.Process | 459 | ||||
-rw-r--r-- | Documentation/development-process/3.Early-stage | 195 | ||||
-rw-r--r-- | Documentation/development-process/4.Coding | 384 | ||||
-rw-r--r-- | Documentation/development-process/5.Posting | 278 | ||||
-rw-r--r-- | Documentation/development-process/6.Followthrough | 202 | ||||
-rw-r--r-- | Documentation/development-process/7.AdvancedTopics | 173 | ||||
-rw-r--r-- | Documentation/development-process/8.Conclusion | 74 |
9 files changed, 2042 insertions, 0 deletions
diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX index 5b5aba404aac..1f3dbdfc9ae3 100644 --- a/Documentation/00-INDEX +++ b/Documentation/00-INDEX | |||
@@ -21,6 +21,9 @@ Changes | |||
21 | - list of changes that break older software packages. | 21 | - list of changes that break older software packages. |
22 | CodingStyle | 22 | CodingStyle |
23 | - how the boss likes the C code in the kernel to look. | 23 | - how the boss likes the C code in the kernel to look. |
24 | development-process/ | ||
25 | - An extended tutorial on how to work with the kernel development | ||
26 | process. | ||
24 | DMA-API.txt | 27 | DMA-API.txt |
25 | - DMA API, pci_ API & extensions for non-consistent memory machines. | 28 | - DMA API, pci_ API & extensions for non-consistent memory machines. |
26 | DMA-ISA-LPC.txt | 29 | DMA-ISA-LPC.txt |
diff --git a/Documentation/development-process/1.Intro b/Documentation/development-process/1.Intro new file mode 100644 index 000000000000..8cc2cba2b10d --- /dev/null +++ b/Documentation/development-process/1.Intro | |||
@@ -0,0 +1,274 @@ | |||
1 | 1: A GUIDE TO THE KERNEL DEVELOPMENT PROCESS | ||
2 | |||
3 | The purpose of this document is to help developers (and their managers) | ||
4 | work with the development community with a minimum of frustration. It is | ||
5 | an attempt to document how this community works in a way which is | ||
6 | accessible to those who are not intimately familiar with Linux kernel | ||
7 | development (or, indeed, free software development in general). While | ||
8 | there is some technical material here, this is very much a process-oriented | ||
9 | discussion which does not require a deep knowledge of kernel programming to | ||
10 | understand. | ||
11 | |||
12 | |||
13 | 1.1: EXECUTIVE SUMMARY | ||
14 | |||
15 | The rest of this section covers the scope of the kernel development process | ||
16 | and the kinds of frustrations that developers and their employers can | ||
17 | encounter there. There are a great many reasons why kernel code should be | ||
18 | merged into the official ("mainline") kernel, including automatic | ||
19 | availability to users, community support in many forms, and the ability to | ||
20 | influence the direction of kernel development. Code contributed to the | ||
21 | Linux kernel must be made available under a GPL-compatible license. | ||
22 | |||
23 | Section 2 introduces the development process, the kernel release cycle, and | ||
24 | the mechanics of the merge window. The various phases in the patch | ||
25 | development, review, and merging cycle are covered. There is some | ||
26 | discussion of tools and mailing lists. Developers wanting to get started | ||
27 | with kernel development are encouraged to track down and fix bugs as an | ||
28 | initial exercise. | ||
29 | |||
30 | Section 3 covers early-stage project planning, with an emphasis on | ||
31 | involving the development community as soon as possible. | ||
32 | |||
33 | Section 4 is about the coding process; several pitfalls which have been | ||
34 | encountered by other developers are discussed. Some requirements for | ||
35 | patches are covered, and there is an introduction to some of the tools | ||
36 | which can help to ensure that kernel patches are correct. | ||
37 | |||
38 | Section 5 talks about the process of posting patches for review. To be | ||
39 | taken seriously by the development community, patches must be properly | ||
40 | formatted and described, and they must be sent to the right place. | ||
41 | Following the advice in this section should help to ensure the best | ||
42 | possible reception for your work. | ||
43 | |||
44 | Section 6 covers what happens after posting patches; the job is far from | ||
45 | done at that point. Working with reviewers is a crucial part of the | ||
46 | development process; this section offers a number of tips on how to avoid | ||
47 | problems at this important stage. Developers are cautioned against | ||
48 | assuming that the job is done when a patch is merged into the mainline. | ||
49 | |||
50 | Section 7 introduces a couple of "advanced" topics: managing patches with | ||
51 | git and reviewing patches posted by others. | ||
52 | |||
53 | Section 8 concludes the document with pointers to sources for more | ||
54 | information on kernel development. | ||
55 | |||
56 | |||
57 | 1.2: WHAT THIS DOCUMENT IS ABOUT | ||
58 | |||
59 | The Linux kernel, at over 6 million lines of code and well over 1000 active | ||
60 | contributors, is one of the largest and most active free software projects | ||
61 | in existence. Since its humble beginning in 1991, this kernel has evolved | ||
62 | into a best-of-breed operating system component which runs on pocket-sized | ||
63 | digital music players, desktop PCs, the largest supercomputers in | ||
64 | existence, and all types of systems in between. It is a robust, efficient, | ||
65 | and scalable solution for almost any situation. | ||
66 | |||
67 | With the growth of Linux has come an increase in the number of developers | ||
68 | (and companies) wishing to participate in its development. Hardware | ||
69 | vendors want to ensure that Linux supports their products well, making | ||
70 | those products attractive to Linux users. Embedded systems vendors, who | ||
71 | use Linux as a component in an integrated product, want Linux to be as | ||
72 | capable and well-suited to the task at hand as possible. Distributors and | ||
73 | other software vendors who base their products on Linux have a clear | ||
74 | interest in the capabilities, performance, and reliability of the Linux | ||
75 | kernel. And end users, too, will often wish to change Linux to make it | ||
76 | better suit their needs. | ||
77 | |||
78 | One of the most compelling features of Linux is that it is accessible to | ||
79 | these developers; anybody with the requisite skills can improve Linux and | ||
80 | influence the direction of its development. Proprietary products cannot | ||
81 | offer this kind of openness, which is a characteristic of the free software | ||
82 | process. But, if anything, the kernel is even more open than most other | ||
83 | free software projects. A typical three-month kernel development cycle can | ||
84 | involve over 1000 developers working for more than 100 different companies | ||
85 | (or for no company at all). | ||
86 | |||
87 | Working with the kernel development community is not especially hard. But, | ||
88 | that notwithstanding, many potential contributors have experienced | ||
89 | difficulties when trying to do kernel work. The kernel community has | ||
90 | evolved its own distinct ways of operating which allow it to function | ||
91 | smoothly (and produce a high-quality product) in an environment where | ||
92 | thousands of lines of code are being changed every day. So it is not | ||
93 | surprising that Linux kernel development process differs greatly from | ||
94 | proprietary development methods. | ||
95 | |||
96 | The kernel's development process may come across as strange and | ||
97 | intimidating to new developers, but there are good reasons and solid | ||
98 | experience behind it. A developer who does not understand the kernel | ||
99 | community's ways (or, worse, who tries to flout or circumvent them) will | ||
100 | have a frustrating experience in store. The development community, while | ||
101 | being helpful to those who are trying to learn, has little time for those | ||
102 | who will not listen or who do not care about the development process. | ||
103 | |||
104 | It is hoped that those who read this document will be able to avoid that | ||
105 | frustrating experience. There is a lot of material here, but the effort | ||
106 | involved in reading it will be repaid in short order. The development | ||
107 | community is always in need of developers who will help to make the kernel | ||
108 | better; the following text should help you - or those who work for you - | ||
109 | join our community. | ||
110 | |||
111 | |||
112 | 1.3: CREDITS | ||
113 | |||
114 | This document was written by Jonathan Corbet, corbet@lwn.net. It has been | ||
115 | improved by comments from Johannes Berg, James Berry, Alex Chiang, Roland | ||
116 | Dreier, Randy Dunlap, Jake Edge, Jiri Kosina, Matt Mackall, Arthur Marsh, | ||
117 | Amanda McPherson, Andrew Morton, Andrew Price, Tsugikazu Shibata, and | ||
118 | Jochen Voß. | ||
119 | |||
120 | This work was supported by the Linux Foundation; thanks especially to | ||
121 | Amanda McPherson, who saw the value of this effort and made it all happen. | ||
122 | |||
123 | |||
124 | 1.4: THE IMPORTANCE OF GETTING CODE INTO THE MAINLINE | ||
125 | |||
126 | Some companies and developers occasionally wonder why they should bother | ||
127 | learning how to work with the kernel community and get their code into the | ||
128 | mainline kernel (the "mainline" being the kernel maintained by Linus | ||
129 | Torvalds and used as a base by Linux distributors). In the short term, | ||
130 | contributing code can look like an avoidable expense; it seems easier to | ||
131 | just keep the code separate and support users directly. The truth of the | ||
132 | matter is that keeping code separate ("out of tree") is a false economy. | ||
133 | |||
134 | As a way of illustrating the costs of out-of-tree code, here are a few | ||
135 | relevant aspects of the kernel development process; most of these will be | ||
136 | discussed in greater detail later in this document. Consider: | ||
137 | |||
138 | - Code which has been merged into the mainline kernel is available to all | ||
139 | Linux users. It will automatically be present on all distributions which | ||
140 | enable it. There is no need for driver disks, downloads, or the hassles | ||
141 | of supporting multiple versions of multiple distributions; it all just | ||
142 | works, for the developer and for the user. Incorporation into the | ||
143 | mainline solves a large number of distribution and support problems. | ||
144 | |||
145 | - While kernel developers strive to maintain a stable interface to user | ||
146 | space, the internal kernel API is in constant flux. The lack of a stable | ||
147 | internal interface is a deliberate design decision; it allows fundamental | ||
148 | improvements to be made at any time and results in higher-quality code. | ||
149 | But one result of that policy is that any out-of-tree code requires | ||
150 | constant upkeep if it is to work with new kernels. Maintaining | ||
151 | out-of-tree code requires significant amounts of work just to keep that | ||
152 | code working. | ||
153 | |||
154 | Code which is in the mainline, instead, does not require this work as the | ||
155 | result of a simple rule requiring any developer who makes an API change | ||
156 | to also fix any code that breaks as the result of that change. So code | ||
157 | which has been merged into the mainline has significantly lower | ||
158 | maintenance costs. | ||
159 | |||
160 | - Beyond that, code which is in the kernel will often be improved by other | ||
161 | developers. Surprising results can come from empowering your user | ||
162 | community and customers to improve your product. | ||
163 | |||
164 | - Kernel code is subjected to review, both before and after merging into | ||
165 | the mainline. No matter how strong the original developer's skills are, | ||
166 | this review process invariably finds ways in which the code can be | ||
167 | improved. Often review finds severe bugs and security problems. This is | ||
168 | especially true for code which has been developed in a closed | ||
169 | environment; such code benefits strongly from review by outside | ||
170 | developers. Out-of-tree code is lower-quality code. | ||
171 | |||
172 | - Participation in the development process is your way to influence the | ||
173 | direction of kernel development. Users who complain from the sidelines | ||
174 | are heard, but active developers have a stronger voice - and the ability | ||
175 | to implement changes which make the kernel work better for their needs. | ||
176 | |||
177 | - When code is maintained separately, the possibility that a third party | ||
178 | will contribute a different implementation of a similar feature always | ||
179 | exists. Should that happen, getting your code merged will become much | ||
180 | harder - to the point of impossibility. Then you will be faced with the | ||
181 | unpleasant alternatives of either (1) maintaining a nonstandard feature | ||
182 | out of tree indefinitely, or (2) abandoning your code and migrating your | ||
183 | users over to the in-tree version. | ||
184 | |||
185 | - Contribution of code is the fundamental action which makes the whole | ||
186 | process work. By contributing your code you can add new functionality to | ||
187 | the kernel and provide capabilities and examples which are of use to | ||
188 | other kernel developers. If you have developed code for Linux (or are | ||
189 | thinking about doing so), you clearly have an interest in the continued | ||
190 | success of this platform; contributing code is one of the best ways to | ||
191 | help ensure that success. | ||
192 | |||
193 | All of the reasoning above applies to any out-of-tree kernel code, | ||
194 | including code which is distributed in proprietary, binary-only form. | ||
195 | There are, however, additional factors which should be taken into account | ||
196 | before considering any sort of binary-only kernel code distribution. These | ||
197 | include: | ||
198 | |||
199 | - The legal issues around the distribution of proprietary kernel modules | ||
200 | are cloudy at best; quite a few kernel copyright holders believe that | ||
201 | most binary-only modules are derived products of the kernel and that, as | ||
202 | a result, their distribution is a violation of the GNU General Public | ||
203 | license (about which more will be said below). Your author is not a | ||
204 | lawyer, and nothing in this document can possibly be considered to be | ||
205 | legal advice. The true legal status of closed-source modules can only be | ||
206 | determined by the courts. But the uncertainty which haunts those modules | ||
207 | is there regardless. | ||
208 | |||
209 | - Binary modules greatly increase the difficulty of debugging kernel | ||
210 | problems, to the point that most kernel developers will not even try. So | ||
211 | the distribution of binary-only modules will make it harder for your | ||
212 | users to get support from the community. | ||
213 | |||
214 | - Support is also harder for distributors of binary-only modules, who must | ||
215 | provide a version of the module for every distribution and every kernel | ||
216 | version they wish to support. Dozens of builds of a single module can | ||
217 | be required to provide reasonably comprehensive coverage, and your users | ||
218 | will have to upgrade your module separately every time they upgrade their | ||
219 | kernel. | ||
220 | |||
221 | - Everything that was said above about code review applies doubly to | ||
222 | closed-source code. Since this code is not available at all, it cannot | ||
223 | have been reviewed by the community and will, beyond doubt, have serious | ||
224 | problems. | ||
225 | |||
226 | Makers of embedded systems, in particular, may be tempted to disregard much | ||
227 | of what has been said in this section in the belief that they are shipping | ||
228 | a self-contained product which uses a frozen kernel version and requires no | ||
229 | more development after its release. This argument misses the value of | ||
230 | widespread code review and the value of allowing your users to add | ||
231 | capabilities to your product. But these products, too, have a limited | ||
232 | commercial life, after which a new version must be released. At that | ||
233 | point, vendors whose code is in the mainline and well maintained will be | ||
234 | much better positioned to get the new product ready for market quickly. | ||
235 | |||
236 | |||
237 | 1.5: LICENSING | ||
238 | |||
239 | Code is contributed to the Linux kernel under a number of licenses, but all | ||
240 | code must be compatible with version 2 of the GNU General Public License | ||
241 | (GPLv2), which is the license covering the kernel distribution as a whole. | ||
242 | In practice, that means that all code contributions are covered either by | ||
243 | GPLv2 (with, optionally, language allowing distribution under later | ||
244 | versions of the GPL) or the three-clause BSD license. Any contributions | ||
245 | which are not covered by a compatible license will not be accepted into the | ||
246 | kernel. | ||
247 | |||
248 | Copyright assignments are not required (or requested) for code contributed | ||
249 | to the kernel. All code merged into the mainline kernel retains its | ||
250 | original ownership; as a result, the kernel now has thousands of owners. | ||
251 | |||
252 | One implication of this ownership structure is that any attempt to change | ||
253 | the licensing of the kernel is doomed to almost certain failure. There are | ||
254 | few practical scenarios where the agreement of all copyright holders could | ||
255 | be obtained (or their code removed from the kernel). So, in particular, | ||
256 | there is no prospect of a migration to version 3 of the GPL in the | ||
257 | foreseeable future. | ||
258 | |||
259 | It is imperative that all code contributed to the kernel be legitimately | ||
260 | free software. For that reason, code from anonymous (or pseudonymous) | ||
261 | contributors will not be accepted. All contributors are required to "sign | ||
262 | off" on their code, stating that the code can be distributed with the | ||
263 | kernel under the GPL. Code which has not been licensed as free software by | ||
264 | its owner, or which risks creating copyright-related problems for the | ||
265 | kernel (such as code which derives from reverse-engineering efforts lacking | ||
266 | proper safeguards) cannot be contributed. | ||
267 | |||
268 | Questions about copyright-related issues are common on Linux development | ||
269 | mailing lists. Such questions will normally receive no shortage of | ||
270 | answers, but one should bear in mind that the people answering those | ||
271 | questions are not lawyers and cannot provide legal advice. If you have | ||
272 | legal questions relating to Linux source code, there is no substitute for | ||
273 | talking with a lawyer who understands this field. Relying on answers | ||
274 | obtained on technical mailing lists is a risky affair. | ||
diff --git a/Documentation/development-process/2.Process b/Documentation/development-process/2.Process new file mode 100644 index 000000000000..d750321acd5a --- /dev/null +++ b/Documentation/development-process/2.Process | |||
@@ -0,0 +1,459 @@ | |||
1 | 2: HOW THE DEVELOPMENT PROCESS WORKS | ||
2 | |||
3 | Linux kernel development in the early 1990's was a pretty loose affair, | ||
4 | with relatively small numbers of users and developers involved. With a | ||
5 | user base in the millions and with some 2,000 developers involved over the | ||
6 | course of one year, the kernel has since had to evolve a number of | ||
7 | processes to keep development happening smoothly. A solid understanding of | ||
8 | how the process works is required in order to be an effective part of it. | ||
9 | |||
10 | |||
11 | 2.1: THE BIG PICTURE | ||
12 | |||
13 | The kernel developers use a loosely time-based release process, with a new | ||
14 | major kernel release happening every two or three months. The recent | ||
15 | release history looks like this: | ||
16 | |||
17 | 2.6.26 July 13, 2008 | ||
18 | 2.6.25 April 16, 2008 | ||
19 | 2.6.24 January 24, 2008 | ||
20 | 2.6.23 October 9, 2007 | ||
21 | 2.6.22 July 8, 2007 | ||
22 | 2.6.21 April 25, 2007 | ||
23 | 2.6.20 February 4, 2007 | ||
24 | |||
25 | Every 2.6.x release is a major kernel release with new features, internal | ||
26 | API changes, and more. A typical 2.6 release can contain over 10,000 | ||
27 | changesets with changes to several hundred thousand lines of code. 2.6 is | ||
28 | thus the leading edge of Linux kernel development; the kernel uses a | ||
29 | rolling development model which is continually integrating major changes. | ||
30 | |||
31 | A relatively straightforward discipline is followed with regard to the | ||
32 | merging of patches for each release. At the beginning of each development | ||
33 | cycle, the "merge window" is said to be open. At that time, code which is | ||
34 | deemed to be sufficiently stable (and which is accepted by the development | ||
35 | community) is merged into the mainline kernel. The bulk of changes for a | ||
36 | new development cycle (and all of the major changes) will be merged during | ||
37 | this time, at a rate approaching 1,000 changes ("patches," or "changesets") | ||
38 | per day. | ||
39 | |||
40 | (As an aside, it is worth noting that the changes integrated during the | ||
41 | merge window do not come out of thin air; they have been collected, tested, | ||
42 | and staged ahead of time. How that process works will be described in | ||
43 | detail later on). | ||
44 | |||
45 | The merge window lasts for two weeks. At the end of this time, Linus | ||
46 | Torvalds will declare that the window is closed and release the first of | ||
47 | the "rc" kernels. For the kernel which is destined to be 2.6.26, for | ||
48 | example, the release which happens at the end of the merge window will be | ||
49 | called 2.6.26-rc1. The -rc1 release is the signal that the time to merge | ||
50 | new features has passed, and that the time to stabilize the next kernel has | ||
51 | begun. | ||
52 | |||
53 | Over the next six to ten weeks, only patches which fix problems should be | ||
54 | submitted to the mainline. On occasion a more significant change will be | ||
55 | allowed, but such occasions are rare; developers who try to merge new | ||
56 | features outside of the merge window tend to get an unfriendly reception. | ||
57 | As a general rule, if you miss the merge window for a given feature, the | ||
58 | best thing to do is to wait for the next development cycle. (An occasional | ||
59 | exception is made for drivers for previously-unsupported hardware; if they | ||
60 | touch no in-tree code, they cannot cause regressions and should be safe to | ||
61 | add at any time). | ||
62 | |||
63 | As fixes make their way into the mainline, the patch rate will slow over | ||
64 | time. Linus releases new -rc kernels about once a week; a normal series | ||
65 | will get up to somewhere between -rc6 and -rc9 before the kernel is | ||
66 | considered to be sufficiently stable and the final 2.6.x release is made. | ||
67 | At that point the whole process starts over again. | ||
68 | |||
69 | As an example, here is how the 2.6.25 development cycle went (all dates in | ||
70 | 2008): | ||
71 | |||
72 | January 24 2.6.24 stable release | ||
73 | February 10 2.6.25-rc1, merge window closes | ||
74 | February 15 2.6.25-rc2 | ||
75 | February 24 2.6.25-rc3 | ||
76 | March 4 2.6.25-rc4 | ||
77 | March 9 2.6.25-rc5 | ||
78 | March 16 2.6.25-rc6 | ||
79 | March 25 2.6.25-rc7 | ||
80 | April 1 2.6.25-rc8 | ||
81 | April 11 2.6.25-rc9 | ||
82 | April 16 2.6.25 stable release | ||
83 | |||
84 | How do the developers decide when to close the development cycle and create | ||
85 | the stable release? The most significant metric used is the list of | ||
86 | regressions from previous releases. No bugs are welcome, but those which | ||
87 | break systems which worked in the past are considered to be especially | ||
88 | serious. For this reason, patches which cause regressions are looked upon | ||
89 | unfavorably and are quite likely to be reverted during the stabilization | ||
90 | period. | ||
91 | |||
92 | The developers' goal is to fix all known regressions before the stable | ||
93 | release is made. In the real world, this kind of perfection is hard to | ||
94 | achieve; there are just too many variables in a project of this size. | ||
95 | There comes a point where delaying the final release just makes the problem | ||
96 | worse; the pile of changes waiting for the next merge window will grow | ||
97 | larger, creating even more regressions the next time around. So most 2.6.x | ||
98 | kernels go out with a handful of known regressions though, hopefully, none | ||
99 | of them are serious. | ||
100 | |||
101 | Once a stable release is made, its ongoing maintenance is passed off to the | ||
102 | "stable team," currently comprised of Greg Kroah-Hartman and Chris Wright. | ||
103 | The stable team will release occasional updates to the stable release using | ||
104 | the 2.6.x.y numbering scheme. To be considered for an update release, a | ||
105 | patch must (1) fix a significant bug, and (2) already be merged into the | ||
106 | mainline for the next development kernel. Continuing our 2.6.25 example, | ||
107 | the history (as of this writing) is: | ||
108 | |||
109 | May 1 2.6.25.1 | ||
110 | May 6 2.6.25.2 | ||
111 | May 9 2.6.25.3 | ||
112 | May 15 2.6.25.4 | ||
113 | June 7 2.6.25.5 | ||
114 | June 9 2.6.25.6 | ||
115 | June 16 2.6.25.7 | ||
116 | June 21 2.6.25.8 | ||
117 | June 24 2.6.25.9 | ||
118 | |||
119 | Stable updates for a given kernel are made for approximately six months; | ||
120 | after that, the maintenance of stable releases is solely the responsibility | ||
121 | of the distributors which have shipped that particular kernel. | ||
122 | |||
123 | |||
124 | 2.2: THE LIFECYCLE OF A PATCH | ||
125 | |||
126 | Patches do not go directly from the developer's keyboard into the mainline | ||
127 | kernel. There is, instead, a somewhat involved (if somewhat informal) | ||
128 | process designed to ensure that each patch is reviewed for quality and that | ||
129 | each patch implements a change which is desirable to have in the mainline. | ||
130 | This process can happen quickly for minor fixes, or, in the case of large | ||
131 | and controversial changes, go on for years. Much developer frustration | ||
132 | comes from a lack of understanding of this process or from attempts to | ||
133 | circumvent it. | ||
134 | |||
135 | In the hopes of reducing that frustration, this document will describe how | ||
136 | a patch gets into the kernel. What follows below is an introduction which | ||
137 | describes the process in a somewhat idealized way. A much more detailed | ||
138 | treatment will come in later sections. | ||
139 | |||
140 | The stages that a patch goes through are, generally: | ||
141 | |||
142 | - Design. This is where the real requirements for the patch - and the way | ||
143 | those requirements will be met - are laid out. Design work is often | ||
144 | done without involving the community, but it is better to do this work | ||
145 | in the open if at all possible; it can save a lot of time redesigning | ||
146 | things later. | ||
147 | |||
148 | - Early review. Patches are posted to the relevant mailing list, and | ||
149 | developers on that list reply with any comments they may have. This | ||
150 | process should turn up any major problems with a patch if all goes | ||
151 | well. | ||
152 | |||
153 | - Wider review. When the patch is getting close to ready for mainline | ||
154 | inclusion, it will be accepted by a relevant subsystem maintainer - | ||
155 | though this acceptance is not a guarantee that the patch will make it | ||
156 | all the way to the mainline. The patch will show up in the maintainer's | ||
157 | subsystem tree and into the staging trees (described below). When the | ||
158 | process works, this step leads to more extensive review of the patch and | ||
159 | the discovery of any problems resulting from the integration of this | ||
160 | patch with work being done by others. | ||
161 | |||
162 | - Merging into the mainline. Eventually, a successful patch will be | ||
163 | merged into the mainline repository managed by Linus Torvalds. More | ||
164 | comments and/or problems may surface at this time; it is important that | ||
165 | the developer be responsive to these and fix any issues which arise. | ||
166 | |||
167 | - Stable release. The number of users potentially affected by the patch | ||
168 | is now large, so, once again, new problems may arise. | ||
169 | |||
170 | - Long-term maintenance. While it is certainly possible for a developer | ||
171 | to forget about code after merging it, that sort of behavior tends to | ||
172 | leave a poor impression in the development community. Merging code | ||
173 | eliminates some of the maintenance burden, in that others will fix | ||
174 | problems caused by API changes. But the original developer should | ||
175 | continue to take responsibility for the code if it is to remain useful | ||
176 | in the longer term. | ||
177 | |||
178 | One of the largest mistakes made by kernel developers (or their employers) | ||
179 | is to try to cut the process down to a single "merging into the mainline" | ||
180 | step. This approach invariably leads to frustration for everybody | ||
181 | involved. | ||
182 | |||
183 | |||
184 | 2.3: HOW PATCHES GET INTO THE KERNEL | ||
185 | |||
186 | There is exactly one person who can merge patches into the mainline kernel | ||
187 | repository: Linus Torvalds. But, of the over 12,000 patches which went | ||
188 | into the 2.6.25 kernel, only 250 (around 2%) were directly chosen by Linus | ||
189 | himself. The kernel project has long since grown to a size where no single | ||
190 | developer could possibly inspect and select every patch unassisted. The | ||
191 | way the kernel developers have addressed this growth is through the use of | ||
192 | a lieutenant system built around a chain of trust. | ||
193 | |||
194 | The kernel code base is logically broken down into a set of subsystems: | ||
195 | networking, specific architecture support, memory management, video | ||
196 | devices, etc. Most subsystems have a designated maintainer, a developer | ||
197 | who has overall responsibility for the code within that subsystem. These | ||
198 | subsystem maintainers are the gatekeepers (in a loose way) for the portion | ||
199 | of the kernel they manage; they are the ones who will (usually) accept a | ||
200 | patch for inclusion into the mainline kernel. | ||
201 | |||
202 | Subsystem maintainers each manage their own version of the kernel source | ||
203 | tree, usually (but certainly not always) using the git source management | ||
204 | tool. Tools like git (and related tools like quilt or mercurial) allow | ||
205 | maintainers to track a list of patches, including authorship information | ||
206 | and other metadata. At any given time, the maintainer can identify which | ||
207 | patches in his or her repository are not found in the mainline. | ||
208 | |||
209 | When the merge window opens, top-level maintainers will ask Linus to "pull" | ||
210 | the patches they have selected for merging from their repositories. If | ||
211 | Linus agrees, the stream of patches will flow up into his repository, | ||
212 | becoming part of the mainline kernel. The amount of attention that Linus | ||
213 | pays to specific patches received in a pull operation varies. It is clear | ||
214 | that, sometimes, he looks quite closely. But, as a general rule, Linus | ||
215 | trusts the subsystem maintainers to not send bad patches upstream. | ||
216 | |||
217 | Subsystem maintainers, in turn, can pull patches from other maintainers. | ||
218 | For example, the networking tree is built from patches which accumulated | ||
219 | first in trees dedicated to network device drivers, wireless networking, | ||
220 | etc. This chain of repositories can be arbitrarily long, though it rarely | ||
221 | exceeds two or three links. Since each maintainer in the chain trusts | ||
222 | those managing lower-level trees, this process is known as the "chain of | ||
223 | trust." | ||
224 | |||
225 | Clearly, in a system like this, getting patches into the kernel depends on | ||
226 | finding the right maintainer. Sending patches directly to Linus is not | ||
227 | normally the right way to go. | ||
228 | |||
229 | |||
230 | 2.4: STAGING TREES | ||
231 | |||
232 | The chain of subsystem trees guides the flow of patches into the kernel, | ||
233 | but it also raises an interesting question: what if somebody wants to look | ||
234 | at all of the patches which are being prepared for the next merge window? | ||
235 | Developers will be interested in what other changes are pending to see | ||
236 | whether there are any conflicts to worry about; a patch which changes a | ||
237 | core kernel function prototype, for example, will conflict with any other | ||
238 | patches which use the older form of that function. Reviewers and testers | ||
239 | want access to the changes in their integrated form before all of those | ||
240 | changes land in the mainline kernel. One could pull changes from all of | ||
241 | the interesting subsystem trees, but that would be a big and error-prone | ||
242 | job. | ||
243 | |||
244 | The answer comes in the form of staging trees, where subsystem trees are | ||
245 | collected for testing and review. The older of these trees, maintained by | ||
246 | Andrew Morton, is called "-mm" (for memory management, which is how it got | ||
247 | started). The -mm tree integrates patches from a long list of subsystem | ||
248 | trees; it also has some patches aimed at helping with debugging. | ||
249 | |||
250 | Beyond that, -mm contains a significant collection of patches which have | ||
251 | been selected by Andrew directly. These patches may have been posted on a | ||
252 | mailing list, or they may apply to a part of the kernel for which there is | ||
253 | no designated subsystem tree. As a result, -mm operates as a sort of | ||
254 | subsystem tree of last resort; if there is no other obvious path for a | ||
255 | patch into the mainline, it is likely to end up in -mm. Miscellaneous | ||
256 | patches which accumulate in -mm will eventually either be forwarded on to | ||
257 | an appropriate subsystem tree or be sent directly to Linus. In a typical | ||
258 | development cycle, approximately 10% of the patches going into the mainline | ||
259 | get there via -mm. | ||
260 | |||
261 | The current -mm patch can always be found from the front page of | ||
262 | |||
263 | http://kernel.org/ | ||
264 | |||
265 | Those who want to see the current state of -mm can get the "-mm of the | ||
266 | moment" tree, found at: | ||
267 | |||
268 | http://userweb.kernel.org/~akpm/mmotm/ | ||
269 | |||
270 | Use of the MMOTM tree is likely to be a frustrating experience, though; | ||
271 | there is a definite chance that it will not even compile. | ||
272 | |||
273 | The other staging tree, started more recently, is linux-next, maintained by | ||
274 | Stephen Rothwell. The linux-next tree is, by design, a snapshot of what | ||
275 | the mainline is expected to look like after the next merge window closes. | ||
276 | Linux-next trees are announced on the linux-kernel and linux-next mailing | ||
277 | lists when they are assembled; they can be downloaded from: | ||
278 | |||
279 | http://www.kernel.org/pub/linux/kernel/people/sfr/linux-next/ | ||
280 | |||
281 | Some information about linux-next has been gathered at: | ||
282 | |||
283 | http://linux.f-seidel.de/linux-next/pmwiki/ | ||
284 | |||
285 | How the linux-next tree will fit into the development process is still | ||
286 | changing. As of this writing, the first full development cycle involving | ||
287 | linux-next (2.6.26) is coming to an end; thus far, it has proved to be a | ||
288 | valuable resource for finding and fixing integration problems before the | ||
289 | beginning of the merge window. See http://lwn.net/Articles/287155/ for | ||
290 | more information on how linux-next has worked to set up the 2.6.27 merge | ||
291 | window. | ||
292 | |||
293 | Some developers have begun to suggest that linux-next should be used as the | ||
294 | target for future development as well. The linux-next tree does tend to be | ||
295 | far ahead of the mainline and is more representative of the tree into which | ||
296 | any new work will be merged. The downside to this idea is that the | ||
297 | volatility of linux-next tends to make it a difficult development target. | ||
298 | See http://lwn.net/Articles/289013/ for more information on this topic, and | ||
299 | stay tuned; much is still in flux where linux-next is involved. | ||
300 | |||
301 | |||
302 | 2.5: TOOLS | ||
303 | |||
304 | As can be seen from the above text, the kernel development process depends | ||
305 | heavily on the ability to herd collections of patches in various | ||
306 | directions. The whole thing would not work anywhere near as well as it | ||
307 | does without suitably powerful tools. Tutorials on how to use these tools | ||
308 | are well beyond the scope of this document, but there is space for a few | ||
309 | pointers. | ||
310 | |||
311 | By far the dominant source code management system used by the kernel | ||
312 | community is git. Git is one of a number of distributed version control | ||
313 | systems being developed in the free software community. It is well tuned | ||
314 | for kernel development, in that it performs quite well when dealing with | ||
315 | large repositories and large numbers of patches. It also has a reputation | ||
316 | for being difficult to learn and use, though it has gotten better over | ||
317 | time. Some sort of familiarity with git is almost a requirement for kernel | ||
318 | developers; even if they do not use it for their own work, they'll need git | ||
319 | to keep up with what other developers (and the mainline) are doing. | ||
320 | |||
321 | Git is now packaged by almost all Linux distributions. There is a home | ||
322 | page at | ||
323 | |||
324 | http://git.or.cz/ | ||
325 | |||
326 | That page has pointers to documentation and tutorials. One should be | ||
327 | aware, in particular, of the Kernel Hacker's Guide to git, which has | ||
328 | information specific to kernel development: | ||
329 | |||
330 | http://linux.yyz.us/git-howto.html | ||
331 | |||
332 | Among the kernel developers who do not use git, the most popular choice is | ||
333 | almost certainly Mercurial: | ||
334 | |||
335 | http://www.selenic.com/mercurial/ | ||
336 | |||
337 | Mercurial shares many features with git, but it provides an interface which | ||
338 | many find easier to use. | ||
339 | |||
340 | The other tool worth knowing about is Quilt: | ||
341 | |||
342 | http://savannah.nongnu.org/projects/quilt/ | ||
343 | |||
344 | Quilt is a patch management system, rather than a source code management | ||
345 | system. It does not track history over time; it is, instead, oriented | ||
346 | toward tracking a specific set of changes against an evolving code base. | ||
347 | Some major subsystem maintainers use quilt to manage patches intended to go | ||
348 | upstream. For the management of certain kinds of trees (-mm, for example), | ||
349 | quilt is the best tool for the job. | ||
350 | |||
351 | |||
352 | 2.6: MAILING LISTS | ||
353 | |||
354 | A great deal of Linux kernel development work is done by way of mailing | ||
355 | lists. It is hard to be a fully-functioning member of the community | ||
356 | without joining at least one list somewhere. But Linux mailing lists also | ||
357 | represent a potential hazard to developers, who risk getting buried under a | ||
358 | load of electronic mail, running afoul of the conventions used on the Linux | ||
359 | lists, or both. | ||
360 | |||
361 | Most kernel mailing lists are run on vger.kernel.org; the master list can | ||
362 | be found at: | ||
363 | |||
364 | http://vger.kernel.org/vger-lists.html | ||
365 | |||
366 | There are lists hosted elsewhere, though; a number of them are at | ||
367 | lists.redhat.com. | ||
368 | |||
369 | The core mailing list for kernel development is, of course, linux-kernel. | ||
370 | This list is an intimidating place to be; volume can reach 500 messages per | ||
371 | day, the amount of noise is high, the conversation can be severely | ||
372 | technical, and participants are not always concerned with showing a high | ||
373 | degree of politeness. But there is no other place where the kernel | ||
374 | development community comes together as a whole; developers who avoid this | ||
375 | list will miss important information. | ||
376 | |||
377 | There are a few hints which can help with linux-kernel survival: | ||
378 | |||
379 | - Have the list delivered to a separate folder, rather than your main | ||
380 | mailbox. One must be able to ignore the stream for sustained periods of | ||
381 | time. | ||
382 | |||
383 | - Do not try to follow every conversation - nobody else does. It is | ||
384 | important to filter on both the topic of interest (though note that | ||
385 | long-running conversations can drift away from the original subject | ||
386 | without changing the email subject line) and the people who are | ||
387 | participating. | ||
388 | |||
389 | - Do not feed the trolls. If somebody is trying to stir up an angry | ||
390 | response, ignore them. | ||
391 | |||
392 | - When responding to linux-kernel email (or that on other lists) preserve | ||
393 | the Cc: header for all involved. In the absence of a strong reason (such | ||
394 | as an explicit request), you should never remove recipients. Always make | ||
395 | sure that the person you are responding to is in the Cc: list. This | ||
396 | convention also makes it unnecessary to explicitly ask to be copied on | ||
397 | replies to your postings. | ||
398 | |||
399 | - Search the list archives (and the net as a whole) before asking | ||
400 | questions. Some developers can get impatient with people who clearly | ||
401 | have not done their homework. | ||
402 | |||
403 | - Avoid top-posting (the practice of putting your answer above the quoted | ||
404 | text you are responding to). It makes your response harder to read and | ||
405 | makes a poor impression. | ||
406 | |||
407 | - Ask on the correct mailing list. Linux-kernel may be the general meeting | ||
408 | point, but it is not the best place to find developers from all | ||
409 | subsystems. | ||
410 | |||
411 | The last point - finding the correct mailing list - is a common place for | ||
412 | beginning developers to go wrong. Somebody who asks a networking-related | ||
413 | question on linux-kernel will almost certainly receive a polite suggestion | ||
414 | to ask on the netdev list instead, as that is the list frequented by most | ||
415 | networking developers. Other lists exist for the SCSI, video4linux, IDE, | ||
416 | filesystem, etc. subsystems. The best place to look for mailing lists is | ||
417 | in the MAINTAINERS file packaged with the kernel source. | ||
418 | |||
419 | |||
420 | 2.7: GETTING STARTED WITH KERNEL DEVELOPMENT | ||
421 | |||
422 | Questions about how to get started with the kernel development process are | ||
423 | common - from both individuals and companies. Equally common are missteps | ||
424 | which make the beginning of the relationship harder than it has to be. | ||
425 | |||
426 | Companies often look to hire well-known developers to get a development | ||
427 | group started. This can, in fact, be an effective technique. But it also | ||
428 | tends to be expensive and does not do much to grow the pool of experienced | ||
429 | kernel developers. It is possible to bring in-house developers up to speed | ||
430 | on Linux kernel development, given the investment of a bit of time. Taking | ||
431 | this time can endow an employer with a group of developers who understand | ||
432 | the kernel and the company both, and who can help to train others as well. | ||
433 | Over the medium term, this is often the more profitable approach. | ||
434 | |||
435 | Individual developers are often, understandably, at a loss for a place to | ||
436 | start. Beginning with a large project can be intimidating; one often wants | ||
437 | to test the waters with something smaller first. This is the point where | ||
438 | some developers jump into the creation of patches fixing spelling errors or | ||
439 | minor coding style issues. Unfortunately, such patches create a level of | ||
440 | noise which is distracting for the development community as a whole, so, | ||
441 | increasingly, they are looked down upon. New developers wishing to | ||
442 | introduce themselves to the community will not get the sort of reception | ||
443 | they wish for by these means. | ||
444 | |||
445 | Andrew Morton gives this advice for aspiring kernel developers | ||
446 | |||
447 | The #1 project for all kernel beginners should surely be "make sure | ||
448 | that the kernel runs perfectly at all times on all machines which | ||
449 | you can lay your hands on". Usually the way to do this is to work | ||
450 | with others on getting things fixed up (this can require | ||
451 | persistence!) but that's fine - it's a part of kernel development. | ||
452 | |||
453 | (http://lwn.net/Articles/283982/). | ||
454 | |||
455 | In the absence of obvious problems to fix, developers are advised to look | ||
456 | at the current lists of regressions and open bugs in general. There is | ||
457 | never any shortage of issues in need of fixing; by addressing these issues, | ||
458 | developers will gain experience with the process while, at the same time, | ||
459 | building respect with the rest of the development community. | ||
diff --git a/Documentation/development-process/3.Early-stage b/Documentation/development-process/3.Early-stage new file mode 100644 index 000000000000..307a159a70ca --- /dev/null +++ b/Documentation/development-process/3.Early-stage | |||
@@ -0,0 +1,195 @@ | |||
1 | 3: EARLY-STAGE PLANNING | ||
2 | |||
3 | When contemplating a Linux kernel development project, it can be tempting | ||
4 | to jump right in and start coding. As with any significant project, | ||
5 | though, much of the groundwork for success is best laid before the first | ||
6 | line of code is written. Some time spent in early planning and | ||
7 | communication can save far more time later on. | ||
8 | |||
9 | |||
10 | 3.1: SPECIFYING THE PROBLEM | ||
11 | |||
12 | Like any engineering project, a successful kernel enhancement starts with a | ||
13 | clear description of the problem to be solved. In some cases, this step is | ||
14 | easy: when a driver is needed for a specific piece of hardware, for | ||
15 | example. In others, though, it is tempting to confuse the real problem | ||
16 | with the proposed solution, and that can lead to difficulties. | ||
17 | |||
18 | Consider an example: some years ago, developers working with Linux audio | ||
19 | sought a way to run applications without dropouts or other artifacts caused | ||
20 | by excessive latency in the system. The solution they arrived at was a | ||
21 | kernel module intended to hook into the Linux Security Module (LSM) | ||
22 | framework; this module could be configured to give specific applications | ||
23 | access to the realtime scheduler. This module was implemented and sent to | ||
24 | the linux-kernel mailing list, where it immediately ran into problems. | ||
25 | |||
26 | To the audio developers, this security module was sufficient to solve their | ||
27 | immediate problem. To the wider kernel community, though, it was seen as a | ||
28 | misuse of the LSM framework (which is not intended to confer privileges | ||
29 | onto processes which they would not otherwise have) and a risk to system | ||
30 | stability. Their preferred solutions involved realtime scheduling access | ||
31 | via the rlimit mechanism for the short term, and ongoing latency reduction | ||
32 | work in the long term. | ||
33 | |||
34 | The audio community, however, could not see past the particular solution | ||
35 | they had implemented; they were unwilling to accept alternatives. The | ||
36 | resulting disagreement left those developers feeling disillusioned with the | ||
37 | entire kernel development process; one of them went back to an audio list | ||
38 | and posted this: | ||
39 | |||
40 | There are a number of very good Linux kernel developers, but they | ||
41 | tend to get outshouted by a large crowd of arrogant fools. Trying | ||
42 | to communicate user requirements to these people is a waste of | ||
43 | time. They are much too "intelligent" to listen to lesser mortals. | ||
44 | |||
45 | (http://lwn.net/Articles/131776/). | ||
46 | |||
47 | The reality of the situation was different; the kernel developers were far | ||
48 | more concerned about system stability, long-term maintenance, and finding | ||
49 | the right solution to the problem than they were with a specific module. | ||
50 | The moral of the story is to focus on the problem - not a specific solution | ||
51 | - and to discuss it with the development community before investing in the | ||
52 | creation of a body of code. | ||
53 | |||
54 | So, when contemplating a kernel development project, one should obtain | ||
55 | answers to a short set of questions: | ||
56 | |||
57 | - What, exactly, is the problem which needs to be solved? | ||
58 | |||
59 | - Who are the users affected by this problem? Which use cases should the | ||
60 | solution address? | ||
61 | |||
62 | - How does the kernel fall short in addressing that problem now? | ||
63 | |||
64 | Only then does it make sense to start considering possible solutions. | ||
65 | |||
66 | |||
67 | 3.2: EARLY DISCUSSION | ||
68 | |||
69 | When planning a kernel development project, it makes great sense to hold | ||
70 | discussions with the community before launching into implementation. Early | ||
71 | communication can save time and trouble in a number of ways: | ||
72 | |||
73 | - It may well be that the problem is addressed by the kernel in ways which | ||
74 | you have not understood. The Linux kernel is large and has a number of | ||
75 | features and capabilities which are not immediately obvious. Not all | ||
76 | kernel capabilities are documented as well as one might like, and it is | ||
77 | easy to miss things. Your author has seen the posting of a complete | ||
78 | driver which duplicated an existing driver that the new author had been | ||
79 | unaware of. Code which reinvents existing wheels is not only wasteful; | ||
80 | it will also not be accepted into the mainline kernel. | ||
81 | |||
82 | - There may be elements of the proposed solution which will not be | ||
83 | acceptable for mainline merging. It is better to find out about | ||
84 | problems like this before writing the code. | ||
85 | |||
86 | - It's entirely possible that other developers have thought about the | ||
87 | problem; they may have ideas for a better solution, and may be willing | ||
88 | to help in the creation of that solution. | ||
89 | |||
90 | Years of experience with the kernel development community have taught a | ||
91 | clear lesson: kernel code which is designed and developed behind closed | ||
92 | doors invariably has problems which are only revealed when the code is | ||
93 | released into the community. Sometimes these problems are severe, | ||
94 | requiring months or years of effort before the code can be brought up to | ||
95 | the kernel community's standards. Some examples include: | ||
96 | |||
97 | - The Devicescape network stack was designed and implemented for | ||
98 | single-processor systems. It could not be merged into the mainline | ||
99 | until it was made suitable for multiprocessor systems. Retrofitting | ||
100 | locking and such into code is a difficult task; as a result, the merging | ||
101 | of this code (now called mac80211) was delayed for over a year. | ||
102 | |||
103 | - The Reiser4 filesystem included a number of capabilities which, in the | ||
104 | core kernel developers' opinion, should have been implemented in the | ||
105 | virtual filesystem layer instead. It also included features which could | ||
106 | not easily be implemented without exposing the system to user-caused | ||
107 | deadlocks. The late revelation of these problems - and refusal to | ||
108 | address some of them - has caused Reiser4 to stay out of the mainline | ||
109 | kernel. | ||
110 | |||
111 | - The AppArmor security module made use of internal virtual filesystem | ||
112 | data structures in ways which were considered to be unsafe and | ||
113 | unreliable. This code has since been significantly reworked, but | ||
114 | remains outside of the mainline. | ||
115 | |||
116 | In each of these cases, a great deal of pain and extra work could have been | ||
117 | avoided with some early discussion with the kernel developers. | ||
118 | |||
119 | |||
120 | 3.3: WHO DO YOU TALK TO? | ||
121 | |||
122 | When developers decide to take their plans public, the next question will | ||
123 | be: where do we start? The answer is to find the right mailing list(s) and | ||
124 | the right maintainer. For mailing lists, the best approach is to look in | ||
125 | the MAINTAINERS file for a relevant place to post. If there is a suitable | ||
126 | subsystem list, posting there is often preferable to posting on | ||
127 | linux-kernel; you are more likely to reach developers with expertise in the | ||
128 | relevant subsystem and the environment may be more supportive. | ||
129 | |||
130 | Finding maintainers can be a bit harder. Again, the MAINTAINERS file is | ||
131 | the place to start. That file tends to not always be up to date, though, | ||
132 | and not all subsystems are represented there. The person listed in the | ||
133 | MAINTAINERS file may, in fact, not be the person who is actually acting in | ||
134 | that role currently. So, when there is doubt about who to contact, a | ||
135 | useful trick is to use git (and "git log" in particular) to see who is | ||
136 | currently active within the subsystem of interest. Look at who is writing | ||
137 | patches, and who, if anybody, is attaching Signed-off-by lines to those | ||
138 | patches. Those are the people who will be best placed to help with a new | ||
139 | development project. | ||
140 | |||
141 | If all else fails, talking to Andrew Morton can be an effective way to | ||
142 | track down a maintainer for a specific piece of code. | ||
143 | |||
144 | |||
145 | 3.4: WHEN TO POST? | ||
146 | |||
147 | If possible, posting your plans during the early stages can only be | ||
148 | helpful. Describe the problem being solved and any plans that have been | ||
149 | made on how the implementation will be done. Any information you can | ||
150 | provide can help the development community provide useful input on the | ||
151 | project. | ||
152 | |||
153 | One discouraging thing which can happen at this stage is not a hostile | ||
154 | reaction, but, instead, little or no reaction at all. The sad truth of the | ||
155 | matter is (1) kernel developers tend to be busy, (2) there is no shortage | ||
156 | of people with grand plans and little code (or even prospect of code) to | ||
157 | back them up, and (3) nobody is obligated to review or comment on ideas | ||
158 | posted by others. If a request-for-comments posting yields little in the | ||
159 | way of comments, do not assume that it means there is no interest in the | ||
160 | project. Unfortunately, you also cannot assume that there are no problems | ||
161 | with your idea. The best thing to do in this situation is to proceed, | ||
162 | keeping the community informed as you go. | ||
163 | |||
164 | |||
165 | 3.5: GETTING OFFICIAL BUY-IN | ||
166 | |||
167 | If your work is being done in a corporate environment - as most Linux | ||
168 | kernel work is - you must, obviously, have permission from suitably | ||
169 | empowered managers before you can post your company's plans or code to a | ||
170 | public mailing list. The posting of code which has not been cleared for | ||
171 | release under a GPL-compatible license can be especially problematic; the | ||
172 | sooner that a company's management and legal staff can agree on the posting | ||
173 | of a kernel development project, the better off everybody involved will be. | ||
174 | |||
175 | Some readers may be thinking at this point that their kernel work is | ||
176 | intended to support a product which does not yet have an officially | ||
177 | acknowledged existence. Revealing their employer's plans on a public | ||
178 | mailing list may not be a viable option. In cases like this, it is worth | ||
179 | considering whether the secrecy is really necessary; there is often no real | ||
180 | need to keep development plans behind closed doors. | ||
181 | |||
182 | That said, there are also cases where a company legitimately cannot | ||
183 | disclose its plans early in the development process. Companies with | ||
184 | experienced kernel developers may choose to proceed in an open-loop manner | ||
185 | on the assumption that they will be able to avoid serious integration | ||
186 | problems later. For companies without that sort of in-house expertise, the | ||
187 | best option is often to hire an outside developer to review the plans under | ||
188 | a non-disclosure agreement. The Linux Foundation operates an NDA program | ||
189 | designed to help with this sort of situation; more information can be found | ||
190 | at: | ||
191 | |||
192 | http://www.linuxfoundation.org/en/NDA_program | ||
193 | |||
194 | This kind of review is often enough to avoid serious problems later on | ||
195 | without requiring public disclosure of the project. | ||
diff --git a/Documentation/development-process/4.Coding b/Documentation/development-process/4.Coding new file mode 100644 index 000000000000..014aca8f14e2 --- /dev/null +++ b/Documentation/development-process/4.Coding | |||
@@ -0,0 +1,384 @@ | |||
1 | 4: GETTING THE CODE RIGHT | ||
2 | |||
3 | While there is much to be said for a solid and community-oriented design | ||
4 | process, the proof of any kernel development project is in the resulting | ||
5 | code. It is the code which will be examined by other developers and merged | ||
6 | (or not) into the mainline tree. So it is the quality of this code which | ||
7 | will determine the ultimate success of the project. | ||
8 | |||
9 | This section will examine the coding process. We'll start with a look at a | ||
10 | number of ways in which kernel developers can go wrong. Then the focus | ||
11 | will shift toward doing things right and the tools which can help in that | ||
12 | quest. | ||
13 | |||
14 | |||
15 | 4.1: PITFALLS | ||
16 | |||
17 | * Coding style | ||
18 | |||
19 | The kernel has long had a standard coding style, described in | ||
20 | Documentation/CodingStyle. For much of that time, the policies described | ||
21 | in that file were taken as being, at most, advisory. As a result, there is | ||
22 | a substantial amount of code in the kernel which does not meet the coding | ||
23 | style guidelines. The presence of that code leads to two independent | ||
24 | hazards for kernel developers. | ||
25 | |||
26 | The first of these is to believe that the kernel coding standards do not | ||
27 | matter and are not enforced. The truth of the matter is that adding new | ||
28 | code to the kernel is very difficult if that code is not coded according to | ||
29 | the standard; many developers will request that the code be reformatted | ||
30 | before they will even review it. A code base as large as the kernel | ||
31 | requires some uniformity of code to make it possible for developers to | ||
32 | quickly understand any part of it. So there is no longer room for | ||
33 | strangely-formatted code. | ||
34 | |||
35 | Occasionally, the kernel's coding style will run into conflict with an | ||
36 | employer's mandated style. In such cases, the kernel's style will have to | ||
37 | win before the code can be merged. Putting code into the kernel means | ||
38 | giving up a degree of control in a number of ways - including control over | ||
39 | how the code is formatted. | ||
40 | |||
41 | The other trap is to assume that code which is already in the kernel is | ||
42 | urgently in need of coding style fixes. Developers may start to generate | ||
43 | reformatting patches as a way of gaining familiarity with the process, or | ||
44 | as a way of getting their name into the kernel changelogs - or both. But | ||
45 | pure coding style fixes are seen as noise by the development community; | ||
46 | they tend to get a chilly reception. So this type of patch is best | ||
47 | avoided. It is natural to fix the style of a piece of code while working | ||
48 | on it for other reasons, but coding style changes should not be made for | ||
49 | their own sake. | ||
50 | |||
51 | The coding style document also should not be read as an absolute law which | ||
52 | can never be transgressed. If there is a good reason to go against the | ||
53 | style (a line which becomes far less readable if split to fit within the | ||
54 | 80-column limit, for example), just do it. | ||
55 | |||
56 | |||
57 | * Abstraction layers | ||
58 | |||
59 | Computer Science professors teach students to make extensive use of | ||
60 | abstraction layers in the name of flexibility and information hiding. | ||
61 | Certainly the kernel makes extensive use of abstraction; no project | ||
62 | involving several million lines of code could do otherwise and survive. | ||
63 | But experience has shown that excessive or premature abstraction can be | ||
64 | just as harmful as premature optimization. Abstraction should be used to | ||
65 | the level required and no further. | ||
66 | |||
67 | At a simple level, consider a function which has an argument which is | ||
68 | always passed as zero by all callers. One could retain that argument just | ||
69 | in case somebody eventually needs to use the extra flexibility that it | ||
70 | provides. By that time, though, chances are good that the code which | ||
71 | implements this extra argument has been broken in some subtle way which was | ||
72 | never noticed - because it has never been used. Or, when the need for | ||
73 | extra flexibility arises, it does not do so in a way which matches the | ||
74 | programmer's early expectation. Kernel developers will routinely submit | ||
75 | patches to remove unused arguments; they should, in general, not be added | ||
76 | in the first place. | ||
77 | |||
78 | Abstraction layers which hide access to hardware - often to allow the bulk | ||
79 | of a driver to be used with multiple operating systems - are especially | ||
80 | frowned upon. Such layers obscure the code and may impose a performance | ||
81 | penalty; they do not belong in the Linux kernel. | ||
82 | |||
83 | On the other hand, if you find yourself copying significant amounts of code | ||
84 | from another kernel subsystem, it is time to ask whether it would, in fact, | ||
85 | make sense to pull out some of that code into a separate library or to | ||
86 | implement that functionality at a higher level. There is no value in | ||
87 | replicating the same code throughout the kernel. | ||
88 | |||
89 | |||
90 | * #ifdef and preprocessor use in general | ||
91 | |||
92 | The C preprocessor seems to present a powerful temptation to some C | ||
93 | programmers, who see it as a way to efficiently encode a great deal of | ||
94 | flexibility into a source file. But the preprocessor is not C, and heavy | ||
95 | use of it results in code which is much harder for others to read and | ||
96 | harder for the compiler to check for correctness. Heavy preprocessor use | ||
97 | is almost always a sign of code which needs some cleanup work. | ||
98 | |||
99 | Conditional compilation with #ifdef is, indeed, a powerful feature, and it | ||
100 | is used within the kernel. But there is little desire to see code which is | ||
101 | sprinkled liberally with #ifdef blocks. As a general rule, #ifdef use | ||
102 | should be confined to header files whenever possible. | ||
103 | Conditionally-compiled code can be confined to functions which, if the code | ||
104 | is not to be present, simply become empty. The compiler will then quietly | ||
105 | optimize out the call to the empty function. The result is far cleaner | ||
106 | code which is easier to follow. | ||
107 | |||
108 | C preprocessor macros present a number of hazards, including possible | ||
109 | multiple evaluation of expressions with side effects and no type safety. | ||
110 | If you are tempted to define a macro, consider creating an inline function | ||
111 | instead. The code which results will be the same, but inline functions are | ||
112 | easier to read, do not evaluate their arguments multiple times, and allow | ||
113 | the compiler to perform type checking on the arguments and return value. | ||
114 | |||
115 | |||
116 | * Inline functions | ||
117 | |||
118 | Inline functions present a hazard of their own, though. Programmers can | ||
119 | become enamored of the perceived efficiency inherent in avoiding a function | ||
120 | call and fill a source file with inline functions. Those functions, | ||
121 | however, can actually reduce performance. Since their code is replicated | ||
122 | at each call site, they end up bloating the size of the compiled kernel. | ||
123 | That, in turn, creates pressure on the processor's memory caches, which can | ||
124 | slow execution dramatically. Inline functions, as a rule, should be quite | ||
125 | small and relatively rare. The cost of a function call, after all, is not | ||
126 | that high; the creation of large numbers of inline functions is a classic | ||
127 | example of premature optimization. | ||
128 | |||
129 | In general, kernel programmers ignore cache effects at their peril. The | ||
130 | classic time/space tradeoff taught in beginning data structures classes | ||
131 | often does not apply to contemporary hardware. Space *is* time, in that a | ||
132 | larger program will run slower than one which is more compact. | ||
133 | |||
134 | |||
135 | * Locking | ||
136 | |||
137 | In May, 2006, the "Devicescape" networking stack was, with great | ||
138 | fanfare, released under the GPL and made available for inclusion in the | ||
139 | mainline kernel. This donation was welcome news; support for wireless | ||
140 | networking in Linux was considered substandard at best, and the Devicescape | ||
141 | stack offered the promise of fixing that situation. Yet, this code did not | ||
142 | actually make it into the mainline until June, 2007 (2.6.22). What | ||
143 | happened? | ||
144 | |||
145 | This code showed a number of signs of having been developed behind | ||
146 | corporate doors. But one large problem in particular was that it was not | ||
147 | designed to work on multiprocessor systems. Before this networking stack | ||
148 | (now called mac80211) could be merged, a locking scheme needed to be | ||
149 | retrofitted onto it. | ||
150 | |||
151 | Once upon a time, Linux kernel code could be developed without thinking | ||
152 | about the concurrency issues presented by multiprocessor systems. Now, | ||
153 | however, this document is being written on a dual-core laptop. Even on | ||
154 | single-processor systems, work being done to improve responsiveness will | ||
155 | raise the level of concurrency within the kernel. The days when kernel | ||
156 | code could be written without thinking about locking are long past. | ||
157 | |||
158 | Any resource (data structures, hardware registers, etc.) which could be | ||
159 | accessed concurrently by more than one thread must be protected by a lock. | ||
160 | New code should be written with this requirement in mind; retrofitting | ||
161 | locking after the fact is a rather more difficult task. Kernel developers | ||
162 | should take the time to understand the available locking primitives well | ||
163 | enough to pick the right tool for the job. Code which shows a lack of | ||
164 | attention to concurrency will have a difficult path into the mainline. | ||
165 | |||
166 | |||
167 | * Regressions | ||
168 | |||
169 | One final hazard worth mentioning is this: it can be tempting to make a | ||
170 | change (which may bring big improvements) which causes something to break | ||
171 | for existing users. This kind of change is called a "regression," and | ||
172 | regressions have become most unwelcome in the mainline kernel. With few | ||
173 | exceptions, changes which cause regressions will be backed out if the | ||
174 | regression cannot be fixed in a timely manner. Far better to avoid the | ||
175 | regression in the first place. | ||
176 | |||
177 | It is often argued that a regression can be justified if it causes things | ||
178 | to work for more people than it creates problems for. Why not make a | ||
179 | change if it brings new functionality to ten systems for each one it | ||
180 | breaks? The best answer to this question was expressed by Linus in July, | ||
181 | 2007: | ||
182 | |||
183 | So we don't fix bugs by introducing new problems. That way lies | ||
184 | madness, and nobody ever knows if you actually make any real | ||
185 | progress at all. Is it two steps forwards, one step back, or one | ||
186 | step forward and two steps back? | ||
187 | |||
188 | (http://lwn.net/Articles/243460/). | ||
189 | |||
190 | An especially unwelcome type of regression is any sort of change to the | ||
191 | user-space ABI. Once an interface has been exported to user space, it must | ||
192 | be supported indefinitely. This fact makes the creation of user-space | ||
193 | interfaces particularly challenging: since they cannot be changed in | ||
194 | incompatible ways, they must be done right the first time. For this | ||
195 | reason, a great deal of thought, clear documentation, and wide review for | ||
196 | user-space interfaces is always required. | ||
197 | |||
198 | |||
199 | |||
200 | 4.2: CODE CHECKING TOOLS | ||
201 | |||
202 | For now, at least, the writing of error-free code remains an ideal that few | ||
203 | of us can reach. What we can hope to do, though, is to catch and fix as | ||
204 | many of those errors as possible before our code goes into the mainline | ||
205 | kernel. To that end, the kernel developers have put together an impressive | ||
206 | array of tools which can catch a wide variety of obscure problems in an | ||
207 | automated way. Any problem caught by the computer is a problem which will | ||
208 | not afflict a user later on, so it stands to reason that the automated | ||
209 | tools should be used whenever possible. | ||
210 | |||
211 | The first step is simply to heed the warnings produced by the compiler. | ||
212 | Contemporary versions of gcc can detect (and warn about) a large number of | ||
213 | potential errors. Quite often, these warnings point to real problems. | ||
214 | Code submitted for review should, as a rule, not produce any compiler | ||
215 | warnings. When silencing warnings, take care to understand the real cause | ||
216 | and try to avoid "fixes" which make the warning go away without addressing | ||
217 | its cause. | ||
218 | |||
219 | Note that not all compiler warnings are enabled by default. Build the | ||
220 | kernel with "make EXTRA_CFLAGS=-W" to get the full set. | ||
221 | |||
222 | The kernel provides several configuration options which turn on debugging | ||
223 | features; most of these are found in the "kernel hacking" submenu. Several | ||
224 | of these options should be turned on for any kernel used for development or | ||
225 | testing purposes. In particular, you should turn on: | ||
226 | |||
227 | - ENABLE_WARN_DEPRECATED, ENABLE_MUST_CHECK, and FRAME_WARN to get an | ||
228 | extra set of warnings for problems like the use of deprecated interfaces | ||
229 | or ignoring an important return value from a function. The output | ||
230 | generated by these warnings can be verbose, but one need not worry about | ||
231 | warnings from other parts of the kernel. | ||
232 | |||
233 | - DEBUG_OBJECTS will add code to track the lifetime of various objects | ||
234 | created by the kernel and warn when things are done out of order. If | ||
235 | you are adding a subsystem which creates (and exports) complex objects | ||
236 | of its own, consider adding support for the object debugging | ||
237 | infrastructure. | ||
238 | |||
239 | - DEBUG_SLAB can find a variety of memory allocation and use errors; it | ||
240 | should be used on most development kernels. | ||
241 | |||
242 | - DEBUG_SPINLOCK, DEBUG_SPINLOCK_SLEEP, and DEBUG_MUTEXES will find a | ||
243 | number of common locking errors. | ||
244 | |||
245 | There are quite a few other debugging options, some of which will be | ||
246 | discussed below. Some of them have a significant performance impact and | ||
247 | should not be used all of the time. But some time spent learning the | ||
248 | available options will likely be paid back many times over in short order. | ||
249 | |||
250 | One of the heavier debugging tools is the locking checker, or "lockdep." | ||
251 | This tool will track the acquisition and release of every lock (spinlock or | ||
252 | mutex) in the system, the order in which locks are acquired relative to | ||
253 | each other, the current interrupt environment, and more. It can then | ||
254 | ensure that locks are always acquired in the same order, that the same | ||
255 | interrupt assumptions apply in all situations, and so on. In other words, | ||
256 | lockdep can find a number of scenarios in which the system could, on rare | ||
257 | occasion, deadlock. This kind of problem can be painful (for both | ||
258 | developers and users) in a deployed system; lockdep allows them to be found | ||
259 | in an automated manner ahead of time. Code with any sort of non-trivial | ||
260 | locking should be run with lockdep enabled before being submitted for | ||
261 | inclusion. | ||
262 | |||
263 | As a diligent kernel programmer, you will, beyond doubt, check the return | ||
264 | status of any operation (such as a memory allocation) which can fail. The | ||
265 | fact of the matter, though, is that the resulting failure recovery paths | ||
266 | are, probably, completely untested. Untested code tends to be broken code; | ||
267 | you could be much more confident of your code if all those error-handling | ||
268 | paths had been exercised a few times. | ||
269 | |||
270 | The kernel provides a fault injection framework which can do exactly that, | ||
271 | especially where memory allocations are involved. With fault injection | ||
272 | enabled, a configurable percentage of memory allocations will be made to | ||
273 | fail; these failures can be restricted to a specific range of code. | ||
274 | Running with fault injection enabled allows the programmer to see how the | ||
275 | code responds when things go badly. See | ||
276 | Documentation/fault-injection/fault-injection.text for more information on | ||
277 | how to use this facility. | ||
278 | |||
279 | Other kinds of errors can be found with the "sparse" static analysis tool. | ||
280 | With sparse, the programmer can be warned about confusion between | ||
281 | user-space and kernel-space addresses, mixture of big-endian and | ||
282 | small-endian quantities, the passing of integer values where a set of bit | ||
283 | flags is expected, and so on. Sparse must be installed separately (it can | ||
284 | be found at http://www.kernel.org/pub/software/devel/sparse/ if your | ||
285 | distributor does not package it); it can then be run on the code by adding | ||
286 | "C=1" to your make command. | ||
287 | |||
288 | Other kinds of portability errors are best found by compiling your code for | ||
289 | other architectures. If you do not happen to have an S/390 system or a | ||
290 | Blackfin development board handy, you can still perform the compilation | ||
291 | step. A large set of cross compilers for x86 systems can be found at | ||
292 | |||
293 | http://www.kernel.org/pub/tools/crosstool/ | ||
294 | |||
295 | Some time spent installing and using these compilers will help avoid | ||
296 | embarrassment later. | ||
297 | |||
298 | |||
299 | 4.3: DOCUMENTATION | ||
300 | |||
301 | Documentation has often been more the exception than the rule with kernel | ||
302 | development. Even so, adequate documentation will help to ease the merging | ||
303 | of new code into the kernel, make life easier for other developers, and | ||
304 | will be helpful for your users. In many cases, the addition of | ||
305 | documentation has become essentially mandatory. | ||
306 | |||
307 | The first piece of documentation for any patch is its associated | ||
308 | changelog. Log entries should describe the problem being solved, the form | ||
309 | of the solution, the people who worked on the patch, any relevant | ||
310 | effects on performance, and anything else that might be needed to | ||
311 | understand the patch. | ||
312 | |||
313 | Any code which adds a new user-space interface - including new sysfs or | ||
314 | /proc files - should include documentation of that interface which enables | ||
315 | user-space developers to know what they are working with. See | ||
316 | Documentation/ABI/README for a description of how this documentation should | ||
317 | be formatted and what information needs to be provided. | ||
318 | |||
319 | The file Documentation/kernel-parameters.txt describes all of the kernel's | ||
320 | boot-time parameters. Any patch which adds new parameters should add the | ||
321 | appropriate entries to this file. | ||
322 | |||
323 | Any new configuration options must be accompanied by help text which | ||
324 | clearly explains the options and when the user might want to select them. | ||
325 | |||
326 | Internal API information for many subsystems is documented by way of | ||
327 | specially-formatted comments; these comments can be extracted and formatted | ||
328 | in a number of ways by the "kernel-doc" script. If you are working within | ||
329 | a subsystem which has kerneldoc comments, you should maintain them and add | ||
330 | them, as appropriate, for externally-available functions. Even in areas | ||
331 | which have not been so documented, there is no harm in adding kerneldoc | ||
332 | comments for the future; indeed, this can be a useful activity for | ||
333 | beginning kernel developers. The format of these comments, along with some | ||
334 | information on how to create kerneldoc templates can be found in the file | ||
335 | Documentation/kernel-doc-nano-HOWTO.txt. | ||
336 | |||
337 | Anybody who reads through a significant amount of existing kernel code will | ||
338 | note that, often, comments are most notable by their absence. Once again, | ||
339 | the expectations for new code are higher than they were in the past; | ||
340 | merging uncommented code will be harder. That said, there is little desire | ||
341 | for verbosely-commented code. The code should, itself, be readable, with | ||
342 | comments explaining the more subtle aspects. | ||
343 | |||
344 | Certain things should always be commented. Uses of memory barriers should | ||
345 | be accompanied by a line explaining why the barrier is necessary. The | ||
346 | locking rules for data structures generally need to be explained somewhere. | ||
347 | Major data structures need comprehensive documentation in general. | ||
348 | Non-obvious dependencies between separate bits of code should be pointed | ||
349 | out. Anything which might tempt a code janitor to make an incorrect | ||
350 | "cleanup" needs a comment saying why it is done the way it is. And so on. | ||
351 | |||
352 | |||
353 | 4.4: INTERNAL API CHANGES | ||
354 | |||
355 | The binary interface provided by the kernel to user space cannot be broken | ||
356 | except under the most severe circumstances. The kernel's internal | ||
357 | programming interfaces, instead, are highly fluid and can be changed when | ||
358 | the need arises. If you find yourself having to work around a kernel API, | ||
359 | or simply not using a specific functionality because it does not meet your | ||
360 | needs, that may be a sign that the API needs to change. As a kernel | ||
361 | developer, you are empowered to make such changes. | ||
362 | |||
363 | There are, of course, some catches. API changes can be made, but they need | ||
364 | to be well justified. So any patch making an internal API change should be | ||
365 | accompanied by a description of what the change is and why it is | ||
366 | necessary. This kind of change should also be broken out into a separate | ||
367 | patch, rather than buried within a larger patch. | ||
368 | |||
369 | The other catch is that a developer who changes an internal API is | ||
370 | generally charged with the task of fixing any code within the kernel tree | ||
371 | which is broken by the change. For a widely-used function, this duty can | ||
372 | lead to literally hundreds or thousands of changes - many of which are | ||
373 | likely to conflict with work being done by other developers. Needless to | ||
374 | say, this can be a large job, so it is best to be sure that the | ||
375 | justification is solid. | ||
376 | |||
377 | When making an incompatible API change, one should, whenever possible, | ||
378 | ensure that code which has not been updated is caught by the compiler. | ||
379 | This will help you to be sure that you have found all in-tree uses of that | ||
380 | interface. It will also alert developers of out-of-tree code that there is | ||
381 | a change that they need to respond to. Supporting out-of-tree code is not | ||
382 | something that kernel developers need to be worried about, but we also do | ||
383 | not have to make life harder for out-of-tree developers than it it needs to | ||
384 | be. | ||
diff --git a/Documentation/development-process/5.Posting b/Documentation/development-process/5.Posting new file mode 100644 index 000000000000..dd48132a74dd --- /dev/null +++ b/Documentation/development-process/5.Posting | |||
@@ -0,0 +1,278 @@ | |||
1 | 5: POSTING PATCHES | ||
2 | |||
3 | Sooner or later, the time comes when your work is ready to be presented to | ||
4 | the community for review and, eventually, inclusion into the mainline | ||
5 | kernel. Unsurprisingly, the kernel development community has evolved a set | ||
6 | of conventions and procedures which are used in the posting of patches; | ||
7 | following them will make life much easier for everybody involved. This | ||
8 | document will attempt to cover these expectations in reasonable detail; | ||
9 | more information can also be found in the files SubmittingPatches, | ||
10 | SubmittingDrivers, and SubmitChecklist in the kernel documentation | ||
11 | directory. | ||
12 | |||
13 | |||
14 | 5.1: WHEN TO POST | ||
15 | |||
16 | There is a constant temptation to avoid posting patches before they are | ||
17 | completely "ready." For simple patches, that is not a problem. If the | ||
18 | work being done is complex, though, there is a lot to be gained by getting | ||
19 | feedback from the community before the work is complete. So you should | ||
20 | consider posting in-progress work, or even making a git tree available so | ||
21 | that interested developers can catch up with your work at any time. | ||
22 | |||
23 | When posting code which is not yet considered ready for inclusion, it is a | ||
24 | good idea to say so in the posting itself. Also mention any major work | ||
25 | which remains to be done and any known problems. Fewer people will look at | ||
26 | patches which are known to be half-baked, but those who do will come in | ||
27 | with the idea that they can help you drive the work in the right direction. | ||
28 | |||
29 | |||
30 | 5.2: BEFORE CREATING PATCHES | ||
31 | |||
32 | There are a number of things which should be done before you consider | ||
33 | sending patches to the development community. These include: | ||
34 | |||
35 | - Test the code to the extent that you can. Make use of the kernel's | ||
36 | debugging tools, ensure that the kernel will build with all reasonable | ||
37 | combinations of configuration options, use cross-compilers to build for | ||
38 | different architectures, etc. | ||
39 | |||
40 | - Make sure your code is compliant with the kernel coding style | ||
41 | guidelines. | ||
42 | |||
43 | - Does your change have performance implications? If so, you should run | ||
44 | benchmarks showing what the impact (or benefit) of your change is; a | ||
45 | summary of the results should be included with the patch. | ||
46 | |||
47 | - Be sure that you have the right to post the code. If this work was done | ||
48 | for an employer, the employer likely has a right to the work and must be | ||
49 | agreeable with its release under the GPL. | ||
50 | |||
51 | As a general rule, putting in some extra thought before posting code almost | ||
52 | always pays back the effort in short order. | ||
53 | |||
54 | |||
55 | 5.3: PATCH PREPARATION | ||
56 | |||
57 | The preparation of patches for posting can be a surprising amount of work, | ||
58 | but, once again, attempting to save time here is not generally advisable | ||
59 | even in the short term. | ||
60 | |||
61 | Patches must be prepared against a specific version of the kernel. As a | ||
62 | general rule, a patch should be based on the current mainline as found in | ||
63 | Linus's git tree. It may become necessary to make versions against -mm, | ||
64 | linux-next, or a subsystem tree, though, to facilitate wider testing and | ||
65 | review. Depending on the area of your patch and what is going on | ||
66 | elsewhere, basing a patch against these other trees can require a | ||
67 | significant amount of work resolving conflicts and dealing with API | ||
68 | changes. | ||
69 | |||
70 | Only the most simple changes should be formatted as a single patch; | ||
71 | everything else should be made as a logical series of changes. Splitting | ||
72 | up patches is a bit of an art; some developers spend a long time figuring | ||
73 | out how to do it in the way that the community expects. There are a few | ||
74 | rules of thumb, however, which can help considerably: | ||
75 | |||
76 | - The patch series you post will almost certainly not be the series of | ||
77 | changes found in your working revision control system. Instead, the | ||
78 | changes you have made need to be considered in their final form, then | ||
79 | split apart in ways which make sense. The developers are interested in | ||
80 | discrete, self-contained changes, not the path you took to get to those | ||
81 | changes. | ||
82 | |||
83 | - Each logically independent change should be formatted as a separate | ||
84 | patch. These changes can be small ("add a field to this structure") or | ||
85 | large (adding a significant new driver, for example), but they should be | ||
86 | conceptually small and amenable to a one-line description. Each patch | ||
87 | should make a specific change which can be reviewed on its own and | ||
88 | verified to do what it says it does. | ||
89 | |||
90 | - As a way of restating the guideline above: do not mix different types of | ||
91 | changes in the same patch. If a single patch fixes a critical security | ||
92 | bug, rearranges a few structures, and reformats the code, there is a | ||
93 | good chance that it will be passed over and the important fix will be | ||
94 | lost. | ||
95 | |||
96 | - Each patch should yield a kernel which builds and runs properly; if your | ||
97 | patch series is interrupted in the middle, the result should still be a | ||
98 | working kernel. Partial application of a patch series is a common | ||
99 | scenario when the "git bisect" tool is used to find regressions; if the | ||
100 | result is a broken kernel, you will make life harder for developers and | ||
101 | users who are engaging in the noble work of tracking down problems. | ||
102 | |||
103 | - Do not overdo it, though. One developer recently posted a set of edits | ||
104 | to a single file as 500 separate patches - an act which did not make him | ||
105 | the most popular person on the kernel mailing list. A single patch can | ||
106 | be reasonably large as long as it still contains a single *logical* | ||
107 | change. | ||
108 | |||
109 | - It can be tempting to add a whole new infrastructure with a series of | ||
110 | patches, but to leave that infrastructure unused until the final patch | ||
111 | in the series enables the whole thing. This temptation should be | ||
112 | avoided if possible; if that series adds regressions, bisection will | ||
113 | finger the last patch as the one which caused the problem, even though | ||
114 | the real bug is elsewhere. Whenever possible, a patch which adds new | ||
115 | code should make that code active immediately. | ||
116 | |||
117 | Working to create the perfect patch series can be a frustrating process | ||
118 | which takes quite a bit of time and thought after the "real work" has been | ||
119 | done. When done properly, though, it is time well spent. | ||
120 | |||
121 | |||
122 | 5.4: PATCH FORMATTING | ||
123 | |||
124 | So now you have a perfect series of patches for posting, but the work is | ||
125 | not done quite yet. Each patch needs to be formatted into a message which | ||
126 | quickly and clearly communicates its purpose to the rest of the world. To | ||
127 | that end, each patch will be composed of the following: | ||
128 | |||
129 | - An optional "From" line naming the author of the patch. This line is | ||
130 | only necessary if you are passing on somebody else's patch via email, | ||
131 | but it never hurts to add it when in doubt. | ||
132 | |||
133 | - A one-line description of what the patch does. This message should be | ||
134 | enough for a reader who sees it with no other context to figure out the | ||
135 | scope of the patch; it is the line that will show up in the "short form" | ||
136 | changelogs. This message is usually formatted with the relevant | ||
137 | subsystem name first, followed by the purpose of the patch. For | ||
138 | example: | ||
139 | |||
140 | gpio: fix build on CONFIG_GPIO_SYSFS=n | ||
141 | |||
142 | - A blank line followed by a detailed description of the contents of the | ||
143 | patch. This description can be as long as is required; it should say | ||
144 | what the patch does and why it should be applied to the kernel. | ||
145 | |||
146 | - One or more tag lines, with, at a minimum, one Signed-off-by: line from | ||
147 | the author of the patch. Tags will be described in more detail below. | ||
148 | |||
149 | The above three items should, normally, be the text used when committing | ||
150 | the change to a revision control system. They are followed by: | ||
151 | |||
152 | - The patch itself, in the unified ("-u") patch format. Using the "-p" | ||
153 | option to diff will associate function names with changes, making the | ||
154 | resulting patch easier for others to read. | ||
155 | |||
156 | You should avoid including changes to irrelevant files (those generated by | ||
157 | the build process, for example, or editor backup files) in the patch. The | ||
158 | file "dontdiff" in the Documentation directory can help in this regard; | ||
159 | pass it to diff with the "-X" option. | ||
160 | |||
161 | The tags mentioned above are used to describe how various developers have | ||
162 | been associated with the development of this patch. They are described in | ||
163 | detail in the SubmittingPatches document; what follows here is a brief | ||
164 | summary. Each of these lines has the format: | ||
165 | |||
166 | tag: Full Name <email address> optional-other-stuff | ||
167 | |||
168 | The tags in common use are: | ||
169 | |||
170 | - Signed-off-by: this is a developer's certification that he or she has | ||
171 | the right to submit the patch for inclusion into the kernel. It is an | ||
172 | agreement to the Developer's Certificate of Origin, the full text of | ||
173 | which can be found in Documentation/SubmittingPatches. Code without a | ||
174 | proper signoff cannot be merged into the mainline. | ||
175 | |||
176 | - Acked-by: indicates an agreement by another developer (often a | ||
177 | maintainer of the relevant code) that the patch is appropriate for | ||
178 | inclusion into the kernel. | ||
179 | |||
180 | - Tested-by: states that the named person has tested the patch and found | ||
181 | it to work. | ||
182 | |||
183 | - Reviewed-by: the named developer has reviewed the patch for correctness; | ||
184 | see the reviewer's statement in Documentation/SubmittingPatches for more | ||
185 | detail. | ||
186 | |||
187 | - Reported-by: names a user who reported a problem which is fixed by this | ||
188 | patch; this tag is used to give credit to the (often underappreciated) | ||
189 | people who test our code and let us know when things do not work | ||
190 | correctly. | ||
191 | |||
192 | - Cc: the named person received a copy of the patch and had the | ||
193 | opportunity to comment on it. | ||
194 | |||
195 | Be careful in the addition of tags to your patches: only Cc: is appropriate | ||
196 | for addition without the explicit permission of the person named. | ||
197 | |||
198 | |||
199 | 5.5: SENDING THE PATCH | ||
200 | |||
201 | Before you mail your patches, there are a couple of other things you should | ||
202 | take care of: | ||
203 | |||
204 | - Are you sure that your mailer will not corrupt the patches? Patches | ||
205 | which have had gratuitous white-space changes or line wrapping performed | ||
206 | by the mail client will not apply at the other end, and often will not | ||
207 | be examined in any detail. If there is any doubt at all, mail the patch | ||
208 | to yourself and convince yourself that it shows up intact. | ||
209 | |||
210 | Documentation/email-clients.txt has some helpful hints on making | ||
211 | specific mail clients work for sending patches. | ||
212 | |||
213 | - Are you sure your patch is free of silly mistakes? You should always | ||
214 | run patches through scripts/checkpatch.pl and address the complaints it | ||
215 | comes up with. Please bear in mind that checkpatch.pl, while being the | ||
216 | embodiment of a fair amount of thought about what kernel patches should | ||
217 | look like, is not smarter than you. If fixing a checkpatch.pl complaint | ||
218 | would make the code worse, don't do it. | ||
219 | |||
220 | Patches should always be sent as plain text. Please do not send them as | ||
221 | attachments; that makes it much harder for reviewers to quote sections of | ||
222 | the patch in their replies. Instead, just put the patch directly into your | ||
223 | message. | ||
224 | |||
225 | When mailing patches, it is important to send copies to anybody who might | ||
226 | be interested in it. Unlike some other projects, the kernel encourages | ||
227 | people to err on the side of sending too many copies; don't assume that the | ||
228 | relevant people will see your posting on the mailing lists. In particular, | ||
229 | copies should go to: | ||
230 | |||
231 | - The maintainer(s) of the affected subsystem(s). As described earlier, | ||
232 | the MAINTAINERS file is the first place to look for these people. | ||
233 | |||
234 | - Other developers who have been working in the same area - especially | ||
235 | those who might be working there now. Using git to see who else has | ||
236 | modified the files you are working on can be helpful. | ||
237 | |||
238 | - If you are responding to a bug report or a feature request, copy the | ||
239 | original poster as well. | ||
240 | |||
241 | - Send a copy to the relevant mailing list, or, if nothing else applies, | ||
242 | the linux-kernel list. | ||
243 | |||
244 | - If you are fixing a bug, think about whether the fix should go into the | ||
245 | next stable update. If so, stable@kernel.org should get a copy of the | ||
246 | patch. Also add a "Cc: stable@kernel.org" to the tags within the patch | ||
247 | itself; that will cause the stable team to get a notification when your | ||
248 | fix goes into the mainline. | ||
249 | |||
250 | When selecting recipients for a patch, it is good to have an idea of who | ||
251 | you think will eventually accept the patch and get it merged. While it | ||
252 | is possible to send patches directly to Linus Torvalds and have him merge | ||
253 | them, things are not normally done that way. Linus is busy, and there are | ||
254 | subsystem maintainers who watch over specific parts of the kernel. Usually | ||
255 | you will be wanting that maintainer to merge your patches. If there is no | ||
256 | obvious maintainer, Andrew Morton is often the patch target of last resort. | ||
257 | |||
258 | Patches need good subject lines. The canonical format for a patch line is | ||
259 | something like: | ||
260 | |||
261 | [PATCH nn/mm] subsys: one-line description of the patch | ||
262 | |||
263 | where "nn" is the ordinal number of the patch, "mm" is the total number of | ||
264 | patches in the series, and "subsys" is the name of the affected subsystem. | ||
265 | Clearly, nn/mm can be omitted for a single, standalone patch. | ||
266 | |||
267 | If you have a significant series of patches, it is customary to send an | ||
268 | introductory description as part zero. This convention is not universally | ||
269 | followed though; if you use it, remember that information in the | ||
270 | introduction does not make it into the kernel changelogs. So please ensure | ||
271 | that the patches, themselves, have complete changelog information. | ||
272 | |||
273 | In general, the second and following parts of a multi-part patch should be | ||
274 | sent as a reply to the first part so that they all thread together at the | ||
275 | receiving end. Tools like git and quilt have commands to mail out a set of | ||
276 | patches with the proper threading. If you have a long series, though, and | ||
277 | are using git, please provide the --no-chain-reply-to option to avoid | ||
278 | creating exceptionally deep nesting. | ||
diff --git a/Documentation/development-process/6.Followthrough b/Documentation/development-process/6.Followthrough new file mode 100644 index 000000000000..a8fba3d83a85 --- /dev/null +++ b/Documentation/development-process/6.Followthrough | |||
@@ -0,0 +1,202 @@ | |||
1 | 6: FOLLOWTHROUGH | ||
2 | |||
3 | At this point, you have followed the guidelines given so far and, with the | ||
4 | addition of your own engineering skills, have posted a perfect series of | ||
5 | patches. One of the biggest mistakes that even experienced kernel | ||
6 | developers can make is to conclude that their work is now done. In truth, | ||
7 | posting patches indicates a transition into the next stage of the process, | ||
8 | with, possibly, quite a bit of work yet to be done. | ||
9 | |||
10 | It is a rare patch which is so good at its first posting that there is no | ||
11 | room for improvement. The kernel development process recognizes this fact, | ||
12 | and, as a result, is heavily oriented toward the improvement of posted | ||
13 | code. You, as the author of that code, will be expected to work with the | ||
14 | kernel community to ensure that your code is up to the kernel's quality | ||
15 | standards. A failure to participate in this process is quite likely to | ||
16 | prevent the inclusion of your patches into the mainline. | ||
17 | |||
18 | |||
19 | 6.1: WORKING WITH REVIEWERS | ||
20 | |||
21 | A patch of any significance will result in a number of comments from other | ||
22 | developers as they review the code. Working with reviewers can be, for | ||
23 | many developers, the most intimidating part of the kernel development | ||
24 | process. Life can be made much easier, though, if you keep a few things in | ||
25 | mind: | ||
26 | |||
27 | - If you have explained your patch well, reviewers will understand its | ||
28 | value and why you went to the trouble of writing it. But that value | ||
29 | will not keep them from asking a fundamental question: what will it be | ||
30 | like to maintain a kernel with this code in it five or ten years later? | ||
31 | Many of the changes you may be asked to make - from coding style tweaks | ||
32 | to substantial rewrites - come from the understanding that Linux will | ||
33 | still be around and under development a decade from now. | ||
34 | |||
35 | - Code review is hard work, and it is a relatively thankless occupation; | ||
36 | people remember who wrote kernel code, but there is little lasting fame | ||
37 | for those who reviewed it. So reviewers can get grumpy, especially when | ||
38 | they see the same mistakes being made over and over again. If you get a | ||
39 | review which seems angry, insulting, or outright offensive, resist the | ||
40 | impulse to respond in kind. Code review is about the code, not about | ||
41 | the people, and code reviewers are not attacking you personally. | ||
42 | |||
43 | - Similarly, code reviewers are not trying to promote their employers' | ||
44 | agendas at the expense of your own. Kernel developers often expect to | ||
45 | be working on the kernel years from now, but they understand that their | ||
46 | employer could change. They truly are, almost without exception, | ||
47 | working toward the creation of the best kernel they can; they are not | ||
48 | trying to create discomfort for their employers' competitors. | ||
49 | |||
50 | What all of this comes down to is that, when reviewers send you comments, | ||
51 | you need to pay attention to the technical observations that they are | ||
52 | making. Do not let their form of expression or your own pride keep that | ||
53 | from happening. When you get review comments on a patch, take the time to | ||
54 | understand what the reviewer is trying to say. If possible, fix the things | ||
55 | that the reviewer is asking you to fix. And respond back to the reviewer: | ||
56 | thank them, and describe how you will answer their questions. | ||
57 | |||
58 | Note that you do not have to agree with every change suggested by | ||
59 | reviewers. If you believe that the reviewer has misunderstood your code, | ||
60 | explain what is really going on. If you have a technical objection to a | ||
61 | suggested change, describe it and justify your solution to the problem. If | ||
62 | your explanations make sense, the reviewer will accept them. Should your | ||
63 | explanation not prove persuasive, though, especially if others start to | ||
64 | agree with the reviewer, take some time to think things over again. It can | ||
65 | be easy to become blinded by your own solution to a problem to the point | ||
66 | that you don't realize that something is fundamentally wrong or, perhaps, | ||
67 | you're not even solving the right problem. | ||
68 | |||
69 | One fatal mistake is to ignore review comments in the hope that they will | ||
70 | go away. They will not go away. If you repost code without having | ||
71 | responded to the comments you got the time before, you're likely to find | ||
72 | that your patches go nowhere. | ||
73 | |||
74 | Speaking of reposting code: please bear in mind that reviewers are not | ||
75 | going to remember all the details of the code you posted the last time | ||
76 | around. So it is always a good idea to remind reviewers of previously | ||
77 | raised issues and how you dealt with them; the patch changelog is a good | ||
78 | place for this kind of information. Reviewers should not have to search | ||
79 | through list archives to familiarize themselves with what was said last | ||
80 | time; if you help them get a running start, they will be in a better mood | ||
81 | when they revisit your code. | ||
82 | |||
83 | What if you've tried to do everything right and things still aren't going | ||
84 | anywhere? Most technical disagreements can be resolved through discussion, | ||
85 | but there are times when somebody simply has to make a decision. If you | ||
86 | honestly believe that this decision is going against you wrongly, you can | ||
87 | always try appealing to a higher power. As of this writing, that higher | ||
88 | power tends to be Andrew Morton. Andrew has a great deal of respect in the | ||
89 | kernel development community; he can often unjam a situation which seems to | ||
90 | be hopelessly blocked. Appealing to Andrew should not be done lightly, | ||
91 | though, and not before all other alternatives have been explored. And bear | ||
92 | in mind, of course, that he may not agree with you either. | ||
93 | |||
94 | |||
95 | 6.2: WHAT HAPPENS NEXT | ||
96 | |||
97 | If a patch is considered to be a good thing to add to the kernel, and once | ||
98 | most of the review issues have been resolved, the next step is usually | ||
99 | entry into a subsystem maintainer's tree. How that works varies from one | ||
100 | subsystem to the next; each maintainer has his or her own way of doing | ||
101 | things. In particular, there may be more than one tree - one, perhaps, | ||
102 | dedicated to patches planned for the next merge window, and another for | ||
103 | longer-term work. | ||
104 | |||
105 | For patches applying to areas for which there is no obvious subsystem tree | ||
106 | (memory management patches, for example), the default tree often ends up | ||
107 | being -mm. Patches which affect multiple subsystems can also end up going | ||
108 | through the -mm tree. | ||
109 | |||
110 | Inclusion into a subsystem tree can bring a higher level of visibility to a | ||
111 | patch. Now other developers working with that tree will get the patch by | ||
112 | default. Subsystem trees typically feed into -mm and linux-next as well, | ||
113 | making their contents visible to the development community as a whole. At | ||
114 | this point, there's a good chance that you will get more comments from a | ||
115 | new set of reviewers; these comments need to be answered as in the previous | ||
116 | round. | ||
117 | |||
118 | What may also happen at this point, depending on the nature of your patch, | ||
119 | is that conflicts with work being done by others turn up. In the worst | ||
120 | case, heavy patch conflicts can result in some work being put on the back | ||
121 | burner so that the remaining patches can be worked into shape and merged. | ||
122 | Other times, conflict resolution will involve working with the other | ||
123 | developers and, possibly, moving some patches between trees to ensure that | ||
124 | everything applies cleanly. This work can be a pain, but count your | ||
125 | blessings: before the advent of the linux-next tree, these conflicts often | ||
126 | only turned up during the merge window and had to be addressed in a hurry. | ||
127 | Now they can be resolved at leisure, before the merge window opens. | ||
128 | |||
129 | Some day, if all goes well, you'll log on and see that your patch has been | ||
130 | merged into the mainline kernel. Congratulations! Once the celebration is | ||
131 | complete (and you have added yourself to the MAINTAINERS file), though, it | ||
132 | is worth remembering an important little fact: the job still is not done. | ||
133 | Merging into the mainline brings its own challenges. | ||
134 | |||
135 | To begin with, the visibility of your patch has increased yet again. There | ||
136 | may be a new round of comments from developers who had not been aware of | ||
137 | the patch before. It may be tempting to ignore them, since there is no | ||
138 | longer any question of your code being merged. Resist that temptation, | ||
139 | though; you still need to be responsive to developers who have questions or | ||
140 | suggestions. | ||
141 | |||
142 | More importantly, though: inclusion into the mainline puts your code into | ||
143 | the hands of a much larger group of testers. Even if you have contributed | ||
144 | a driver for hardware which is not yet available, you will be surprised by | ||
145 | how many people will build your code into their kernels. And, of course, | ||
146 | where there are testers, there will be bug reports. | ||
147 | |||
148 | The worst sort of bug reports are regressions. If your patch causes a | ||
149 | regression, you'll find an uncomfortable number of eyes upon you; | ||
150 | regressions need to be fixed as soon as possible. If you are unwilling or | ||
151 | unable to fix the regression (and nobody else does it for you), your patch | ||
152 | will almost certainly be removed during the stabilization period. Beyond | ||
153 | negating all of the work you have done to get your patch into the mainline, | ||
154 | having a patch pulled as the result of a failure to fix a regression could | ||
155 | well make it harder for you to get work merged in the future. | ||
156 | |||
157 | After any regressions have been dealt with, there may be other, ordinary | ||
158 | bugs to deal with. The stabilization period is your best opportunity to | ||
159 | fix these bugs and ensure that your code's debut in a mainline kernel | ||
160 | release is as solid as possible. So, please, answer bug reports, and fix | ||
161 | the problems if at all possible. That's what the stabilization period is | ||
162 | for; you can start creating cool new patches once any problems with the old | ||
163 | ones have been taken care of. | ||
164 | |||
165 | And don't forget that there are other milestones which may also create bug | ||
166 | reports: the next mainline stable release, when prominent distributors pick | ||
167 | up a version of the kernel containing your patch, etc. Continuing to | ||
168 | respond to these reports is a matter of basic pride in your work. If that | ||
169 | is insufficient motivation, though, it's also worth considering that the | ||
170 | development community remembers developers who lose interest in their code | ||
171 | after it's merged. The next time you post a patch, they will be evaluating | ||
172 | it with the assumption that you will not be around to maintain it | ||
173 | afterward. | ||
174 | |||
175 | |||
176 | 6.3: OTHER THINGS THAT CAN HAPPEN | ||
177 | |||
178 | One day, you may open your mail client and see that somebody has mailed you | ||
179 | a patch to your code. That is one of the advantages of having your code | ||
180 | out there in the open, after all. If you agree with the patch, you can | ||
181 | either forward it on to the subsystem maintainer (be sure to include a | ||
182 | proper From: line so that the attribution is correct, and add a signoff of | ||
183 | your own), or send an Acked-by: response back and let the original poster | ||
184 | send it upward. | ||
185 | |||
186 | If you disagree with the patch, send a polite response explaining why. If | ||
187 | possible, tell the author what changes need to be made to make the patch | ||
188 | acceptable to you. There is a certain resistance to merging patches which | ||
189 | are opposed by the author and maintainer of the code, but it only goes so | ||
190 | far. If you are seen as needlessly blocking good work, those patches will | ||
191 | eventually flow around you and get into the mainline anyway. In the Linux | ||
192 | kernel, nobody has absolute veto power over any code. Except maybe Linus. | ||
193 | |||
194 | On very rare occasion, you may see something completely different: another | ||
195 | developer posts a different solution to your problem. At that point, | ||
196 | chances are that one of the two patches will not be merged, and "mine was | ||
197 | here first" is not considered to be a compelling technical argument. If | ||
198 | somebody else's patch displaces yours and gets into the mainline, there is | ||
199 | really only one way to respond: be pleased that your problem got solved and | ||
200 | get on with your work. Having one's work shoved aside in this manner can | ||
201 | be hurtful and discouraging, but the community will remember your reaction | ||
202 | long after they have forgotten whose patch actually got merged. | ||
diff --git a/Documentation/development-process/7.AdvancedTopics b/Documentation/development-process/7.AdvancedTopics new file mode 100644 index 000000000000..a2cf74093aa1 --- /dev/null +++ b/Documentation/development-process/7.AdvancedTopics | |||
@@ -0,0 +1,173 @@ | |||
1 | 7: ADVANCED TOPICS | ||
2 | |||
3 | At this point, hopefully, you have a handle on how the development process | ||
4 | works. There is still more to learn, however! This section will cover a | ||
5 | number of topics which can be helpful for developers wanting to become a | ||
6 | regular part of the Linux kernel development process. | ||
7 | |||
8 | 7.1: MANAGING PATCHES WITH GIT | ||
9 | |||
10 | The use of distributed version control for the kernel began in early 2002, | ||
11 | when Linus first started playing with the proprietary BitKeeper | ||
12 | application. While BitKeeper was controversial, the approach to software | ||
13 | version management it embodied most certainly was not. Distributed version | ||
14 | control enabled an immediate acceleration of the kernel development | ||
15 | project. In current times, there are several free alternatives to | ||
16 | BitKeeper. For better or for worse, the kernel project has settled on git | ||
17 | as its tool of choice. | ||
18 | |||
19 | Managing patches with git can make life much easier for the developer, | ||
20 | especially as the volume of those patches grows. Git also has its rough | ||
21 | edges and poses certain hazards; it is a young and powerful tool which is | ||
22 | still being civilized by its developers. This document will not attempt to | ||
23 | teach the reader how to use git; that would be sufficient material for a | ||
24 | long document in its own right. Instead, the focus here will be on how git | ||
25 | fits into the kernel development process in particular. Developers who | ||
26 | wish to come up to speed with git will find more information at: | ||
27 | |||
28 | http://git.or.cz/ | ||
29 | |||
30 | http://www.kernel.org/pub/software/scm/git/docs/user-manual.html | ||
31 | |||
32 | and on various tutorials found on the web. | ||
33 | |||
34 | The first order of business is to read the above sites and get a solid | ||
35 | understanding of how git works before trying to use it to make patches | ||
36 | available to others. A git-using developer should be able to obtain a copy | ||
37 | of the mainline repository, explore the revision history, commit changes to | ||
38 | the tree, use branches, etc. An understanding of git's tools for the | ||
39 | rewriting of history (such as rebase) is also useful. Git comes with its | ||
40 | own terminology and concepts; a new user of git should know about refs, | ||
41 | remote branches, the index, fast-forward merges, pushes and pulls, detached | ||
42 | heads, etc. It can all be a little intimidating at the outset, but the | ||
43 | concepts are not that hard to grasp with a bit of study. | ||
44 | |||
45 | Using git to generate patches for submission by email can be a good | ||
46 | exercise while coming up to speed. | ||
47 | |||
48 | When you are ready to start putting up git trees for others to look at, you | ||
49 | will, of course, need a server that can be pulled from. Setting up such a | ||
50 | server with git-daemon is relatively straightforward if you have a system | ||
51 | which is accessible to the Internet. Otherwise, free, public hosting sites | ||
52 | (Github, for example) are starting to appear on the net. Established | ||
53 | developers can get an account on kernel.org, but those are not easy to come | ||
54 | by; see http://kernel.org/faq/ for more information. | ||
55 | |||
56 | The normal git workflow involves the use of a lot of branches. Each line | ||
57 | of development can be separated into a separate "topic branch" and | ||
58 | maintained independently. Branches in git are cheap, there is no reason to | ||
59 | not make free use of them. And, in any case, you should not do your | ||
60 | development in any branch which you intend to ask others to pull from. | ||
61 | Publicly-available branches should be created with care; merge in patches | ||
62 | from development branches when they are in complete form and ready to go - | ||
63 | not before. | ||
64 | |||
65 | Git provides some powerful tools which can allow you to rewrite your | ||
66 | development history. An inconvenient patch (one which breaks bisection, | ||
67 | say, or which has some other sort of obvious bug) can be fixed in place or | ||
68 | made to disappear from the history entirely. A patch series can be | ||
69 | rewritten as if it had been written on top of today's mainline, even though | ||
70 | you have been working on it for months. Changes can be transparently | ||
71 | shifted from one branch to another. And so on. Judicious use of git's | ||
72 | ability to revise history can help in the creation of clean patch sets with | ||
73 | fewer problems. | ||
74 | |||
75 | Excessive use of this capability can lead to other problems, though, beyond | ||
76 | a simple obsession for the creation of the perfect project history. | ||
77 | Rewriting history will rewrite the changes contained in that history, | ||
78 | turning a tested (hopefully) kernel tree into an untested one. But, beyond | ||
79 | that, developers cannot easily collaborate if they do not have a shared | ||
80 | view of the project history; if you rewrite history which other developers | ||
81 | have pulled into their repositories, you will make life much more difficult | ||
82 | for those developers. So a simple rule of thumb applies here: history | ||
83 | which has been exported to others should generally be seen as immutable | ||
84 | thereafter. | ||
85 | |||
86 | So, once you push a set of changes to your publicly-available server, those | ||
87 | changes should not be rewritten. Git will attempt to enforce this rule if | ||
88 | you try to push changes which do not result in a fast-forward merge | ||
89 | (i.e. changes which do not share the same history). It is possible to | ||
90 | override this check, and there may be times when it is necessary to rewrite | ||
91 | an exported tree. Moving changesets between trees to avoid conflicts in | ||
92 | linux-next is one example. But such actions should be rare. This is one | ||
93 | of the reasons why development should be done in private branches (which | ||
94 | can be rewritten if necessary) and only moved into public branches when | ||
95 | it's in a reasonably advanced state. | ||
96 | |||
97 | As the mainline (or other tree upon which a set of changes is based) | ||
98 | advances, it is tempting to merge with that tree to stay on the leading | ||
99 | edge. For a private branch, rebasing can be an easy way to keep up with | ||
100 | another tree, but rebasing is not an option once a tree is exported to the | ||
101 | world. Once that happens, a full merge must be done. Merging occasionally | ||
102 | makes good sense, but overly frequent merges can clutter the history | ||
103 | needlessly. Suggested technique in this case is to merge infrequently, and | ||
104 | generally only at specific release points (such as a mainline -rc | ||
105 | release). If you are nervous about specific changes, you can always | ||
106 | perform test merges in a private branch. The git "rerere" tool can be | ||
107 | useful in such situations; it remembers how merge conflicts were resolved | ||
108 | so that you don't have to do the same work twice. | ||
109 | |||
110 | One of the biggest recurring complaints about tools like git is this: the | ||
111 | mass movement of patches from one repository to another makes it easy to | ||
112 | slip in ill-advised changes which go into the mainline below the review | ||
113 | radar. Kernel developers tend to get unhappy when they see that kind of | ||
114 | thing happening; putting up a git tree with unreviewed or off-topic patches | ||
115 | can affect your ability to get trees pulled in the future. Quoting Linus: | ||
116 | |||
117 | You can send me patches, but for me to pull a git patch from you, I | ||
118 | need to know that you know what you're doing, and I need to be able | ||
119 | to trust things *without* then having to go and check every | ||
120 | individual change by hand. | ||
121 | |||
122 | (http://lwn.net/Articles/224135/). | ||
123 | |||
124 | To avoid this kind of situation, ensure that all patches within a given | ||
125 | branch stick closely to the associated topic; a "driver fixes" branch | ||
126 | should not be making changes to the core memory management code. And, most | ||
127 | importantly, do not use a git tree to bypass the review process. Post an | ||
128 | occasional summary of the tree to the relevant list, and, when the time is | ||
129 | right, request that the tree be included in linux-next. | ||
130 | |||
131 | If and when others start to send patches for inclusion into your tree, | ||
132 | don't forget to review them. Also ensure that you maintain the correct | ||
133 | authorship information; the git "am" tool does its best in this regard, but | ||
134 | you may have to add a "From:" line to the patch if it has been relayed to | ||
135 | you via a third party. | ||
136 | |||
137 | When requesting a pull, be sure to give all the relevant information: where | ||
138 | your tree is, what branch to pull, and what changes will result from the | ||
139 | pull. The git request-pull command can be helpful in this regard; it will | ||
140 | format the request as other developers expect, and will also check to be | ||
141 | sure that you have remembered to push those changes to the public server. | ||
142 | |||
143 | |||
144 | 7.2: REVIEWING PATCHES | ||
145 | |||
146 | Some readers will certainly object to putting this section with "advanced | ||
147 | topics" on the grounds that even beginning kernel developers should be | ||
148 | reviewing patches. It is certainly true that there is no better way to | ||
149 | learn how to program in the kernel environment than by looking at code | ||
150 | posted by others. In addition, reviewers are forever in short supply; by | ||
151 | looking at code you can make a significant contribution to the process as a | ||
152 | whole. | ||
153 | |||
154 | Reviewing code can be an intimidating prospect, especially for a new kernel | ||
155 | developer who may well feel nervous about questioning code - in public - | ||
156 | which has been posted by those with more experience. Even code written by | ||
157 | the most experienced developers can be improved, though. Perhaps the best | ||
158 | piece of advice for reviewers (all reviewers) is this: phrase review | ||
159 | comments as questions rather than criticisms. Asking "how does the lock | ||
160 | get released in this path?" will always work better than stating "the | ||
161 | locking here is wrong." | ||
162 | |||
163 | Different developers will review code from different points of view. Some | ||
164 | are mostly concerned with coding style and whether code lines have trailing | ||
165 | white space. Others will focus primarily on whether the change implemented | ||
166 | by the patch as a whole is a good thing for the kernel or not. Yet others | ||
167 | will check for problematic locking, excessive stack usage, possible | ||
168 | security issues, duplication of code found elsewhere, adequate | ||
169 | documentation, adverse effects on performance, user-space ABI changes, etc. | ||
170 | All types of review, if they lead to better code going into the kernel, are | ||
171 | welcome and worthwhile. | ||
172 | |||
173 | |||
diff --git a/Documentation/development-process/8.Conclusion b/Documentation/development-process/8.Conclusion new file mode 100644 index 000000000000..1990ab4b4949 --- /dev/null +++ b/Documentation/development-process/8.Conclusion | |||
@@ -0,0 +1,74 @@ | |||
1 | 8: FOR MORE INFORMATION | ||
2 | |||
3 | There are numerous sources of information on Linux kernel development and | ||
4 | related topics. First among those will always be the Documentation | ||
5 | directory found in the kernel source distribution. The top-level HOWTO | ||
6 | file is an important starting point; SubmittingPatches and | ||
7 | SubmittingDrivers are also something which all kernel developers should | ||
8 | read. Many internal kernel APIs are documented using the kerneldoc | ||
9 | mechanism; "make htmldocs" or "make pdfdocs" can be used to generate those | ||
10 | documents in HTML or PDF format (though the version of TeX shipped by some | ||
11 | distributions runs into internal limits and fails to process the documents | ||
12 | properly). | ||
13 | |||
14 | Various web sites discuss kernel development at all levels of detail. Your | ||
15 | author would like to humbly suggest http://lwn.net/ as a source; | ||
16 | information on many specific kernel topics can be found via the LWN kernel | ||
17 | index at: | ||
18 | |||
19 | http://lwn.net/Kernel/Index/ | ||
20 | |||
21 | Beyond that, a valuable resource for kernel developers is: | ||
22 | |||
23 | http://kernelnewbies.org/ | ||
24 | |||
25 | Information about the linux-next tree gathers at: | ||
26 | |||
27 | http://linux.f-seidel.de/linux-next/pmwiki/ | ||
28 | |||
29 | And, of course, one should not forget http://kernel.org/, the definitive | ||
30 | location for kernel release information. | ||
31 | |||
32 | There are a number of books on kernel development: | ||
33 | |||
34 | Linux Device Drivers, 3rd Edition (Jonathan Corbet, Alessandro | ||
35 | Rubini, and Greg Kroah-Hartman). Online at | ||
36 | http://lwn.net/Kernel/LDD3/. | ||
37 | |||
38 | Linux Kernel Development (Robert Love). | ||
39 | |||
40 | Understanding the Linux Kernel (Daniel Bovet and Marco Cesati). | ||
41 | |||
42 | All of these books suffer from a common fault, though: they tend to be | ||
43 | somewhat obsolete by the time they hit the shelves, and they have been on | ||
44 | the shelves for a while now. Still, there is quite a bit of good | ||
45 | information to be found there. | ||
46 | |||
47 | Documentation for git can be found at: | ||
48 | |||
49 | http://www.kernel.org/pub/software/scm/git/docs/ | ||
50 | |||
51 | http://www.kernel.org/pub/software/scm/git/docs/user-manual.html | ||
52 | |||
53 | |||
54 | 9: CONCLUSION | ||
55 | |||
56 | Congratulations to anybody who has made it through this long-winded | ||
57 | document. Hopefully it has provided a helpful understanding of how the | ||
58 | Linux kernel is developed and how you can participate in that process. | ||
59 | |||
60 | In the end, it's the participation that matters. Any open source software | ||
61 | project is no more than the sum of what its contributors put into it. The | ||
62 | Linux kernel has progressed as quickly and as well as it has because it has | ||
63 | been helped by an impressively large group of developers, all of whom are | ||
64 | working to make it better. The kernel is a premier example of what can be | ||
65 | done when thousands of people work together toward a common goal. | ||
66 | |||
67 | The kernel can always benefit from a larger developer base, though. There | ||
68 | is always more work to do. But, just as importantly, most other | ||
69 | participants in the Linux ecosystem can benefit through contributing to the | ||
70 | kernel. Getting code into the mainline is the key to higher code quality, | ||
71 | lower maintenance and distribution costs, a higher level of influence over | ||
72 | the direction of kernel development, and more. It is a situation where | ||
73 | everybody involved wins. Fire up your editor and come join us; you will be | ||
74 | more than welcome. | ||