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.133.124]) by sourceware.org (Postfix) with ESMTPS id 0038F385840C for ; Tue, 12 Mar 2024 14:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0038F385840C 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 0038F385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710254359; cv=none; b=Aa1j2tOWkRrLhsZOXHXE/9MXcyh1rOeJYUUbL66Ua8dsq9VqrBArUYaxat981DZTFeS595r3HmjxUh7izi+QaJHdBxqf3kYseieMd0KSd6POeWeR3+BgyC91OncJ7GTtHPMR8M5xi2RT7nisGvyijgooc2j7cZ7xG8DZZkEkKPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710254359; c=relaxed/simple; bh=inw2hymmIYkwqXW8awHqBksI2m4uqXjTF1cQEcQdHcM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZSh1vs11oE2fJVh0iunRYrbTN7XbJ46BkNSmnO/cxnVL+qT5LPjWSVFpnGjzcX1HN0NGw/3RRgWKy8AKRM6Czh6I6mDkkEQQ3A7nRlHuZPmCusdhzn8nwtgeianMAyXk/wNRQr8HcSVAcMbmscVBKheH3koWErS3f/5hqG+ADWc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710254357; 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: in-reply-to:in-reply-to:references:references; bh=RgjEjyPvQtGZWYCIj3APeImyx2eZhe+YaSaBzJz5oc0=; b=USzDPRAXb4c9aAlij09dODRndgYhvirmy1MseIJHiwsZFWA/2nQ7GbZrWbzokCZtlZuElc FFMXbrfkB1Rv4t/t/aCLlwZ87uPTTt+fhsPqB9jxlJWnDuDWwE/hKraleSo9y+RxByO4Sx cuXR20gJ9ssqtd/oMUptoGUmMDfO3IU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-EmavwsmqN3eVt062dTMCLg-1; Tue, 12 Mar 2024 10:39:13 -0400 X-MC-Unique: EmavwsmqN3eVt062dTMCLg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A88180026B; Tue, 12 Mar 2024 14:39:13 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B4621C060A4; Tue, 12 Mar 2024 14:39:12 +0000 (UTC) From: Florian Weimer To: Peng Zheng Cc: libc-alpha@sourceware.org Subject: Re: Priority Inversion and Unlimited Spin of pthread_rwlock_t References: <0e210b7b-5349-41fe-a476-87958990e03e@apache.org> Date: Tue, 12 Mar 2024 15:39:11 +0100 In-Reply-To: <0e210b7b-5349-41fe-a476-87958990e03e@apache.org> (Peng Zheng's message of "Tue, 12 Mar 2024 11:19:53 +0800") Message-ID: <87jzm7tsz4.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,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: * Peng Zheng: > And the SCHED_OTHER writer was just about to enable the `__wrphase_futex` in > `__pthread_rwlock_wrlock_full` (just one ARM instruction away) > but never able to do that (the two readers ate nearly all available CPUs): > > while ((r & PTHREAD_RWLOCK_WRPHASE) == 0 > && (r >> PTHREAD_RWLOCK_READER_SHIFT) == 0) > { > if (atomic_compare_exchange_weak_acquire (&rwlock->__data.__readers, > &r, r | PTHREAD_RWLOCK_WRPHASE)) > { > atomic_store_relaxed (&rwlock->__data.__wrphase_futex, 1); /* writer was stuck HERE! */ > > goto done; > } > /* TODO Back-off. */ > } Is this about filling in the TODO? > Unlimited user space spin is too dangerous to be used, how about > limiting the total number of spins before suspending using futex? Or > using rseq as mentioned in the LWN artible? > [0] https://lwn.net/Articles/944895/ The LWN article does not talk about priority inversion. With rseq, userspace can detect preemption, but that may never happen with certain realtime scheduling priorities. Thanks, Florian