From patchwork Thu Jun 20 16:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 806007 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp382062wrt; Thu, 20 Jun 2024 09:33:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWheBPXuQ9WVYQEetqX+o1kDROln726vO9S3p9ovN4z75BgIkcWjUWJm2IdF8jTgRE/4OEDxhWSm9EE7oXf6Zg2 X-Google-Smtp-Source: AGHT+IEv/jT1NcZkdjD19zJtnjGRiXK0HXFRw9juf9LUy3DOM5RHGrna5qBdcTneonfH73KST/0k X-Received: by 2002:a05:6122:a1d:b0:4bd:32c9:acb with SMTP id 71dfb90a1353d-4ef276cfc01mr6297539e0c.7.1718901202042; Thu, 20 Jun 2024 09:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718901202; cv=none; d=google.com; s=arc-20160816; b=FNBtOLw1iYt9omz0i5CeyxgEZ3mr/0uBIGtT/OAdB5VgMC4bmd0E5U1FGZEiGfiOWl 3a9y6ePxSP6TsEPjT54wIZ8JiAttGLKx98itffE6PtZ9EGJGuHpmmlCm2QorHfxQqOfL My0tNh24ZyghSpZblsGU6c6WHhSdxIr1P+/8n2kSrO8/Me7E+PfBq7YzvZEfpZr5KyuT wssib3M3bC+PnGqAlNjCQZHJavVQ9fbpgxcdW6AHoIivzgLQa+B/n2+z3Q0VUrxUVOch 7VClpNNbZmDqHGrlsOFXNaEDZWKCDHPkcVJRv5H00ch01hBnijeXR01ZhRditYCUbYfm 5Zjw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=BETFTTWU9xVFhpYusm7c0IREOV0G6oO8cUsS5wkRjSk=; fh=Y1lTFfMB85iHnXQMZWkJYDL80EgpxLD2NqC3F1zgJXw=; b=abi4h1aPiSfUXJgHv6IxTl8I23CxoqvAksmoUKWykqKraM11CsGE7/uk30SWN1S8Ou PY5laYvE9o1oa0tjy0EW6Deee5WgcymQ58C0IwDAqI1xx4umXby311/1kZkMWh2u2Qhz gERmUbQESRCu7lr/RcCZBIa3wVnbxkZ+hO1PGymNwZEhKQZ1Yj66bAY6PecPjw4xmFwY blY1w4l+oEuSa/ld25GEpW95gkwMLH24dUZ8x2DYJDB5sNus06f5hGwQT4ris8f9nw89 puI/N2nq4WxDCAUJdBsO+k0ro2SsWDrtBc663B1Jyfy9CkY7qee8aYYkggrmb3XSUgWf H1Hg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GKtnvsGh; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 71dfb90a1353d-4ef38a25083si371126e0c.163.2024.06.20.09.33.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jun 2024 09:33:22 -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=GKtnvsGh; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKKi0-0003Fg-8Y; Thu, 20 Jun 2024 12:32:24 -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 1sKKhx-0003FV-Ss for qemu-devel@nongnu.org; Thu, 20 Jun 2024 12:32:21 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKKhv-0004Ce-2z for qemu-devel@nongnu.org; Thu, 20 Jun 2024 12:32:21 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-57d1012e52fso1218732a12.3 for ; Thu, 20 Jun 2024 09:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718901136; x=1719505936; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BETFTTWU9xVFhpYusm7c0IREOV0G6oO8cUsS5wkRjSk=; b=GKtnvsGhtBkn3rRQC4qx6bIBwHAILEFyXomr4R0Ah4zk+ksvjTolXa6pfyxqoyKro1 RtNGxoomD3xS41fd5vgwnVq5PDJ0TVkWhYnpewmUgcrUiqRSKAda/hxVb0JVcOMrsk6c DAEBiTf0/HH2mEwBcrXKQ7jlmz2SNQ05CSDIRLpuCPTQsU6W2x1XeCFksTX+0HLFIa3V FIj+tVnYCbxuC1dcjqsumK6NNJhZN9j4Noql/x/4UvrH9DXQAEhXaeTNXj0xON3SnpCo qU8AkRXzLJgxaz5R3Rllo8FS2f0k2Sq/DBvIkz/U+5Uxh0txLppmoINBtAo/6Ozq+l1B Wucg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718901136; x=1719505936; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BETFTTWU9xVFhpYusm7c0IREOV0G6oO8cUsS5wkRjSk=; b=IuqF8j2i5TQPm7tJ0X7NCYNjiBng3ksCKTAiPToM9vc2Nvjq8LBY4jO7/XK5FdYrKk M4pzyQ3GIyOYJTEsDFcZ2eypkjOBu5hE5Y2EkPLMCwbXmtpHNcL+1/j1+XQNEC7R8vRl 71IXSYFFLmCC0LxuH4v/fIxHdb1Jz8WrVUWy2qLznFAjfh5dutQKeSfCWbgiFqohrQqk 6LIRJFemj8uFahCBADXovAL2V0uPt9IbqUD6jdSHI1LiZ43XEPcEvC8wW2x/M+az4cRS vu8PLSuG5+5S0GUbUf4GUH8Mi7Z/xgbYjFxewm1l5m03R0WwvlNZAFmoQA3q27Ef8M4n Q7XA== X-Gm-Message-State: AOJu0YyTYNEoIz0QeBfWjjI6rmNGrJ4wKrCbieEZUFlySvCxMtneiccU L5Ppl6xHQSPk6lvmbdGkXdr3b2mOuPJnqib9OjRljzmkPaCuveId/+c1MhvQlXc= X-Received: by 2002:a50:ab52:0:b0:57d:50e:d76b with SMTP id 4fb4d7f45d1cf-57d07e2c81amr3465198a12.7.1718901135916; Thu, 20 Jun 2024 09:32:15 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cb741e78fsm9927796a12.71.2024.06.20.09.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 09:32:11 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id ED5ED5F7B1; Thu, 20 Jun 2024 17:32:09 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?q?aud=C3=A9?= , Yanan Wang Subject: [RFC PATCH] hw/core/cpu.h: try and document CPU_FOREACH[_SAFE] Date: Thu, 20 Jun 2024 17:32:04 +0100 Message-Id: <20240620163204.2213916-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x535.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, T_SCC_BODY_TEXT_LINE=-0.01 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 There is some confusion about when you should use one over the other. Lets try and address that by adding some kdoc comments. Suggested-by: Paolo Bonzini Signed-off-by: Alex Bennée --- include/hw/core/cpu.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index a2c8536943..7122f742c1 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -587,8 +587,25 @@ extern CPUTailQ cpus_queue; #define first_cpu QTAILQ_FIRST_RCU(&cpus_queue) #define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node) + +/** + * CPU_FOREACH - Helper to iterate over all CPUs + * + * This macro iterates over all CPUs in the system. It must be used + * under an RCU read protection, e.g. WITH_RCU_READ_LOCK_GUARD(). If + * you don't want the CPU list to change while iterating use + * CPU_FOREACH_SAFE under the cpu_list_lock(). + */ #define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus_queue, node) -#define CPU_FOREACH_SAFE(cpu, next_cpu) \ + +/** + * CPU_FOREACH_SAFE - Helper to iterate over all CPUs, safe against CPU changes + * + * This macro iterates over all CPUs in the system, and is safe + * against CPU list changes. The target data structure must be + * protected by cpu_list_lock(), and does not need RCU. + */ +#define CPU_FOREACH_SAFE(cpu, next_cpu) \ QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus_queue, node, next_cpu) extern __thread CPUState *current_cpu;