I've been experimenting with the TeensySdioLogger example in the SdFat library on the suggestion of joepasquariello in a couple of threads e.g. Best Teensy for a datalogger, Fastest Way to Log to SD Card. Here are some details:
However I notice that after every 4 MB, I get a spike in sync() time to around 1-2 ms. Every 32 MB, I get a larger spike in sync() time to around 6-10 ms. Sometimes the 32 MB and 4 MB spikes line up with each other, other times not.
Here's an example of when the 4 MB and 32 MB spikes line up (this was a 588 MB total size):
And here is an example of when the 4 MB and 32 MB spikes don't line up (this was about 146 MB total size):
I am trying to work out why this is happening. I can't see anything in the TeensySdioLogger example that would cause this behavior. Perhaps something in another library?
I considered whether it is some SD card configuration thing that causes this behavior, like a boundary that the data is saved across. This is territory I am not familiar with. I tried to find numbers in the specs that would sort of line up with these boundaries. An SD card has a Cylinder/Head/Sector (CHS) code that I think is a throwback to hard drives, and I found this SD card has a CHS code of 3880, 255, 63 (found using Testdisk). If these numbers related to physical things, each cylinder would be ~8MB, track would be ~32 MB, and head ~125 MB. So maybe each track boundary are the 32 MB spikes, but still no idea what the 4 MB spikes are. I could very well be barking up the wrong tree here as I don't think the CHS means anything anymore, but that was my best attempt at finding something that lines up with these spikes.
The write speeds are more or less within the range found by joepasquariello (Fastest Way to Log to SD Card). I'm not trying to eliminate these spikes, but I definitely want consistency. If these are a fact of life, then that is fine, but I would like to know if they are consistent. A large part of that is knowing why they happen.
Any ideas?
- Teensy 4.1
- using the in-built SD card with a 32GB SDSQXCG-032G-GN6MA
- ring buffer of ~400 KB
- maximum log file size of 600 MB
- data logging interval of 100 us
- approx. 1.8 KB bytes for each new data log line
- performing rb.sync() approximately every 4KB (guessing this is the optimized equivalent to flush() which I have been using until now)
However I notice that after every 4 MB, I get a spike in sync() time to around 1-2 ms. Every 32 MB, I get a larger spike in sync() time to around 6-10 ms. Sometimes the 32 MB and 4 MB spikes line up with each other, other times not.
Here's an example of when the 4 MB and 32 MB spikes line up (this was a 588 MB total size):
And here is an example of when the 4 MB and 32 MB spikes don't line up (this was about 146 MB total size):
I am trying to work out why this is happening. I can't see anything in the TeensySdioLogger example that would cause this behavior. Perhaps something in another library?
I considered whether it is some SD card configuration thing that causes this behavior, like a boundary that the data is saved across. This is territory I am not familiar with. I tried to find numbers in the specs that would sort of line up with these boundaries. An SD card has a Cylinder/Head/Sector (CHS) code that I think is a throwback to hard drives, and I found this SD card has a CHS code of 3880, 255, 63 (found using Testdisk). If these numbers related to physical things, each cylinder would be ~8MB, track would be ~32 MB, and head ~125 MB. So maybe each track boundary are the 32 MB spikes, but still no idea what the 4 MB spikes are. I could very well be barking up the wrong tree here as I don't think the CHS means anything anymore, but that was my best attempt at finding something that lines up with these spikes.
The write speeds are more or less within the range found by joepasquariello (Fastest Way to Log to SD Card). I'm not trying to eliminate these spikes, but I definitely want consistency. If these are a fact of life, then that is fine, but I would like to know if they are consistent. A large part of that is knowing why they happen.
Any ideas?