WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: High cpu load (kworker) - Troubleshooting the cause  (Read 1203 times)

Offline eSPee

  • Newbie
  • *
  • Posts: 16
High cpu load (kworker) - Troubleshooting the cause
« on: June 25, 2023, 06:23:26 AM »
Hi all,

On a zero w pi I am running:
- Tinycorelinux 9.x (armv6)
- python-RPi.GPIO
- wiringpi
- apache2.4-mod-php5

When i start a simple python GPIO script a kworker cpu-load of ~40% starts and keeps running at this level until reboot.
Apache and python seem to work fine, but after some time the Pi becomes instable (i expect this is due to the kworker cpu-load).
I tried to troubleshoot this problem, but can't seem to find the issue.

- Is there a way to see/check what is the source/cause of this kworker process?
- Can anybody help me point in the right direction to troubleshoot this issue?

Tried this, but nothing came up:
- sudo python script.py >> logfile.log 2>> error.log

Thanx for helping!

script.py:
Quote
import sys
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(15, GPIO.OUT)

GPIO.output(15,GPIO.LOW)
sleep(1.3)
GPIO.output(15,GPIO.HIGH)
sleep(0.1)
GPIO.cleanup()
sys.exit()
« Last Edit: June 25, 2023, 06:34:01 AM by eSPee »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1211
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #1 on: June 25, 2023, 07:06:30 AM »
It’s not they python gpio script doing it.  What  are you doing with Apache? And network?


Offline eSPee

  • Newbie
  • *
  • Posts: 16
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #2 on: June 25, 2023, 07:33:25 AM »
Hi Paul,

Thank you for helping.

The kworker cpu load starts as soon as i run the python script from a console (checked by viewing "top" from another console).

- The pi runs headless on Wifi (6 meters apart from router)
- Apache is used for running a php website + reading & controlling some GPIO inputs & outputs

bootlocal.sh:
Quote
#
!/bin/sh
/usr/sbin/startserialtty &
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
/sbin/modprobe i2c-dev
/usr/local/etc/init.d/openssh start

wifi.sh -a
sh /etc/init.d/settime.sh
sudo /usr/local/etc/init.d/avahi start
sudo apachectl -k start
sudo smbd start
crond -L /dev/null 2>&1
sudo syslogd -O /var/log/messages

onboot.1st:
Quote
tzdata.tcz
mc.tcz
openssh.tcz
wireless-4.9.22-piCore.tcz
firmware-rpi3-wireless.tcz
wifi.tcz
apache2.4-mod-php5.tcz
samba4.tcz
nano.tcz
python-RPi.GPIO.tcz
iw.tcz
avahi.tcz
wiringpi.tcz
« Last Edit: June 25, 2023, 07:37:47 AM by eSPee »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1211
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #3 on: June 25, 2023, 07:51:57 AM »
You have a lot going on there.  Those apps are all heavy applications.    How is the memory usage?

What does triggering GPIO15 do?

Offline eSPee

  • Newbie
  • *
  • Posts: 16
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #4 on: June 25, 2023, 09:02:31 AM »
Hi Paul,

A start to the solution may have been found! Thanx to your questions i experimented with another gpio port.
When i start the script with port 25 or 14 everything goes well, no kworker cpu-load anymore!
So, somehow it is related to port 15, something to figure out in the coming days.

Additonally, answering your question on memory usage:

Before running the script on GPIO 15:
Quote
Mem: 345348K used, 99068K free, 133832K shrd, 19524K buff, 234892K cached
CPU:  0.0% usr  1.3% sys  0.0% nic 98.2% idle  0.0% io  0.0% irq  0.3% sirq

After running the script on GPIO 15 (kworker @ 40%):
Quote
Mem: 361332K used, 83084K free, 134184K shrd, 20876K buff, 239416K cached
CPU:  1.4% usr 41.5% sys  0.0% nic 56.6% idle  0.0% io  0.0% irq  0.2% sirq

Is this too much, or still an acceptable level of the memory usage?
« Last Edit: June 25, 2023, 09:05:00 AM by eSPee »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1211
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #5 on: June 25, 2023, 09:24:52 AM »
GPIO15 is a serial uart.  Depending on the serial port you are using for the console, or tty.  That is likely the cause.

If you are not using the serialtty, then remove that from your bootlocal.sh. (We don’t do that by default anymore).   Also check the cmdline.   Remove the console running on the serial port.

Offline eSPee

  • Newbie
  • *
  • Posts: 16
Re: High cpu load (kworker) - Troubleshooting the cause
« Reply #6 on: June 25, 2023, 01:23:26 PM »
Paul, you solved the problem!   ;)

I removed the serialtty from bootlocal.sh and removed the serialtext from cmdline.txt.
Now it is running fine even with the use of GPIO15  8)

Thank you for your time helping out!