目录

Linux lscpu指令

概念-超线程

概念-sys高的理解:

system (sy)

user (us)

nice (ni)

idle (id)

iowait (wa)

Other statistics

Stress CPU

C++控制线程运行在哪个核:

C计算cpu的整体以及各个逻辑核的使用率:

Code实现

工具 - linux查看某个进程被分配的cpu 核:

工具 - Linux查看某个进程的所有线程:

工具-htop


Linux lscpu指令

该指令的输出项理解:

Socket:  物理插槽的个数;

Core(s) per socket:每个socket中的物理核的个数

Thread(s) per core:   

每个物理核所支持的线程数。如果支持hyper-threading,每个支持2个线程,相当于一个物理核上有两个逻辑核;

CPU(s):  逻辑核的总数;

NUMA node:

“NUMA node” represents the memory architecture; “NUMA” stands for “non-uniform memory architecture”. In your system, each socket is attached to certain DIMM slots, and each physical CPU package contains a memory controller which handles part of the total RAM. As a result, not all physical memory is equally accessible from all CPUs: one physical CPU can directly access the memory it controls, but has to go through the other physical CPU to access the rest of memory. In your system, logical cores 0–13 and 28–41 are in one NUMA node, the rest in the other. So yes, one NUMA node equals one socket, at least in typical multi-socket Xeon systems.

Non-uniform memory access (NUMA) is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory (memory local to another processor or memory shared between processors). The benefits of NUMA are limited to particular workloads, notably on servers where the data is often associated strongly with certain tasks or users.[1]

cpu - Understanding output of lscpu - Unix & Linux Stack Exchange

Other:

lscpu(1) - Linux manual page

Linux lscpu Command Tutorial for Beginners (5 Examples)

How many physical and logical CPU cores in your computer | Wei Bai 白巍

概念-超线程

https://en.wikipedia.org/wiki/Hyper-threading

Hyper-threading (officially called Hyper-Threading Technology or HT Technology and abbreviated as HTT or HT) is Intel's proprietary simultaneous multithreading (SMT) implementation used to improve parallelization of computations (doing multiple tasks at once) performed on x86 microprocessors. It was introduced on Xeon server processors in February 2002 and on Pentium 4 desktop processors in November 2002.[4] Since then, Intel has included this technology in ItaniumAtom, and Core 'i' Series CPUs, among others.[5]

For each processor core that is physically present, the operating system addresses two virtual (logical) cores and shares the workload between them when possible. The main function of hyper-threading is to increase the number of independent instructions in the pipeline; it takes advantage of superscalar architecture, in which multiple instructions operate on separate data in parallel. With HTT, one physical core appears as two processors to the operating system, allowing concurrent scheduling of two processes per core. In addition, two or more processes can use the same resources: If resources for one process are not available, then another process can continue if its resources are available.

In addition to requiring simultaneous multithreading support in the operating system, hyper-threading can be properly utilized only with an operating system specifically optimized for it.

概念-sys高的理解:

Understanding CPU statistics | AppSignal Blog

On a Linux machine, running top will print a CPU line that looks like this:

%Cpu(s): 13.2 us,  1.3 sy,  0.0 ni, 85.3 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st

These eight states are "user" (us), "system", (sy), "nice" (ni), "idle" (id), "iowait" (wa), "hardware interrupt" (hi), "software interrupt" (si), and "steal" (st).

Of these eight, "system", "user" and "idle" are the main states the CPU can be in.

system (sy)

The "system" CPU state shows the amount of CPU time used by the kernel. The kernel is responsible for low-level tasks, like interacting with the hardware, memory allocation, communicating between OS processes, running device drivers and managing the file system. Even the CPU scheduler, which determines which process gets access to the CPU, is run by the kernel.

While usually low, the "system" category can spike when a lot of data is being read from or written to disk, for example. If it stays high for longer periods of time, you might have a problem with a device driver.

user (us)

One level up, the "user" CPU state shows CPU time used by user space processes. These are higher-level processes, like your application, or the database server running on your machine. In short, every CPU time used by anything else than the kernel is marked "user", even if it wasn't started from any user account. If a user-space process needs access to the hardware, it needs to ask the kernel, meaning that would count towards "system" state.

Usually, the "user" category uses most of your CPU time. If it stays close to the maximum without leaving much idle time for too long, you might have a problem with your application, or another utility running on the machine.

nice (ni)

The "nice" CPU state is a subset of the "user" state and shows the CPU time used by processes that have a positive niceness, meaning a lower priority than other tasks. The nice utility is used to start a program with a particular priority. The default niceness is 0, but can be set anywhere between -20 for the highest priority to 19 for the lowest. CPU time in the "nice" category marks lower-priority tasks that are run when the CPU has some time left to do extra tasks.

idle (id)

The "idle" CPU state shows the CPU time that's not actively being used. Internally, idle time is usually calculated by a task with the lowest possible priority (using a positive nice value).

iowait (wa)

"iowait" is a sub category of the "idle" state. It marks time spent waiting for input or output operations, like reading or writing to disk. When the processor waits for a file to be opened, for example, the time spend will be marked as "iowait".

Elevated CPU time in the "iowait" category can reveal problems outside of the processor. For example, when an in-memory database needs to flush a lot of data to disk, or when memory is swapped to disk.

Other statistics

Besides "nice" in "user" and "iowait" in idle, there are more subcategories the main CPU states can be divided in. The "hardware interrupt" (hi or irq) and "software interrupt" (si, or softirq) categories are time spent servicing interrupts, and the "steal" (st) subcategory marks time spent waiting for a virtual CPU in a virtual machine.

Stress CPU

C++控制线程运行在哪个核:

C++11 threads, affinity and hyperthreading - Eli Bendersky's website

C计算cpu的整体以及各个逻辑核的使用率:

