tags:

views:

70

answers:

2

does fread takes processing power / works with DMA ?

Assume that device on which file is residing has DMA support ?

+1  A: 

Yes it does. But it will show up as "system" time when you use the "time" command in Linux.

Basically, you make a system call, telling the OS what data to read and where to put it, then the OS (here comes the CPU cycles) sets up the buffers and tells the DMA where to put the data. Your process is blocked, and the OS picks a new process to run, but that's not really counting against your fread call. Eventually, the reading completes, and the DMA system issues an interrupt to the processor (more CPU cycles coming up) at which point the OS sees what data is ready returns to your program (and puts your thread on ready queue -- end of the CPU time).

Dave
+1  A: 

Whether DMA is used or nt is independent of which C library call you use to read from a file. Usually you can't influence it anyhow without admin privileges.

EDIT:

Whether system uses DMA to access a device does not depend on whether you use scanf, fread, read or any other file access function. It depends on device driver settings, which a normal user can't change.

As far as time spent communicating with the device is concerned, nearly all of it will be counted by your process's system timer (as the answer above stated) and a small part won't be counted at all.

Robert Obryk
I am not getting you. Can you please explain in some detail?
Sunny