FatFs hogging the OS

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

FatFs hogging the OS

Post by Tabulous »

Ive got a thread that writes data to a file, the file write is about 10KB.

Thus in the thread that writes the data it does

open->write->close.

It seems when it does this it consumes the RTOS 100% i.e no other threads are scheduled whilst this is happening.

Ive got the window watchdog running, and this ends up getting reset as thread servicing the watchdog gets starved, it needs to run every 10ms to reload the window watchdog.

If i disable the watchdog i dont get any system resets, but them i dont have the system protection the watchdog gives.

At the moment all threads are running with the same prority, default NORMALPRIO.

PS before anyone asks, using IWDG is not a option, this makes a sleeping system messy.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: FatFs hogging the OS

Post by Tabulous »

increasing the window watchdog thread priority seems to fix the issue.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: FatFs hogging the OS

Post by Giovanni »

Hi,

If all threads are at NORMALPRIO then one thread hogging the CPU prevents the others to execute, there is no preemptive round robin, round robin is collaborative and requires threads to yield.

You need to put such threads at a lower priority and, in general, choose appropriate priorities for all threads.

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: FatFs hogging the OS

Post by Tabulous »

whats the thoughts on thread priories and allocating them.....

At the moment most of them are not time critical/low demand and also cooperative thus threads with same priority should just share the CPU in a round robin fashion.

The window watchdog and a time critical sampling thread are the two I've elevated.

But you said you should chose priories for all threads, so whats the best methodology to achieve this. The system at the moment is very stable, as such i dont want to add in at the cost of this.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: FatFs hogging the OS

Post by Giovanni »

A common strategy is to measure the worst case code path for threads then ordering them to have the short paths on top.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: FatFs hogging the OS

Post by faisal »

Try looking up rate monotonic scheduling. Giovanni gave a wonderful summary of it in his reply.
Post Reply