Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3008203
  • 博文数量: 272
  • 博客积分: 5544
  • 博客等级: 大校
  • 技术积分: 5496
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 00:48
个人简介

  每个人都要有一个骨灰级的爱好,不为金钱,而纯粹是为了在这个领域享受追寻真理的快乐。

文章分类

全部博文(272)

文章存档

2015年(2)

2014年(5)

2013年(25)

2012年(58)

2011年(182)

分类: LINUX

2013-08-07 11:23:57

在grup启动时传给内核参数: isolcpus=2-15, 这里表示隔离第3到16个CPU, Linux程序只跑在第一和第二个CPU上, 空闲的CPU我们可以指定跑进程了.
这是内核文档里对内核参数的解释:
  1. isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler.
  2.                         Format:
  3.                         <cpu number>,...,<cpu number>
  4.                         or
  5.                         <cpu number>-<cpu number>
  6.                         (must be a positive range in ascending order)
  7.                         or a mixture
  8.                         <cpu number>,...,<cpu number>-<cpu number>

  9.                         This option can be used to specify one or more CPUs
  10.                         to isolate from the general SMP balancing and scheduling
  11.                         algorithms. You can move a process onto or off an
  12.                         "isolated" CPU via the CPU affinity syscalls or cpuset.
  13.                         <cpu number> begins at 0 and the maximum value is
  14.                         "number of CPUs in system - 1".

  15.                         This option is the preferred way to isolate CPUs. The
  16.                         alternative -- manually setting the CPU mask of all
  17.                         tasks in the system -- can cause problems and
  18.                         suboptimal load balancer performance.

然后我们利用taskset程序来设置运行的程序跑在哪个CPU上, 本例是16个CPU, 用mask表示:
  1. Anshion> ./test.sh &
  2. [1] 684
  3. Anshion> taskset -p 0x8000 684
  4. pid 684's current affinity mask: 3
  5. pid 684's new affinity mask: 8000

这样在top中就可以看到, 这个进程跑在15号CPU上了, top命令运行按f, 再按j, 可以显示命令运行的cpu.然后用W保存配置.


  1. taskset -c 15 ./test.sh &
这样可以直接调用程序时指定跑在哪个CPU上.







阅读(7357) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~