简体   繁体   English

Linux PCIe 驱动程序和应用程序显示高 CPU 使用率

[英]Linux PCIe driver and app showing high CPU Usage

I've a custom Xilinx PCIe Endpoint Hardware, I've written a linux driver for it and also a sample app to test it.我有一个定制的 Xilinx PCIe 端点硬件,我已经为它编写了一个 linux 驱动程序以及一个示例应用程序来测试它。 Driver loads correctly and Device is also recognized.驱动程序正确加载并且设备也被识别。 Then the CPU Usage is also stable until I run my application.然后 CPU 使用率也很稳定,直到我运行我的应用程序。 When I run my application, one out of my 4 Cores are Hitting 100% when other cores stay below 10%.当我运行我的应用程序时,我的 4 个核心中有一个达到 100%,而其他核心保持在 10% 以下。 Then opening any other application (may be firefox browser as I did), The system completely Hangs and requires a hard restart to get back to normal.然后打开任何其他应用程序(可能是 firefox 浏览器,就像我一样),系统完全挂起,需要硬重启才能恢复正常。 The process wise CPU Usage shows only my application at 25% and remaining all stays at 0-1%.进程明智的 CPU 使用率仅显示我的应用程序为 25%,其余全部保持在 0-1%。

The communication between the Driver and Application is only the Interrupts.驱动程序和应用程序之间的通信只是中断。 When there is an MSI Interrupt, the read call on the device file in the application unblocks and again application starts waiting for another interrupt.当出现 MSI 中断时,应用程序中对设备文件的读取调用解除阻塞,应用程序再次开始等待另一个中断。 Also I access the BAR Regions from the application using resource files.我还使用资源文件从应用程序访问 BAR 区域。

Why does only one core is showing 100% CPU Usage?为什么只有一个核心显示 100% CPU 使用率? and Why my system completely hangs when another application is started even when 3 cores are almost completely free?为什么我的系统在启动另一个应用程序时完全挂起,即使 3 个核心几乎完全空闲?

Found the issue.发现问题。

In the app I run, 4 Threads are created which will handle each PCIe Interrupt.在我运行的应用程序中,创建了 4 个线程来处理每个 PCIe 中断。 Apart from that, The main function polls on a global variable with an empty while loop.除此之外,主要的 function 使用空的 while 循环轮询全局变量。 This is the reason for high CPU Usage.这就是 CPU 使用率高的原因。 Figured out a way and used usleep instead of while loop and done.想出一种方法并使用 usleep 而不是 while 循环并完成。 CPU Usage is less than 20% now.现在 CPU 使用率低于 20%。

Thanks for your comments.感谢您的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM