From patchwork Wed Oct 14 20:56:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1382349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=OeI6SJLK; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CBPpp4R3Lz9sTr for ; Thu, 15 Oct 2020 07:56:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E1223951415; Wed, 14 Oct 2020 20:56:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E1223951415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1602708992; bh=76bUIilpQb/a+LtP8aw79tqO9KFwTa0aWP0dLRP+AF0=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OeI6SJLKeqhGr36G5b7Z4BpTVW9ejYBukCPFRdgWl5qbxGAsORVkBnBdZRX46tUM3 cibPABkg5B8n8rjd3HBAYM+xj1/pcMmL56tneawLU/ngqZVVxLUXfiL8rnd+X3OnSq KzBQLD8MIil4Cbs/301L7i4WgHRcDeYyhuBwp0Hw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 993353950C59 for ; Wed, 14 Oct 2020 20:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 993353950C59 Received: by mail-ej1-x635.google.com with SMTP id p5so507745ejj.2 for ; Wed, 14 Oct 2020 13:56:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=76bUIilpQb/a+LtP8aw79tqO9KFwTa0aWP0dLRP+AF0=; b=H6kUKvp84+/1I5JWYtt/HeCgr78EqXVWLjQ9jmEGXkPIpQ73ihUAF808+MA1460NTd GjgKujAcA6igfd3Evee+Bx6bbRxnuV57+JWanQCBflbiwz7b86SmBR+DbJ5qQrYZeONa nK125a9Uahm02Id0+tVhCzEoAmcDUfS1IaeaRj+daWznu1M3WVvec7aB+MguxliMNlDH QbXyj9Fyipg36N0SJyhPHmGBpfXGjiUBZgm3GGNRqQDUkuIuC99yp3/+zlQHphEWzAfM XnUMdKjc9EInvg75XDwpkMs0aL12dc7wZpfex90ROpamfsHEVGHvFZwpPRpim2+nswV/ GvNQ== X-Gm-Message-State: AOAM533aJROIINKA2T1Gkm9eCg8iniWmLB5WucaIwzXbXy9ExH68a9tB 6DJQvXqNrRngUtkicgz+TWcR/Pb9QjdkACxlOuSMuUiuUeOfGg== X-Google-Smtp-Source: ABdhPJy3lEt+gC8c0mChX6YFzbsOZ69z7tG05Zs40O3WugzdEAUvH0uRJJblnkOgan8KUTY3gGWnK7UfQ9I66UgXL+E= X-Received: by 2002:a17:906:1644:: with SMTP id n4mr1028281ejd.332.1602708987834; Wed, 14 Oct 2020 13:56:27 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 14 Oct 2020 13:56:16 -0700 Message-ID: Subject: libgo patch committed: correct semaphore implementation on NetBSD To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This libgo patch by Nikhil Benesch corrects the semaphore implementation on NetBSD. NetBSD's semaphores use the underlying lighweight process mechanism (LWP) on NetBSD, rather than pthreads. This means the m.prodcid needs to be set to the LWP ID rather than the pthread ID in order for unpark notifications to get sent to the right place. This introduces a new getProcID() method that selects the correct ID for the platform. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 05bc5d61b7a25381684b92932592f134a940135f diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 2c7a9bde825..c37df37db51 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -6cb7b9e924d84125f21f4a2a96aa0d59466056fe +c5505c4e626fa4217911443b4db8b065855a0206 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/runtime/os_aix.go b/libgo/go/runtime/os_aix.go index 951aeb6cffd..f49b83ccbe4 100644 --- a/libgo/go/runtime/os_aix.go +++ b/libgo/go/runtime/os_aix.go @@ -21,6 +21,10 @@ type mOS struct { waitsema uintptr // semaphore for parking on locks } +func getProcID() uint64 { + return uint64(gettid()) +} + //extern malloc func libc_malloc(uintptr) unsafe.Pointer diff --git a/libgo/go/runtime/os_gccgo.go b/libgo/go/runtime/os_gccgo.go index ab190229860..a8859c085a3 100644 --- a/libgo/go/runtime/os_gccgo.go +++ b/libgo/go/runtime/os_gccgo.go @@ -27,8 +27,7 @@ func mpreinit(mp *m) { func minit() { minitSignals() - // FIXME: only works on linux for now. - getg().m.procid = uint64(gettid()) + getg().m.procid = getProcID() } // Called from dropm to undo the effect of an minit. diff --git a/libgo/go/runtime/os_hurd.go b/libgo/go/runtime/os_hurd.go index b3c6f8062ca..1613b410e2c 100644 --- a/libgo/go/runtime/os_hurd.go +++ b/libgo/go/runtime/os_hurd.go @@ -18,6 +18,10 @@ type mOS struct { waitsema uintptr // semaphore for parking on locks } +func getProcID() uint64 { + return uint64(gettid()) +} + //extern malloc func libc_malloc(uintptr) unsafe.Pointer diff --git a/libgo/go/runtime/os_linux.go b/libgo/go/runtime/os_linux.go index 5d550646715..627b6d6d43c 100644 --- a/libgo/go/runtime/os_linux.go +++ b/libgo/go/runtime/os_linux.go @@ -13,6 +13,10 @@ type mOS struct { unused byte } +func getProcID() uint64 { + return uint64(gettid()) +} + func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32 { return int32(syscall(_SYS_futex, uintptr(addr), uintptr(op), uintptr(val), uintptr(ts), uintptr(addr2), uintptr(val3))) } diff --git a/libgo/go/runtime/os_netbsd.go b/libgo/go/runtime/os_netbsd.go index 69d2c710449..89a8d076f12 100644 --- a/libgo/go/runtime/os_netbsd.go +++ b/libgo/go/runtime/os_netbsd.go @@ -14,12 +14,19 @@ type mOS struct { waitsemacount uint32 } +func getProcID() uint64 { + return uint64(lwp_self()) +} + +//extern _lwp_self +func lwp_self() int32 + //go:noescape -//extern lwp_park +//extern _lwp_park func lwp_park(ts int32, rel int32, abstime *timespec, unpark int32, hint, unparkhint unsafe.Pointer) int32 //go:noescape -//extern lwp_unpark +//extern _lwp_unpark func lwp_unpark(lwp int32, hint unsafe.Pointer) int32 //go:noescape @@ -88,7 +95,7 @@ func semasleep(ns int64) int32 { tsp = &ts } ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil) - if ret == _ETIMEDOUT { + if ret != 0 && errno() == _ETIMEDOUT { return -1 } } @@ -101,10 +108,10 @@ func semawakeup(mp *m) { // "If the target LWP is not currently waiting, it will return // immediately upon the next call to _lwp_park()." ret := lwp_unpark(int32(mp.procid), unsafe.Pointer(&mp.waitsemacount)) - if ret != 0 && ret != _ESRCH { + if ret != 0 && errno() != _ESRCH { // semawakeup can be called on signal stack. systemstack(func() { - print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " ret=", ret, "\n") + print("thrwakeup addr=", &mp.waitsemacount, " sem=", mp.waitsemacount, " errno=", errno(), "\n") }) } } diff --git a/libgo/go/runtime/os_solaris.go b/libgo/go/runtime/os_solaris.go index 63b5cd70c8c..c568629e566 100644 --- a/libgo/go/runtime/os_solaris.go +++ b/libgo/go/runtime/os_solaris.go @@ -10,6 +10,10 @@ type mOS struct { waitsema uintptr // semaphore for parking on locks } +func getProcID() uint64 { + return uint64(gettid()) +} + //extern malloc func libc_malloc(uintptr) unsafe.Pointer