From patchwork Thu Oct 26 19:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 56285 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D5433882AC2 for ; Thu, 26 Oct 2023 19:15:23 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id 81FC538618C2 for ; Thu, 26 Oct 2023 19:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81FC538618C2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 81FC538618C2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698347685; cv=none; b=mQa9xTb0LiZzl4CJT8wtK4NAtRmN7EZz7Ey9Lnhg11H/gmDFLcXW1J9h04rCOOM9Fmd+uIXDfzM+FAJ9fg/ao8wYF/yNtZOftPLI0j7bU5Sfsjo7GH5raBmCQXZt0ehK+fijui2d/h3M2OkLJ1MVeux8oRHp3ToIKRcnYyXcFmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698347685; c=relaxed/simple; bh=7u7A+iC/6bxmpDHeUngA0jAei224NFLBwu0Mowl1o1c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vR8J86zxQlMeipT4xVhXnNMhmn8xMCSdXgzRzXZfftcg5hTjBqrI8LctAI6lliEurKWakwlgw83bUHUEc7Od6fFrTFRl5AtXtGD6UNh5mb64ejyN+r56xI/wU07TNNoW2cZe1EaSSvKKc+QrxYZKXwbID0pQlP2nsTJJkufHbV8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id w5D2qFvMEKOkLw5oXq6uXI; Thu, 26 Oct 2023 19:14:41 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id w5oWqwzFu5ZLUw5oWqphuO; Thu, 26 Oct 2023 19:14:40 +0000 X-Authority-Analysis: v=2.4 cv=S57KfagP c=1 sm=1 tr=0 ts=653abaa0 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=bhdUkHdE2iEA:10 a=Qbun_eYptAEA:10 a=u0b5Z_p_XDLdDjKux6oA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: To:From:Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hzPYhjnG+sI02DylfSsVsGWkgZrr1OSPSCUL0U7kb6s=; b=iUqA43kdbDpOYRU4jrbJ0Cy4AS G2JZqVM5ICzqa/SakLYXeEY1Q0Et2lxNNPTLCedmLAxsH9uBJqhWRpUk9202HpnJUqGmqhDdv9qh6 j8/tuykKFQqZDryZ4ZmYOqHEl; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:33818 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1qw5oW-004InV-0K for binutils@sourceware.org; Thu, 26 Oct 2023 13:14:40 -0600 From: Tom Tromey To: binutils@sourceware.org Subject: [PATCH 0/3] Threads and BFD Date: Thu, 26 Oct 2023 13:07:48 -0600 Message-ID: <20231026191435.204144-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.77.73 X-Source-L: No X-Exim-ID: 1qw5oW-004InV-0K X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:33818 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGFykNalnGCi9Qoez1gG9+BjtXNiHHFgX14u3sTV/HhzN+l7JzNBSBPxskbDWhDG8OzjP5IwjPYI/m235oqF9CDeBkAQW60VMegHSNe/zdn6h1YT+lPm OgJJfzN4yA2Hy8KTKvQhFa9RB8qc7lnbMt9RzI6qrWPZlPLB3nu5rQ7AfQN5qaTjIlBgCIjtP0SbKADHdcbVljSgFuUg1xFf2dk= X-Spam-Status: No, score=-3018.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org gdb started using threads a while ago. So far we've (mostly) avoided doing anything BFD-related off the main thread, but I would like to change that. In particular, I'd like gdb to do most of its DWARF reading in the background. To achieve this, gdb only really needs threading on a per-BFD basis. That is, all access to any particular BFD will be from a single thread at a given time. However, due to DWO, gdb may also need to create a new BFD from a worker thread. For gdb's purposes, I think only BFD globals really need to be protected. There are a few spots to consider. The first is BFD error handling. In this series, I chose to make it thread-local. This approach seemed simple and straightforward. Locking seemed impractical here. Maybe moving the error into a BFD would work, but I didn't serious investigate that. The second set of globals involve opening and closing BFD, and also the fd cache. I went back and forth on ways to solve this. In this series I let the BFD client provide lock- and unlock-functions, and change BFD to use these when needed. I took this approach because it means that current BFD clients don't need to be changed in any way. (I do have a variant of this patch where BFD implements its own locking using a POSIX or Windows mutex; I can send that if you'd prefer.) I have a larger patch series to implement the background reading in gdb, based on these patches. I've run this under TSAN quite a bit and I think all the races (there were none in BFD, of course) and deadlocks (I found one in my first draft of this patch) have been ironed out. Also, it's worth noting that the approach taken here won't really affect single-threaded BFD users, i.e., everything except gdb. Let me know what you think. Tom