我正在研究基于pcie的网络驱动程序。不同的示例使用pci_alloc_consistent或dma_alloc_coherent中的一个来获取用于传输和接收描述符的内存。哪一个更好,如果有的话,两者有什么区别?
发布于 2015-01-02 23:26:08
两者之间的差别是微妙的,但非常重要。pci_alloc_consistent()是这两种功能中较旧的一种,遗留驱动程序仍然使用它。现在,pci_alloc_consistent()只打电话给dma_alloc_coherent()。
区别是什么?分配的内存的类型。
pci_alloc_consistent() -分配GFP_ATOMIC类型的内存。分配不睡觉,用于例如中断处理程序,底部半部。dma_alloc_coherent()- -您可以自己指定要分配的内存类型。您不应该使用高优先级的GFP_ATOMIC内存,除非您需要它,而且在大多数情况下,您对GFP_KERNEL分配都很满意。内核3.18 pci_alloc_consistent()的定义非常简单,即:
static inline void *
pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
dma_addr_t *dma_handle)
{
return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
}简而言之,请使用dma_alloc_coherent()。
https://stackoverflow.com/questions/27677452
复制相似问题