From owner-freebsd-arch@FreeBSD.ORG Thu Apr 9 06:14:54 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BBB3258C; Thu, 9 Apr 2015 06:14:54 +0000 (UTC) Received: from mail-wg0-x22d.google.com (mail-wg0-x22d.google.com [IPv6:2a00:1450:400c:c00::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5F669BC2; Thu, 9 Apr 2015 06:14:54 +0000 (UTC) Received: by wgbdm7 with SMTP id dm7so109422587wgb.1; Wed, 08 Apr 2015 23:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=Kt82c2Y7Fi6dloPDczuFMn5c6Rb0tMk5OwpSZegWwQY=; b=ROdZfEM3B1tVaqd9JHmNKKRvhFwvTiuFsNbiYZ9DFNMDhPixgV2ddriFgBiYw7cY1+ uBYOqar4ABV3T5oMJDTXyiAt1oS2+NzJBmTgvpZ1u7EmvfeggZkqJnRZJdjzhmbzzb2T CK0jVkjHaFe6DFlBQnPWRQbvOt2f4xJxVYGZNtITiie3rPuKzI60BOq3oLpvtkpvrmPo fM23m6PDn/4kquQbZKXUrWvW4wJ8s9MyIAJnxV70RVaEHdDcsQqBL8WEciH9H1Yslixz vL88DMWk0N4w6cgL2S2zMiarVZFVlgKL1P/kAEVvKkXSCkVHY0WpyzlrXipXoIDUFMvP WVCQ== X-Received: by 10.180.96.65 with SMTP id dq1mr3232088wib.46.1428560092972; Wed, 08 Apr 2015 23:14:52 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id e2sm18643873wij.5.2015.04.08.23.14.51 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 08 Apr 2015 23:14:51 -0700 (PDT) Date: Thu, 9 Apr 2015 08:14:49 +0200 From: Mateusz Guzik To: freebsd-arch@freebsd.org Subject: Re: atomic ops Message-ID: <20150409061448.GB6086@dft-labs.eu> References: <20141028025222.GA19223@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20141028025222.GA19223@dft-labs.eu> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Attilio Rao , adrian@freebsd.org, Konstantin Belousov , Alan Cox X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Apr 2015 06:14:54 -0000 On Tue, Oct 28, 2014 at 03:52:22AM +0100, Mateusz Guzik wrote: [scratching old content so that I hopefully re-state it nicer] I would like to reviwe the discussion about memory barriers provided in the kernel. The kernel (at least on amd64) lacks lightweight barriers providing only following guarantees: - all writes are completed prior to given point - all reads are completed prior to given point On amd64 such barriers require only compiler barrier, and as such obviously beat currently used operations like load_acq (which uses cmpxchg). Example consumer which would benefit greatly from such barriers is seq.h: https://svnweb.freebsd.org/base/head/sys/sys/seq.h?view=markup _load_acq on amd64 provides full barrier and it was noted we should not change that in order to not break possible 3rd party consumers. Also I don't see any alternative naming convention trying to stick to this scheme that we could use. As such I propose stealing naming from Linux and introduction of smp_wmb and smp_rmb macros providing aforementioned funcionality. So for amd64 this would be: #define smp_wmb() __compiler_membar() #define smp_rmb() __compiler_membar() Any objections? I'm happy to talk to arch maintainers in order to get relevant implementations for all architectures. -- Mateusz Guzik