From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CF3D8385782F for ; Wed, 6 Dec 2023 11:28:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF3D8385782F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CF3D8385782F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701862082; cv=none; b=df/ZC3Hx9cP73dQrZlELmM3/pgfUPTXjLdA3hTVcxiY0+bUXI96zLdmEyyTRyakLYObO5dEWrpPSOnOBFkQClq3B0LglJh9BI93gqUA33h3r4n2uyoHlqWh/a6cTWjetVhDneDvFzjEPBC9cYvitmf/A8yc1ckyspKshWiUC9mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701862082; c=relaxed/simple; bh=sneoGYqYAOPwcvNPsD6ycy/bjDxFjwIks2Un1prblL8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vY6IyvbxuZQdHjONueHbPCI7hq5CLDZD1KHWI8v/pJCaOQp3dVJx4qR4i03jYIx/0nQ3AatA5DZUN1aAY1gMEiwZNRwlOrkbU1bhM9HOw+FELTw8Ca5ZpLrsHhWnb3zsiZyQwMW9E9v2fQR071mlB3fNh0UOkpRsZj92fk0X8X0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701862080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Mu/w4WyRmy6XSP7+g4SjdEmhH0t1Ly5zYVjYelDIjM=; b=ONJ8yiL6705N1q90fLjxOztOLipbRg+ZbV8vk6O5bxnWgrlTDug2SeVY3XdkQYy0FnXz/0 0mw8eD0eCEDk/C2jLZExI727IpL3rM0nK0dNU2+0BGEhel3JM6Na10v/CFrrpNrGHh/ers J2aWtoj2Z7+xHI4FGFnSZ683rjXg9YM= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-503-nB17mRQzOfevxy4xHYESzQ-1; Wed, 06 Dec 2023 06:27:58 -0500 X-MC-Unique: nB17mRQzOfevxy4xHYESzQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-334adbe43acso149223f8f.0 for ; Wed, 06 Dec 2023 03:27:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701862077; x=1702466877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Mu/w4WyRmy6XSP7+g4SjdEmhH0t1Ly5zYVjYelDIjM=; b=YrQZVY9JN8XVJjEsKHxdQY9WsStx7strGgCBR7R+uVkFZytOVY8ReTMhMsFHYFmuif QD+o/Nq52HOP5iYRG+eIcNtyPXOdzFNHIBSIrSPJhaAANMhZK/l4ly+huYVTO7uhsIVD lPQmJwiY/sAJqMVq/+ozNldhdIbHsqTK7fzW3hVC9RowqKaCCHuFEfLBY/8hv8cb1ZJZ MytbOAYlAJzhZY3HnwO6WeLiekBnqvmT+RZYwtM0jZ17oZBVBqISsWlFdojvPU0UVXYY ARDSCyC8zB83NHHhl0IqgDlGPg5QPdxrtiLnqWUPsGQjPT7SDudhdd9D/r1B0XGjG1hR KRJA== X-Gm-Message-State: AOJu0YzIEOQD94+Nz0mPSoFW9DWoTJSwF4QbHGU9ew8SuShzUWJzzVMu QDcoYMR1L7wa7FV4Qpc/VaiTFD/6TIlEIl8QfYtG29RBQxt1r5+b9QNJGCGYIKl2D1/x4M1YSzu TCuE2LrtDUp9gyoZwcznc1pxty0TrxVpnvjQfbYz8UDAkcFP0sDuuZLTg3vOIPxXHY0JqIZUvWP CJ8nCBBA== X-Received: by 2002:a05:600c:5490:b0:40b:5e4a:235c with SMTP id iv16-20020a05600c549000b0040b5e4a235cmr1309062wmb.94.1701862077256; Wed, 06 Dec 2023 03:27:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFL1orVaLiO1zTELOt5aEWIhjQJaTCCi+YZSyy21a39OEd6FkvtAx21zlFeriS0IDOybOiUzg== X-Received: by 2002:a05:600c:5490:b0:40b:5e4a:235c with SMTP id iv16-20020a05600c549000b0040b5e4a235cmr1309051wmb.94.1701862076847; Wed, 06 Dec 2023 03:27:56 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id d7-20020a05600c3ac700b0040b632f31d2sm16620856wms.5.2023.12.06.03.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:27:56 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Richard Bunt , Tom Tromey Subject: [PUSHED] gdb: fix libstdc++ assert caused by invalid use of std::clamp Date: Wed, 6 Dec 2023 11:26:33 +0000 Message-Id: <5a22e042e41db962cd6a79cd59cab46cbbe58a98.1701861952.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20231124161321.572511-3-richard.bunt@linaro.org> References: <20231124161321.572511-3-richard.bunt@linaro.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: After this commit: commit 33ae45434d0ab1f7de365b9140ad4e4ffc34b8a2 Date: Mon Dec 4 14:23:17 2023 +0000 gdb: Enable early init of thread pool size I am now seeing this assert from libstdc++: /usr/include/c++/9/bits/stl_algo.h:3715: constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&) [with _Tp = int]: Assertion '!(__hi < __lo)' failed. This may only be visible because I compile with: -D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1 but I haven't checked. The issue the assert is highlighting is real, and is caused by this block of code: if (n_threads < 0) { const int hardware_threads = std::thread::hardware_concurrency (); /* Testing in #29959 indicates that parallel efficiency drops between n_threads=5 to 8. Therefore, clamp the default value to 8 to avoid an excessive number of threads in the pool on many-core systems. */ const int throttle = 8; n_threads = std::clamp (hardware_threads, hardware_threads, throttle); } The arguments to std::clamp are VALUE, LOW, HIGH, but in the above, if we have more than 8 hardware threads available the LOW will be greater than the HIGH, which is triggering the assert I see above. I believe std::clamp is the wrong tool to use here. Instead std::min would be a better choice; we want the smaller value of HARDWARE_THREADS or THROTTLE. If h/w threads is 2, then we want 2, but if h/w threads is 16 we want 8, this is what std::min gives us. After this commit, I no longer see the assert. --- gdb/maint.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gdb/maint.c b/gdb/maint.c index 2e6754c9558..68b70bf403d 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -855,11 +855,12 @@ update_thread_pool_size () if (n_threads < 0) { const int hardware_threads = std::thread::hardware_concurrency (); - /* Testing in #29959 indicates that parallel efficiency drops between - n_threads=5 to 8. Therefore, clamp the default value to 8 to avoid an - excessive number of threads in the pool on many-core systems. */ - const int throttle = 8; - n_threads = std::clamp (hardware_threads, hardware_threads, throttle); + /* Testing in PR gdb/29959 indicates that parallel efficiency drops + between n_threads=5 to 8. Therefore, use no more than 8 threads + to avoid an excessive number of threads in the pool on many-core + systems. */ + const int max_thread_count = 8; + n_threads = std::min (hardware_threads, max_thread_count); } gdb::thread_pool::g_thread_pool->set_thread_count (n_threads); base-commit: b17ef9dcd8d16eedf4e60565cd7701698b5a0b6b -- 2.25.4