From owner-freebsd-current@freebsd.org Mon Jul 1 17:41:23 2019 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB8C915E0B8B for ; Mon, 1 Jul 2019 17:41:23 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound3d.ore.mailhop.org (outbound3d.ore.mailhop.org [54.186.57.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 15366891AA for ; Mon, 1 Jul 2019 17:41:22 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1562002876; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=fqOa+foTKjVmMfw1xNyHzVDQW2Fa3o1IkYCMeR1AEy26PGFLcuFFc7H8Q46gkTecI2pzY6ip82Lvy Of1OMOHc8fl2ObcRsmy/6H8OxSduCHnG5K2amwhpB4NRzu7l68GIAj0O+AhnUlr3SXeA57XCyIFeJ1 tD5tWVjE3GiEraWLAli8rHfxH9jBp/n7cAoWP1bkMeQbbzxvBBP1jq/rBJ4apiwFUU7Zs9yJwQ1Dal b7iZcQ+RKGT952epWBoLJSa8ShxjEjq70vKm9e3zJXAQsuasMhi4mJhzfo5vaM1YhUxtZkhTN+y1sY Lmic8SdOcgpBKMLr/+OiaBx151X8V8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:dkim-signature:from; bh=Xkf/MkDTZX/qO6EtHE3mRRlNSr88iI8nRb9by0EHOZE=; b=oZeO/QMOFRLhB0xJUr7u6nATyYdXJEPR0Ndc45R9QR48937/iEyx0UulFd/WMYcSuHXVxlvDjx3CD gJUQbl2Nfqs9EDOnoflBOfFesoi0O3QONQNOy2DYIrXBD6YtA+fUXdgVfaefbF2Mmpn3RaOg7DqoCT 60C5eTJw75v4OabcVW85m9UzbbCpNkcdqhvQaLkuj2io0PnaDkyNA+6BBkbMacI+zdjJF5yDasw/37 A06YB+rHcFyFa/dcW+dGQRw+3c7bxaBMwmDmU1mZo7bzmBKvVJc1Un/oB/PBntXABJaX+oAVOyIvtM xdOYUCqbTyUt5PGqCkShrnXYNTogz0A== ARC-Authentication-Results: i=1; outbound3.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:from; bh=Xkf/MkDTZX/qO6EtHE3mRRlNSr88iI8nRb9by0EHOZE=; b=d8s6S7lljPG8cal2m3GvZLDLJOTt8U8GTxQQ1xo4DxVvsJXHiDo3+26NdcThjsElYWqop2xvWRDWS ypaWjzEw+fT/escVjUOxn27r5oJy6QyzHb9dOY2Ve+Qt22t5RU99h7RF+BkP9RYRu4RXHYRRhFG5H+ oyWdGE9uVmhY0nXmlXJ1QXWQiJonM4R6XFlOFBTrSY81iAVZR8ZNZ3W3v9XD9yUfB0w82FGK99tVEb HPdVE/H71BDee06rSQtVx9TTv9KHPG8lAIPcDgBDwyO7IBQSjtTtJQPSPLfxKougO4cMk1Jkpmwepo Ej3nQZxJUC9xipK6d6jGchkMfSvovvA== X-MHO-RoutePath: aGlwcGll X-MHO-User: 6b295fcf-9c27-11e9-90d7-2f7ae9aadc99 X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (unknown [67.177.211.60]) by outbound3.ore.mailhop.org (Halon) with ESMTPSA id 6b295fcf-9c27-11e9-90d7-2f7ae9aadc99; Mon, 01 Jul 2019 17:41:14 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id x61HfCmf075111; Mon, 1 Jul 2019 11:41:12 -0600 (MDT) (envelope-from ian@freebsd.org) Message-ID: <291f26bcc4b4b30cda4f5b23855e889aa5883ee3.camel@freebsd.org> Subject: Re: i2c bit banging timeout for SCL From: Ian Lepore To: Warner Losh , Poul-Henning Kamp Cc: Andriy Gapon , FreeBSD Current Date: Mon, 01 Jul 2019 11:41:12 -0600 In-Reply-To: References: <7e5d8a06bc2d46263262369464e9348b82263847.camel@freebsd.org> <93148.1562001288@critter.freebsd.dk> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 15366891AA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.99)[-0.989,0]; ASN(0.00)[asn:16509, ipnet:54.186.0.0/15, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 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: Mon, 01 Jul 2019 17:41:24 -0000 On Mon, 2019-07-01 at 11:25 -0600, Warner Losh wrote: > On Mon, Jul 1, 2019 at 11:14 AM Poul-Henning Kamp > > wrote: > > > -------- > > In message < > > CANCZdfoFBvmxPtnEL4GOqXTvp6Zd-xrtja4rmUO1rAcy0JdeSw@mail.gmail.com> > > , > > Warner Losh writes: > > > > > The only issue, really, is that this timeout is a busy loop and > > > there may > > > be I/O bus contention introduced on these systems. > > > > Does it have to be a busy loop for the entire duration ? > > > > Spin for the median, timeout+poll for the rest of the time ? > > > > That's a good suggestion. I'd be inclined to spin for 1 tick or so, > then do > a timeout per tick after that (eg, shift from DELAY to pause(1)). It > won't > be super accurate or high performance, but when the devices are slow, > that > would add only a little extra time. > > Ideally, that's what we'd do. In the short term, bumping the timeout > wouldn't be horrible. > > Warner Most of the DELAY() in i2c bitbang is just the idle time before toggling the clock line to achieve the 100khz bus rate. That's a 10us delay, and on modern hardware those delays should be pause() calls because that's enough time to get useful work done. When polling for ack at the end of a byte, using a DELAY(1) loop makes more sense (actually, just polling without delay may make even more sense, since DELAY() is generally just polling a clock register). Hmm, actually, it looks like iicbb hardcodes the bus frequency delay as 10us and delays after every toggle, so I guess it's really running the bus at 50khz. -- Ian