From owner-freebsd-multimedia@FreeBSD.ORG Mon May 9 18:12:49 2011 Return-Path: Delivered-To: multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 45A2C1065670; Mon, 9 May 2011 18:12:49 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 58D5A8FC12; Mon, 9 May 2011 18:12:47 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p49ICi3R080225 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 9 May 2011 21:12:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id p49ICiLc076649; Mon, 9 May 2011 21:12:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id p49IChGJ076648; Mon, 9 May 2011 21:12:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 9 May 2011 21:12:43 +0300 From: Kostik Belousov To: John Baldwin Message-ID: <20110509181243.GI48734@deviant.kiev.zoral.com.ua> References: <4DC3B764.4030801@FreeBSD.org> <201105090945.05130.jhb@freebsd.org> <201105091338.25086.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sF4+LqaTi7T9hg64" Content-Disposition: inline In-Reply-To: <201105091338.25086.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_20, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: alc@freebsd.org, freebsd-current@freebsd.org, Andriy Gapon , multimedia@freebsd.org Subject: Re: dsp mmap change X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2011 18:12:49 -0000 --sF4+LqaTi7T9hg64 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 09, 2011 at 01:38:24PM -0400, John Baldwin wrote: > On Monday, May 09, 2011 11:35:07 am Alan Cox wrote: > > On Mon, May 9, 2011 at 8:45 AM, John Baldwin wrote: > >=20 > > > On Saturday, May 07, 2011 3:16:25 pm Kostik Belousov wrote: > > > > On Fri, May 06, 2011 at 04:16:40PM -0400, John Baldwin wrote: > > > > > On Friday, May 06, 2011 10:04:28 am Kostik Belousov wrote: > > > > > > On Fri, May 06, 2011 at 04:38:00PM +0300, Andriy Gapon wrote: > > > > > > > on 06/05/2011 16:32 Kostik Belousov said the following: > > > > > > > > On Fri, May 06, 2011 at 11:55:00AM +0300, Andriy Gapon wrot= e: > > > > > > > >> > > > > > > > >> I would like to ask for a review and/or testing of the fol= lowing > > > patch: > > > > > > > >> http://people.freebsd.org/~avg/dev_dsp_mmap.diff > > > > > > > >> > > > > > > > >> It's supposed to fix an issue described here: > > > > > > > >> http://lists.freebsd.org/pipermail/freebsd-multimedia/2011- > > > > > February/011691.html > > > > > > > >> > > > > > > > >> In short, the following pseudo-code should do the right th= ing: > > > > > > > >> fd =3D open(/dev/dsp, O_RDWR); > > > > > > > >> mmap(PROT_READ, fd); > > > > > > > >> mmap(PROT_WRITE, fd); > > > > > > > >> > > > > > > > >> Thank you! > > > > > > > > > > > > > > > > I think that you have to call PCM_GIANT_LEAVE() when return= ing > > > > > > > > EINVAL on the vm_pager_alloc() failure. > > > > > > > > > > > > > > Yes, thank you. > > > > > > > > > > > > > > > Your patch hardcodes an assumption that sndbufs are always > > > > > > > > contiguous. I was unable to convince myself that this is tr= ue. > > > > > > > > > > > > > > I think that this should be true for the case when DMA is use= d? > > > > > > In the current driver, yes, but there is nothing that theoretic= ally > > > > > > prevents scatter-gather from be used. > > > > > > > > > > You could "fix" this by creating an sglist (via sglist_build()) a= nd an > > > > > OBJT_SG VM object that the d_mmap_single callback returned. I wi= sh > > > there > > > > > was a cleaner way to just create a VM object and populate it with= pages > > > > > though, and then use vm_map_insert() to map it into the kernel ra= ther > > > > > than the more roundabout method of OBJT_SG. > > > > > > > > You cannot have one page inserted into two vm objects. Contigmalloc= () > > > > inserts the allocated pages into kernel_object. > > > > > > Yes, I would want to allocate N unmapped pages and stuff them into a = VM > > > object that can then be mapped into the kernel and/or into user mappi= ngs. > > > This would be a much cleaner approach for the nvidia driver for examp= le. > > > > > > > > There is a relatively new function, vm_object_populate(), that allocate= s a > > collection of pages, inserts them into a vm object, and validates them = for > > use. This function exits in FreeBSD 7.x, 8.x, and HEAD. >=20 > Hmm, is there a way to specify restrictions on the pages allocated simila= r to > what contigmalloc() supports (e.g. being able to allocate pages in the lo= wer > 4GB is something the Nvidia driver needs)? >=20 > IOW, a method about like contigmalloc() that returned a VM object holding > pages meeting the desired restrictions but didn't necessarily map the > pages. kmem_alloc_attr() is close to this except it always inserts the > pages into the kernel_object and always maps the pages into the address s= pace. >=20 For GEM, that needs something very similar, I just allocate the swap object, and then do vm_page_grab() over all range. In fact, I never need the full kernel mapping of the object into the KVA using physical addresses, it is enough to do only per-page temporal mappings with sfbuf. On the other hand, both usermode and kernelmode need to access the pages through the aperture remap. Usermode might need to establish several mappings for one GTT page, and this causes troubles because pmap_remove_all() does not work on the fictitious pages. [You was on Cc:]. Other then that, and the fact that vm_page_grab() cannot satisfy the restrictions on the page placement in the physical space, normal swap object is enough for much more complicated device then Azalia. --sF4+LqaTi7T9hg64 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk3ILpsACgkQC3+MBN1Mb4jaBQCg1MqHxXR0V1xJBvw3N4O4VMRX XqsAn22odtOfnb5vv148fvN+bxC5WnzF =yvE7 -----END PGP SIGNATURE----- --sF4+LqaTi7T9hg64--