Received: by 10.223.164.202 with SMTP id h10csp420646wrb; Wed, 22 Nov 2017 09:12:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMaLqNyyBPr/nzw0/3CwYcUB+zAFicFBJXaPgyqrsKH8JS6lSV+kNAUcffYxF1H7rq1DCGwK X-Received: by 10.99.178.14 with SMTP id x14mr6156367pge.423.1511370749019; Wed, 22 Nov 2017 09:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511370748; cv=none; d=google.com; s=arc-20160816; b=nxcdBEK+GFp2mhA+e+OJXZ2hBELJLoTa4+K2OyP4f6aXq3r97v0wPUhkNOCYpK7ohx TewrguNYRfIC/3/wE3PekqI+7iwQjEozNCh/N8Nd68iYBw5dn1TZgX94kADbz5fx1gOK 0rGsWbWzr/bs+fqsgzL8Dx1fkzFePGDC5ZGyOGFBMupLUmtyXeYSCaw5zuuATga0JXht gChJlZILtk+OK08Q5vc4+YMMlL39FXQ357hPsV9kBA167WmRIkw/O59iWAOQyibHL4qA BVUDPd79kiWE8ry2Tu35P+AE7P5PHB3sHt9J056Qfh6TA2O1mD69KEFLHZPbDbMs7Yjp MNyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature :arc-authentication-results; bh=qon3weLF8bmlJzRqIFZhYQ+c8TRhafqWyGeSdAxzafQ=; b=fKZrYNoNbdzEIulNscNZuKWT+oYeo2OOXdrEr9OeApzCnb6AyxdCQzfjiP+/LlXlCt VOFNHAkusL18II488So34U5GtUQ1/gCfXib3RzuPSz7POb924Qyp960xr+amol5KsmGH Wy/nbh/0oA94WtY14oZDflWSM56/Q0JudfACIh2kigxc582l7lAxke1hjtedWZzutUG4 vKOoQbfWRAmithbGnZdg3D2EVkQUsgNvP72bo5lO0dhTrsnZbuZCuTypvvqnLomwnkY5 pE0jsr89N61tGOJ5xZAgMceLuKzaQnrKHa8l344pEJspvMQCjKc6I9n90sPeYxrG0Fo7 fEog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=k6TsL30J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si13557264pgp.421.2017.11.22.09.12.16; Wed, 22 Nov 2017 09:12:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=k6TsL30J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751796AbdKVRLi (ORCPT + 78 others); Wed, 22 Nov 2017 12:11:38 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:46626 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751472AbdKVRLg (ORCPT ); Wed, 22 Nov 2017 12:11:36 -0500 Received: by mail-pl0-f68.google.com with SMTP id k7so1084823pln.13 for ; Wed, 22 Nov 2017 09:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=qon3weLF8bmlJzRqIFZhYQ+c8TRhafqWyGeSdAxzafQ=; b=k6TsL30JDTEGD80I0wGh9Z89yCwZ0H7hvJInPxvsEU4AnEZtZnwac/PSuz9qx+pp6f ZFwiHKkNh99H39mpOzYojMUOOHsoKn9nHjhwUe1tPDNkfGkCuUGDHfImnAKr2lPvQ5Pu 0Qn5eNOLIeEJkhqF5lbNv4nxTeru7geEffXNr9aqlNDcRGxhmsy75teGU/xtfEo+xtkN bj5Y1CCxTtuEb6tyQ21nSQbgtGyXHSMaGnphIrPbCXa7lrlUsBCKGvHt3LFek+bgkfsC yO1ZRp2Hl7w147hnsxXdMlCX+KBj+4yw2v1g62/imB2j7Vq/eITxea+R8+odHp3rZ7SH 1dDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=qon3weLF8bmlJzRqIFZhYQ+c8TRhafqWyGeSdAxzafQ=; b=RP+eNA5MJwoe+4WXVG7bkrhEOmIFxtAvBVgj1rb/v5N/jhdrH4F5wkhtWfQkzhRqNZ N7hLswMG/EOT/LvgP+eq5QES+9L/Vk+rP7V4azjfPMZib/Q/HM71zkfjBp7Q6na6uYNQ Dgko3Kofh6/tBDktx0CJheuD/r6NAXIkBdz5zcneVAiAjNjWZROcbVbcFDw/FbW9ez+4 2RKXdlIQZicyW+vHY7imu/oapt3KUhrjnAFhJLszk0yAD2hbUF93KGhjSzLf8bUwY90J t+ERT5hJLkpbJb17XVRXQHZI/yfEekH9I7/tTEJRBmLzlUTsBp8Wh8QbMGkMBvTsYfsF 034w== X-Gm-Message-State: AJaThX5A5n/VuB5eTx9gP5rUaLm9YfrhtZiCt3WHfBCPu59ul/uHUNlf ucu1EPeGjq/ll+fqlGPy+Qb8PsWYXPcZjQ== X-Received: by 10.84.201.6 with SMTP id u6mr21799596pld.51.1511370695608; Wed, 22 Nov 2017 09:11:35 -0800 (PST) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id x11sm7280946pge.16.2017.11.22.09.11.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 09:11:34 -0800 (PST) Date: Wed, 22 Nov 2017 09:11:34 -0800 (PST) X-Google-Original-Date: Wed, 22 Nov 2017 09:11:32 PST (-0800) Subject: Re: [patches] Re: [PATCH] dt-bindings: Add an enable method to RISC-V In-Reply-To: <20171121110451.qm5cy5s4audfvwu5@lakrids.cambridge.arm.com> CC: robh+dt@kernel.org, devicetree@vger.kernel.org, patches@groups.riscv.org, linux-kernel@vger.kernel.org From: Palmer Dabbelt To: mark.rutland@arm.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 21 Nov 2017 03:04:52 PST (-0800), mark.rutland@arm.com wrote: > Hi Palmer, > > On Mon, Nov 20, 2017 at 11:50:22AM -0800, Palmer Dabbelt wrote: >> RISC-V doesn't currently specify a mechanism for enabling or disabling >> CPUs. Instead, we assume that all CPUs are enabled on boot, and if >> someone wants to save power we instead put a CPU to sleep via a WFI >> loop. >> >> This patch adds "enable-method" to the RISC-V CPU binding, which >> currently only has the value "none". This allows us to change the >> enable method in the future. > > I think you might want to be a bit more explicit about what this means, > and this could do with a better name, as "none" sounds like the CPU is > unusable, rather than it having been placed within the kernel already by > the FW/bootloader (which IIUC is what happens currently). It was proposed to make "enable-method" optional, and have the lack of an enable method signify the current scheme. The current scheme is that the bootloader starts every hart at the kernel's entry point. Calling this "always-enabled" was also suggested, which seems fine to me. > As previosuly commented, I also really think you'll want to define a > simple boot protocol (like PPC spin-table) whereby the kernel can bring > each CPU into the kernel independently. That will save you a lot of pain > in future with things like kexec, suspend/resume, etc. > > For arm64 we had a spin-table clone (implemented in our boot-wrapper > firmware) that allowed us to bring CPUs into the kernel explicitly. > However, we made the mistake of allowing CPUs to share a mailbox, and we > couldn't tell how many CPUs were stuck in the kernel at any point in > time (rendering kexec, suspend, etc impossible). This is actually why I'm kind of pushing back on this: because we don't know how we're actually going to handle this, I don't want to go build an interface to the firmware that might be broken. Essentially what we're doing now is just keeping the spin table entirely within Linux, so we can change this interface whenever we want. The start of our kernel looks like _start(char *dtb_pointer, long hartid) if (atomic_increment_return(hart_lottery) == 0) start_kernel() else while (READ_ONCE(__cpu_up_has_turned_on_hart[hartid]) == 0) wait_for_interrupt() smp_callin() If I understand correctly, this is essentially what the spin tables are doing in arm64. Our mechanism is a bit different because we can expose a much more complicated interface here, but since the interface can change (it's a kernel-internal interface, not a firmware->kernel interface) that's the natural thing to do. While I haven't actually gone through and looked at any of this (and I admit I have only a vague idea of how it works), I think this should work fine for kexec, CPU hotplug, and suspend. kexec is easy: the fresh kernel's image will boot exactly like a regular one, as all the harts can just jump to the entry point at the same time. Since "hart_lottery" is initialized to 0 by the ELF there isn't anything special required to make it work. Actually turning off harts will require us to add an interface that does so, which will probably happen via an SBI call. We haven't actually designed the interface yet, but I'm assuming it'll just reset the hart. In general, we like to make any interface that sleeps also work as a NOP, so for now let's just pretend that this interface does nothing and go straight to_start. This should map pretty well, our __cpu_down could just be the mirror of __cpu_up __cpu_down(int hartid) __cpu_up_has_turned_on_hart[hartid] = false; atomic_decrement(hart_lottery); __sbi_suspend_hart(); jump _start That should cover hotplug, and then suspend is just a matter of hotplugging out the last CPU. I assume that lots of our stuff will blow up when we start removing harts at runtime, but that'll all happen regardless of how we wake them up. There's also a bit of a race here (bringing up a hart while the last one is suspending), and that counter overflows, but those seem solvable. Does that sound sane? If not, I'd be happy to go and design a spin table firmware interface. We just like to avoid inventing external interfaces until we really know what we're doing :). > Thanks, > Mark. > >> CC: Mark Rutland >> Signed-off-by: Palmer Dabbelt >> --- >> Documentation/devicetree/bindings/riscv/cpus.txt | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/Documentation/devicetree/bindings/riscv/cpus.txt b/Documentation/devicetree/bindings/riscv/cpus.txt >> index adf7b7af5dc3..dd9e1ae197e2 100644 >> --- a/Documentation/devicetree/bindings/riscv/cpus.txt >> +++ b/Documentation/devicetree/bindings/riscv/cpus.txt >> @@ -82,6 +82,11 @@ described below. >> Value type: >> Definition: Contains the RISC-V ISA string of this hart. These >> ISA strings are defined by the RISC-V ISA manual. >> + - cpu-enable-method: >> + Usage: required >> + Value type: >> + Definition: Must be one of >> + "none": This CPU's state cannot be changed. >> >> Example: SiFive Freedom U540G Development Kit >> --------------------------------------------- >> @@ -105,6 +110,7 @@ Linux is allowed to run on. >> reg = <0>; >> riscv,isa = "rv64imac"; >> status = "disabled"; >> + enable-method = "none"; >> L10: interrupt-controller { >> #interrupt-cells = <1>; >> compatible = "riscv,cpu-intc"; >> @@ -130,6 +136,7 @@ Linux is allowed to run on. >> reg = <1>; >> riscv,isa = "rv64imafdc"; >> status = "okay"; >> + enable-method = "none"; >> tlb-split; >> L13: interrupt-controller { >> #interrupt-cells = <1>; >> -- >> 2.13.6 >> From 1584698455975193211@xxx Tue Nov 21 17:43:36 +0000 2017 X-GM-THRID: 1584615917740464042 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread