Chinaunix首页 | 论坛 | 博客
  • 博客访问: 686047
  • 博文数量: 152
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1793
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 12:26
个人简介

相信自己,只有不想做的,没有做不到的。

文章分类

全部博文(152)

文章存档

2021年(1)

2015年(2)

2014年(74)

2013年(75)

分类: LINUX

2014-09-05 16:48:02

尝试把pandaboard images升级为,SMP热插拔测试了一下。第一组测试评估在高负载情况下热插拔CPU进程迁移的情况,希望是拔出和插入CPU1后,各进程仍然活跃,测试case如下:


  1. int main(int argc, char *argv[])  
  2. {  
  3.     struct timeval last_tv, cur_tv;  
  4.     int pid;  
  5.     char p_proc[50], on = '1', off = '0';  
  6.     int fd = open("/sys/devices/system/cpu/cpu1/online", O_RDWR);  
  7.     if (fd < 0)  
  8.         exit (0);  
  9.   
  10.     sprintf(p_proc, "/proc/%d", getpid());  
  11.   
  12.     gettimeofday (&last_tv , NULL);  
  13.   
  14.     /* fork to 16 processes with high cpu usage */  
  15.     pid = fork();  
  16.     if (pid > 0) {  
  17.         printf("before unplugging cpu1\n");  
  18.         sleep(5);  
  19.         /* unplug cpu1 */  
  20.         write(fd, &off, 1);  
  21.         printf("after unplugging cpu1, we want to see all processes are still alive\n");  
  22.         sleep(5);  
  23.         /* re-plug cpu1 */  
  24.         printf("after re-plugging cpu1\n");  
  25.         write(fd, &on, 1);  
  26.         sleep(5);  
  27.     } else {  
  28.         /* lauch multi-processes with 100% cpu usage */  
  29.         fork();     fork();     fork();     fork();  
  30.         while(1) {  
  31.             gettimeofday (&cur_tv , NULL);  
  32.             if (cur_tv.tv_sec - last_tv.tv_sec == 4) {  
  33.                 printf("pid: %d\n", getpid());  
  34.                 last_tv = cur_tv;  
  35.             }  
  36.             /* if parent process exit, sub-process exit */  
  37.             if (access(p_proc, 0) < 0)  
  38.                 _exit(0);  
  39.         }  
  40.     }  
  41. }  

Fork出16个CPU利用率100%的进程,在热插拔CPU的情况下,这些16个进程保持活跃,证明热插拔的情况下,进程可迁移:

[plain] view plaincopy
  1. root@android:/ # smp-unplug-process-alive  
  2. before unplugging cpu1  
  3. pid: 582 pid: 583 pid: 576 pid: 579 pid: 574 pid: 587 pid: 580 pid: 586  
  4. pid: 581 pid: 588 pid: 575 pid: 573 pid: 577 pid: 584 pid: 578 pid: 585  
  5. [   68.295593] CPU1: shutdown  
  6. after unplugging cpu1, we want to see all processes are still alive  
  7. pid: 587 pid: 581 pid: 578 pid: 576 pid: 582 pid: 585 pid: 577 pid: 574  
  8. pid: 573 pid: 580 pid: 586 pid: 579 pid: 583 pid: 575 pid: 584 pid: 588  
  9. after re-plugging cpu1  
  10. [   73.520935] CPU1: Booted secondary processor  
  11. [   73.528350] Switched to NOHz mode on CPU #1  
  12. pid: 588 pid: 581 pid: 582 pid: 576 pid: 586 pid: 585 pid: 579 pid: 584  
  13. pid: 587 pid: 573 pid: 578 pid: 580 pid: 577 pid: 583 pid: 575 pid: 574  
  14. …  

第二组测试评估2个processes并行计算下,CPU hotplug后对时间的影响,以彻底验证拔掉CPU1后只有CPU0在运算,重新插入后2个开始一起运算,测试case如下:

  1. int main(int argc, char *argv[])  
  2. {  
  3.     volatile int i;  
  4.     int pid = fork();  
  5.       
  6.     if (pid > 0) {  
  7.         for (i=0;i<90000000;i++);  
  8.         wait(0);  
  9.     } else {  
  10.         for (i=0;i<90000000;i++);  
  11.     }  
  12. }  

在不unplug cpu1的情况下:

[plain] view plaincopy
  1. root@android:/ # time /system/bin/smp-time  
  2.     0m0.73s real     0m1.42s user     0m0.03s system  
  3. root@android:/ # time /system/bin/smp-time  
  4.     0m0.72s real     0m1.41s user     0m0.01s system  
  5. root@android:/ # time /system/bin/smp-time  
  6.     0m0.72s real     0m1.43s user     0m0.00s system  

实际运行时间0.73秒,在2个CPU上累积耗费了1.42秒, 各自贡献1/2力量。
现在我们拔出cpu1,再运行:

[plain] view plaincopy
  1. echo 0 > /sys/devices/system/cpu/cpu1/online                                                  
  2. [  234.565521] CPU1: shutdown  
  3. root@android:/ #  time /system/bin/smp-time  
  4.     0m1.45s real     0m1.38s user     0m0.06s system  
  5. root@android:/ #  time /system/bin/smp-time  
  6.     0m1.45s real     0m1.44s user     0m0.00s system  
  7. root@android:/ #  time /system/bin/smp-time  
  8.     0m1.45s real     0m1.45s user     0m0.00s system  

实际运行耗时1.45秒,等于user耗时,因为现在只有1个CPU0顺序执行2个进程。
我们把CPU1插入,再执行:

[plain] view plaincopy
  1. echo 1 > /sys/devices/system/cpu/cpu1/online  
  2. [  364.515075] CPU1: Booted secondary processor  
  3. root@android:/ # time /system/bin/smp-time  
  4.     0m0.72s real     0m1.42s user     0m0.00s system  
  5. root@android:/ # time /system/bin/smp-time  
  6.     0m0.72s real     0m1.43s user     0m0.00s system  

真实时间又变成user时间1/2,证明CPU1活跃,开始与CPU0并行运算。
结论是Linux kernel有较好的CPU热插拔支持,在热插拔情况下,进程能够顺利迁移与再次负载均衡。
阅读(840) | 评论(0) | 转发(0) |
0

上一篇:platform设备驱动全透析

下一篇:WIFI架构

给主人留下些什么吧!~~