View multi-core loads in CentOS

Source: Internet
Author: User

View multi-core loads in CentOS

1. in Linux, how does one view the CPU usage:

# Top-M

Then press the number 1 (or press 1 after top) to display the information of multiple CPUs and memory:

[Root @ testpc ~] # Top-M
Top-15:38:40 up 2 days, 2 users, load average: 0.00, 0.00, 0.00
Task: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie
Cpu0: 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Cpu1: 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Cpu2: 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Cpu3: 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Mem: 3725.047 M total, 263.312 M used, 3461.734 M free, 45.711 M buffers
Swap: 8095.992 M total, 0.000 k used, 8095.992 M free, 55.977 M cached

Pid user pr ni virt res shr s % CPU % mem time + COMMAND
1 root 20 0 19228 1512 S 1224 0.0. 61 init
2 root 20 0 0 0 S 0.0 0.0. 00 kthreadd

2. in Linux, how can I check whether it is multi-core or multi-CPU:

# Cat/proc/cpuinfo

If there are multiple projects similar to the following, it is multi-core or multi-CPU:

Processor: 0

......

Processor: 1

3. How to check the CPU on which a process runs:

# Top-d 1

Then press f. To go to the top Current Fields settings page:

Selected: j: P = Last used cpu (SMP)

If this parameter is left blank, P indicates the CPU used by the process.

Sam has been tested and found that different CPU cores are used for the same process at different times. This should be handled by Linux Kernel SMP.

4. Configure Linux Kernel to support multiple cores:

It must be enabled during Kernel configurationCONFIG_SMPTo make the kernel aware of SMP.

Processor type and features ---> hierarchical Ric multi-processing support

Check whether or not Linux Kernel supports (or uses) SMP

# Uname-

5. SMP load balancing of Kernel 2.6:

When creating tasks in the SMP system, these tasks are put into a given CPU running queue. Generally, we cannot know when a task is short-lived or needs to run for a long time. Therefore, the initial task to CPU allocation may not be ideal.

To maintain task load balancing among CPUs, tasks can be re-distributed: Move tasks from the CPU with heavy loads to the CPU with light loads. Use of the scheduler in Linux 2.6Load balancing)This function is provided. Every 200 ms, the processor checks whether the CPU load is not balanced. If not, the processor performs a task balancing operation between CPUs.

One negative impact of this process is that the cache of the new CPU is cold for the migrated tasks (data needs to be read into the cache ).

Remember that the CPU cache is a local (On-Chip) memory that provides faster access than the system memory. If a task is executed on a CPU, data related to the task will be stored in the local cache of the CPU.Hot. If there is no data in the local cache of the CPU for a task, the cache is calledCold.

Unfortunately, keeping the CPU busy will cause the CPU cache to be cold for the migrated tasks.

6. How to use multiple cores for applications:

Developers can write code in parallel to threads, which are scheduled to run concurrently by the SMP operating system.

In addition, Sam assumes that code that must be executed sequentially. It can be divided into multiple nodes, each node is a thread, and channel is placed between nodes. the nodes are like pipelines. This can also greatly enhance the CPU usage.

For example:

The game can be divided into three nodes.

1. Accept external information, claim data (1 ms)

2. Data and Physical Operations (3 ms)

3. display the results of physical operations. (2 ms)

For linear programming, the entire process takes 6 ms.

However, if each node is used as a thread. But the threads are executed simultaneously. The entire process only takes 3 ms.

Declaration Source: sam's technical blog

Http://blog.sina.com.cn/samzhen1977

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.