From patchwork Thu Aug 17 13:32:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1822368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RRQtN6nfXz22PN for ; Thu, 17 Aug 2023 23:33:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 87171385DC11 for ; Thu, 17 Aug 2023 13:32:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 3AF103858D35 for ; Thu, 17 Aug 2023 13:32:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AF103858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.01,180,1684828800"; d="diff'?scan'208";a="14696930" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 17 Aug 2023 05:32:42 -0800 IronPort-SDR: brbbPBrAt3f+/Z8sbdj7jrGwTfs1KUXIGV5+lPtlBrJUl4ATvBQZKugwSIAnHns6XbqupKFdIR QE/gXRJ48hK6vNtJPlfL7DJUNWZS9WaUWtuaqtpl4fU7gq9hLj8MjzwTKFgg+R2xqBAvZY8mJo dJjlh2jG5thMaV3EcbJwg0Z89rwj5E5LhzHNoXFyy36pM63KS/uIzV6UUDWpu3Hd2CwtiyReXL 2f8ouJ8LhyK1UJAf6aqleI6h2lijbyjRy4OfFkZSQmOb2dfPGtTtdiRkJx+zxWJott4GVWIQPb lIY= Message-ID: <9cb0b7cb-1049-68c7-e38c-c02553aae7d7@codesourcery.com> Date: Thu, 17 Aug 2023 15:32:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Content-Language: en-US To: gcc-patches From: Tobias Burnus Subject: [committed] libgomp: call numa_available first when using libnuma X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Found when looking at libnuma/libmemkind test issues discussing in https://gcc.gnu.org/PR111024 [The fails of the PR are not fully understood but point towards a buggy libmemkind or combination or libmemkind + other libraries; they only show up recently as before no libgomp testcase checked for interleaved allocation - and on newer Linux systems it does pass.] Calling numa_available() just ensures that the get_mempolicy syscall is available in the Linux kernel, which is likely the case for Linux distros in use, but still it makes sense to play be the rules and to check that that's indeed the case - as recommended/demanded by the (lib)numa manpage. The call is only done once and also only when libnuma is supposed to get used. Committed to mainline as Rev. r14-3287-g8f3c4517b1fff9 Tobias PS: Crossref - some more doc + libmemkind improvements could/should eventually be done. See https://gcc.gnu.org/PR111044 for details. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 commit 8f3c4517b1fff965f2bdedcf376dcfd91cda422b Author: Tobias Burnus Date: Thu Aug 17 15:20:55 2023 +0200 libgomp: call numa_available first when using libnuma The documentation requires that numa_available() is called and only when successful, other libnuma function may be called. Internally, it does a syscall to get_mempolicy with flag=0 (which would return the default policy if mode were not NULL). If this returns -1 (and not 0) and errno == ENOSYS, the Linux kernel does not have the get_mempolicy syscall function; if so, numa_available() returns -1 (otherwise: 0). libgomp/ PR libgomp/111024 * allocator.c (gomp_init_libnuma): Call numa_available; if not available or not returning 0, disable libnuma usage. --- libgomp/allocator.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libgomp/allocator.c b/libgomp/allocator.c index 90f2dcb60d6..b4e50e2ad72 100644 --- a/libgomp/allocator.c +++ b/libgomp/allocator.c @@ -107,28 +107,39 @@ static pthread_once_t libnuma_data_once = PTHREAD_ONCE_INIT; static void gomp_init_libnuma (void) { void *handle = dlopen ("libnuma.so.1", RTLD_LAZY); struct gomp_libnuma_data *data; data = calloc (1, sizeof (struct gomp_libnuma_data)); if (data == NULL) { if (handle) dlclose (handle); return; } + if (handle) + { + int (*numa_available) (void); + numa_available + = (__typeof (numa_available)) dlsym (handle, "numa_available"); + if (!numa_available || numa_available () != 0) + { + dlclose (handle); + handle = NULL; + } + } if (!handle) { __atomic_store_n (&libnuma_data, data, MEMMODEL_RELEASE); return; } data->numa_handle = handle; data->numa_alloc_local = (__typeof (data->numa_alloc_local)) dlsym (handle, "numa_alloc_local"); data->numa_realloc = (__typeof (data->numa_realloc)) dlsym (handle, "numa_realloc"); data->numa_free = (__typeof (data->numa_free)) dlsym (handle, "numa_free"); __atomic_store_n (&libnuma_data, data, MEMMODEL_RELEASE); }