0

I like to know how linux function prefetch works

It is defined as

    #ifndef ARCH_HAS_PREFETCH
    #define prefetch(x) __builtin_prefetch(x)
    #endif

so in drivers this can be found

        rx_buf = page_address(tp->Rx_databuff[entry]);//Rx_databuff[] are Page type array
        dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
        prefetch(rx_buf);
        skb_copy_to_linear_data(skb, rx_buf, pkt_size);

So rtl 8139 device has 256 Rx descriptors. and addr parameter to dma_sync_single_for_cpu is I think enables reading from device and save the data in some temporary memory(what is this memory area?) and so prefetch I think is just reading that memory area and populating the rx_buf from that memory area.

I wish I could see __builtin_prefetch(x) defination but I could not find it so what's going on with prefetch call can anyone please tell me this

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
user786
  • 3,902
  • 4
  • 40
  • 72
  • It is just a hint that you are likely to use some memory, so try to load it into cache. See https://stackoverflow.com/questions/8460563/builtin-prefetch-how-much-does-it-read It hopefully does nothing on uncacheable memory areas. – stark Nov 18 '21 at 20:49
  • DMA sync API in reality are cache flushes (they also handle bounce buffers when it’s the case). And note, that these flushes are architecture dependent, e.g. on x86 they are no-ops (except bounce buffers case). – 0andriy Dec 18 '21 at 09:17

0 Answers0