Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the usage of each CPU under CentOS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to check the utilization rate of each CPU under CentOS". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Under Linux, how to view the utilization of each CPU:

# top-M

Then press the number 1. (or press 1 after top) to display information about multiple CPU and memory:

[root@testpc] # top-M

Top-15:38:40 up 2 days, 2:05, 2 users, load average: 0.00,0.00,0.00

Tasks: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie

Cpu0: 0.0%us, 0.0%sy, 0.0% Nijie 100.0% id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Cpu1: 0.0%us, 0.0%sy, 0.0% Nijie 100.0% id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Cpu2: 0.0%us, 0.0%sy, 0.0% Nijie 100.0% id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Cpu3: 0.0%us, 0.0%sy, 0.0% Nijie 100.0% id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

Mem: 3725.047M total, 263.312M used, 3461.734M free, 45.711M buffers

Swap: 8095.992M total, 0.000k used, 8095.992M free, 55.977M cached

PID USER PR NI VIRT RES SHR S CPU MEM TIME+ COMMAND

1 root 20 0 19228 1512 1224 S 0.0 0.0 0:00.61 init

2 root 20 00 00 S 0.0 0.00: 00.00 kthreadd

two。 Under Linux, how to confirm multicore or multi-CPU:

# cat / proc/cpuinfo

Multicore or multi-CPU if there are multiple items like the following:

Processor: 0

.

Processor: 1

3. How to see which CPU a process is running on:

# top-d 1

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

Check: J: P = Last used cpu (SMP)

There is one more item: P shows which CPU is used by this process.

After experiments, Sam found that the same process, at different times, will use different CPU Core. This should be handled by Linux Kernel SMP.

4. Configure Linux Kernel to support multiple Core:

The CONFIG_SMP option must be enabled during kernel configuration to make the kernel SMP-aware.

Processor type and features-> Symmetric multi-processing support

Check whether the current Linux Kernel supports (or uses) SMP

# uname-a

5. SMP load balancing for Kernel 2.6:

When tasks are created in the SMP system, they are put into a given CPU run queue. Generally speaking, we cannot know when a task exists in the short term and when it needs to be run for a long time. Therefore, the initial assignment of tasks to CPU may not be ideal.

In order to maintain task load balancing between CPU, tasks can be redistributed: moving tasks from heavily loaded CPU to lightly loaded CPU. The Linux 2.6 scheduler provides this capability using load balancing (load balancing). Every 200ms, the processor checks whether the load of the CPU is unbalanced; if not, the processor performs a task balancing operation between the CPU.

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

Keep in mind that the CPU cache is a local (on-chip) memory that provides faster access than system memory. If a task is executed on a CPU, all data related to the task will be put into the local cache of that CPU, which is called hot. If there is no data in CPU's local cache for a task, the cache is called cold.

Unfortunately, keeping the CPU busy can lead to situations where the CPU cache is cold for migrated tasks.

6. How applications take advantage of multiple Core:

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

In addition, Sam assumes that for code that must be executed sequentially. It can be divided into multiple nodes, each of which is a thread. And place channel. The nodes are shaped like pipelines. This can also greatly enhance CPU utilization.

For example:

The game can be divided into three nodes.

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

two。 Using data, physical operations (3ms)

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

If linear programming, the whole process requires 6ms.

But if you treat each node as a thread. But it is executed synchronously between thread. Then the whole process only needs 3ms.

This is the end of the content of "how to check the usage of each CPU under CentOS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report