> I did try that testcase.
There are three different ways to code this. Which one (or ones) did you try?
- fwrite(fp);
- fwrite(fp); fflush(fp);
- write(fd);
The last two should be the same, but should be different to the first one.
> write 512 bytes
You may only have 46 us before the overflow. If the SD card is using a slow SPI channel it might take a lot longer than that to write 512 bytes.
It would be worth measuring the interrupt latency. Take a timestamp on every exit from the SPI RX ISR. When it overflows, grab another timestamp, subtract the first one and "printk()" the result. That will show how long it was between interrupts.
Better still, build a kernel with FTRACE enabled.
I had all the details on how to do this typed in, then "Jive" locked up and lost the lot when I tried to paste some text and it blew up.
ftrace - Wikipedia, the free encyclopedia
That tells you to read the following, which is also with your kernel sources:
https://www.kernel.org/doc/Documentation/trace/ftrace.txt
If you're lucky and your kernel already has this in it, try "mount -t debugfs nodev /sys/kernel/debug".
If this isn't enabled, basically "make menuconfig", then turn stuff on in "kernel hacking / enable tracers select tracers".
Then interesting stuff shows up in "/sys/kernel/debug/tracing/", including stuff to find what's locking out interrupts. This is the PROPER way to trace down these things.
Not that you'll be then able to rewrite enough of everything to fix it, but it is very educational.
You should get something like this (I'm about to try another paste, it will probably go horribly wrong again...)
# tracer: irqsoff
#
# irqsoff latency trace v1.1.5 on 3.8.0-test+
# --------------------------------------------------------------------
# latency: 259 us, #4/4, CPU#2 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4)
# -----------------
# | task: ps-6143 (uid:0 nice:0 policy:0 rt_prio:0)
# -----------------
# => started at: __lock_task_sighand
# => ended at: _raw_spin_unlock_irqrestore
#
#
# _------=> CPU#
# / _-----=> irqs-off
# | / _----=> need-resched
# || / _---=> hardirq/softirq
# ||| / _--=> preempt-depth
# |||| / delay
# cmd pid ||||| time | caller
# \ / ||||| \ | /
ps-6143 2d... 0us!: trace_hardirqs_off <-__lock_task_sighand
ps-6143 2d..1 259us+: trace_hardirqs_on <-_raw_spin_unlock_irqrestore
ps-6143 2d..1 263us+: time_hardirqs_on <-_raw_spin_unlock_irqrestore
ps-6143 2d..1 306us : <stack trace>
=> trace_hardirqs_on_caller
=> trace_hardirqs_on
=> _raw_spin_unlock_irqrestore
=> do_task_stat
=> proc_tgid_stat
=> proc_single_show
=> seq_read
=> vfs_read
=> sys_read
=> system_call_fastpath
(Edit) Not horribly wrong, but the multiple spaces didn't survive, and only the first four lines after "||||" survived.. What is it with a "Show Code" filter that removes multiple spaces and destroys the formatting!
Let's see if I can use raw HTML, plus lots of hacking and editing...
# tracer: irqsoff # # irqsoff latency trace v1.1.5 on 3.4.0-rc3-karo # -------------------------------------------------------------------- # latency: 559 us, #374/374, CPU#0 | (M:server VP:0, KP:0, SP:0 HP:0) # ----------------- # | task: swapper-0 (uid:0 nice:0 policy:0 rt_prio:0) # ----------------- # => started at: trace_hardirqs_off # => ended at: trace_hardirqs_on # # # _------=> CPU# # / _-----=> irqs-off # | / _----=> need-resched # || / _---=> hardirq/softirq # ||| / _--=> preempt-depth # |||| / delay # cmd pid ||||| time | caller # \ / ||||| \ | / # [idle]-0 0d... 1us : __irq_svc There was meant to lots of other interesting stuff in here, but "Jive" trips over it and kills it.
That looked fine on my screen. Then it got destroyed so it is now all on one line!
Maybe the only way to show code samples in here is to insert a video or a photo of it, or to attach a separate file that people have to click on to open?
So here's a JPEG PICTURE of the text!

Tom