Finding overall and per core CPU utilization – Phoxis

Code实现

工具 - linux查看某个进程被分配的cpu 核:

taskset -c -p  xxx, xxx也可为线程id

显示的是逻辑核,有超线程的话,一个物理核对应两个逻辑核。


Note: 如果该进程的主线程没有被制定在一个具体的核, 子线程都被指定过。该指令显示的是所有核。

工具 - Linux查看某个进程的所有线程:

ps -Tp pid

pstree -p 407057 (有层次结构,better)

工具-htop

可以查看各个cpu逻辑核的占用率

Cpu占用率检测以及 Cpu Burn相关推荐

  1. 测试软件cpu占用率 可以用,CPU占用率检测工具

    面对性能问题,我们第一件事情就是查看CPU使用率.查看CPU使用率的方式是大家都熟悉的top命令,但是top在多核系统中指示的是所有CPU的平均使用率,这一点大家必须理解.比如说,对于一个4核的系统, ...

  2. oracle查询cpu占用率高,ORACLE CPU过高的sql查询

    1. 根据占用CPU高的进程号来查询这个进程执行的SQL语句: CPU过高的进程号: #首先找到CPU过高的进程号 # top -bn1 是静态找到占用最高的进程 [root@localhost ~] ...

  3. Linux环境下程序的多核CPU占用率高的问题分析和解决

    1.项目问题 前端PDC双目倾斜相机客流统计项目中排查平台服务程序延时大的问题时,平台demo程序测试发现多核cpu中的某个核的占用率达到100%,导致组件中的目标检测线程和客流统计线程的单帧耗时达不 ...

  4. [原]调试实战——程序CPU占用率飙升,你知道如何快速定位吗?

    前言 如果我们自己的程序的CPU Usage(CPU占用率)飙升,并且居高不下,很有可能陷入了死循环.你知道怎么快速定位并解决吗?今天跟大家分享几种定位方法,希望对你有所帮助. 如何判断是否有死循环? ...

  5. CPU占用率过高和OOM场景下如何排查问题

    本文来说下CPU占用率过高和OOM场景下如何排查问题 文章目录 CPU占用率过高 OOM场景下如何排查问题 CPU占用率过高 CPU占用率过高 CPU占用率过高可以通过top命令去看占用CPU最多的J ...

  6. 深度解读鸿蒙轻内核CPU占用率

    摘要:CPUP(Central Processing Unit Percentage,CPU占用率)分为系统CPU占用率和任务CPU占用率.用户通过系统级的CPU占用率,判断当前系统负载是否超出设计规 ...

  7. 服务器cpu占用率高怎么解决,线上服务器CPU占用率高怎么办?

    如果线上服务器发生CPU占用率高时,应该如何排查并定位问题. 1.问题发现 本文整理自一个真实的案例,是楼主负责的业务,在一次大促之前的压测时发现了这个问题. 在每次大促之前,我们的测试人员都会对网站 ...

  8. c++ 计算cpu占用率

    计算CPU占用率就是获取系统总的内核时间 用户时间及空闲时间 其中空闲时间就是内核空转 所以内核时间包含空闲时间 然后计算 运行时间 = 内核时间 加 用户时间 减去 空闲时间 间隔时间 =  内核时 ...

  9. Linux系统中CPU占用率过高问题原因分析

    背景: 在服务器上部署了一个项目,发现项目部署完成之后,CPU占用率居高不下,现将原因分析过程总结如下: 通过top命令查看CPU占用率,分析CPU占用过高的原因 步骤一: 通过top命令,查看占用C ...

最新文章

  1. 针对 Windows Phone 7 上的独立存储的 Sterling
  2. postman无法获得响应_【原创翻译】POSTMAN从入门到精通系列(二):发送第一个请求...
  3. Javascript之RegExp
  4. Gestalt - 在浏览器里用 python/ruby 写客户端脚本
  5. 【华为云实战开发】2.Docker镜像部署怎么玩才酷炫?
  6. java poi生.docx_java – Apache POI或docx4j处理docx文件
  7. android dsd 播放器,Android中播放DSD音乐
  8. 关于网络直播营销活动监管中的《广告法》
  9. 月老在线牵盲盒+交友盲盒+一元交友+小纸条盲盒+交友匹配+同城交友小程序源码
  10. week 5 session and cookie
  11. 【区块链扩容】侧链技术 Plasma(Layer 2)
  12. canvas画线变粗变模糊的解决办法
  13. MySQL8.0密码找回与权限刷新
  14. linux无法添加网络连接到服务器地址,ubuntu9.1服务器版局域网IP设置 网络无法连接(急)...
  15. 注册登录会员抽奖系统
  16. 什么是穿透式监管,需要投资者做什么?
  17. 机器人操作系统ROS/ROS2(1)
  18. 机械键盘轴的小知识详解
  19. Scipy-kmeans聚类
  20. 私有和公开IP地址的区别是什么?

热门文章

  1. 速翔头条系统-高仿今日头条源码|速翔头条源码|新闻源码|资讯源码|新闻资讯系统|头条系统|自媒体源码系统
  2. 为什么男人死了烧马,女人死了烧牛?别怕,文末有段子缓解气氛……
  3. java实现Json格式美化【工具包系列】
  4. 未能加载文件或程序集Noesis.Javascript.DLL或它的某一个依赖项。找不到指定的模块。
  5. 关于 mat0_c.jpg 风格的 PBR 材质贴图与 Noesis 加入 .mview 文件的问题解决
  6. 华为交换机DHCP配置
  7. poi导出excel添加数据验证
  8. 360桌面与QQWEB桌面体验对比
  9. 全球及中国盐酸肼屈嗪行业竞争格局与招商引资策略分析报告2022-2028年
  10. layu tab切换table