diff options
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r-- | Documentation/CodingStyle | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index eb7db3c19227..ce780ef648f1 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -344,7 +344,7 @@ Remember: if another thread can find your data structure, and you don't | |||
344 | have a reference count on it, you almost certainly have a bug. | 344 | have a reference count on it, you almost certainly have a bug. |
345 | 345 | ||
346 | 346 | ||
347 | Chapter 11: Macros, Enums, Inline functions and RTL | 347 | Chapter 11: Macros, Enums and RTL |
348 | 348 | ||
349 | Names of macros defining constants and labels in enums are capitalized. | 349 | Names of macros defining constants and labels in enums are capitalized. |
350 | 350 | ||
@@ -429,7 +429,35 @@ from void pointer to any other pointer type is guaranteed by the C programming | |||
429 | language. | 429 | language. |
430 | 430 | ||
431 | 431 | ||
432 | Chapter 14: References | 432 | Chapter 14: The inline disease |
433 | |||
434 | There appears to be a common misperception that gcc has a magic "make me | ||
435 | faster" speedup option called "inline". While the use of inlines can be | ||
436 | appropriate (for example as a means of replacing macros, see Chapter 11), it | ||
437 | very often is not. Abundant use of the inline keyword leads to a much bigger | ||
438 | kernel, which in turn slows the system as a whole down, due to a bigger | ||
439 | icache footprint for the CPU and simply because there is less memory | ||
440 | available for the pagecache. Just think about it; a pagecache miss causes a | ||
441 | disk seek, which easily takes 5 miliseconds. There are a LOT of cpu cycles | ||
442 | that can go into these 5 miliseconds. | ||
443 | |||
444 | A reasonable rule of thumb is to not put inline at functions that have more | ||
445 | than 3 lines of code in them. An exception to this rule are the cases where | ||
446 | a parameter is known to be a compiletime constant, and as a result of this | ||
447 | constantness you *know* the compiler will be able to optimize most of your | ||
448 | function away at compile time. For a good example of this later case, see | ||
449 | the kmalloc() inline function. | ||
450 | |||
451 | Often people argue that adding inline to functions that are static and used | ||
452 | only once is always a win since there is no space tradeoff. While this is | ||
453 | technically correct, gcc is capable of inlining these automatically without | ||
454 | help, and the maintenance issue of removing the inline when a second user | ||
455 | appears outweighs the potential value of the hint that tells gcc to do | ||
456 | something it would have done anyway. | ||
457 | |||
458 | |||
459 | |||
460 | Chapter 15: References | ||
433 | 461 | ||
434 | The C Programming Language, Second Edition | 462 | The C Programming Language, Second Edition |
435 | by Brian W. Kernighan and Dennis M. Ritchie. | 463 | by Brian W. Kernighan and Dennis M. Ritchie. |
@@ -444,10 +472,13 @@ ISBN 0-201-61586-X. | |||
444 | URL: http://cm.bell-labs.com/cm/cs/tpop/ | 472 | URL: http://cm.bell-labs.com/cm/cs/tpop/ |
445 | 473 | ||
446 | GNU manuals - where in compliance with K&R and this text - for cpp, gcc, | 474 | GNU manuals - where in compliance with K&R and this text - for cpp, gcc, |
447 | gcc internals and indent, all available from http://www.gnu.org | 475 | gcc internals and indent, all available from http://www.gnu.org/manual/ |
448 | 476 | ||
449 | WG14 is the international standardization working group for the programming | 477 | WG14 is the international standardization working group for the programming |
450 | language C, URL: http://std.dkuug.dk/JTC1/SC22/WG14/ | 478 | language C, URL: http://www.open-std.org/JTC1/SC22/WG14/ |
479 | |||
480 | Kernel CodingStyle, by greg@kroah.com at OLS 2002: | ||
481 | http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/ | ||
451 | 482 | ||
452 | -- | 483 | -- |
453 | Last updated on 16 February 2004 by a community effort on LKML. | 484 | Last updated on 30 December 2005 by a community effort on LKML. |