0、准备知识

超线程技术(Hyper-Threading):就是利用特殊的硬件指令,把两个逻辑内核(CPU core)模拟成两个物理芯片,

    让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的运行效率。

    我们常听到的双核四线程/四核八线程指的就是支持超线程技术的CPU.

物理CPU:机器上安装的实际CPU, 比如说你的主板上安装了一个8核CPU,那么物理CPU个数就是1个,所以物理CPU个数就是主板上安装的CPU个数。

逻辑CPU:一般情况,我们认为一颗CPU可以有多核,加上intel的超线程技术(HT), 可以在逻辑上再分一倍数量的CPU core出来;

  1. 逻辑CPU数量 = 物理CPU数量 x CPU cores x 2(如果支持并开启HT) //前提是CPU的型号一致,如果不一致只能一个一个的加起来,不用直接乘以物理CPU数量
  2. //比如你的电脑安装了一块4核CPU,并且支持且开启了超线程(HT)技术,那么逻辑CPU数量 = 1 × 4 × 2 = 8

Linux下查看CPU相关信息, CPU的信息主要都在/proc/cupinfo中,

  1. # 查看物理CPU个数
  2. cat /proc/cpuinfo|grep "physical id"|sort -u|wc -l
  3.  
  4. # 查看每个物理CPU中core的个数(即核数)
  5. cat /proc/cpuinfo|grep "cpu cores"|uniq
  6.  
  7. # 查看逻辑CPU的个数
  8. cat /proc/cpuinfo|grep "processor"|wc -l
  9.  
  10. # 查看CPU的名称型号
  11. cat /proc/cpuinfo|grep "name"|cut -f2 -d:|uniq

Linux查看某个进程运行在哪个逻辑CPU上

  1. ps -eo pid,args,psr
    #参数的含义:
  2. pid - 进程ID
  3. args - 该进程执行时传入的命令行参数
  4. psr - 分配给进程的逻辑CPU
  5.  
  6. 例子:
    [~]# ps -eo pid,args,psr | grep nginx
    9073 nginx: master process /usr/   1
    9074 nginx: worker process         0
    9075 nginx: worker process         1
    9076 nginx: worker process         2
    9077 nginx: worker process         3
    13857 grep nginx                   3

 Linux查看线程的TID

TID就是Thread ID,他和POSIX中pthread_t表示的线程ID完全不是同一个东西.

Linux中的POSIX线程库实现的线程其实也是一个轻量级进程(LWP),这个TID就是这个线程的真实PID.

但是又不能通过getpid()函数获取,Linux中定义了gettid()这个接口,但是通常都是未实现的,所以需要使用下面的方式获取TID。

  1. //program
  2. #include <sys/syscall.h>
  3. pid_t tid;
  4. tid = syscall(__NR_gettid);// or syscall(SYS_gettid)
  5.  
  6. //command-line 3种方法(推荐第三种方法)
  7. 1ps -efL | grep prog_name
  8. 2ls /proc/pid/task //文件夹名即TID
    3ps -To 'pid,lwp,psr,cmd' -p PID

1、CPU亲和性(亲和力)

1.1 基本概念

CPU affinity 是一种调度属性(scheduler property), 它可以将一个进程"绑定" 到一个或一组CPU上.

在SMP(Symmetric Multi-Processing对称多处理)架构下,Linux调度器(scheduler)会根据CPU affinity的设置让指定的进程运行在"绑定"的CPU上,而不会在别的CPU上运行.

Linux调度器同样支持自然CPU亲和性(natural CPU affinity): 调度器会试图保持进程在相同的CPU上运行, 这意味着进程通常不会在处理器之间频繁迁移,进程迁移的频率小就意味着产生的负载小。

因为程序的作者比调度器更了解程序,所以我们可以手动地为其分配CPU核,而不会过多地占用CPU0,或是让我们关键进程和一堆别的进程挤在一起,所有设置CPU亲和性可以使某些程序提高性能。

1.2 表示方法

