VPP程式碼閱讀中文註解--cache.h
阿新 • • 發佈:2018-10-31
/* * Allow CFLAGS to override the configured / deduced cache line size */ #ifndef CLIB_LOG2_CACHE_LINE_BYTES /* Default cache line size of 64 bytes. */ #ifndef CLIB_LOG2_CACHE_LINE_BYTES #define CLIB_LOG2_CACHE_LINE_BYTES 6 #endif #endif /* CLIB_LOG2_CACHE_LINE_BYTES defined */ #if (CLIB_LOG2_CACHE_LINE_BYTES >= 9) #error Cache line size 512 bytes or greater #endif #define CLIB_CACHE_LINE_BYTES (1 << CLIB_LOG2_CACHE_LINE_BYTES) #define CLIB_CACHE_LINE_ALIGN_MARK(mark) u8 mark[0] __attribute__((aligned(CLIB_CACHE_LINE_BYTES)))
在編譯器沒有指定cache line大小的情況下,我們將它指定成64位元組。不允許編譯器指定的cache line超過256位元組。
cache line bytes指的是一次性從記憶體讀入到CPU快取中的位元組數目。CPU訪問自己內部的快取比訪問記憶體的效率高得多。
cache line對齊的目的是,減少cache失效的次數,避免無畏的效能降低。
/* Default cache line fill buffers. */ #ifndef CLIB_N_PREFETCHES #define CLIB_N_PREFETCHES 16 #endif /* Read/write arguments to __builtin_prefetch. */ #define CLIB_PREFETCH_READ 0 #define CLIB_PREFETCH_LOAD 0 /* alias for read */ #define CLIB_PREFETCH_WRITE 1 #define CLIB_PREFETCH_STORE 1 /* alias for write */ #define _CLIB_PREFETCH(n,size,type) \ if ((size) > (n)*CLIB_CACHE_LINE_BYTES) \ __builtin_prefetch (_addr + (n)*CLIB_CACHE_LINE_BYTES, \ CLIB_PREFETCH_##type, \ /* locality */ 3); #define CLIB_PREFETCH(addr,size,type) \ do { \ void * _addr = (addr); \ \ ASSERT ((size) <= 4*CLIB_CACHE_LINE_BYTES); \ _CLIB_PREFETCH (0, size, type); \ _CLIB_PREFETCH (1, size, type); \ _CLIB_PREFETCH (2, size, type); \ _CLIB_PREFETCH (3, size, type); \ } while (0) #undef _
對指定的記憶體塊,進行預先讀取,或者預先寫入。提升效率。