Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp92954lqt; Thu, 18 Apr 2024 09:13:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5mSYvf4//Af7kuye5s8rOtiY6xNKDRkhbA8u/dSiTb6c4olNiOtLbvjXSUw1vfeTih33G7NMjQx2nVZa6BkvzO3v2FTfhmorjwigY7w== X-Google-Smtp-Source: AGHT+IHN2muSUy4A0/5LcoNH/cqPfUzHHtmaR4ZZOvd5jMyHMh13jwBrk+BTRPV1cZqtSCuu+Yux X-Received: by 2002:a17:902:ec8c:b0:1e4:6e70:25d8 with SMTP id x12-20020a170902ec8c00b001e46e7025d8mr4159894plg.13.1713456806387; Thu, 18 Apr 2024 09:13:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713456806; cv=pass; d=google.com; s=arc-20160816; b=l8i3h/cMFLX3yCh+C8Crd5LGBsoiNSQ9NSprumZ2i+XyJzSla3ruGk8gpIbAEdoHYF 91fBTZkhvMfm6wPXW8kHTyxmr2Tb9zogIvtGk8XBH3AfT+hSMMWbzImI72GwGUd1m22R a7hAgR/fqaNmLF197tkB/JcE3pym80QjKvoypvxENjXHOM8wVBUQHwGKe8sSeOViMLZp aGSuXFyQg0a6BLw6KWsFKYc8NZ4EtwW+w94xjGkEBNAOeI7NLYgOqq6WKmRJJToc6hR/ 6VfJETuurSNeHU5KEsaIuw7zyrKQqBISXYJmvufgMyaCDm/nvWU3WHID76UbV6fG5c/o myMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=/WYegnjNIT6ITUxIPv0/Q8MWBXWcokuDnEdLFw52f4Y=; fh=WB8k4CW0P7UlWCLGsGYJywJ8AxNl2Mgyw1wahEMPRRM=; b=gGYS2dn1DOX4gA7Q4Qvh+sPH659BwZbHBGmi7bVf+l5maUuyrUGzk+vjbNotSIGjr+ L1OWYNzEmWk0cD3TS6bZn2d+3nHcfWvQKFndLBkoGM+ks26YD1xtObbZl57yT8LNq/hk GDQFDAFitwrYLDD6/dhPYkxLjzJyAdFXkU8ph9fpWA7WM5g0YOrhcrb3xxFrGI3CjSU1 4D4i9LaEn5ZSoKsqCvizpkxdM1g65T/5qTVZt2z0E2lX37IobtADHBkMXpFCFi/uueCy IHbLC1SHjAFCoa/rO2Ldvrz3TCUe4p/XtSU7goiRCoJtB/gLtjZvBor4BLYWRSnZlKzP SlZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=jDdf8fco; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-150461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p10-20020a170902f08a00b001e510a27c78si1646418pla.52.2024.04.18.09.13.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:13:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=jDdf8fco; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-150461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ECB0B2852D8 for ; Thu, 18 Apr 2024 16:13:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B780F4D9E8; Thu, 18 Apr 2024 16:13:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="jDdf8fco" Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A15B223D7 for ; Thu, 18 Apr 2024 16:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456782; cv=none; b=FhdBJa4saOyVCHdxe/hpoxLgt/hcfFAvVUkDMxbuamd4ryAjZlYrw04Zp+CnFyr603wobMXd1Y+OQa3KEhD4cqIciKG5GZMyib4ixa8RSENagCnAmA4gRdTiRCAAjILVKs5pL/mwo1pB183j4ccfgwrVYX5r5xyOxWDJ2XakrcA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456782; c=relaxed/simple; bh=7O5CaiYMx3o81DATDCx+mdTRxyfXstzYIysSrKy8ixI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=utOtU7iliGhkk6vvXScoYuWEr9ZuePEsc7LcHQ+Kgj86OgIBBSYveyXvnLnF2eihHo7SRW5tBZ0RHoseFctXWCA+zPnKZ0LaYWhubQnSESLk0nKp1jDWxsAUCXCEr1xW5K7aMHNzcbEXS/pZQCsoyhtPr45oZjcQYYARPgFQZ0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=jDdf8fco; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2a7e19c43faso818537a91.2 for ; Thu, 18 Apr 2024 09:13:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1713456780; x=1714061580; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/WYegnjNIT6ITUxIPv0/Q8MWBXWcokuDnEdLFw52f4Y=; b=jDdf8fcoxdYv1zIvWActMsrWTBqzfgWUVi8QW4kpIpkCy7zKx3jpTxqnoTpzQaP0n0 cXMbS846m1O0KLEMkJPluKwyG6Pa7uQnpPTpN9/kLh30ObqWscVjpBrZ0HN3+t7gJE5o ASLUQvBrWXTAOz0BnANv8evlGN+3Cv3/dJO7NyzfD58orvcSoBk0G3H6X2U6DuCTwI7u MD4ULmnTkz21lWz1p1/zkLQVWMkRQvUA3bd6UB22z/k6Nn2u7vTd63xBBJWlZgiHR/ld Wvtl+qUGThRxbod+DZPaqenFEnUhq69lGSj9FlMfakTgRBFc++8NnJe92hrqZEhVJOku uGpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456780; x=1714061580; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/WYegnjNIT6ITUxIPv0/Q8MWBXWcokuDnEdLFw52f4Y=; b=OQnx7Vxm2reKxnpeLaorXatjObodpLfpB3pbcHhNtWzAtWV/yUzbR79+Q6qeV1utzf 6sv/s5pmjG1XutCUYNq+zBdykJnmXg/VUUPNML9VXcdcSAwkUGNHa8JJol5PwFGg65NI 0bdgnEXxNPfuCElFB4xq4tIkj+rYjjUv3QLqDW9y4Oug64mIAXkUeT3KkkS8SsxycVSi T5PgcOrxqdHUrgbabKHEf7O+x+zIt3yCQYHjmJ3TQc5zdoqvApcATexL7psDbcQc0Re1 xa2y3uxgPkIf87PhLhinEwuVcgIzvVqSF42XwfIJbinrVxLhvzGLtMkRG2mXCEe2qP/M LLRg== X-Forwarded-Encrypted: i=1; AJvYcCUyHrQy0Lv+8fcCp15FNt2jUiMdXQg/zoXWdJ93YOQUAjW8XoitU9EY5Ek0ujOVmL2n3m9lJ/4rQu48oax4eohmhKoGlnJ22dWeChX1 X-Gm-Message-State: AOJu0Yx4mCL29YbEjAeSfS2ijcFkxP3oHZW/4T5quj3OqyBU+H5DOaSW MpwkF04/+qIAa+2BsiMj/w3tc7AlNY0g+SyZhGvZvpC+fV7PRzJC/ZDf9XYiNoiImWLPClez44O vdZC2FVLhjd4x0lvJcQOhNgIxU8F6I+xWl7mobg== X-Received: by 2002:a17:90b:4c92:b0:2a5:395e:8673 with SMTP id my18-20020a17090b4c9200b002a5395e8673mr3284250pjb.5.1713456779903; Thu, 18 Apr 2024 09:12:59 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418114942.52770-1-luxu.kernel@bytedance.com> <20240418114942.52770-2-luxu.kernel@bytedance.com> <20240418-dove-deferral-2b01100e13ca@spud> In-Reply-To: <20240418-dove-deferral-2b01100e13ca@spud> From: Xu Lu Date: Fri, 19 Apr 2024 00:14:47 +0800 Message-ID: Subject: Re: [External] Re: [RFC 1/2] riscv: process: Introduce idle thread using Zawrs extension To: Conor Dooley Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, andy.chiu@sifive.com, guoren@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, lihangjing@bytedance.com, dengliang.1214@bytedance.com, xieyongji@bytedance.com, chaiwen.cc@bytedance.com, Andrew Jones Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 18, 2024 at 11:06=E2=80=AFPM Conor Dooley wr= ote: > > + Drew, > > On Thu, Apr 18, 2024 at 07:49:41PM +0800, Xu Lu wrote: > > The Zawrs extension introduces a new instruction WRS.NTO, which will > > register a reservation set and causes the hart to temporarily stall > > execution in a low-power state until a store occurs to the reservation > > set or an interrupt is observed. > > > > This commit implements new version of idle thread for RISC-V via Zawrs > > extension. > > > > Signed-off-by: Xu Lu > > Reviewed-by: Hangjing Li > > Reviewed-by: Liang Deng > > Reviewed-by: Wen Chai > > --- > > arch/riscv/Kconfig | 24 +++++++++++++++++ > > arch/riscv/include/asm/cpuidle.h | 11 +------- > > arch/riscv/include/asm/hwcap.h | 1 + > > arch/riscv/include/asm/processor.h | 17 +++++++++++++ > > arch/riscv/kernel/cpu.c | 5 ++++ > > arch/riscv/kernel/cpufeature.c | 1 + > > arch/riscv/kernel/process.c | 41 +++++++++++++++++++++++++++++- > > 7 files changed, 89 insertions(+), 11 deletions(-) > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index be09c8836d56..a0d344e9803f 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -19,6 +19,7 @@ config RISCV > > select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 > > select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE > > select ARCH_HAS_BINFMT_FLAT > > + select ARCH_HAS_CPU_FINALIZE_INIT > > select ARCH_HAS_CURRENT_STACK_POINTER > > select ARCH_HAS_DEBUG_VIRTUAL if MMU > > select ARCH_HAS_DEBUG_VM_PGTABLE > > @@ -525,6 +526,20 @@ config RISCV_ISA_SVPBMT > > > > If you don't know what to do here, say Y. > > > > +config RISCV_ISA_ZAWRS > > + bool "Zawrs extension support for wait-on-reservation-set instruc= tions" > > + depends on RISCV_ALTERNATIVE > > + default y > > + help > > + Adds support to dynamically detect the presence of the Zawrs > > + extension and enable its usage. > > Drew, could you, in your update, use the wording: > Add support for enabling optimisations in the kernel when the > Zawrs extension is detected at boot. > > There was some confusion recently about what these options were actually > for, because this option doesn't control "dynamic detection" as the > ACPI or DT detection is compiled at all times. I had written a patch for > this wording in other options at the time but had forgotten to properly > send it: > https://lore.kernel.org/linux-riscv/20240418-stable-railway-7cce07e1e440@= spud/T/#u > > > + > > + The Zawrs extension defines a pair of instructions to be used > > + in polling loops that allows a core to enter a low-power state > > + and wait on a store to a memory location. > > + > > + If you don't know what to do here, say Y. > > + > > config TOOLCHAIN_HAS_V > > bool > > default y > > @@ -1075,6 +1090,15 @@ endmenu # "Power management options" > > > > menu "CPU Power Management" > > > > +config RISCV_ZAWRS_IDLE > > + bool "Idle thread using ZAWRS extensions" > > + depends on RISCV_ISA_ZAWRS > > + default y > > + help > > + Adds support to implement idle thread using ZAWRS extensi= on. > > + > > + If you don't know what to do here, say Y. > > I don't think this second option is needed, why would we not always want > to use the Zawrs version of this when it is available? Can we do it > unconditionally when RISCV_ISA_ZAWRS is set and the extension is > detected at runtime? > > Cheers, > Conor. Indeed, we can always choose WRS.NTO when entering idle. This config is introduced for the second commit in this patch series. In the second commit, we detect whether the target cpu is idle when sending IPI and write IPI info to the reserve set of idle cpu so as to avoid sending a physical IPI. Besides, the target idle cpu need not to go through traditional interrupt handling routine. However, if all cpus are busy and hardly enter idle, this commit may introduce performance overhead of extra instructions when sending IPI. Thus we introduce this config just in case. Regards, Xu Lu > >