|
|
|
|
|
by LowerThanZero
2230 days ago
|
|
Your question though rises an interesting problem: ULTIMATELY, is there a piece of code which loops while waiting for data? I guess the answer is "maybe" but it's more of a philosophical question... in my previous example the OS kernel running on the main CPU doesn't loop awaiting for a disk drive block or a network packet but the code running on the controller CPU most likely does. So it's a matter of perspective I guess. You don't want to poll in your code and you want to let the kernel do the job for you. Does it mean that the kernel doesn't poll? Not necessarily; The kernel itself might be forced to "poll" (e.g. the device driver can't do otherwise) or it can outsource ;-) the dirty and time consuming poll job to a peripheral which in turn will have an embedded CPU and firmware. Bottom line: if you poll it is GUARANTEED to be a waste of time and CPU cycles but if you let the kernel do it there's a chance that the system might do a better overall job. That's because main CPU time is really expensive while peripheral CPU resources might be cheaper in the big picture so ultimately it's not a "poll vs. no poll" but rather "specialized poll vs wasteful poll" |
|