Re: prefetch(x)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your reply.

I found this , I thought I must share this with you :

    This function is used to minimize cache-miss latency by moving
data into a cache before it is accessed. You can insert calls to
__builtin_prefetch into code for which you know addresses of data in
memory that is likely to be accessed soon. If the target supports
them, data prefetch instructions will be generated. If the prefetch is
done early enough before the access then the data will be in the cache
by the time it is accessed.

    The value of addr is the address of the memory to prefetch. There
are two optional arguments, rw and locality. The value of rw is a
compile-time constant one or zero; one means that the prefetch is
preparing for a write to the memory address and zero, the default,
means that the prefetch is preparing for a read. The value locality
must be a compile-time constant integer between zero and three. A
value of zero means that the data has no temporal locality, so it need
not be left in the cache after the access. A value of three means that
the data has a high degree of temporal locality and should be left in
all levels of cache possible. Values of one and two mean,
respectively, a low or moderate degree of temporal locality. The
default is three.

              for (i = 0; i < n; i++)
                {
                  a[i] = a[i] + b[i];
                  __builtin_prefetch (&a[i+j], 1, 1);
                  __builtin_prefetch (&b[i+j], 0, 1);
                  /* ... */
                }


    Data prefetch does not generate faults if addr is invalid, but the
address expression itself must be valid. For example, a prefetch of
p->next will not fault if p->next is not a valid address, but
evaluation will fault if p is not a valid address.

    If the target does not support data prefetch, the address
expression is evaluated if it includes side effects but no other code
is generated and GCC does not issue a warning.


On Mon, Apr 19, 2010 at 6:54 PM, Mulyadi Santosa
<mulyadi.santosa@xxxxxxxxx> wrote:
> Hi Onkar...
>
> On Mon, Apr 19, 2010 at 17:59, Onkar Mahajan <kern.devel@xxxxxxxxx> wrote:
>> More specifically :
>>
>> What is the benefit of using prefetch(x) ?
>
> IMHO, it will told the CPU to prefetch the data from memory...or in
> other word, reading them before it is really needed. AFAIK, by doing
> so, we reduce processor get into stalled condition...or at least
> "blocked" waiting for data to be really inside the L1 or L2 cache...
>
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux