using prefetch

Kevin Wilson wkevils at gmail.com
Fri Feb 15 05:16:02 EST 2013


Hello, kernelnewbies
There are many cases in drivers where I see calls to prefetch|() of
some variable.
For example,
    prefetch(&skb->end); in 1 bnx2_tx_int(),
http://lxr.free-electrons.com/source/drivers/net/ethernet/broadcom/bnx2.c

AFAIK, what prefetch does is get a variable from memory and put it in
cache (L2 cache I believe).
Is the prefetch operation synchronous ? I mean, after calling it, are
we gauranteed that the variable is
indeed in the cache ?

So this is probably for improving performance, assuming that you will
need this variable in the near
future.
The comment there says:
/* prefetch skb_end_pointer() to speedup skb_shinfo(skb) */

According to this logic, anywhere that we want to call skb_shinfo(skb)
we better do a prefetch before.

In fact, if we prefetch any variable that we want to use then we end up
with performance boost.

So - any hints, what are the guidlines for using prefetch()?

rgs,
Kevin



More information about the Kernelnewbies mailing list