From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9553EC433E0 for ; Tue, 9 Mar 2021 12:54:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1731E64F25 for ; Tue, 9 Mar 2021 12:54:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1731E64F25 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dme.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJbsu-0004bp-4B for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 07:54:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJaz6-00088t-11 for qemu-devel@nongnu.org; Tue, 09 Mar 2021 06:57:08 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:40841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJaz4-0006iL-Ix for qemu-devel@nongnu.org; Tue, 09 Mar 2021 06:57:07 -0500 Received: by mail-wm1-x331.google.com with SMTP id y124-20020a1c32820000b029010c93864955so5752378wmy.5 for ; Tue, 09 Mar 2021 03:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=to:cc:subject:in-reply-to:references:from:date:message-id :mime-version; bh=D00tlaWh0D0zg6qfxP2WbPIE21o6XC5zlMKsk7pUCPs=; b=tMJexgtHnnPpNNeClaml0RRcQ2H5lkL0OegszX2av8VaZvqCz4v5Lc6MBqzu9M5PxH b89HjZpY8TTCZOA6KGrfVWNpPXf1n7KU0FmXm152XpplFCOEQu5uUq8HxXz0kcqGB/3r IoCZ4eUdlX3DEDJRCqyoPO+Ym7+JSNcu7gZjQol7r1EAJdUTp+j41QpFnnI1buBPc04U DmVRaRZz/on9R5l7+ju1/1PHeQc0PArAsZhaDuiF03W1lvKEJRf+6SA72c5GjBZ8Br5j sDgQfZRDDHCf1fYQLo0pAiTmmalq51EaSxlkwFKo5H9Vgj4c3Gs3HkSvzbSK+kh8fF2m yhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:subject:in-reply-to:references:from:date :message-id:mime-version; bh=D00tlaWh0D0zg6qfxP2WbPIE21o6XC5zlMKsk7pUCPs=; b=HTV10RS7/WNxaJkrTzekPt6aeFDGLuLeSPHtR6WIAGdR9pk7hrnow4Av6J5mrWFYyF 0x5Y4Csyx8sjGTSCl5GgepwJQ99sD2CVSPE84UONWUCLWxONyApPbR6ZF5Pc8VjhG4/D A9PZmUN7l8S5gOvaNA+HUbE/SzE9ZrtY0aV4TmVB9Ctk9kO8l7ANBzoAylEtjbpihZNm BV4lsqEbNKZiieVkP40jMoYuzsRu2fb6LZRG8xOx5eLIrQpQsfjfpa17doaDE4AT35Jb mQEbZ1vt7d65PfgnGdKRCW7eoXdXCNc4zUuZJ1lCcEwRIXRxxDToNUF5Ls2dsGRHOIOa PGkA== X-Gm-Message-State: AOAM533Ih+Y3SNlaOTuXjEo+htEnJ/Kc3Ol1CNbPI8hHBCiUW7Ur4kVD f1hv2ayEgc33Yv5rHRwJZJI73g== X-Google-Smtp-Source: ABdhPJyg6LX7foEPfqUTufkfMZvPRp4d1hTVkNkcOygDZyMF1CDIqaJ2lFuRiDJNt0DHymEJ6gkCTA== X-Received: by 2002:a05:600c:2945:: with SMTP id n5mr3652857wmd.78.1615291024034; Tue, 09 Mar 2021 03:57:04 -0800 (PST) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [2001:8b0:bb71:7140:64::1]) by smtp.gmail.com with ESMTPSA id h20sm3580413wmp.38.2021.03.09.03.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 03:57:03 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 48118348; Tue, 9 Mar 2021 11:57:02 +0000 (UTC) To: Paolo Bonzini , qemu-devel@nongnu.org Subject: Re: [RFC PATCH 4/4] coroutine/rwlock: Wake writers in preference to readers In-Reply-To: <8de7f2e6-825f-a803-cf12-870559b5e787@redhat.com> References: <20210309102157.365356-1-david.edmondson@oracle.com> <20210309102157.365356-5-david.edmondson@oracle.com> <8de7f2e6-825f-a803-cf12-870559b5e787@redhat.com> X-HGTTG: heart-of-gold From: David Edmondson Date: Tue, 09 Mar 2021 11:57:02 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: neutral client-ip=2a00:1450:4864:20::331; envelope-from=dme@dme.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefan Weil , Stefan Hajnoczi , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tuesday, 2021-03-09 at 12:06:22 +01, Paolo Bonzini wrote: > On 09/03/21 11:21, David Edmondson wrote: >> - /* The critical section started in qemu_co_rwlock_wrlock. */ >> - qemu_co_queue_restart_all(&lock->queue); >> + /* The critical section started in qemu_co_rwlock_wrlock or >> + * qemu_co_rwlock_upgrade. >> + */ >> + qemu_co_queue_restart_all(&lock->wqueue); >> + qemu_co_queue_restart_all(&lock->rqueue); > > Hmm, the devil is in the details---this is a thundering herd waiting to > happen. But fortunately this can be fixed while making the unlock > primitive even simpler: > > if (lock->reader) { > self->locks_held--; > > /* Read-side critical sections do not keep lock->mutex. */ > qemu_co_mutex_lock(&lock->mutex); > lock->reader--; > assert(lock->reader >= 0); > } > > /* If there are no remaining readers wake one waiting writer > * or all waiting readers. > */ > if (!lock->reader && !qemu_co_queue_next(&lock->wqueue)) { > assert(!lock->pending_writer); > qemu_co_queue_restart_all(&lock->rqueue); > } That's a nice improvement, I agree. I'll roll it into another revision and work on a test. dme. -- But uh oh, I love her because, she moves in her own way.