From owner-freebsd-drivers@freebsd.org Sun Sep 6 18:03:16 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E75839CC1CC for ; Sun, 6 Sep 2015 18:03:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5B037792 for ; Sun, 6 Sep 2015 18:03:16 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t86I3B8v006620 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 6 Sep 2015 21:03:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua t86I3B8v006620 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t86I3BUI006619; Sun, 6 Sep 2015 21:03:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 6 Sep 2015 21:03:11 +0300 From: Konstantin Belousov To: Leonardo Fogel Cc: freebsd-drivers@freebsd.org Subject: Re: Memory barrier Message-ID: <20150906180311.GS2072@kib.kiev.ua> References: <2149458.2Hg3JbBXY3@ralph.baldwin.cx> <1441547636.78646.YahooMailBasic@web120801.mail.ne1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1441547636.78646.YahooMailBasic@web120801.mail.ne1.yahoo.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Sep 2015 18:03:17 -0000 On Sun, Sep 06, 2015 at 06:53:56AM -0700, Leonardo Fogel wrote: > Hi. > Please, what are the correct barriers for the following cases? > > Case 1: > bus_write_1(region_0, ...); > /* barrier here */ > DELAY(some_time); > > Case 2: > bus_write_1(region_0, ...); > /* barrier here */ > bus_write_1(region_2, ...); > > In the first one, I want the write to reach the device before the thread busy-waits. As I understand it, bus_space_barrier(9) is not adequate, because it does not prevent the processor from executing instructions (or load/store to RAM) before the write completes. > > In the second one, I want the write to a device (e.g. power management) to complete before the write to another starts/completes. Again, bus_space_barrier() seems not to be adequate because it can not cover two regions. I believe that the bus_write semantic includes the required serialization. E.g., on x86 all CPU write buffers are flushed before the write instruction is declared completed, because this is the semantic of the uncacheable memory. For powerpc, the system automatically inserts powerpc_iomb() after the write, which is full sync. I am not aware of other architectures.