3.Early-stage 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. 3: EARLY-STAGE PLANNING
  2. When contemplating a Linux kernel development project, it can be tempting
  3. to jump right in and start coding. As with any significant project,
  4. though, much of the groundwork for success is best laid before the first
  5. line of code is written. Some time spent in early planning and
  6. communication can save far more time later on.
  7. 3.1: SPECIFYING THE PROBLEM
  8. Like any engineering project, a successful kernel enhancement starts with a
  9. clear description of the problem to be solved. In some cases, this step is
  10. easy: when a driver is needed for a specific piece of hardware, for
  11. example. In others, though, it is tempting to confuse the real problem
  12. with the proposed solution, and that can lead to difficulties.
  13. Consider an example: some years ago, developers working with Linux audio
  14. sought a way to run applications without dropouts or other artifacts caused
  15. by excessive latency in the system. The solution they arrived at was a
  16. kernel module intended to hook into the Linux Security Module (LSM)
  17. framework; this module could be configured to give specific applications
  18. access to the realtime scheduler. This module was implemented and sent to
  19. the linux-kernel mailing list, where it immediately ran into problems.
  20. To the audio developers, this security module was sufficient to solve their
  21. immediate problem. To the wider kernel community, though, it was seen as a
  22. misuse of the LSM framework (which is not intended to confer privileges
  23. onto processes which they would not otherwise have) and a risk to system
  24. stability. Their preferred solutions involved realtime scheduling access
  25. via the rlimit mechanism for the short term, and ongoing latency reduction
  26. work in the long term.
  27. The audio community, however, could not see past the particular solution
  28. they had implemented; they were unwilling to accept alternatives. The
  29. resulting disagreement left those developers feeling disillusioned with the
  30. entire kernel development process; one of them went back to an audio list
  31. and posted this:
  32. There are a number of very good Linux kernel developers, but they
  33. tend to get outshouted by a large crowd of arrogant fools. Trying
  34. to communicate user requirements to these people is a waste of
  35. time. They are much too "intelligent" to listen to lesser mortals.
  36. (http://lwn.net/Articles/131776/).
  37. The reality of the situation was different; the kernel developers were far
  38. more concerned about system stability, long-term maintenance, and finding
  39. the right solution to the problem than they were with a specific module.
  40. The moral of the story is to focus on the problem - not a specific solution
  41. - and to discuss it with the development community before investing in the
  42. creation of a body of code.
  43. So, when contemplating a kernel development project, one should obtain
  44. answers to a short set of questions:
  45. - What, exactly, is the problem which needs to be solved?
  46. - Who are the users affected by this problem? Which use cases should the
  47. solution address?
  48. - How does the kernel fall short in addressing that problem now?
  49. Only then does it make sense to start considering possible solutions.
  50. 3.2: EARLY DISCUSSION
  51. When planning a kernel development project, it makes great sense to hold
  52. discussions with the community before launching into implementation. Early
  53. communication can save time and trouble in a number of ways:
  54. - It may well be that the problem is addressed by the kernel in ways which
  55. you have not understood. The Linux kernel is large and has a number of
  56. features and capabilities which are not immediately obvious. Not all
  57. kernel capabilities are documented as well as one might like, and it is
  58. easy to miss things. Your author has seen the posting of a complete
  59. driver which duplicated an existing driver that the new author had been
  60. unaware of. Code which reinvents existing wheels is not only wasteful;
  61. it will also not be accepted into the mainline kernel.
  62. - There may be elements of the proposed solution which will not be
  63. acceptable for mainline merging. It is better to find out about
  64. problems like this before writing the code.
  65. - It's entirely possible that other developers have thought about the
  66. problem; they may have ideas for a better solution, and may be willing
  67. to help in the creation of that solution.
  68. Years of experience with the kernel development community have taught a
  69. clear lesson: kernel code which is designed and developed behind closed
  70. doors invariably has problems which are only revealed when the code is
  71. released into the community. Sometimes these problems are severe,
  72. requiring months or years of effort before the code can be brought up to
  73. the kernel community's standards. Some examples include:
  74. - The Devicescape network stack was designed and implemented for
  75. single-processor systems. It could not be merged into the mainline
  76. until it was made suitable for multiprocessor systems. Retrofitting
  77. locking and such into code is a difficult task; as a result, the merging
  78. of this code (now called mac80211) was delayed for over a year.
  79. - The Reiser4 filesystem included a number of capabilities which, in the
  80. core kernel developers' opinion, should have been implemented in the
  81. virtual filesystem layer instead. It also included features which could
  82. not easily be implemented without exposing the system to user-caused
  83. deadlocks. The late revelation of these problems - and refusal to
  84. address some of them - has caused Reiser4 to stay out of the mainline
  85. kernel.
  86. - The AppArmor security module made use of internal virtual filesystem
  87. data structures in ways which were considered to be unsafe and
  88. unreliable. This concern (among others) kept AppArmor out of the
  89. mainline for years.
  90. In each of these cases, a great deal of pain and extra work could have been
  91. avoided with some early discussion with the kernel developers.
  92. 3.3: WHO DO YOU TALK TO?
  93. When developers decide to take their plans public, the next question will
  94. be: where do we start? The answer is to find the right mailing list(s) and
  95. the right maintainer. For mailing lists, the best approach is to look in
  96. the MAINTAINERS file for a relevant place to post. If there is a suitable
  97. subsystem list, posting there is often preferable to posting on
  98. linux-kernel; you are more likely to reach developers with expertise in the
  99. relevant subsystem and the environment may be more supportive.
  100. Finding maintainers can be a bit harder. Again, the MAINTAINERS file is
  101. the place to start. That file tends to not always be up to date, though,
  102. and not all subsystems are represented there. The person listed in the
  103. MAINTAINERS file may, in fact, not be the person who is actually acting in
  104. that role currently. So, when there is doubt about who to contact, a
  105. useful trick is to use git (and "git log" in particular) to see who is
  106. currently active within the subsystem of interest. Look at who is writing
  107. patches, and who, if anybody, is attaching Signed-off-by lines to those
  108. patches. Those are the people who will be best placed to help with a new
  109. development project.
  110. The task of finding the right maintainer is sometimes challenging enough
  111. that the kernel developers have added a script to ease the process:
  112. .../scripts/get_maintainer.pl
  113. This script will return the current maintainer(s) for a given file or
  114. directory when given the "-f" option. If passed a patch on the
  115. command line, it will list the maintainers who should probably receive
  116. copies of the patch. There are a number of options regulating how hard
  117. get_maintainer.pl will search for maintainers; please be careful about
  118. using the more aggressive options as you may end up including developers
  119. who have no real interest in the code you are modifying.
  120. If all else fails, talking to Andrew Morton can be an effective way to
  121. track down a maintainer for a specific piece of code.
  122. 3.4: WHEN TO POST?
  123. If possible, posting your plans during the early stages can only be
  124. helpful. Describe the problem being solved and any plans that have been
  125. made on how the implementation will be done. Any information you can
  126. provide can help the development community provide useful input on the
  127. project.
  128. One discouraging thing which can happen at this stage is not a hostile
  129. reaction, but, instead, little or no reaction at all. The sad truth of the
  130. matter is (1) kernel developers tend to be busy, (2) there is no shortage
  131. of people with grand plans and little code (or even prospect of code) to
  132. back them up, and (3) nobody is obligated to review or comment on ideas
  133. posted by others. Beyond that, high-level designs often hide problems
  134. which are only reviewed when somebody actually tries to implement those
  135. designs; for that reason, kernel developers would rather see the code.
  136. If a request-for-comments posting yields little in the way of comments, do
  137. not assume that it means there is no interest in the project.
  138. Unfortunately, you also cannot assume that there are no problems with your
  139. idea. The best thing to do in this situation is to proceed, keeping the
  140. community informed as you go.
  141. 3.5: GETTING OFFICIAL BUY-IN
  142. If your work is being done in a corporate environment - as most Linux
  143. kernel work is - you must, obviously, have permission from suitably
  144. empowered managers before you can post your company's plans or code to a
  145. public mailing list. The posting of code which has not been cleared for
  146. release under a GPL-compatible license can be especially problematic; the
  147. sooner that a company's management and legal staff can agree on the posting
  148. of a kernel development project, the better off everybody involved will be.
  149. Some readers may be thinking at this point that their kernel work is
  150. intended to support a product which does not yet have an officially
  151. acknowledged existence. Revealing their employer's plans on a public
  152. mailing list may not be a viable option. In cases like this, it is worth
  153. considering whether the secrecy is really necessary; there is often no real
  154. need to keep development plans behind closed doors.
  155. That said, there are also cases where a company legitimately cannot
  156. disclose its plans early in the development process. Companies with
  157. experienced kernel developers may choose to proceed in an open-loop manner
  158. on the assumption that they will be able to avoid serious integration
  159. problems later. For companies without that sort of in-house expertise, the
  160. best option is often to hire an outside developer to review the plans under
  161. a non-disclosure agreement. The Linux Foundation operates an NDA program
  162. designed to help with this sort of situation; more information can be found
  163. at:
  164. http://www.linuxfoundation.org/en/NDA_program
  165. This kind of review is often enough to avoid serious problems later on
  166. without requiring public disclosure of the project.