From nobody Fri May 16 05:31:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1500474965437866.0329748597119; Wed, 19 Jul 2017 07:36:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7440E7EBC3; Wed, 19 Jul 2017 14:36:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F3066292E; Wed, 19 Jul 2017 14:36:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B4FAC27C; Wed, 19 Jul 2017 14:35:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6JEWSJO024133 for ; Wed, 19 Jul 2017 10:32:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E625D7BCAE; Wed, 19 Jul 2017 14:32:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F55D7BCD0 for ; Wed, 19 Jul 2017 14:32:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7440E7EBC3 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7440E7EBC3 From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 16:31:48 +0200 Message-Id: <47463b42bbf9799d925ac627c2a037a82f045f3a.1500474525.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] virthread: Introduce virRWLockInitPreferWriter X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 19 Jul 2017 14:36:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We already have virRWLockInit. But this uses pthread defaults which prefer reader to initialize the RW lock. This may lead to writer starvation. Therefore we need to have the counterpart that prefers writers. Now, according to the pthread_rwlockattr_setkind_np() man page setting PTHREAD_RWLOCK_PREFER_WRITER_NP attribute is no-op. Therefore we need to use PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP attribute. So much for good enum value names. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virthread.c | 35 +++++++++++++++++++++++++++++++++++ src/util/virthread.h | 1 + 3 files changed, 37 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 187b12b32..a792e00c8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2728,6 +2728,7 @@ virMutexUnlock; virOnce; virRWLockDestroy; virRWLockInit; +virRWLockInitPreferWriter; virRWLockRead; virRWLockUnlock; virRWLockWrite; diff --git a/src/util/virthread.c b/src/util/virthread.c index 6c495158f..a8dd72f8b 100644 --- a/src/util/virthread.c +++ b/src/util/virthread.c @@ -95,6 +95,15 @@ void virMutexUnlock(virMutexPtr m) } =20 =20 +/** + * virRWLockInit: + * @m: rwlock to init + * + * Initializes RW lock using pthread default attributes (which + * is PTHREAD_RWLOCK_PREFER_READER_NP). + * + * Returns 0 on success, -1 otherwise. + */ int virRWLockInit(virRWLockPtr m) { int ret; @@ -106,6 +115,32 @@ int virRWLockInit(virRWLockPtr m) return 0; } =20 + +/** + * virRWLockInitPreferWriter: + * @m: rwlock to init + * + * Initializes RW lock which prefers writers over readers. + * + * Returns 0 on success, -1 otherwise. + */ +int virRWLockInitPreferWriter(virRWLockPtr m) +{ + int ret; + pthread_rwlockattr_t attr; + + pthread_rwlockattr_init(&attr); + pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONR= ECURSIVE_NP); + ret =3D pthread_rwlock_init(&m->lock, &attr); + pthread_rwlockattr_destroy(&attr); + if (ret !=3D 0) { + errno =3D ret; + return -1; + } + return 0; +} + + void virRWLockDestroy(virRWLockPtr m) { pthread_rwlock_destroy(&m->lock); diff --git a/src/util/virthread.h b/src/util/virthread.h index e466d9bf0..18b785af2 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -136,6 +136,7 @@ void virMutexUnlock(virMutexPtr m); =20 =20 int virRWLockInit(virRWLockPtr m) ATTRIBUTE_RETURN_CHECK; +int virRWLockInitPreferWriter(virRWLockPtr m) ATTRIBUTE_RETURN_CHECK; void virRWLockDestroy(virRWLockPtr m); =20 void virRWLockRead(virRWLockPtr m); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list