系统相关
首页 > 系统相关> > linux – 是否有必要由程序员明确刷新组合内存?

linux – 是否有必要由程序员明确刷新组合内存?

作者:互联网

我知道写入组合写入将被缓存,并且不会直接到达内存.
但是,在其他人可以访问之前,程序员是否有必要明确地清除这个内存?

我从图形驱动程序代码中得到了这个问题.例如,CPU填充顶点缓冲区(映射为WC).但在GPU访问之前,我没有在代码中看到任何刷新操作.
架构(x86)已经为我们解决了这个问题吗?关于这个的更详细的文件?

解决方法:

根据英特尔®64和IA-32架构软件开发人员手册,第3A卷:系统编程指南,第1部分(2012年8月版,但这不应该更改),第11.3.1节,必须刷新缓冲区:

The protocol for evicting the WC buffers is implementation dependent and should not be relied on by software for system memory coherency. When using the WC memory type, software must be sensitive to the fact that the writing of data to system memory is being delayed and must deliberately empty the WC buffers when system memory coherency is required.

如果图形驱动程序实际上没有刷新写入组合缓冲区,那么它们取决于系统特定的时序和/或缓冲区大小(假设后续的WC写入将被分配给缓冲区,这在架构上没有保证).这可能在普通工作负载下的现有系统上工作(或似乎工作),但在架构上保证不起作用.

由于广泛的序列化事件将刷新写入组合缓冲区,因此很可能存在刷新操作/事件但不明显(如SFENCE所示).英特尔®64和IA-32架构软件开发人员手册(版本052,2014年9月),第3卷,第11.3节可用的缓存方法:

If the WC buffer is partially filled, the writes may be delayed until the next occurrence of a serializing event; such as, an SFENCE or MFENCE instruction, CPUID execution, a read or write to uncached memory, an interrupt occurrence, or a LOCK instruction execution.

例如,写入GPU寄存器(如果映射到未缓存的存储器)将刷新写入组合缓冲区.

标签:linux,graphics,architecture,cpu-cache
来源: https://codeday.me/bug/20190824/1713557.html