CPU affinity 使用位掩码(bitmask)表示, 每一位都表示一个CPU, 置1表示"绑定".

最低位表示第一个逻辑CPU, 最高位表示最后一个逻辑CPU.

CPU affinity典型的表示方法是使用16进制,具体如下.

  1. 0x00000001
  2. is processor #0
  3.  
  4. 0x00000003
  5. is processors #0 and #1
  6.  
  7. 0xFFFFFFFF
  8. is all processors (#0 through #31)

2、taskset命令

taskset命名用于获取或者设定CPU亲和性.

  1. # 命令行形式
  2. taskset [options] mask command [arg]...
    taskset [options] -p [mask] pid
  3.  
  4. PARAMETER
     
       mask : cpu亲和性,当没有-c选项时, 其值前无论有没有0x标记都是16进制的,
            当有-c选项时,其值是十进制的.
        command : 命令或者可执行程序
        arg : command的参数
        pid : 进程ID,可以通过ps/top/pidof等命令获取
  5.  
  6. OPTIONS
        
    -a, --all-tasks (旧版本中没有这个选项)
            这个选项涉及到了linuxTID的概念,他会将一个进程中所有的TID都执行一次CPU亲和性设置.
            TID就是Thread ID,他和POSIXpthread_t表示的线程ID完全不是同一个东西.
            Linux中的POSIX线程库实现的线程其实也是一个进程(LWP),这个TID就是这个线程的真实PID.
  7. -p, --pid
  8. 操作已存在的PID,而不是加载一个新的程序
  9. -c, --cpu-list
  10. 声明CPU的亲和力使用数字表示而不是用位掩码表示. 例如 0,5,7,9-11.
  11. -h, --help
  12. display usage information and exit
  13. -V, --version
  14. output version information and exit

USAGE

    1) 使用指定的CPU亲和性运行一个新程序

      taskset [-c] mask command [arg]...

        举例:使用CPU0运行ls命令显示/etc/init.d下的所有内容

          taskset -c 0 ls -al /etc/init.d/

    2) 显示已经运行的进程的CPU亲和性

      taskset -p pid

        举例:查看init进程(PID=1)的CPU亲和性

          taskset -p 1

    3) 改变已经运行进程的CPU亲和力

        taskset -p[c] mask pid

        举例:打开2个终端,在第一个终端运行top命令,第二个终端中

          首先运行:[~]# ps -eo pid,args,psr | grep top #获取top命令的pid和其所运行的CPU号

          其次运行:[~]# taskset -cp 新的CPU号 pid       #更改top命令运行的CPU号

          最后运行:[~]# ps -eo pid,args,psr | grep top #查看是否更改成功

  PERMISSIONS
        一个用户要设定一个进程的CPU亲和性,如果目标进程是该用户的,则可以设置,如果是其他用户的,则会设置失败,提示 Operation not permitted.当然root用户没有任何限制.

任何用户都可以获取任意一个进程的CPU亲和性.

taskset命令其实就是使用sched_getaffinity()和sched_setaffinity()接口实现的,相信看完了第3节你也能自己实现一个taskset命令.

有兴趣的可以看一下其源代码:ftp://ftp.kernel.org/pub/linux/utils/util-linux/vX.YZ/util-linux-X.YZ-xxx.tar.gz   /schedutils/taskset.c

3、编程API

