From owner-freebsd-bugs@FreeBSD.ORG Tue Oct 11 19:40:09 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2723B1065673 for ; Tue, 11 Oct 2011 19:40:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id EFB5F8FC0C for ; Tue, 11 Oct 2011 19:40:08 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p9BJe86C075764 for ; Tue, 11 Oct 2011 19:40:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p9BJe8WT075763; Tue, 11 Oct 2011 19:40:08 GMT (envelope-from gnats) Resent-Date: Tue, 11 Oct 2011 19:40:08 GMT Resent-Message-Id: <201110111940.p9BJe8WT075763@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ian Lepore Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BCB40106567A for ; Tue, 11 Oct 2011 19:38:55 +0000 (UTC) (envelope-from ilepore@damnhippie.dyndns.org) Received: from qmta10.emeryville.ca.mail.comcast.net (qmta10.emeryville.ca.mail.comcast.net [76.96.30.17]) by mx1.freebsd.org (Postfix) with ESMTP id A17978FC16 for ; Tue, 11 Oct 2011 19:38:55 +0000 (UTC) Received: from omta21.emeryville.ca.mail.comcast.net ([76.96.30.88]) by qmta10.emeryville.ca.mail.comcast.net with comcast id jSkL1h0031u4NiLAAXeoNM; Tue, 11 Oct 2011 19:38:48 +0000 Received: from damnhippie.dyndns.org ([24.8.232.202]) by omta21.emeryville.ca.mail.comcast.net with comcast id jXle1h00L4NgCEG8hXleuj; Tue, 11 Oct 2011 19:45:38 +0000 Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id p9BJcrmD013487 for ; Tue, 11 Oct 2011 13:38:53 -0600 (MDT) (envelope-from ilepore@damnhippie.dyndns.org) Received: (from ilepore@localhost) by revolution.hippie.lan (8.14.4/8.14.4/Submit) id p9BJcrU0082757; Tue, 11 Oct 2011 13:38:53 -0600 (MDT) (envelope-from ilepore) Message-Id: <201110111938.p9BJcrU0082757@revolution.hippie.lan> Date: Tue, 11 Oct 2011 13:38:53 -0600 (MDT) From: Ian Lepore To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: gnu/161499: [patch] Use FreeBSD's atomic.h if no cpu-specific code is available X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ian Lepore List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Oct 2011 19:40:09 -0000 >Number: 161499 >Category: gnu >Synopsis: [patch] Use FreeBSD's atomic.h if no cpu-specific code is available >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Oct 11 19:40:08 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Ian Lepore >Release: FreeBSD 8.2-STABLE arm >Organization: Symmetricom, Inc. >Environment: FreeBSD tflex 8.2-STABLE FreeBSD 8.2-STABLE #29: Tue Oct 11 13:32:35 UTC 2011 root@revolution.hippie.lan:/usr/obj/arm/usr/src/sys/TFLEX arm >Description: The attached patch adds contrib/libstdc++/config/os/bsd/freebsd/atomicity.h which implements the libstdc++ atomic ops in terms of FreeBSD's atomic.h, and changes the Makefile to use this implementation when a cpu-specific implementation is not available. On the ARM platform this give us fast atomic ops using the ARM RAS routines instead of generic pthread mutexes. It may confer similar benefits on other non-x86 platforms. I created this file by cloning an existing atomicity.h and replacing the guts of each function. I left the original GPL license block from the file I started with in place, but I'm not sure that's appropriate; perhaps it should be BSD-licensed. I personally don't wish to assert any copyright or license of my own, so please feel free to change the license block to whatever makes the most sense. >How-To-Repeat: N/A >Fix: --- libstdcpp_atomicity.diff begins here --- diff -r 8c63128f0de0 -r 18d5166659aa gnu/lib/libstdc++/Makefile --- gnu/lib/libstdc++/Makefile Mon Aug 01 17:47:21 2011 -0600 +++ gnu/lib/libstdc++/Makefile Tue Aug 02 09:55:50 2011 -0600 @@ -77,6 +77,8 @@ MARCHDIR= ${MACHINE_ARCH} .if exists(${SRCDIR}/config/cpu/${MARCHDIR}/atomicity.h) ATOMICITY_H= ${SRCDIR}/config/cpu/${MARCHDIR}/atomicity.h +.elif exists(${SRCDIR}/config/os/bsd/freebsd/atomicity.h) +ATOMICITY_H= ${SRCDIR}/config/os/bsd/freebsd/atomicity.h .else ATOMICITY_H= ${SRCDIR}/config/cpu/generic/atomicity_mutex/atomicity.h .endif --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ contrib/libstdc++/config/os/bsd/freebsd/atomicity.h Tue Aug 02 09:55:50 2011 -0600 @@ -0,0 +1,73 @@ +// Low-level functions for atomic operations: FreeBSD MI version -*- C++ -*- + +// Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include + +/* The FreeBSD machine/atomic.h header defines fast atomic math operations + * appropriate to the target hardware (handling SMP vs. non-SMP, etc). + * However, it defines everything in terms of unsigned 32 bit operands. + * We can safely cast away the unsignedness to keep the compiler happy, + * as long as GCC's _Atomic_word is 32 bits (hence the CTASSERT below). + * I'd like to use FreeBSD's CTASSERT macro, but it lives in a header + * that has eleventymillion dependencies, so it's just pasted in here. + */ + +extern "C" +{ +#include +#include +#include +} + +#ifndef CTASSERT +#define CTASSERT(x) _CTASSERT(x, __LINE__) +#define _CTASSERT(x, y) __CTASSERT(x, y) +#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] +#endif + +CTASSERT(sizeof(_Atomic_word) == sizeof(uint32_t)); + + +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add (volatile _Atomic_word* __mem, int __val) + { + return (_Atomic_word) ::atomic_fetchadd_32((uint32_t *)__mem, (uint32_t)__val); + } + + void + __attribute__ ((__unused__)) + __atomic_add (volatile _Atomic_word* __mem, int __val) + { + ::atomic_add_32((uint32_t *)__mem, (uint32_t)__val); + } + +_GLIBCXX_END_NAMESPACE --- libstdcpp_atomicity.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: