From patchwork Wed Dec 12 19:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1012221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-492287-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xpEkm+Fd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43FS535sRyz9s2P for ; Thu, 13 Dec 2018 06:47:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=GLIes CMaynrmocn9fgMfTheSWvFO96MKXKywNVLQ5rQkSvLakIa2csvGl6CKx9vqMJcYg MXn5DrvzpXyq6p5if3dSRWIYSdnsl7gpGiIY2kk4BEs0SjaDm2/EFMiAj642+von KD3vy+xYjK3wr5QAc47vEFQErRbZRrrY6jfupo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=kSAGgd3Zxd/ b0gIzb+Ky0zSlS1A=; b=xpEkm+FdUkrWQ34dln/bb+cA4e0BV6Zb1O68B9P7N2h d3C0oeQEorpQfeqK4sroCgKcUJk7k/fnS+qiPIh0ty+Pe2a5yRwq3tpyntJxM+vL ir/Uc3xhARCX42dHlY6BdusiC6OVQnAkBBWybgRbkaLFrusTLg3R/sHGz1fSatPM = Received: (qmail 85833 invoked by alias); 12 Dec 2018 19:47:12 -0000 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 Received: (qmail 85818 invoked by uid 89); 12 Dec 2018 19:47:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=his X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Dec 2018 19:47:10 +0000 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wBCJhYkg036444 for ; Wed, 12 Dec 2018 14:47:08 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2pb793m0h2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 12 Dec 2018 14:47:08 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 12 Dec 2018 19:47:07 -0000 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 12 Dec 2018 19:47:04 -0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wBCJl3UW29163746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Dec 2018 19:47:03 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE4EE7805F; Wed, 12 Dec 2018 19:47:02 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B79767805C; Wed, 12 Dec 2018 19:47:02 +0000 (GMT) Received: from otta.rchland.ibm.com (unknown [9.10.86.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 12 Dec 2018 19:47:02 +0000 (GMT) To: Segher Boessenkool Cc: GCC Patches From: Peter Bergner Subject: [PATCH, rs6000] Allow libitm to use HTM on newer hw and kernels Date: Wed, 12 Dec 2018 13:47:02 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 x-cbid: 18121219-8235-0000-0000-00000E37B96B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010215; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000270; SDB=6.01130823; UDB=6.00587637; IPR=6.00910956; MB=3.00024670; MTD=3.00000008; XFM=3.00000015; UTC=2018-12-12 19:47:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18121219-8236-0000-0000-000043AE3695 Message-Id: X-IsSubscribed: yes Libitm on POWER hardware looks for the "htm" bit in AT_HWCAP2 to determine whether it can use HTM when executing code within __transaction_atomic code blocks. However, on newer hardware and kernels, the "htm" bit is no longer set and instead the "htm-no-suspend" bit is set, so we currently don't use HTM on new hw and kernels. The following patch adds support for htm-no-suspend to libitm. I have also added code to use the __builtin_cpu_supports() builtin if it is available, since that is much faster than using the getauxval libc call. This passed bootstrap and regtesting with no errors and someone within IBM how had a POWER9 box with a newish kernel how ran into the problem confirmed it works for his test case. Ok for mainline? Should be backport this? Peter * config/powerpc/target.h (PPC_FEATURE2_HTM_NO_SUSPEND): Conditionally define. (htm_available): Add support for PPC_FEATURE2_HTM_NO_SUSPEND. Use __builtin_cpu_supports if available. Index: libitm/config/powerpc/target.h =================================================================== --- libitm/config/powerpc/target.h (revision 267062) +++ libitm/config/powerpc/target.h (working copy) @@ -26,6 +26,11 @@ #include #endif +/* This is a fairly new feature bit, so handle it not being defined. */ +#ifndef PPC_FEATURE2_HTM_NO_SUSPEND +# define PPC_FEATURE2_HTM_NO_SUSPEND 0 +#endif + namespace GTM HIDDEN { typedef int v128 __attribute__((vector_size(16), may_alias, aligned(16))); @@ -81,7 +86,16 @@ cpu_relax (void) static inline bool htm_available (void) { - return (getauxval (AT_HWCAP2) & PPC_FEATURE2_HAS_HTM) ? true : false; +#ifdef __BUILTIN_CPU_SUPPORTS__ + if (__builtin_cpu_supports ("htm-no-suspend") + || __builtin_cpu_supports ("htm")) + return true; +#else + if (getauxval (AT_HWCAP2) + & (PPC_FEATURE2_HAS_HTM | PPC_FEATURE2_HTM_NO_SUSPEND)) + return true; +#endif + return false; } static inline uint32_t