Samuel Thibault
2009-Oct-21 15:36 UTC
[Xen-devel] Re: [Xen-changelog] [xen-unstable] stubdom: mmap on /dev/mem support
Xen patchbot-unstable, le Wed 21 Oct 2009 08:10:15 -0700, a écrit :> + unsigned long mfns[n]; > + for (i = 0; i < n; i++) > + mfns[i] = ((unsigned long) offset + (i * PAGE_SIZE)) >> PAGE_SHIFT;Mmm, is there a reason for adding (i*PAGE_SIZE) before right-shifting?> + return map_frames_ex(mfns, n, 1, 0, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW);Actually I think the whole could just be unsigned long first_mfn = offset >> PAGE_SHIFT; return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); which avoids the need to prepare a table. Samuel _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Stefano Stabellini
2009-Oct-21 15:57 UTC
Re: [Xen-devel] Re: [Xen-changelog] [xen-unstable] stubdom: mmap on /dev/mem support
On Wed, 21 Oct 2009, Samuel Thibault wrote:> Xen patchbot-unstable, le Wed 21 Oct 2009 08:10:15 -0700, a écrit : > > + unsigned long mfns[n]; > > + for (i = 0; i < n; i++) > > + mfns[i] = ((unsigned long) offset + (i * PAGE_SIZE)) >> PAGE_SHIFT; > > Mmm, is there a reason for adding (i*PAGE_SIZE) before right-shifting? > > > + return map_frames_ex(mfns, n, 1, 0, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); > > Actually I think the whole could just be > > unsigned long first_mfn = offset >> PAGE_SHIFT; > return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); > > which avoids the need to prepare a table.Yeah, you are right. Both versions are fine for me. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Samuel Thibault
2009-Oct-21 16:13 UTC
Re: [Xen-devel] Re: [Xen-changelog] [xen-unstable] stubdom: mmap on /dev/mem support
Optimize mmap(open("/dev/mem")) Set map_frames_ex''s stride parameter to 0 and increment to 1 to avoid building an explicit list of mfns. Signed-Off-By: Samuel Thibault <samuel.thibault@ens-lyon.org> diff -r 37829fd7c1e3 extras/mini-os/lib/sys.c --- a/extras/mini-os/lib/sys.c Wed Oct 21 16:08:28 2009 +0100 +++ b/extras/mini-os/lib/sys.c Wed Oct 21 18:10:33 2009 +0200 @@ -1256,11 +1268,8 @@ unsigned long zero = 0; return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0); } else if (files[fd].type == FTYPE_MEM) { - int i; - unsigned long mfns[n]; - for (i = 0; i < n; i++) - mfns[i] = ((unsigned long) offset + (i * PAGE_SIZE)) >> PAGE_SHIFT; - return map_frames_ex(mfns, n, 1, 0, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); + unsigned long first_mfn = offset >> PAGE_SHIFT; + return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); } else ASSERT(0); } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel