From patchwork Wed Jun 23 18:45:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 56701 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 91BDBB6F10 for ; Thu, 24 Jun 2010 04:46:18 +1000 (EST) Received: (qmail 8019 invoked by alias); 23 Jun 2010 18:46:15 -0000 Received: (qmail 8010 invoked by uid 22791); 23 Jun 2010 18:46:14 -0000 X-SWARE-Spam-Status: No, hits=-5.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 23 Jun 2010 18:46:09 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5NIk7YG024292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 23 Jun 2010 14:46:08 -0400 Received: from stone.twiddle.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5NIk7Zj017376; Wed, 23 Jun 2010 14:46:07 -0400 Message-ID: <4C22565B.60704@redhat.com> Date: Wed, 23 Jun 2010 11:45:47 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Thunderbird/3.0.5 MIME-Version: 1.0 To: GCC Patches CC: patrick.marlier@unine.ch Subject: [trans-mem] Fix concurrency error in libitm free page list X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Patrick Marlier pointed out that there was an ABA error in managing the page free list. Fixed by not trying to be so clever. r~ * config/posix/cachepage.cc (gtm_cacheline_page::operator new): Use a mutex instead of trying a lock-free compare-and-swap on the list. (gtm_cacheline_page::operator delete): Likewise. diff --git a/libitm/config/posix/cachepage.cc b/libitm/config/posix/cachepage.cc index 9888ef5..240d09f 100644 --- a/libitm/config/posix/cachepage.cc +++ b/libitm/config/posix/cachepage.cc @@ -136,6 +136,7 @@ init_alloc_page (void) #endif static gtm_cacheline_page *free_pages; +static pthread_mutex_t free_page_lock = PTHREAD_MUTEX_INITIALIZER; void * gtm_cacheline_page::operator new (size_t size) @@ -143,19 +144,14 @@ gtm_cacheline_page::operator new (size_t size) assert (size == sizeof (gtm_cacheline_page)); assert (size <= PAGE_SIZE); + pthread_mutex_lock(&free_page_lock); + gtm_cacheline_page *r = free_pages; - restart: - if (r) - { - gtm_cacheline_page *n, *p = r->prev; - n = __sync_val_compare_and_swap (&free_pages, r, p); - if (n != r) - { - r = n; - goto restart; - } - } - else + free_pages = r ? r->prev : NULL; + + pthread_mutex_unlock(&free_page_lock); + + if (r == NULL) r = alloc_page (); return r; @@ -165,7 +161,7 @@ void gtm_cacheline_page::operator delete (void *xhead) { gtm_cacheline_page *head = static_cast(xhead); - gtm_cacheline_page *tail, *n, *p; + gtm_cacheline_page *tail; if (head == 0) return; @@ -175,15 +171,12 @@ gtm_cacheline_page::operator delete (void *xhead) for (tail = head; tail->prev != 0; tail = tail->prev) continue; - p = free_pages; - restart: - tail->prev = p; - n = __sync_val_compare_and_swap (&free_pages, p, head); - if (n != p) - { - p = n; - goto restart; - } + pthread_mutex_lock(&free_page_lock); + + tail->prev = free_pages; + free_pages = head; + + pthread_mutex_unlock(&free_page_lock); } } // namespace GTM