Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1478367
  • 博文数量: 842
  • 博客积分: 12411
  • 博客等级: 上将
  • 技术积分: 5772
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-14 14:43
文章分类

全部博文(842)

文章存档

2013年(157)

2012年(685)

分类: LINUX

2012-05-05 18:51:22

 


Linux系统的宏HZ的值一般在体系相关的目录下,例如arch/arm/include/asm/param.h下,代码如下:


  1. /* -------------------------------------------------------------------- */

  2. /*
  3.  * arch/arm/include/asm/param.h
  4.  *
  5.  * Copyright (C) 1995-1999 Russell King
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 2 as
  9.  * published by the Free Software Foundation.
  10.  */
  11. #ifndef __ASM_PARAM_H
  12. #define __ASM_PARAM_H


  13. #ifdef __KERNEL__
  14. # define HZ CONFIG_HZ /* Internal kernel timer frequency */
  15. # define USER_HZ 100 /* User interfaces are in "ticks" */
  16. # define CLOCKS_PER_SEC (USER_HZ) /* like times() */
  17. #else
  18. # define HZ 100
  19. #endif


  20. #define EXEC_PAGESIZE 4096


  21. #ifndef NOGROUP
  22. #define NOGROUP (-1)
  23. #endif


  24. /* max length of hostname */
  25. #define MAXHOSTNAMELEN 64


  26. #endif
  27. /* -------------------------------------------------------------------- */

一般在make menuconfig下面会有100、250、300、1000的默认配置值,但是其实这些值包含在kernel/timeconst.pl中,这是一个perl脚本:

  1. /* -------------------------------------------------------------------- */
  2. #!/usr/bin/perl
  3. # -----------------------------------------------------------------------
  4. #
  5. # Copyright 2007-2008 rPath, Inc. - All Rights Reserved
  6. #
  7. # This file is part of the Linux kernel, and is made available under
  8. # the terms of the GNU General Public License version 2 or (at your
  9. # option) any later version; incorporated herein by reference.
  10. #
  11. # -----------------------------------------------------------------------
  12. #


  13. #
  14. # Usage: timeconst.pl HZ > timeconst.h
  15. #


  16. # Precomputed values for systems without Math::BigInt
  17. # Generated by:
  18. # timeconst.pl --can 24 32 48 64 100 122 128 200 250 256 300 512 1000 1024 1200
  19. %canned_values = (
  20. 24 => [
  21. '0xa6aaaaab','0x2aaaaaa',26,
  22. 125,3,
  23. '0xc49ba5e4','0x1fbe76c8b4',37,
  24. 3,125,
  25. '0xa2c2aaab','0xaaaa',16,
  26. 125000,3,
  27. '0xc9539b89','0x7fffbce4217d',47,
  28. 3,125000,
  29. ], 32 => [
  30. '0xfa000000','0x6000000',27,
  31. 125,4,
  32. '0x83126e98','0xfdf3b645a',36,
  33. 4,125,
  34. '0xf4240000','0x0',17,
  35. 31250,1,
  36. '0x8637bd06','0x3fff79c842fa',46,
  37. 1,31250,
  38. ], 48 => [
  39. '0xa6aaaaab','0x6aaaaaa',27,
  40. 125,6,
  41. '0xc49ba5e4','0xfdf3b645a',36,
  42. 6,125,
  43. '0xa2c2aaab','0x15555',17,
  44. 62500,3,
  45. '0xc9539b89','0x3fffbce4217d',46,
  46. 3,62500,
  47. ], 64 => [
  48. '0xfa000000','0xe000000',28,
  49. 125,8,
  50. '0x83126e98','0x7ef9db22d',35,
  51. 8,125,
  52. '0xf4240000','0x0',18,
  53. 15625,1,
  54. '0x8637bd06','0x1fff79c842fa',45,
  55. 1,15625,
  56. ], 100 => [
  57. '0xa0000000','0x0',28,
  58. 10,1,
  59. '0xcccccccd','0x733333333',35,
  60. 1,10,
  61. '0x9c400000','0x0',18,
  62. 10000,1,
  63. '0xd1b71759','0x1fff2e48e8a7',45,
  64. 1,10000,
  65. ], 122 => [
  66. '0x8325c53f','0xfbcda3a',28,
  67. 500,61,
  68. '0xf9db22d1','0x7fbe76c8b',35,
  69. 61,500,
  70. '0x8012e2a0','0x3ef36',18,
  71. 500000,61,
  72. '0xffda4053','0x1ffffbce4217',45,
  73. 61,500000,
  74. ], 128 => [
  75. '0xfa000000','0x1e000000',29,
  76. 125,16,
  77. '0x83126e98','0x3f7ced916',34,
  78. 16,125,
  79. '0xf4240000','0x40000',19,
  80. 15625,2,
  81. '0x8637bd06','0xfffbce4217d',44,
  82. 2,15625,
  83. ], 200 => [
  84. '0xa0000000','0x0',29,
  85. 5,1,
  86. '0xcccccccd','0x333333333',34,
  87. 1,5,
  88. '0x9c400000','0x0',19,
  89. 5000,1,
  90. '0xd1b71759','0xfff2e48e8a7',44,
  91. 1,5000,
  92. ], 250 => [
  93. '0x80000000','0x0',29,
  94. 4,1,
  95. '0x80000000','0x180000000',33,
  96. 1,4,
  97. '0xfa000000','0x0',20,
  98. 4000,1,
  99. '0x83126e98','0x7ff7ced9168',43,
  100. 1,4000,
  101. ], 256 => [
  102. '0xfa000000','0x3e000000',30,
  103. 125,32,
  104. '0x83126e98','0x1fbe76c8b',33,
  105. 32,125,
  106. '0xf4240000','0xc0000',20,
  107. 15625,4,
  108. '0x8637bd06','0x7ffde7210be',43,
  109. 4,15625,
  110. ], 300 => [
  111. '0xd5555556','0x2aaaaaaa',30,
  112. 10,3,
  113. '0x9999999a','0x1cccccccc',33,
  114. 3,10,
  115. '0xd0555556','0xaaaaa',20,
  116. 10000,3,
  117. '0x9d495183','0x7ffcb923a29',43,
  118. 3,10000,
  119. ], 512 => [
  120. '0xfa000000','0x7e000000',31,
  121. 125,64,
  122. '0x83126e98','0xfdf3b645',32,
  123. 64,125,
  124. '0xf4240000','0x1c0000',21,
  125. 15625,8,
  126. '0x8637bd06','0x3ffef39085f',42,
  127. 8,15625,
  128. ], 1000 => [
  129. '0x80000000','0x0',31,
  130. 1,1,
  131. '0x80000000','0x0',31,
  132. 1,1,
  133. '0xfa000000','0x0',22,
  134. 1000,1,
  135. '0x83126e98','0x1ff7ced9168',41,
  136. 1,1000,
  137. ], 1024 => [
  138. '0xfa000000','0xfe000000',32,
  139. 125,128,
  140. '0x83126e98','0x7ef9db22',31,
  141. 128,125,
  142. '0xf4240000','0x3c0000',22,
  143. 15625,16,
  144. '0x8637bd06','0x1fff79c842f',41,
  145. 16,15625,
  146. ], 1200 => [
  147. '0xd5555556','0xd5555555',32,
  148. 5,6,
  149. '0x9999999a','0x66666666',31,
  150. 6,5,
  151. '0xd0555556','0x2aaaaa',22,
  152. 2500,3,
  153. '0x9d495183','0x1ffcb923a29',41,
  154. 3,2500,
  155. ]
  156. );
  157. /* -------------------------------------------------------------------- */

上面红色部分简绍了使用方法,有的时候,修改了HZ的值,可能要手动运行一下,例如,修改HZ=512,则可以在kernel目录下:
 timeconst.pl 512 > timeconst.h
也就是说kernel目录下的timeconst.h是动态生成的

  1. /* -------------------------------------------------------------------- */
  2. /* Automatically generated by kernel/timeconst.pl */
  3. /* Conversion constants for HZ == 512 */


  4. #ifndef KERNEL_TIMECONST_H
  5. #define KERNEL_TIMECONST_H


  6. #include <linux/param.h>
  7. #include <linux/types.h>


  8. #if HZ != 512
  9. #error "kernel/timeconst.h has the wrong HZ value!"
  10. #endif


  11. #define HZ_TO_MSEC_MUL32 U64_C(0xfa000000)
  12. #define HZ_TO_MSEC_ADJ32 U64_C(0x7e000000)
  13. #define HZ_TO_MSEC_SHR32 31
  14. #define HZ_TO_MSEC_NUM U64_C(125)
  15. #define HZ_TO_MSEC_DEN U64_C(64)
  16. #define MSEC_TO_HZ_MUL32 U64_C(0x83126e98)
  17. #define MSEC_TO_HZ_ADJ32 U64_C(0xfdf3b645)
  18. #define MSEC_TO_HZ_SHR32 32
  19. #define MSEC_TO_HZ_NUM U64_C(64)
  20. #define MSEC_TO_HZ_DEN U64_C(125)
  21. #define HZ_TO_USEC_MUL32 U64_C(0xf4240000)
  22. #define HZ_TO_USEC_ADJ32 U64_C(0x1c0000)
  23. #define HZ_TO_USEC_SHR32 21
  24. #define HZ_TO_USEC_NUM U64_C(15625)
  25. #define HZ_TO_USEC_DEN U64_C(8)
  26. #define USEC_TO_HZ_MUL32 U64_C(0x8637bd06)
  27. #define USEC_TO_HZ_ADJ32 U64_C(0x3ffef39085f)
  28. #define USEC_TO_HZ_SHR32 42
  29. #define USEC_TO_HZ_NUM U64_C(8)
  30. #define USEC_TO_HZ_DEN U64_C(15625)


  31. #endif /* KERNEL_TIMECONST_H */
  32. /* -------------------------------------------------------------------- */

因此,下次如果修改了HZ的值,而这个值是perl脚本支持的,但却报类似的错:

  1. In file included from kernel/time.c:45:
  2. kernel/timeconst.h:11:2: error: #error "kernel/timeconst.h has the wrong HZ value!"
  3. make[1]: *** [kernel/time.o] Error 1
  4. make: *** [kernel] Error 2
  5. make: *** Waiting for unfinished jobs....

那就要手动执行以下这个perl脚本了。而对于这个HZ值与您的系统的性能关系,还需要仔细斟酌,我目前的项目也遇到了类似的问题,可能有关,继续研究。
阅读(925) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~