Chinaunix
标题:
dma分配中coherent 和 noncoherent区别是什么,连续调用dma_alloc_coherent()失败
[打印本页]
作者:
testh
时间:
2012-11-30 16:44
标题:
dma分配中coherent 和 noncoherent区别是什么,连续调用dma_alloc_coherent()失败
本帖最后由 testh 于 2012-11-30 19:11 编辑
熟悉的请讲讲。
连续调用两次dma_alloc_coherent(NULL,1024*1024,&addr,GFP_KERNEL)只有第一次成功,后面的就会失败,这是什么原因导致的呢?
代码如下:
dma_addr_t addr[2];
unsigned char *vir[2];
static int __init testmacro_init(void)
{
int i;
printk("enter init\n");
for(i=0;i<2;i++)
{
vir[i]=dma_alloc_coherent(NULL,1024,&addr[i],GFP_KERNEL);
if(vir[i]==NULL)
{
printk("alloc error\n");
return -1;
}
else
{
printk("alloc ok,addr[0]=[0x%x],vir[0]=[0x%x]\n",addr[i],vir[i]);
}
}
return 0;
}
module_init(testmacro_init);
static void __exit testmacro_exit(void)
{
int i;
for(i=0;i<2;i++)
{
dma_free_coherent(NULL,1024,vir[i],addr[i]);
}
}
module_exit(testmacro_exit);
复制代码
作者:
amarant
时间:
2012-11-30 18:53
就是对cache一致性的区别。
作者:
testh
时间:
2012-11-30 19:57
将dma_alloc_coherent()申请的空间大小改为512就2次都可以了,后来又改为1024,两次也都可以成功申请。
这样很不稳定呀,如何能保证申请成功呢
作者:
鬼鬼一哈
时间:
2012-11-30 21:53
本帖最后由 鬼鬼一哈 于 2012-11-30 21:55 编辑
dma_alloc_coherent(NULL,1024,&addr
,GFP_KERNEL);你的这个NULL决定了你是从DMA zone分配的(在2.6。27中是,但新内核中好像有改动。忘记差异了。),你用cat /proc/buddy看看你的可用内存,为什么512k容易成功,伙伴算法,你懂的。。。
想要多个4M的DMA区域。要么从DMA32里分,但是每个4M之间不连续,想要连续的。开机内核预留,貌似有个什么bootmem函数什么的。。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2