User avatar
PeterO
Posts: 5156
Joined: Sun Jul 22, 2012 4:14 pm

Re: High CPU usage when booting from USB

Wed May 30, 2018 12:01 pm

Is there an option to just reduce the polling rate ? Once every 10 seconds would have minimal CPU load but still allow inserted cards to be auto mounted.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

fanoush
Posts: 491
Joined: Mon Feb 27, 2012 2:37 pm

Re: High CPU usage when booting from USB

Wed May 30, 2018 1:07 pm

I already asked here https://github.com/raspberrypi/linux/is ... -392761118 but didn't quite get the answer.

And when checking mysellf I got a bit lost but I guess it is hardcoded once per second.

I guess the right method is mmc_rescan which is first set to be scheduled here
https://elixir.bootlin.com/linux/v4.14/ ... ost.c#L390

Code: Select all

	INIT_DELAYED_WORK(&host->detect, mmc_rescan);
and after it is first called it reschedules itself with HZ (=1 second?) delay when it ends here:
https://elixir.bootlin.com/linux/v4.14/ ... re.c#L2665

Code: Select all

mmc_schedule_delayed_work(&host->detect, HZ);

EDIT:
Oh, looks like HZ is much faster than once per second
https://www.google.cz/search?q=kernel+HZ
EDIT2: It is 1 second after all. While the value varies the meaning is number of kernel ticks per second so sleeping fo HZ ticks should last one second.
Last edited by fanoush on Wed May 30, 2018 3:17 pm, edited 1 time in total.

jerrm
Posts: 200
Joined: Wed May 02, 2018 7:35 pm

Re: High CPU usage when booting from USB

Wed May 30, 2018 2:00 pm

fanoush wrote:
Wed May 30, 2018 10:11 am
Nice. However having system set to 'stop' such service and initialize card at shutdown right before poweroff is not very optimal. Hopefuly the worst case is that the shutdown will be a tiny bit slower.
I would agree, but my Pi's are up for months at a time, the "one file" fix was my choice.

Easy enough to remove the ExecStop and have a separate script handle adding the driver back if desired (or break all the code out into a script).

What I don't know about systemd is if there is a way to detect if the start/stop is executing because of a system startup or shutdown(maybe a better target choice?). If so, not processing the "stop" process during an actual shutdown would be ideal.

I don't have enough time to go googling, but would welcome insight if anyone knows.

jerrm
Posts: 200
Joined: Wed May 02, 2018 7:35 pm

Re: High CPU usage when booting from USB

Thu May 31, 2018 6:34 pm

jerrm wrote:
Wed May 30, 2018 2:00 pm
fanoush wrote:
Wed May 30, 2018 10:11 am
Nice. However having system set to 'stop' such service and initialize card at shutdown right before poweroff is not very optimal. Hopefuly the worst case is that the shutdown will be a tiny bit slower.
I would agree, but my Pi's are up for months at a time, the "one file" fix was my choice.
I updated the original post (viewtopic.php?f=28&t=211912#p1321571) with a check for shutdown. The rebind should not occur during a shutdown.

That said, I'm not sure it was ever occurring. There is no console output for it during shutdown. It may just be too late in the sequence for console output. Adding the check is still worthwhile.

jerrm
Posts: 200
Joined: Wed May 02, 2018 7:35 pm

Re: High CPU usage when booting from USB

Fri Jun 01, 2018 4:25 pm

I updated the systemd hack for Jessie compatibility: viewtopic.php?f=28&t=211912#p1321571.

Also, looks like the sdtweak.dtbo changes have been merged and should available via rpi-update now.

The sdtweak method is the better of the two. It hopefully will be good going forward. For now, if you don't want to do a full rpi-update for, you can copy over just updated sdtweak.dtbo from the git repository: https://github.com/raspberrypi/firmware ... tweak.dtbo.

For those that still need Jessie, even though the sdtweak.dtbo overlay was built against the Stretch kernel/firmware/drivers, it appears to work as expected when copied into an otherwise pure Jessie boot(at least as of today's version).

EDIT: The updated sdtweak.dtbo is now in the official Raspbian as of the 06-27-2018 release and will be installed with your preferred apt commands. No rpi-update needed.
Last edited by jerrm on Fri Jun 29, 2018 1:02 pm, edited 4 times in total.

User avatar
PeterO
Posts: 5156
Joined: Sun Jul 22, 2012 4:14 pm

Re: High CPU usage when booting from USB

Sat Jun 02, 2018 6:12 am

Has anyone written a simple sd slot control script...
"sdslot on" and "sdslot off" would seem useful.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jerrm
Posts: 200
Joined: Wed May 02, 2018 7:35 pm

Re: High CPU usage when booting from USB

Sat Jun 02, 2018 2:09 pm

PeterO wrote:
Sat Jun 02, 2018 6:12 am
Has anyone written a simple sd slot control script...
"sdslot on" and "sdslot off" would seem useful.
PeterO
Just cut and paste the code from the systemd script. The only thing to change is the "%n" value for the /var/run file - replace it with something like "$(basename $0)".

Also - no problem installing the systemd script but leaving disabled, then just toggle with systemctl start/stop.

jerrm
Posts: 200
Joined: Wed May 02, 2018 7:35 pm

Re: High CPU usage when booting from USB

Fri Jun 29, 2018 1:01 pm

The updated sdtweak.dtbo is now in the official Raspbian as of the 06-27-2018 release and will be installed with your preferred apt commands. No rpi-update needed.

User avatar
sapnho
Posts: 216
Joined: Sun Sep 14, 2014 3:49 pm
Location: Frankfurt am Main
Contact: Website

Re: High CPU usage when booting from USB

Mon Sep 10, 2018 6:31 pm

Has this issue gone away for you with the latest updates? For me it hasn't. No SD card, happy flashing..
www.TheDigitalPictureFrame.com
Build a really great digital picture frame with the Raspberry Pi.
With lots of great tips from this forum.

fanoush
Posts: 491
Joined: Mon Feb 27, 2012 2:37 pm

Re: High CPU usage when booting from USB

Mon Sep 10, 2018 7:03 pm

It won't just go away, you need to set it up yourself to not to check for card, this is feature, not bug ;-)
https://www.raspberrypi.org/forums/view ... 2#p1321458

LTolledo
Posts: 2158
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: High CPU usage when booting from USB

Mon Sep 10, 2018 9:22 pm

fanoush wrote:
Mon Sep 10, 2018 7:03 pm
It won't just go away, you need to set it up yourself to not to check for card, this is feature, not bug ;-)
https://www.raspberrypi.org/forums/view ... 2#p1321458
As pointed out by fanoush you need to set it not to check for the card.
to summarize from the link you only need to add one line to the config.txt to "silence" the led

Code: Select all

dtoverlay=sdtweak,poll_once
make sure to do update and full-upgrade before rebooting.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

Return to “Troubleshooting”