下面是用用于设置和获取CPU亲和性相关的API.

  1. #define _GNU_SOURCE
  2. #include <sched.h>
  3. #include <pthread.h> //for pthread functions(last 4) 注意<pthread.h>包含<sched.h>
  4.  
  5. /* MACRO */
  6. /* The following macros are provided to operate on the CPU set set */
  7. /* Clears set, so that it contains no CPUs */
  8. void CPU_ZERO(cpu_set_t *set);
  9. void CPU_ZERO_S(size_t setsize, cpu_set_t *set);
  10.  
  11. /* Add CPU cpu to set */
  12. void CPU_SET(int cpu, cpu_set_t *set);
  13. void CPU_SET_S(int cpu, size_t setsize, cpu_set_t *set);
  14.  
  15. /* Remove CPU cpu from set */
  16. void CPU_CLR(int cpu, cpu_set_t *set);
  17. void CPU_CLR_S(int cpu, size_t setsize, cpu_set_t *set);
  18.  
  19. /* Test to see if CPU cpu is a member of set */
  20. int CPU_ISSET(int cpu, cpu_set_t *set);
  21. int CPU_ISSET_S(int cpu, size_t setsize, cpu_set_t *set);
  22.  
  23. /* Return the number of CPUs in set */
  24. void CPU_COUNT(cpu_set_t *set);
  25. void CPU_COUNT_S(size_t setsize, cpu_set_t *set);
  26.  
  27. /* The following macros perform logical operations on CPU sets */
  28. /* Store the logical AND of the sets srcset1 and srcset2 in destset (which may be one of the source sets). */
  29. void CPU_AND(cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  30. void CPU_AND_S(size_t setsize, cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  31.  
  32. /* Store the logical OR of the sets srcset1 and srcset2 in destset (which may be one of the source sets). */
  33. void CPU_OR(cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  34. void CPU_OR_S(size_t setsize, cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  35.  
  36. /* Store the logical XOR of the sets srcset1 and srcset2 in destset (which may be one of the source sets). */
  37. void CPU_XOR(cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  38. void CPU_XOR_S(size_t setsize, cpu_set_t *destset, cpu_set_t *srcset1, cpu_set_t *srcset2);
  39.  
  40. /* Test whether two CPU set contain exactly the same CPUs. */
  41. int CPU_EQUAL(cpu_set_t *set1, cpu_set_t *set2);
  42. int CPU_EQUAL_S(size_t setsize, cpu_set_t *set1, cpu_set_t *set2);
  43.  
  44. /* The following macros are used to allocate and deallocate CPU sets: */
  45. /* Allocate a CPU set large enough to hold CPUs in the range 0 to num_cpus-1 */
  46. cpu_set_t *CPU_ALLOC(int num_cpus);
  47.  
  48. /* Return the size in bytes of the CPU set that would be needed to hold CPUs in the range 0 to num_cpus-1.
  49. This macro provides the value that can be used for the setsize argument in the CPU_*_S() macros */
  50. size_t CPU_ALLOC_SIZE(int num_cpus);
  51.  
  52. /* Free a CPU set previously allocated by CPU_ALLOC(). */
  53. void CPU_FREE(cpu_set_t *set);
  54.  
  55. /* API */
  56. /* Set the CPU affinity for a task */
  57. int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
  58. /* Get the CPU affinity for a task */
  59. int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
  60.  
  61. /* set CPU affinity attribute in thread attributes object */
  62. int pthread_attr_setaffinity_np(pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *cpuset);
  63. /* get CPU affinity attribute in thread attributes object */
  64. int pthread_attr_getaffinity_np(const pthread_attr_t *attr, size_t cpusetsize, cpu_set_t *cpuset);
  65.  
  66. /* set CPU affinity of a thread */
  67. int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset);
  68. /* get CPU affinity of a thread */
  69. int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset);

相关的宏通常都分为2种,一种是带_S后缀的,一种不是不带_S后缀的, 从声明上看带_S后缀的宏都多出一个参数 setsize.

从功能上看他们的区别是带_S后缀的宏是用于操作动态申请的CPU set(s),所谓的动态申请其实就是使用宏 CPU_ALLOC 申请,

参数setsize 可以是通过宏 CPU_ALLOC_SIZE 获得,两者的用法详见下面的例子.

相关的API只有6个, 前2个是用来设置进程的CPU亲和性,需要注意的一点是,当这2个API的第一个参数pid为0时,表示使用调用进程的进程ID;

后4个是用来设置线程的CPU亲和性。其实sched_setaffinity()也可以用来设置线程的CPU的亲和性,也就是taskset “-a”选项中提到的TID概念。

3.1 例子一:使用2种方式(带和不带_S后缀的宏)获取当前进程的CPU亲和性

  1. #define _GNU_SOURCE
  2. #include <sched.h>
  3. #include <unistd.h> /* sysconf */
  4. #include <stdlib.h> /* exit */
  5. #include <stdio.h>
  6.  
  7. int main(void)
  8. {
  9. int i, nrcpus;
  10. cpu_set_t mask;
  11. unsigned long bitmask = ;
  12.  
  13. CPU_ZERO(&mask);
  14.  
  15. /* Get the CPU affinity for a pid */
  16. if (sched_getaffinity(, sizeof(cpu_set_t), &mask) == -)
  17. {
  18. perror("sched_getaffinity");
  19. exit(EXIT_FAILURE);
  20. }
  21.  
  22. /* get logical cpu number */
  23. nrcpus = sysconf(_SC_NPROCESSORS_CONF);
  24.  
  25. for (i = ; i < nrcpus; i++)
  26. {
  27. if (CPU_ISSET(i, &mask))
  28. {
  29. bitmask |= (unsigned long)0x01 << i;
  30. printf("processor #%d is set\n", i);
  31. }
  32. }
  33. printf("bitmask = %#lx\n", bitmask);
  34.  
  35. exit(EXIT_SUCCESS);
  36. }
  37. /*----------------------------------------------------------------*/
  38. #define _GNU_SOURCE
  39. #include <sched.h>
  40. #include <unistd.h> /* sysconf */
  41. #include <stdlib.h> /* exit */
  42. #include <stdio.h>
  43.  
  44. int main(void)
  45. {
  46. int i, nrcpus;
  47. cpu_set_t *pmask;
  48. size_t cpusize;
  49. unsigned long bitmask = ;
  50.  
  51. /* get logical cpu number */
  52. nrcpus = sysconf(_SC_NPROCESSORS_CONF);
  53.  
  54. pmask = CPU_ALLOC(nrcpus);
  55. cpusize = CPU_ALLOC_SIZE(nrcpus);
  56. CPU_ZERO_S(cpusize, pmask);
  57.  
  58. /* Get the CPU affinity for a pid */
  59. if (sched_getaffinity(, cpusize, pmask) == -)
  60. {
  61. perror("sched_getaffinity");
  62. CPU_FREE(pmask);
  63. exit(EXIT_FAILURE);
  64. }
  65. for (i = ; i < nrcpus; i++)
  66. {
  67. if (CPU_ISSET_S(i, cpusize, pmask))
  68. {
  69. bitmask |= (unsigned long)0x01 << i;
  70. printf("processor #%d is set\n", i);
  71. }
  72. }
  73. printf("bitmask = %#lx\n", bitmask);
  74.  
  75. CPU_FREE(pmask);
  76. exit(EXIT_SUCCESS);
  77. }

执行结果如下(4核CPU):

  1. [cpu_affinity #1]$ gcc -g -Wall cpu_affinity.c
  2. [cpu_affinity #2]$ taskset 1 ./a.out
  3. processor #0 is set
  4. bitmask = 0x1
  5. [cpu_affinity #3]$ taskset 1 ./a.out
  6. processor #0 is set
  7. bitmask = 0x1
  8. [cpu_affinity #4]$ taskset 2 ./a.out
  9. processor #1 is set
  10. bitmask = 0x2
  11. [cpu_affinity #5]$ taskset 3 ./a.out
  12. processor #0 is set
  13. processor #1 is set
  14. bitmask = 0x3
  15. [cpu_affinity #6]$ taskset 4 ./a.out
  16. processor #2 is set
  17. bitmask = 0x4
  18. [cpu_affinity #7]$ taskset 5 ./a.out
  19. processor #0 is set
  20. processor #2 is set
  21. bitmask = 0x5
  22. [cpu_affinity #8]$ taskset 6 ./a.out
  23. processor #1 is set
  24. processor #2 is set
  25. bitmask = 0x6
  26. [cpu_affinity #9]$ taskset 7 ./a.out
  27. processor #0 is set
  28. processor #1 is set
  29. processor #2 is set
  30. bitmask = 0x7
  31. [cpu_affinity #10]$ taskset 8 ./a.out
  32. processor #3 is set
  33. bitmask = 0x8
  34. [cpu_affinity #11]$ taskset 9 ./a.out
  35. processor #0 is set
  36. processor #3 is set
  37. bitmask = 0x9
  38. [cpu_affinity #12]$ taskset A ./a.out
  39. processor #1 is set
  40. processor #3 is set
  41. bitmask = 0xa
  42. [cpu_affinity #13]$ taskset B ./a.out
  43. processor #0 is set
  44. processor #1 is set
  45. processor #3 is set
  46. bitmask = 0xb
  47. [cpu_affinity #14]$ taskset C ./a.out
  48. processor #2 is set
  49. processor #3 is set
  50. bitmask = 0xc
  51. [cpu_affinity #15]$ taskset D ./a.out
  52. processor #0 is set
  53. processor #2 is set
  54. processor #3 is set
  55. bitmask = 0xd
  56. [cpu_affinity #16]$ taskset E ./a.out
  57. processor #1 is set
  58. processor #2 is set
  59. processor #3 is set
  60. bitmask = 0xe
  61. [cpu_affinity #17]$ taskset F ./a.out
  62. processor #0 is set
  63. processor #1 is set
  64. processor #2 is set
  65. processor #3 is set
  66. bitmask = 0xf
  67. [cpu_affinity #18]$ taskset 0 ./a.out
  68. sched_setaffinity: Invalid argument
  69. failed to set pid 0's affinity.

执行结果

3.2 例子二:设置进程的CPU亲和性后再获取显示CPU亲和性

  1. #define _GNU_SOURCE
  2. #include <sched.h>
  3. #include <unistd.h> /* sysconf */
  4. #include <stdlib.h> /* exit */
  5. #include <stdio.h>
  6.  
  7. int main(void)
  8. {
  9. int i, nrcpus;
  10. cpu_set_t mask;
  11. unsigned long bitmask = ;
  12.  
  13. CPU_ZERO(&mask);
  14.  
  15. CPU_SET(, &mask); /* add CPU0 to cpu set */
  16. CPU_SET(, &mask); /* add CPU2 to cpu set */
  17.  
  18. /* Set the CPU affinity for a pid */
  19. if (sched_setaffinity(, sizeof(cpu_set_t), &mask) == -)
  20. {
  21. perror("sched_setaffinity");
  22. exit(EXIT_FAILURE);
  23. }
  24.  
  25. CPU_ZERO(&mask);
  26.  
  27. /* Get the CPU affinity for a pid */
  28. if (sched_getaffinity(, sizeof(cpu_set_t), &mask) == -)
  29. {
  30. perror("sched_getaffinity");
  31. exit(EXIT_FAILURE);
  32. }
  33.  
  34. /* get logical cpu number */
  35. nrcpus = sysconf(_SC_NPROCESSORS_CONF);
  36.  
  37. for (i = ; i < nrcpus; i++)
  38. {
  39. if (CPU_ISSET(i, &mask))
  40. {
  41. bitmask |= (unsigned long)0x01 << i;
  42. printf("processor #%d is set\n", i);
  43. }
  44. }
  45. printf("bitmask = %#lx\n", bitmask);
  46.  
  47. exit(EXIT_SUCCESS);
  48. }

3.3 例子三:设置线程的CPU属性后再获取显示CPU亲和性

这个例子来源于Linux的man page.

  1. #define _GNU_SOURCE
  2. #include <pthread.h> //不用再包含<sched.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <errno.h>
  6.  
  7. #define handle_error_en(en, msg) \
  8. do { errno = en; perror(msg); exit(EXIT_FAILURE); } while ()
  9.  
  10. int
  11. main(int argc, char *argv[])
  12. {
  13. int s, j;
  14. cpu_set_t cpuset;
  15. pthread_t thread;
  16.  
  17. thread = pthread_self();
  18.  
  19. /* Set affinity mask to include CPUs 0 to 7 */
  20. CPU_ZERO(&cpuset);
  21. for (j = ; j < ; j++)
  22. CPU_SET(j, &cpuset);
  23.  
  24. s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
  25. if (s != )
  26. {
  27. handle_error_en(s, "pthread_setaffinity_np");
  28. }
  29.  
  30. /* Check the actual affinity mask assigned to the thread */
  31. s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
  32. if (s != )
  33. {
  34. handle_error_en(s, "pthread_getaffinity_np");
  35. }
  36.  
  37. printf("Set returned by pthread_getaffinity_np() contained:\n");
  38. for (j = ; j < CPU_SETSIZE; j++) //CPU_SETSIZE 是定义在<sched.h>中的宏,通常是1024
  39. {
  40. if (CPU_ISSET(j, &cpuset))
  41. {
  42. printf(" CPU %d\n", j);
  43. }
  44. }
  45. exit(EXIT_SUCCESS);
  46. }

3.4 例子四:使用seched_setaffinity设置线程的CPU亲和性

  1. #define _GNU_SOURCE
  2. #include <sched.h>
  3. #include <stdlib.h>
  4. #include <sys/syscall.h> // syscall
  5.  
  6. int main(void)
  7. {
  8. pid_t tid;
  9. int i, nrcpus;
  10. cpu_set_t mask;
  11. unsigned long bitmask = ;
  12.  
  13. CPU_ZERO(&mask);
  14. CPU_SET(, &mask); /* add CPU0 to cpu set */
  15. CPU_SET(, &mask); /* add CPU2 to cpu set */
  16.  
  17. // get tid(线程的PID,线程是轻量级进程,所以其本质是一个进程)
  18. tid = syscall(__NR_gettid); // or syscall(SYS_gettid);
  19.  
  20. /* Set the CPU affinity for a pid */
  21. if (sched_setaffinity(tid, sizeof(cpu_set_t), &mask) == -)
  22. {
  23. perror("sched_setaffinity");
  24. exit(EXIT_FAILURE);
  25. }
  26.  
  27. exit(EXIT_SUCCESS);
  28. }

---------------------------------------------------------------------------------------------------------------------

参考文献:

http://www.yboren.com/posts/44412.html?utm_source=tuicool

http://www.ibm.com/developerworks/cn/linux/l-affinity.html

http://saplingidea.iteye.com/blog/633616

http://blog.csdn.net/ttyttytty12/article/details/11726569

https://en.wikipedia.org/wiki/Processor_affinity

http://blog.chinaunix.net/uid-23622436-id-3311579.html

http://www.cnblogs.com/emanlee/p/3587571.html

http://blog.chinaunix.net/uid-26651253-id-3342161.html

http://blog.csdn.net/delphiwcdj/article/details/8476547

http://www.man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.html

http://www.man7.org/linux/man-pages/man3/pthread_attr_setaffinity_np.3.html

man CPU_SET taskset

Linux中CPU亲和性(affinity)的更多相关文章

  1. Linux中CPU亲和性(go)

    http://www.cnblogs.com/LubinLew/p/cpu_affinity.html

  2. 【操作系统之十二】分支预测、CPU亲和性(affinity)

    一.分支预测 当包含流水线技术的处理器处理分支指令时就会遇到一个问题,根据判定条件的真/假的不同,有可能会产生转跳,而这会打断流水线中指令的处理,因为处理器无法确定该指令的下一条指令,直到分支执行完毕 ...

  3. Linux 中CPU 和 GPU 的行为监控

    由于 Steam(包括 Steam Play,即 Proton)和一些其他的发展,GNU/Linux 正在成为越来越多计算机用户的日常游戏平台的选择.也有相当一部分用户在遇到像视频编辑或图形设计等(K ...

  4. linux中进程亲和性绑定

    什么是绑核所谓绑核,其实就是设定某个进程/线程与某个CPU核的亲和力(affinity).设定以后,Linux调度器就会让这个进程/线程只在所绑定的核上面去运行.但并不是说该进程/线程就独占这个CPU ...

  5. 聊聊Linux中CPU上下文切换

    目录 什么是CPU上下文 CPU上下文切换 上一任务的CPU上下文保存在哪? 进程上下文切换 内核空间和用户空间 top命令查看CPU资源 系统调用 进程上下文切换 和 系统调用的区别? 进程切换的常 ...

  6. cpu 亲和性 affinity

    http://www.ibm.com/developerworks/cn/linux/l-affinity.html

  7. 如何在 Linux 中找出 CPU 占用高的进程

    1) 怎样使用 top 命令找出 Linux 中 CPU 占用高的进程 在所有监控 Linux 系统性能的工具中,Linux 的 top 命令是最好的也是最知名的一个.top 命令提供了 Linux ...

  8. 在 Linux 中找出 CPU 占用高的进程

    列出系统中 CPU 占用高的进程列表来确定.我认为只有两种方法能实现:使用 top 命令 和 ps 命令.出于一些理由,我更倾向于用 top 命令而不是 ps 命令.但是两个工具都能达到你要的目的,所 ...

  9. Nginx中的进程亲和性 affinity

    Nginx采用多进程Master/Worker结构,Worker进程数为CPU个数时工作效率最高,Nginx通过affinity为每个Worker进程绑定一个CPU,避免进程切换带来的消耗,同时能够保 ...

随机推荐

  1. ubuntu下adb的使用以及开启黑域

    ubuntu使用adb开启黑域 刷了原生后经好友推荐, 黑域对于App的管控效果还是很不错的 adb的安装 此处顺带着就把fastboot也安装了 sudo apt update sudo apt i ...

  2. 运行adb命令报错adb server version (31) doesn't match this client (39); killing...

    执行adb devices 报错 原因分析: 这个是socket 的端口被占用了,我这里是因为360手机助手占用了这个端口,所以其他的就不能够用了. 解决办法: 卸载了360的手机助手就可以了 首先 ...

  3. (十) 编写UVC程序

    目录 编写UVC程序 流程简述 11个ioctl函数 查询属性 VIDIOC_QUERYCAP 枚举格式 VIDIOC_ENUM_FMT 查询当前格式 VIDIOC_G_FMT 尝试某种格式 VIDI ...

  4. 0426JavaSE01day02.txt=========正则、Object、包装类详解

    正则表达式 基本正则表达式:正则表达式简介.分组(). "^"和"$" String正则API:matches方法.split方法.replaceAll方法 O ...

  5. Python高级笔记(五)--实例方法、静态方法和类方法

    1. 类属性.实例属性 类属性在内存中只保存一份 实例属性在每个对象中都要保持一份 obj.__class__.country="xxx": 可以修改类属性 2. 实例方法.静态方 ...

  6. java接口多实现和多继承

    package test; interface mouth { public abstract void speak(); } interface nose{ public abstract void ...

  7. C# NPOI 操作Excel 案例

    1.加入NPOI 程序集,使用nuget添加程序集 2.引用NPOI程序集 private IWorkbook ExportExcel(PrintQuotationOrderViewModel mod ...

  8. springboot整合springdata-jpa

    1.简介  SpringData : Spring 的一个子项目.用于简化数据库访问,支持NoSQL 和 关系数据存储.其主要目标是使数据库的访问变得方便快捷. SpringData 项目所支持 No ...

  9. [转载]在termux上安装Kali Linux

    最近在手机上下了个Termux,然后想装个kali,就找到了这篇文章. 不过其中的命令有一处错误(在我进行配置的时候报错了): 命令应该是 ./atilo install kali

  10. 【转】一文掌握 Linux 性能分析之 CPU 篇

    [转]一文掌握 Linux 性能分析之 CPU 篇 平常工作会涉及到一些 Linux 性能分析的问题,因此决定总结一下常用的一些性能分析手段,仅供参考. 说到性能分析,基本上就是 CPU.内存.磁盘 ...