<html><body>
<p><font size="2">Thanks for the replies.</font><br>
<br>
<font size="2">In the Linux Device Drivers book regarding mmap(), it states:</font><br>

<ul><font size="2" face="Birka">Mapping a device means associating a range of user-space addresses to device memory.</font><br>
<font size="2" face="Birka">Whenever the program reads or writes in the assigned address range, it is actually</font><br>
<font size="2" face="Birka">accessing the device. In the X server example, using </font><i><font size="2" face="Birka-Italic">mmap </font></i><font size="2" face="Birka">allows quick and easy</font><br>
<font size="2" face="Birka">access to the video card’s memory. For a performance-critical application like this,</font><br>
<font size="2" face="Birka">direct access makes a large difference.</font><br>
</ul>
<font size="2">For whatever reason, mmap() is definitely not quick and does not appear to be a direct access to device memory. After the application completes a large write into physical memory (via the pointer returned from mmap()), the application performs an ioctl() to query whether the data actually arrived into the memory region. It seems to take some time before the associated kernel module actually "sees" the data in the physical memory region.</font><br>
<br>
<font size="2">There's a few things I should say about this memory region. There's a total of 512 MB of physical memory. U-Boot passes "mem=256M" as a kernel parameter to tell Linux to only directly manage the lower 256 MB. The special region of physical memory that the application is trying to access is the upper 256 MB of memory not directly managed by Linux. The mmap() call from the application is:</font>
<ul><font size="2" face="Courier New">*memptr = (void *) mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, _fdTerAlloc, (off_t) 0x10000000);</font></ul>
<br>
<font size="2">On the kernel module side, the function handling the mmap() file operation is:</font>
<ul><font size="2" face="Courier New">static int ter_alloc_mmap( struct file *pFile, struct vm_area_struct *vma )</font><br>
<font size="2" face="Courier New">{</font><br>
<font size="2" face="Courier New">    if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot))</font><br>
<font size="2" face="Courier New">        return -EAGAIN;</font><br>
<br>
<font size="2" face="Courier New">    vma->vm_ops = &ter_alloc_remap_vm_ops;</font><br>
<font size="2" face="Courier New">    ter_alloc_vma_open(vma);</font><br>
<font size="2" face="Courier New">    return 0;</font><br>
<font size="2" face="Courier New">}</font><br>
</ul>
<font size="2">-Steve Lin</font><br>
<br>
<br>
<img width="16" height="16" src="cid:1__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt="Inactive hide details for David Gibson <david@gibson.dropbear.id.au>"><font size="2">David Gibson <david@gibson.dropbear.id.au></font><br>
<br>
<br>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td style="background-image:url(cid:2__=07BBFD4CDFC430D78f9e8@notes.teradyne.com); background-repeat: no-repeat; " width="40%">
<ul>
<ul>
<ul>
<ul><b><font size="2">David Gibson <david@gibson.dropbear.id.au></font></b><font size="2"> </font>
<p><font size="2">11/18/2010 06:54 AM</font></ul>
</ul>
</ul>
</ul>
</td><td width="60%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="1%"><img width="58" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<div align="right"><font size="2">To</font></div></td><td width="100%"><img width="1" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<font size="2">Michael Ellerman <michael@ellerman.id.au></font></td></tr>

<tr valign="top"><td width="1%"><img width="58" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<div align="right"><font size="2">cc</font></div></td><td width="100%"><img width="1" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<font size="2">steven.lin@teradyne.com, Steven_Lin@notes.teradyne.com, linuxppc-dev@lists.ozlabs.org</font></td></tr>

<tr valign="top"><td width="1%"><img width="58" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<div align="right"><font size="2">Subject</font></div></td><td width="100%"><img width="1" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""><br>
<font size="2">Re: application needs fast access to physical memory</font></td></tr>
</table>

<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="58"><img width="1" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""></td><td width="336"><img width="1" height="1" src="cid:3__=07BBFD4CDFC430D78f9e8@notes.teradyne.com" border="0" alt=""></td></tr>
</table>
</td></tr>
</table>
<br>
<tt><font size="2">On Thu, Nov 18, 2010 at 11:24:22PM +1100, Michael Ellerman wrote:<br>
> On Wed, 2010-11-17 at 16:03 -0600, steven.lin@teradyne.com wrote:<br>
> > My application needs a fast way to access a specific physical DDR<br>
> > memory region. The application runs on an MPC8548 PowerPC which has an<br>
> > MMU. I've tried two approaches that are typical for Linux, mmap() and<br>
> > using a kernel module that implements read()/write() into this region<br>
> > and I'm finding that performance is very slow for both. It's a couple<br>
> > orders of magnitude slower than, for example, copying a large buffer<br>
> > from one place in the application's virtual memory to another place in<br>
> > the application's virtual memory.<br>
> <br>
> The mmap() version should basically run at "full speed", at least once<br>
> you've faulted the address range in.<br>
> <br>
> This specific DDR region isn't specifically slow is it ? :)<br>
<br>
The other theory that springs to mind is whatever method you're using<br>
to access the region enabling cacheing?<br>
<br>
-- <br>
David Gibson                                             | I'll have my music baroque, and my code<br>
david AT gibson.dropbear.id.au           | minimalist, thank you.  NOT _the_ _other_<br>
                                                                 | _way_ _around_!<br>
</font></tt><tt><font size="2"><a href="http://www.ozlabs.org/~dgibson">http://www.ozlabs.org/~dgibson</a></font></tt><tt><font size="2"><br>
[attachment "signature.asc" deleted by Steven Lin/USW/Teradyne] </font></tt><br>
</body></html>