树莓派3b+ usb设备启动 kworker占用cpu高的问题

本文介绍了一个Raspberry Pi系统中kworker进程导致的高CPU占用率问题及解决方案。通过在boot目录下创建overlay文件并修改config.txt加入dtoverlay=sdtweak,poll_once行,有效解决了kworker频繁读取SD卡的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把sd卡上的系统通过Win32DiskImager做一个img镜像文件到笔记本电脑上,

然后再这个img镜像文件写入到新的usb移动硬盘上。

然后开机启动,成功。

无意间发现top中 kworker1/1 或者1/3的CPU占用率很高,一直在8%-12%之间。我重启了几次设备都一样,没办法,百度上查了好久也没查到多少资料。

 

然后Google上发现了这个官网的github上的东西,说的就是这个问题,地址:https://github.com/raspberrypi/linux/issues/2567

 

解决办法就是:

Thanks a lot. it works.

First the overlay - copying your file to /boot/overlays

and adding line "dtoverlay=sdtweak,poll_once" to /boot/config.txt solved the kworker issue with polling the card.

So far so good :-)

 

那么这个your file就是在这里https://drive.google.com/file/d/1JOwJpvWNYbQI4AwwzlQPCJMNehuCFQoy/view?usp=sharing

 

通过这两步,我发现我重启之后,top中cpu都正常了。

 

config.txt

 

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on


dtoverlay=sdtweak,poll_once

 

 

03-26
<think>好的,用户想了解Linux内核中的kworker线程。我需要根据提供的引用内容来整理相关信息,并确保回答正确且符合用户的要求。 首先,查看引用[1]提到cmwq(并发管理工作队列),kworker属于工作队列机制的一部分,每个CPU有不同优先级的kworker线程处理工作项。引用[4]详细比较了工作队列和线程化中断处理,指出kworker是普通内核线程,调度类别为SCHED_NORMAL,而线程化中断是实时线程。此外,kworker由线程池管理,可能影响多核并发效率,但资源占用较少。 需要组织这些信息,分点概述kworker的功能、调度、多核处理、命名规则及管理工具。然后生成相关问题,比如调度优先级、监控方法、性能优化等。确保回答结构清晰,引用正确,并符合格式要求,如数学表达式用$...$,独立公式用$$...$$,不过这个问题可能不需要数学公式,但需要注意其他格式要求,如代码块和引用标识。 最后检查引用是否自然添加,比如在讨论调度优先级时引用[4],在命名规则时引用[2]。确保回答准确,并覆盖用户可能关心的方面,如性能、监控、配置选项等。</think>### kworker内核线程概述 kworker是Linux内核中用于处理工作队列(workqueue)的内核线程,主要负责执行中断下半部(bottom half)和异步任务。其核心特征如下: 1. **线程功能** - 处理延迟中断任务(如硬件初始化、网络协议栈处理等)[^2] - 执行内核模块提交的异步工作请求 - 管理并发任务队列,采用CMWQ(Concurrency Managed Workqueue)机制实现负载均衡[^1] 2. **调度特性** - 调度类别为$SCHED\_NORMAL$(普通优先级) - 默认时间片为$100ms$(可通过`/proc/sys/kernel/sched_latency_ns`调整) - 相比实时线程($SCHED\_FIFO$),资源占用更少但实时性较低[^4] 3. **多核处理机制** ```c // 内核创建kworker的典型代码路径 init_workqueues() -> create_worker() -> kthread_create() ``` - 每个CPU核心默认创建$8$个不同优先级的kworker线程池 - 工作项通过$per-CPU$或$unbound$方式进行分发[^1] 4. **线程命名规则** - 标准格式:`kworker/[CPU_ID]:[FLAGS][POOL_ID]` - 示例:`kworker/1:3H`表示: - 运行在CPU 1 - 优先级(H标志) - 属于3号线程池 5. **监控工具** ```bash # 查看线程状态 ps -eLo pid,tid,psr,rtprio,cls,cmd | grep kworker # 统计CPU占用 perf record -e sched:sched_switch -a -g -- sleep 10 ``` ### 配置优化参数 $$ \text{最大工作线程数} = \frac{min\_active}{2} \times num\_online\_cpus + 256 $$ 可通过`/sys/module/workqueue/parameters/`调整参数: - `max_active`:单个CPU最大活动线程数 - `powersave`:省电模式开关
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值