From owner-freebsd-current@FreeBSD.ORG Wed Aug 29 04:12:45 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D20A10656B7; Wed, 29 Aug 2012 04:12:45 +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 BEB138FC15; Wed, 29 Aug 2012 04:12:44 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q7T4CqFS084106; Wed, 29 Aug 2012 07:12:53 +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.5/8.14.5) with ESMTP id q7T4Ce6W070292; Wed, 29 Aug 2012 07:12:40 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q7T4CeRQ070291; Wed, 29 Aug 2012 07:12:40 +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: Wed, 29 Aug 2012 07:12:40 +0300 From: Konstantin Belousov To: Luigi Rizzo Message-ID: <20120829041240.GT33100@deviant.kiev.zoral.com.ua> References: <20120827073403.GA49223@onelab2.iet.unipi.it> <201208271227.54785.jhb@freebsd.org> <20120828155025.GA66068@onelab2.iet.unipi.it> <201208281240.29612.jhb@freebsd.org> <20120828172606.GR33100@deviant.kiev.zoral.com.ua> <20120828184226.GB68683@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AFXWwd8AV04RZu1u" Content-Disposition: inline In-Reply-To: <20120828184226.GB68683@onelab2.iet.unipi.it> 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=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: Andriy Gapon , freebsd-current@freebsd.org, current@freebsd.org Subject: Re: per file descriptor device callbacks ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Aug 2012 04:12:45 -0000 --AFXWwd8AV04RZu1u Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 28, 2012 at 08:42:26PM +0200, Luigi Rizzo wrote: > On Tue, Aug 28, 2012 at 08:26:06PM +0300, Konstantin Belousov wrote: > ... > > > dev_clone() is rather gross and a lot harder to use than > > > devfs_set_cdevpriv(). If you are fine with the inherent problems > > > of the device pager (you can't ever make mappings go away), you can > > > just assign each client a unique offset into your shared object's > > > memory space. However, if you are exporting shared memory buffers, > > > then a better model might be to let your clients use > > > shm_open(SHM_ANON) to create buffers, then pass them into your driver > > > via an ioctl() and use shm_map() to map them into the kernel. > >=20 > > Well, there is a new OBJT_MGTDEVICE pager, which together with > > d_mmap_single() allows to have even per-mapping data. i915kms uses it. > > You do not need cdevpriv for the per-mapping data. > >=20 > > Also, MGTDEVICE does track the mappings of the pages, so you can clean > > up on device destruction. >=20 > interesting, thanks for the pointer, i'll look it up in i915kms. > Does this exist also in stable/9 ? > It would be a shame otherwise... Yes, it was merged. >=20 > > Normal callbacks of the device pager allows to execute ctr/dtr methods > > at the time of mapping creation and tear down. >=20 > what would be a good way to install my own ctr/dtr methods ? > I only found out a rather crude one, and it only works for > the destructor: See below. >=20 > static struct cdev_pager_ops saved_cdev_pager_ops; > static struct cdev_pager_ops netmap_cdev_pager_ops; >=20 > static void > netmap_dev_pager_dtor(void *handle) > { > saved_cdev_pager_ops.cdev_pg_dtor(handle); > // my code here > D("ready to release memory for %p", handle); > } >=20 >=20 > static int > netmap_mmap_single(struct cdev *cdev, vm_ooffset_t *foff, > vm_size_t objsize, vm_object_t *objp, int prot) > { > vm_object_t obj; > =20 > /* XXX check size etc. */ > obj =3D vm_pager_allocate(OBJT_DEVICE, cdev, objsize, prot, *foff, > curthread->td_ucred); Use cdev_pager_allocate(). > if (obj =3D=3D NULL) > return EINVAL; > if (saved_cdev_pager_ops.cdev_pg_fault =3D=3D NULL) { I do not understand what are you trying to accomplish with the check and reinitialization, but I assume that cdev_pager_allocate() would take care of it. > D("initialize cdev_pager_ops"); > saved_cdev_pager_ops =3D *(obj->un_pager.devp.ops); > netmap_cdev_pager_ops =3D *(obj->un_pager.devp.ops); > netmap_cdev_pager_ops.cdev_pg_dtor =3D netmap_dev_pager_d= tor; > }; > obj->un_pager.devp.ops =3D &netmap_cdev_pager_ops; > *objp =3D obj; > /* XXX perhaps do something more here, such as install > * mappings for the pages so we have no faults later. > */ > return 0; > } >=20 > static struct cdevsw netmap_cdevsw =3D { > .d_version =3D D_VERSION, > .d_name =3D "netmap", > .d_open =3D netmap_open, > .d_mmap =3D netmap_mmap, > .d_mmap_single =3D netmap_mmap_single, > .d_ioctl =3D netmap_ioctl, > .d_poll =3D netmap_poll, > .d_close =3D netmap_close, > }; >=20 > cheers > luigi --AFXWwd8AV04RZu1u Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlA9lrgACgkQC3+MBN1Mb4jP6ACcCMmlQWybZzcQ0E46r0W8QO0i C+cAnR+5HSBZ7TIswEPM7MATirJuZQfP =iv01 -----END PGP SIGNATURE----- --AFXWwd8AV04RZu1u--