将数据写入 PCIe 设备时,可以使用写入组合映射来提示 CPU 应该向设备生成 64 字节的 TLP。
是否可以为读取做类似的事情?以某种方式提示 CPU 读取整个缓存行或更大的缓冲区,而不是一次读取一个字?
最佳答案
英特尔有 a white-paper on copying from video RAM to main memory ;这应该是相似的,但要简单得多(因为数据适合 2 或 4 个向量寄存器)。
它说 NT 加载会将整个缓存行数据从 WC 内存拉入 LFB:
Ordinary load instructions pull data from USWC memory in units of the same size the instruction requests. By contrast, a streaming load instruction such as MOVNTDQA will commonly pull a full cache line of data to a special "fill buffer" in the CPU. Subsequent streaming loads would read from that fill buffer, incurring much less delay.
使用 AVX2
_mm256_stream_load_si256()
或 SSE4.1/AVX1 128 位版本。填充缓冲区是一种有限的资源,因此您肯定希望编译器生成 asm 来执行 64 字节缓存行的两个对齐加载,然后存储到常规内存中。
如果您一次处理多个 64 字节块,请参阅 Intel 的白皮书,了解有关使用在 L1d 中保持热态的小型反弹缓冲区的建议,以避免将存储与 NT 负载混合到 DRAM。 (到 DRAM 的 L1d 驱逐,如 NT 存储,也需要行填充缓冲区,LFB)。
请注意
_mm256_stream_load_si256()
对 WC 以外的内存类型根本没有用。 NT 提示在当前硬件上被忽略,但与常规负载相比,它无论如何都要花费额外的 ALU uop。有prefetchnta
,但那是完全不同的野兽。
关于x86 - 从 x86 CPU 生成 64 字节读取 PCIe TLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51918804/