From nobody Wed May 14 21:33:49 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 1516382625837527.5004701735627; Fri, 19 Jan 2018 09:23:45 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84F65C07F9B1; Fri, 19 Jan 2018 17:23:44 +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 5839C60BE7; Fri, 19 Jan 2018 17:23:44 +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 2047C410B3; Fri, 19 Jan 2018 17:23:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0JHNMox003666 for ; Fri, 19 Jan 2018 12:23:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0B01E5C543; Fri, 19 Jan 2018 17:23:22 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCD535C25E for ; Fri, 19 Jan 2018 17:23:21 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 19 Jan 2018 12:23:06 -0500 Message-Id: <20180119172311.15525-5-jferlan@redhat.com> In-Reply-To: <20180119172311.15525-1-jferlan@redhat.com> References: <20180119172311.15525-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/9] util: Introduce virThreadPoolDrain 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 17:23:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a mechanism to allow the domain/server quit code to be able to cause any pending jobs to be be purged and request current workers to quit. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virthreadpool.c | 64 ++++++++++++++++++++++++++++++++++++++++----= ---- src/util/virthreadpool.h | 2 ++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bc8cc1fba..6ffceb46b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2865,6 +2865,7 @@ virThreadJobSetWorker; =20 =20 # util/virthreadpool.h +virThreadPoolDrain; virThreadPoolFree; virThreadPoolGetCurrentWorkers; virThreadPoolGetFreeWorkers; diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 10f2bd2c3..0baa05d12 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -30,9 +30,12 @@ #include "viralloc.h" #include "virthread.h" #include "virerror.h" +#include "virlog.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 +VIR_LOG_INIT("util.threadpool"); + typedef struct _virThreadPoolJob virThreadPoolJob; typedef virThreadPoolJob *virThreadPoolJobPtr; =20 @@ -93,6 +96,24 @@ static inline bool virThreadPoolWorkerQuitHelper(size_t = count, size_t limit) return count > limit; } =20 + +static void +virThreadPoolJobRemove(virThreadPoolPtr pool, + virThreadPoolJobPtr job) +{ + if (job->prev) + job->prev->next =3D job->next; + else + pool->jobList.head =3D job->next; + if (job->next) + job->next->prev =3D job->prev; + else + pool->jobList.tail =3D job->prev; + + pool->jobQueueDepth--; +} + + static void virThreadPoolWorker(void *opaque) { struct virThreadPoolWorkerData *data =3D opaque; @@ -152,16 +173,7 @@ static void virThreadPoolWorker(void *opaque) pool->jobList.firstPrio =3D tmp; } =20 - if (job->prev) - job->prev->next =3D job->next; - else - pool->jobList.head =3D job->next; - if (job->next) - job->next->prev =3D job->prev; - else - pool->jobList.tail =3D job->prev; - - pool->jobQueueDepth--; + virThreadPoolJobRemove(pool, job); =20 virMutexUnlock(&pool->mutex); (pool->jobFunc)(job->data, pool->jobOpaque); @@ -307,6 +319,38 @@ void virThreadPoolFree(virThreadPoolPtr pool) } =20 =20 +/* + * virThreadPoolDrain: + * @pool: Pointer to thread pool + * + * Cause any pending job to be purged and notify the current workers + * of the impending quit. + */ +void +virThreadPoolDrain(virThreadPoolPtr pool) +{ + virMutexLock(&pool->mutex); + + VIR_DEBUG("nWorkers=3D%zd, nPrioWorkers=3D%zd jobQueueDepth=3D%zd", + pool->nWorkers, pool->nPrioWorkers, pool->jobQueueDepth); + + while (pool->jobList.head !=3D pool->jobList.tail) { + virThreadPoolJobPtr job =3D pool->jobList.head; + + virThreadPoolJobRemove(pool, job); + VIR_FREE(job); + } + + pool->quit =3D true; + if (pool->nWorkers > 0) + virCondBroadcast(&pool->cond); + if (pool->nPrioWorkers > 0) + virCondBroadcast(&pool->prioCond); + + virMutexUnlock(&pool->mutex); +} + + size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool) { size_t ret; diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h index e1f362f5b..c54b166b1 100644 --- a/src/util/virthreadpool.h +++ b/src/util/virthreadpool.h @@ -52,6 +52,8 @@ size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr poo= l); =20 void virThreadPoolFree(virThreadPoolPtr pool); =20 +void virThreadPoolDrain(virThreadPoolPtr pool); + int virThreadPoolSendJob(virThreadPoolPtr pool, unsigned int priority, void *jobdata) ATTRIBUTE_NONNULL(1) --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list