From nobody Tue Feb 10 05:46:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591988698; cv=none; d=zohomail.com; s=zohoarc; b=eU4aRsrGKz6KmtL7K0ITLAJqTOibLMQR3+fA822Ytmebk+RjvRuf7n4YzgkP/hVUZ+KMygM7w1LH2zePnKmeUBItACel+n39LwJMGinvqPqi0TDruhY9DyWVEzMwX7AnS8HTNy64fJByRPKSx6bsgnxCSJ6IrvTNg1hwAk+c62c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591988698; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wyd2lV6dHVaHmALDhpJ+ImxFwC2VFtV6fvWZJjaxR+k=; b=dNFS/PJ5NYkBYN6Bvp3crWG8Hikf3p9hCtVIyIlR41gCXdcmQGBMVvd/agT5zPsCFXEq8kpXUo5QjUiHd+72AP2Y5GyDpSYhzXpdXaCh57Un5iAhZZFD2D0VqgXaQwjZTBIIhMo0alv19foIDgyBfdHAo2BWAjwNneuSIqn3ulo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159198869845124.92651460197999; Fri, 12 Jun 2020 12:04:58 -0700 (PDT) Received: from localhost ([::1]:45878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjoz3-0002s0-1G for importer@patchew.org; Fri, 12 Jun 2020 15:04:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjoxA-0000rn-Fi for qemu-devel@nongnu.org; Fri, 12 Jun 2020 15:03:02 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39284) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jjox7-0006sy-CV for qemu-devel@nongnu.org; Fri, 12 Jun 2020 15:03:00 -0400 Received: by mail-wr1-x441.google.com with SMTP id t18so10820581wru.6 for ; Fri, 12 Jun 2020 12:02:49 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u4sm10071329wmb.48.2020.06.12.12.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 12:02:43 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C20EA1FF91; Fri, 12 Jun 2020 20:02:38 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wyd2lV6dHVaHmALDhpJ+ImxFwC2VFtV6fvWZJjaxR+k=; b=Zm9mPVG80LvE0mgp8OuKUggdheh/c0sfRSykA/sMbDmMnsgQ8sX5qMxumxGxH8dLML Pi9tzLINWyM855+zZyWmHnyY13O0cGVHJOwiQG48V4ggziwOlJl+ozRbHnLWy3yiAm7G b/ZJqUcrJRQYNDnGDSX5CoF0QIzMFYZdSyMapRgQC9T0YHNxspY4r34XdGaNHXReQKy8 ZEXN5etUvpyX1ZmyTU3MbgUhfBhluEV6C3cCjHczohZm4OtLR59/asQ0qjK18nzDKLNe y8aXVhTC38hu54rL0uj8/JG9MLUdBEm4Vb5YQRaFn7tqgSfWMSGbhb1v+hjg7rKP9Ono 0PGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wyd2lV6dHVaHmALDhpJ+ImxFwC2VFtV6fvWZJjaxR+k=; b=kEj0O+RqIyrQ5LIDbYLUDB5buwu8qH8aM3jUwMG/AIr/dRxYhXSWJAtY0eO+pR2LIe 7OLmQPefAL+44wCzmLXhwtCezkyXnKtnn8G7R7IL7vHTYiX0xRC/r2XKieGRzANPdCOd D8S2c6tIBkQbiSOlDFRRbPgXiXhz6GoJq0DLIjCkq/pSBSpUHRiLLeEyvG7al7naqSpp B6cI20/Q5GrL7NXDXUEiWe+WrGqbBIDHNOVx7VfVH3K6wQDqWS+5OVnNezvdZTDTQPrc M0GhX/iu9Mn5SgHLzH4Ldvk3yex7tG3iV8jnBuiawui7K96EW5pUZ/YWVC3keUHorXtb R9Vw== X-Gm-Message-State: AOAM5315VXMJVIz37gJ/075ktzbCX3cj6zOIw41hR+8S0U7q2VPPWYYs C7zSKp816hj9q+L+C1zxc6jPqg== X-Google-Smtp-Source: ABdhPJxS0Oxi3HGnB6gHMIf02Ks34bSEIvMTTOWdVjhoejdNGE5eUabiik0kLcWj07qqJV9JWlD2EA== X-Received: by 2002:adf:a51a:: with SMTP id i26mr16015377wrb.406.1591988568145; Fri, 12 Jun 2020 12:02:48 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 05/18] cpu: convert queued work to a QSIMPLEQ Date: Fri, 12 Jun 2020 20:02:24 +0100 Message-Id: <20200612190237.30436-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200612190237.30436-1-alex.bennee@linaro.org> References: <20200612190237.30436-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: fam@euphon.net, berrange@redhat.com, Robert Foley , =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , cota@braap.org, Paolo Bonzini , aurelien@aurel32.net, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" We convert queued work to a QSIMPLEQ, instead of open-coding it. While at it, make sure that all accesses to the list are performed while holding the list's lock. Reviewed-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley Signed-off-by: Alex Benn=C3=A9e Message-Id: <20200609200738.445-3-robert.foley@linaro.org> --- include/hw/core/cpu.h | 6 +++--- cpus-common.c | 25 ++++++++----------------- cpus.c | 14 ++++++++++++-- hw/core/cpu.c | 1 + 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 497600c49ef..b3f4b793182 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -331,8 +331,8 @@ struct qemu_work_item; * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. * @kvm_fd: vCPU file descriptor for KVM. - * @work_mutex: Lock to prevent multiple access to queued_work_*. - * @queued_work_first: First asynchronous work pending. + * @work_mutex: Lock to prevent multiple access to @work_list. + * @work_list: List of pending asynchronous work. * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all ch= anges * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). @@ -376,7 +376,7 @@ struct CPUState { sigjmp_buf jmp_env; =20 QemuMutex work_mutex; - struct qemu_work_item *queued_work_first, *queued_work_last; + QSIMPLEQ_HEAD(, qemu_work_item) work_list; =20 CPUAddressSpace *cpu_ases; int num_ases; diff --git a/cpus-common.c b/cpus-common.c index 70a9d12981a..8f5512b3d78 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -97,7 +97,7 @@ void cpu_list_remove(CPUState *cpu) } =20 struct qemu_work_item { - struct qemu_work_item *next; + QSIMPLEQ_ENTRY(qemu_work_item) node; run_on_cpu_func func; run_on_cpu_data data; bool free, exclusive, done; @@ -106,13 +106,7 @@ struct qemu_work_item { static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) { qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first =3D=3D NULL) { - cpu->queued_work_first =3D wi; - } else { - cpu->queued_work_last->next =3D wi; - } - cpu->queued_work_last =3D wi; - wi->next =3D NULL; + QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); wi->done =3D false; qemu_mutex_unlock(&cpu->work_mutex); =20 @@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; =20 - if (cpu->queued_work_first =3D=3D NULL) { + qemu_mutex_lock(&cpu->work_mutex); + if (QSIMPLEQ_EMPTY(&cpu->work_list)) { + qemu_mutex_unlock(&cpu->work_mutex); return; } - - qemu_mutex_lock(&cpu->work_mutex); - while (cpu->queued_work_first !=3D NULL) { - wi =3D cpu->queued_work_first; - cpu->queued_work_first =3D wi->next; - if (!cpu->queued_work_first) { - cpu->queued_work_last =3D NULL; - } + while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { + wi =3D QSIMPLEQ_FIRST(&cpu->work_list); + QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); qemu_mutex_unlock(&cpu->work_mutex); if (wi->exclusive) { /* Running work items outside the BQL avoids the following dea= dlock: diff --git a/cpus.c b/cpus.c index 5670c96bcfa..af440275495 100644 --- a/cpus.c +++ b/cpus.c @@ -97,9 +97,19 @@ bool cpu_is_stopped(CPUState *cpu) return cpu->stopped || !runstate_is_running(); } =20 +static inline bool cpu_work_list_empty(CPUState *cpu) +{ + bool ret; + + qemu_mutex_lock(&cpu->work_mutex); + ret =3D QSIMPLEQ_EMPTY(&cpu->work_list); + qemu_mutex_unlock(&cpu->work_mutex); + return ret; +} + static bool cpu_thread_is_idle(CPUState *cpu) { - if (cpu->stop || cpu->queued_work_first) { + if (cpu->stop || !cpu_work_list_empty(cpu)) { return false; } if (cpu_is_stopped(cpu)) { @@ -1498,7 +1508,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu =3D first_cpu; } =20 - while (cpu && !cpu->queued_work_first && !cpu->exit_request) { + while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { =20 atomic_mb_set(&tcg_current_rr_cpu, cpu); current_cpu =3D cpu; diff --git a/hw/core/cpu.c b/hw/core/cpu.c index f31ec48ee61..80d51c24dd2 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -370,6 +370,7 @@ static void cpu_common_initfn(Object *obj) cpu->nr_threads =3D 1; =20 qemu_mutex_init(&cpu->work_mutex); + QSIMPLEQ_INIT(&cpu->work_list); QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); =20 --=20 2.20.1