From patchwork Tue Jul 16 18:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 812784 Delivered-To: patch@linaro.org Received: by 2002:a5d:42c4:0:b0:367:895a:4699 with SMTP id t4csp435802wrr; Tue, 16 Jul 2024 11:11:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV6GfbdH5Gpuk7+t1KoGkWPS2reyPFYLChkakIEwUNLWqBrYR186lhHW0062Fu6VuMOjl80ywdNxnUHoDZW3dG8 X-Google-Smtp-Source: AGHT+IFihDYrZMQWCDQH8CQ+l25Kehs1vfFtY46pFlSTogm6oVr3N/5becDyUT8MipYhMtjZesud X-Received: by 2002:a05:622a:5cb:b0:446:5764:3c9f with SMTP id d75a77b69052e-44f7ac3b91dmr37425331cf.22.1721153516533; Tue, 16 Jul 2024 11:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153516; cv=none; d=google.com; s=arc-20160816; b=saMPlSZEhWUYB7dSp8vITybXb/Bg8nnjGpeT/mLYCTsnPFfSw7CrNEJ/7H7sX8szn9 WtXLuxU6ZaWjECfrKebM/lS88SRrkAjdbpBh6O55Er8YXLq8BiMFTBQnySIRuWMbdDuL cFrFMxnwtwjreKiJpHLjiYUi/YaSENspnNJC5/ouvbTp97To0bNXh/T++7JrPmyyj/a1 /U7Zj3MUlYPgZhFA9ICllCE1RS3Za1xl69jBqvCHBIXOSBsugf4FSUhFL8XXrUwXaPt4 BJs75nCkLuvK1m9sBcov/peaclAyJmOpIurr2gXM77krPGttJEiVYXffn5EGq3FXYCcg T/Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=J/fWelIsDk94bV5CUZ155GFV3Kb2G+dluPKM584VupM=; fh=QF/JOPHaZZtQXIB8vEzxUZ9RIvYo4vCjR/Qv3feI8es=; b=CC4NizG8vKQTOF5eNrMsuMi1v+lClWSH3eMHTw0YdyXCwwrKwikMe0p6rw/3i3aV5W GUQozMsy5ATyWch1wH/TX6ppOXohn6b31oPQmW1ojiX76ObLL9HSweob21WVdrDoUXFV nwUp1+leKagLsigu5miNDTvFr29bG7vYiwcPUmlzVfZ2ZC93qwcw1fJSVyIh/aAllkTg KcSGIwAQLrlD9nIOjHa2CHYTgKvNRWSHbMePiBnYn2lMJmcZOp/H+LdbO5iLVbdFzCjJ dHlBwY3hDKkaBHrjNocxzpLI9PFuO8unSFNKSMHlDXzIVZYr6KPSA1mdA2SGPC8LnCzZ O+NQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I2n9uXes; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44f5b7f66adsi82041781cf.235.2024.07.16.11.11.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jul 2024 11:11:56 -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=pass header.i=@linaro.org header.s=google header.b=I2n9uXes; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTmd5-0008DD-8W; Tue, 16 Jul 2024 14:10:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTmd2-0007ys-Na for qemu-devel@nongnu.org; Tue, 16 Jul 2024 14:10:20 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sTmd0-0001AY-U9 for qemu-devel@nongnu.org; Tue, 16 Jul 2024 14:10:20 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4257d5fc9b7so46453835e9.2 for ; Tue, 16 Jul 2024 11:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721153417; x=1721758217; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J/fWelIsDk94bV5CUZ155GFV3Kb2G+dluPKM584VupM=; b=I2n9uXesiILmZMw4DqEKU37v8iPPPG90TR2n/IPhfnEEeYO64uPxQVO/T89VR7HoI2 FpLIvBycJhuMrBlInrhGOxcHuIiu/iqULdm9Sb3IZLVTtHWGxEWSp9O4eoqpOuRzs+9U 3ataOTTFWMgkbin+GQmtH//MzMPL8craq9cArUwYMgUpxw75yfn0bXBpV2ywZe4OaU5m A6nZd14cr9T6qkJgJC2jW05Y1uM8SQCXJy6GYw2eQ3Fsq6mkU2T/bZBzy4rwlts0bKJn 2lVb4sJoihBZvW3F2vLs0D1uHMSLbpYBCqh2xqnR5m1dfU6zo61Qjkl2ualZKQTqSs3m Fgzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721153417; x=1721758217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J/fWelIsDk94bV5CUZ155GFV3Kb2G+dluPKM584VupM=; b=wutjvGfOZt1ZLWiCIsiJE4Lv/Tdsyf39fEoHo4xEhmYq2/GwcbIH9LCSZaaQ8/qyXC 0YQvkjcM5iG4Tsm/fOFO/lV7skx1Q20ir/3fdOHzVCFTZLdTs2ed/VHm091g4A7Qp2iD RD9bWQoSYe5mjw31ByPWaVaIysPVWZz4tIB7GG0/dCdEpj73LGtqEv8ba9CN8hInPmnH M13HEy3nt9qneJ6lBoBC59ur+UVmnYI/9sQBg9kemiBbV8QT+Vdf6uZsNDGAqg+uzByN 8at0lHXWa1MjTCi7svCTA6IRzGuM2WWqoVUtRxlpXghdI8KLVJgH+NikrhXhJEJlq95k D9Gw== X-Gm-Message-State: AOJu0YwAi6lgzinvWvqyaZjSG6yeBOdcA+v2QGTdipxsZ73usx8Pk8jW AVg7aHOfQGRMfZFNBdX+0WE+hAAjskG0BkiD1FzQEuqyiviHR/ewuNUuz4T9HVU9uLEgyV86cR1 9zItL2g== X-Received: by 2002:a05:600c:198e:b0:426:52a5:1ca4 with SMTP id 5b1f17b1804b1-427ba69ae4emr23743705e9.21.1721153417039; Tue, 16 Jul 2024 11:10:17 -0700 (PDT) Received: from localhost.localdomain ([176.187.209.82]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3680dabf133sm9532426f8f.37.2024.07.16.11.10.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 16 Jul 2024 11:10:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Nicholas Piggin , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Peter Xu , Richard Henderson Subject: [PULL 06/13] system/cpus: Add cpu_pause() function Date: Tue, 16 Jul 2024 20:09:33 +0200 Message-ID: <20240716180941.40211-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240716180941.40211-1-philmd@linaro.org> References: <20240716180941.40211-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philmd@linaro.org; helo=mail-wm1-x330.google.com 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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Nicholas Piggin This factors the CPU pause function from pause_all_vcpus() into a new cpu_pause() function, similarly to cpu_resume(). cpu_resume() is moved to keep it next to cpu_pause(). Cc: Philippe Mathieu-Daudé Cc: Peter Xu Cc: Richard Henderson Signed-off-by: Nicholas Piggin Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Xu Message-ID: <20240712120247.477133-17-npiggin@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- include/hw/core/cpu.h | 8 ++++++++ system/cpus.c | 30 +++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index a2c8536943..e6acfcb59a 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -984,6 +984,14 @@ void cpu_reset_interrupt(CPUState *cpu, int mask); */ void cpu_exit(CPUState *cpu); +/** + * cpu_pause: + * @cpu: The CPU to pause. + * + * Pauses CPU, i.e. puts CPU into stopped state. + */ +void cpu_pause(CPUState *cpu); + /** * cpu_resume: * @cpu: The CPU to resume. diff --git a/system/cpus.c b/system/cpus.c index d3640c9503..5e3a988a0a 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -568,6 +568,22 @@ void cpu_thread_signal_destroyed(CPUState *cpu) qemu_cond_signal(&qemu_cpu_cond); } +void cpu_pause(CPUState *cpu) +{ + if (qemu_cpu_is_self(cpu)) { + qemu_cpu_stop(cpu, true); + } else { + cpu->stop = true; + qemu_cpu_kick(cpu); + } +} + +void cpu_resume(CPUState *cpu) +{ + cpu->stop = false; + cpu->stopped = false; + qemu_cpu_kick(cpu); +} static bool all_vcpus_paused(void) { @@ -588,12 +604,7 @@ void pause_all_vcpus(void) qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false); CPU_FOREACH(cpu) { - if (qemu_cpu_is_self(cpu)) { - qemu_cpu_stop(cpu, true); - } else { - cpu->stop = true; - qemu_cpu_kick(cpu); - } + cpu_pause(cpu); } /* We need to drop the replay_lock so any vCPU threads woken up @@ -613,13 +624,6 @@ void pause_all_vcpus(void) bql_lock(); } -void cpu_resume(CPUState *cpu) -{ - cpu->stop = false; - cpu->stopped = false; - qemu_cpu_kick(cpu); -} - void resume_all_vcpus(void) { CPUState *cpu;