From patchwork Thu Mar 26 19:31:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 184919 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp477834ilr; Thu, 26 Mar 2020 13:10:24 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtIuGlnSbcYWVivdGCviZDjsNeGiiExXrhj4qzjXnZNAbyCA011I+OCaEtieSeM4tyDSfbY X-Received: by 2002:ac8:d8e:: with SMTP id s14mr10478226qti.204.1585253424204; Thu, 26 Mar 2020 13:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585253424; cv=none; d=google.com; s=arc-20160816; b=q6BSB500Ll9HnEyNy6HFst8/iHMvgoAGR4okTYnCkpTM2sk6Do3prKPzlXFjV9Jg78 vjcP3yhJJsNLxrWiYLGmQELJyXidPIzF+0MRMmN8D95A+95rP0D7x5em6tItbHZAQeYQ A25JnHYWLTM61Wn9pQBgs4zyEQd7BFRFsRt1rVBxNMKLydmTlN2FER7FlzMc1CIWdHH4 XQqaIRQqtuFWCde1IUlBF3RE7Rg+a4XxNgw0R9gZUyOONP8qlQYu3wKcY1NGL3prpFgd 7P8Zx/mRTFjOUYH6CAOOsjK9rzCyx2B++jk3Z5j3SUCEKOOkY72x3bPoSDdFOJiIQDhJ ytsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=+znDl+e4Ijoaeb8N9+twYWXre7kV5d4tOF3Cbrdh+d8=; b=AESqyRu7PxaBdZwXAx7b/6D6s3FXtjIzYbrUKotiE7b7h8BF+TpP8FcKP+/o7hwB6r oAU/9XxuylJ+UVVClvztydmsclLr8ltZeksB0GwUmiQGmO5UPYD9IspG17WBDKwCZiAr IpgA3JkHR+4UWKwD2ktRAVEQ6hMu8ZZvqyXHRymY+UkvvJNPN0QBhdo39CKCHscokDlq i8LyXK0dzo/3L25+acS/FCi7OK0uFz0I68bW3OSXcIicK7Z1U+ki5bijibTEB27DmlpB u+7zqlchJrVISc9UnVhGIUFiIQ/ctStHirbaEm5fvCr7r/s22ZmCLUKqMyxmu/lNyprZ sSAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XessdbHN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h7si2047187qvr.215.2020.03.26.13.10.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Mar 2020 13:10:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XessdbHN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHYpb-0005ee-Kd for patch@linaro.org; Thu, 26 Mar 2020 16:10:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59327) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHYLH-0008QO-Hp for qemu-devel@nongnu.org; Thu, 26 Mar 2020 15:39:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHYLG-00029u-Ca for qemu-devel@nongnu.org; Thu, 26 Mar 2020 15:39:03 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:36794) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHYLG-00029m-8O for qemu-devel@nongnu.org; Thu, 26 Mar 2020 15:39:02 -0400 Received: by mail-qk1-x744.google.com with SMTP id d11so8195804qko.3 for ; Thu, 26 Mar 2020 12:39:02 -0700 (PDT) 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=+znDl+e4Ijoaeb8N9+twYWXre7kV5d4tOF3Cbrdh+d8=; b=XessdbHNqdlhsujH92G+AZWufPiC7tjIBNftkvgrRo7HOs/3MnrAxHpphSF7QCxp9J WeK4GS9m0Z1Opphaqsz9WpCnzM73wXaUv2nMA59mOqZiETEiLbPD7mhZrD2o4cf9ASj0 ayrGBtZHCDFaseT85qs3x5+wziNDsPA+zj/T1ruCGwnApwmoH70VynsRQCmbea6uoiyD tvbkbfxMufeZFPs1uctOfY4CGf5EdXmlLRVzyKTwqJNNiz2DOKIJad54PeNUDgyFsgZG 8x9AM5IBAHYuqGJyPRTlyuxRyMxotVtWvnTmo4gs3KdhxnV9Eje2qPrV5Q6dp4o4qThV N3GA== 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=+znDl+e4Ijoaeb8N9+twYWXre7kV5d4tOF3Cbrdh+d8=; b=M5ZIHyGxoaxpHWw6Cj26XmxdyALa5ouf755d+00At0k6IfckuBPJ7qQynIVm6wA3fd YPbSCXygiDK2MgDiNVYmcWnpA9lpOja6mm8p54OBfVsQoTR2S+g96Wmy7ONu4HI53Win hYf9uOv5dxUdlaafUukZNYsPvlXHkq1ab9GZqZ1aKIyCNRlXiMvgGaBibzKIHQaXyvhf 4y0jiYeqWKeCQBD6xTjUAR7issjCnyo1PFtvUG2KkZXCAjgh5Jgmp3q1ihNyiZdSXdJY /nlniUfFDHW6hnBlcsok9GLA+G03f6hqatE7Fm+PBkHpvipORCEedq6JJgNb0jn29MtA IrSw== X-Gm-Message-State: ANhLgQ077cj2aRlyKl9cgvMyr33tjA33r4onvdjLzOBkq4psYU2tb+Hj T7+yxf6YhaPfIGEqi8WON1CFtdrggYbPdA== X-Received: by 2002:a37:2d83:: with SMTP id t125mr10373982qkh.359.1585251541396; Thu, 26 Mar 2020 12:39:01 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:fd55:4e67:1038:8302]) by smtp.gmail.com with ESMTPSA id u51sm2161916qth.46.2020.03.26.12.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:39:00 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v8 63/74] cpu: introduce cpu_has_work_with_iothread_lock Date: Thu, 26 Mar 2020 15:31:45 -0400 Message-Id: <20200326193156.4322-64-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326193156.4322-1-robert.foley@linaro.org> References: <20200326193156.4322-1-robert.foley@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::744 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: richard.henderson@linaro.org, "Emilio G. Cota" , alex.bennee@linaro.org, robert.foley@linaro.org, peter.puhov@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" It will gain some users soon. Suggested-by: Paolo Bonzini Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/hw/core/cpu.h | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index a01c258320..e3527b6194 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -26,6 +26,7 @@ #include "exec/memattrs.h" #include "qapi/qapi-types-run-state.h" #include "qemu/bitmap.h" +#include "qemu/main-loop.h" #include "qemu/rcu_queue.h" #include "qemu/queue.h" #include "qemu/thread.h" @@ -82,6 +83,8 @@ struct TranslationBlock; * @reset_dump_flags: #CPUDumpFlags to use for reset logging. * @has_work: Callback for checking if there is work to do. Called with the * CPU lock held. + * @has_work_with_iothread_lock: Callback for checking if there is work to do. + * Called with both the BQL and the CPU lock held. * @do_interrupt: Callback for interrupt handling. * @do_unaligned_access: Callback for unaligned access handling, if * the target defines #TARGET_ALIGNED_ONLY. @@ -167,6 +170,7 @@ typedef struct CPUClass { int reset_dump_flags; bool (*has_work)(CPUState *cpu); + bool (*has_work_with_iothread_lock)(CPUState *cpu); void (*do_interrupt)(CPUState *cpu); void (*do_unaligned_access)(CPUState *cpu, vaddr addr, MMUAccessType access_type, @@ -800,14 +804,41 @@ const char *parse_cpu_option(const char *cpu_option); static inline bool cpu_has_work(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); + bool has_cpu_lock = cpu_mutex_locked(cpu); + bool (*func)(CPUState *cpu); bool ret; + /* some targets require us to hold the BQL when checking for work */ + if (cc->has_work_with_iothread_lock) { + if (qemu_mutex_iothread_locked()) { + func = cc->has_work_with_iothread_lock; + goto call_func; + } + + if (has_cpu_lock) { + /* avoid deadlock by acquiring the locks in order */ + cpu_mutex_unlock(cpu); + } + qemu_mutex_lock_iothread(); + cpu_mutex_lock(cpu); + + ret = cc->has_work_with_iothread_lock(cpu); + + qemu_mutex_unlock_iothread(); + if (!has_cpu_lock) { + cpu_mutex_unlock(cpu); + } + return ret; + } + g_assert(cc->has_work); - if (cpu_mutex_locked(cpu)) { - return cc->has_work(cpu); + func = cc->has_work; + call_func: + if (has_cpu_lock) { + return func(cpu); } cpu_mutex_lock(cpu); - ret = cc->has_work(cpu); + ret = func(cpu); cpu_mutex_unlock(cpu); return ret; }