From owner-svn-src-head@FreeBSD.ORG Fri Oct 24 19:33:16 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B9741BDF; Fri, 24 Oct 2014 19:33:16 +0000 (UTC) Received: from st11p02mm-asmtp001.mac.com (st11p02mm-asmtp001.mac.com [17.172.220.236]) (using TLSv1 with cipher DES-CBC3-SHA (112/168 bits)) (Client CN "smtp.me.com", Issuer "VeriSign Class 3 Extended Validation SSL SGC CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 85A591FF; Fri, 24 Oct 2014 19:33:15 +0000 (UTC) Received: from st11p02mm-spool002.mac.com ([17.172.220.247]) by st11p02mm-asmtp001.mac.com (Oracle Communications Messaging Server 7u4-27.10(7.0.4.27.9) 64bit (built Jun 6 2014)) with ESMTP id <0NDY00JY0RN68T20@st11p02mm-asmtp001.mac.com>; Fri, 24 Oct 2014 19:33:08 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52,1.0.28,0.0.0000 definitions=2014-10-24_06:2014-10-24,2014-10-24,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1408290000 definitions=main-1410240163 MIME-version: 1.0 Received: from localhost ([17.172.220.161]) by st11p02mm-spool002.mac.com (Oracle Communications Messaging Server 7u4-27.08(7.0.4.27.7) 64bit (built Aug 22 2013)) with ESMTP id <0NDY00FD7RN7A660@st11p02mm-spool002.mac.com>; Fri, 24 Oct 2014 19:33:07 +0000 (GMT) To: Konstantin Belousov From: Rui Paulo Subject: Re: svn commit: r273598 - in head: include sys/dev/acpica Date: Fri, 24 Oct 2014 19:33:07 +0000 (GMT) X-Mailer: iCloud MailClient14G39 MailServer14G.17174 X-Originating-IP: [12.218.212.178] Message-id: <33decfcd-e77c-4e4c-8161-9f4a232213c6@me.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Rui Paulo X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Oct 2014 19:33:16 -0000 On Oct 24, 2014, at 12:20 PM, Konstantin Belousov wr= ote:=0A=0AOn Fri, Oct 24, 2014 at 06:39:16PM +0000, Rui Paulo wrote:=0A> A= uthor: rpaulo=0A> Date: Fri Oct 24 18:39:15 2014=0A> New Revision: 273598=0A= > URL: https://svnweb.freebsd.org/changeset/base/273598=0A> =0A> Log:=0A> = HPET: create /dev/hpetN as a way to access HPET from userland.=0A> =0A> In= some cases, TSC is broken and special applications might benefit=0A> from= memory mapping HPET and reading the registers to count time.=0A> Most oft= en the main HPET counter is 32-bit only[1], so this only gives=0A> the app= lication a 300 second window based on the default HPET=0A> interval.=0A> O= ther applications, such as Intel's DPDK, expect /dev/hpet to be=0A> presen= t and use it to count time as well.=0A> =0A> Although we have an almost us= erland version of gettimeofday() which=0A> uses rdtsc in userland, it's no= t always possible to use it, depending=0A> on how broken the multi-socket = hardware is.=0AYes, and hpet userland mapping would be better handled thro= ugh the same=0Afake-vdso framework. As designed, it has discriminator to i= nform=0Auserspace about algorithm, and can happilly utilize HPET timecount= er=0Aautomatically mapped by kernel into the process address space.=0A=C2=A0= =0AI'm aware of that, but I found the vdso a bit confusing and decided to = work on that later.=0A=0A> +static int=0A> +hpet_open(struct cdev *cdev, i= nt oflags, int devtype, struct thread *td)=0A> +{=0A> + =C2=A0 =C2=A0 =C2=A0= struct hpet_softc *sc;=0A> +=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0sc =3D cdev-= >si_drv1;=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!sc->mmap_allow)=0A> + =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0return (EPERM);=0A> + =C2=A0 =C2=A0 =C2=A0if (= atomic_cmpset_32(&sc->devinuse, 0, 1) =3D=3D 0)=0A> + =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0return (EBUSY);=0AThis is extra-weird.=0AThe devinuse= business disallows simultaneous opens, which prevents=0Aother process fro= m opening and mapping. But if the original caller=0Adoes mmap and close, s= econd process now is allowed to open and mmap.=0A=0AThat said, why do you = need this devinuse at all ?=0A=C2=A0=0AHmm, I wanted to avoid multiple mma= p's, but that doesn't work like you said. =C2=A0I may just remove this res= triction.=C2=A0=0A=0A> +static int=0A> +hpet_mmap(struct cdev *cdev, vm_oo= ffset_t offset, vm_paddr_t *paddr,=0A> + int nprot, vm_memattr_t *memattr)= =0A> +{=0A> + =C2=A0 =C2=A0struct hpet_softc *sc;=0A> +=0A> + =C2=A0 =C2=A0= sc =3D cdev->si_drv1;=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (offset > rman_g= et_size(sc->mem_res))=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0return (EINVAL);=0A> + =C2=A0 =C2=A0if (!sc->mmap_allow_write && (n= prot & PROT_WRITE))=0A> + =C2=A0 =C2=A0 =C2=A0return (EPERM);=0A> + =C2=A0= =C2=A0 =C2=A0*paddr =3D rman_get_start(sc->mem_res) + offset;=0AWhat is t= he memattr for the backing page ? Is it set to non-cached=0Amode somehow ?= I was not able to find place where would this happen.=0A=C2=A0=0AI expect= it to be set to non-cached since it's a device anyway, but I don't know w= here it is. =C2=A0During my testing, I did not see any problems with cache= d values, though.=0A=0A> + =C2=A0sc->pdev =3D make_dev(&hpet_cdevsw, 0, UI= D_ROOT, GID_WHEEL,=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 0600, "hpet%d", devic= e_get_unit(dev));=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (sc->pdev) {=0A> + =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sc->pdev->si_drv1 =3D = sc;=0A> + =C2=A0 =C2=A0 =C2=A0sc->mmap_allow =3D 1;=0A> + =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TUNABLE_INT_FETCH("hw.acpi.hpet.mmap= _allow",=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &sc->mmap_allow);= =0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sc->mmap_allow_write =3D 1= ;=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0TUNABLE_INT_FETCH("hw.acp= i.hpet.mmap_allow_write",=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 &sc->mmap_allow_write);=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),=0A> + =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SYSCTL_CHILDREN(devic= e_get_sysctl_tree(dev)),=0A> + =C2=A0 =C2=A0 =C2=A0 OID_AUTO, "mmap_allow"= ,=0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 CTLFLAG_RW, &sc->mmap_allow, 0,= =0A> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "Allow user= land to memory map HPET");=0AWhy is mmap_allow is per-instance, while mmap= _allow_write taken from=0Athe global tunable ?=0A=C2=A0=0AAre you asking w= hy there's no sysctl for it?=