Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1777793imm; Thu, 16 Aug 2018 02:24:16 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxMKMejbqpVz4zNMnGhnDQm4vN82Z5NRqjMNJqiyCyWm8czl/wwM3uyp+VW7QZsMaVn70VA X-Received: by 2002:a17:902:7b87:: with SMTP id w7-v6mr28417863pll.142.1534411456532; Thu, 16 Aug 2018 02:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534411456; cv=none; d=google.com; s=arc-20160816; b=qNMYcpdualVWv7ObIFAwrmqiYsDfTpeMNBvAMK6iCzvrcfsHr7xaIJH76/8RqBWEfy NkmxWkgimk1sKjA3nHkYsRgx3wBq/XSe4tVEy2hQYC2sZlJvfxyTyxRmkUmd/oDZa5xB 4FmKWEFWRYPgRNkluoiTT5oU75RiAOAsn6EFoVq40AscUlkt3hdrcMGRPd5WTJiD+Ayw dK0ZXDTGV88YXypg478e3OP5n3LKQ0Xz9rznu5HgdqmET94RocmoA50w7BEy/Cja6fTp 5Ipnl7wDGHPbLcD/SRozpQ+6rZ/y39waI+CUIQMuiVs3+XCpbpBVS7MYsmgYnC/EyraZ 5usA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=E2XnoDSy7cWFCpd7ZCV1aPFZuUhPkkliODkkf4ZHKpU=; b=rCKR7tGKz6RvGHITV33ssCBYcJhi/Atc1jJHAKFG4SjIMLE6bp5cOEQhcgTKZYlocz qcfcg+vgh7E7YxKGHfKmy5OF4FZzzEUnf5mvc7BxUyP3lLIBK2XiNJfH3+W74cTVkO3W mRm729rL1ovLtDnH5gHxxCww6Fvf+LaXcRhryhxOl/pS0ODJ3eQx6k9rdSP/AF/1WzG2 z8BKzM4uVrovWtFmFlGup5OB+oT6ZNyuCs84lpoC8IoTCPZ2jnRpwrIFUHt2jAIS3dD4 egkklejo0My5zMFjhm6wECHWWAra8s8Dj1IIPD4AJs7R8gSDT+ryXzLfe4rUJ856Ck4d kbkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=pl6GPADu; 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 y6-v6si18354510plp.279.2018.08.16.02.24.01; Thu, 16 Aug 2018 02:24:16 -0700 (PDT) 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=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=pl6GPADu; 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 S2387730AbeHPIfr (ORCPT + 99 others); Thu, 16 Aug 2018 04:35:47 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53266 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730182AbeHPIfq (ORCPT ); Thu, 16 Aug 2018 04:35:46 -0400 Received: by mail-wm0-f68.google.com with SMTP id s9-v6so3230907wmh.3 for ; Wed, 15 Aug 2018 22:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=E2XnoDSy7cWFCpd7ZCV1aPFZuUhPkkliODkkf4ZHKpU=; b=pl6GPADuo7XB8BkusQ/mlS4vC3T0g6npBpZtW36zdM0ZzLOOX9a22wTTOgKNTm3fKa JTC2g75uMod6jXT7NfJdRlLYS8/qJBkSmByy9o4I8unPb2+6gUOax6+xzCrIhZuvjofI QCrWG2jvacPUAP5oTfAYmSKPjPVlW0nCgb1ArDd5pfEigdX4bWBeSMzfPhCO6x63YV6/ lMk/BCTqiA0FT0EyJ/jcet5/ck6ZvEt2kSpbCXNCCHeAfZPgu7MYnWv9JgXYEJ1c0Ms+ fRZYCcqmzw853AyIjMiwUpxNvWX7GpbdEu2os9eq9IM6OPwee29ZPMfaxlhZijSoIIhZ TM6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=E2XnoDSy7cWFCpd7ZCV1aPFZuUhPkkliODkkf4ZHKpU=; b=oF4C5h6sVgOhxBCFm3hdQa/pQj6vywYc+izoE1R96THtP890DpAPHcRs3VHa+lBdcB BUN/tq4dFsft4DRL7t1JU34WbzVJ8di4jos96ENHiGcxv7xk7Y0B0g1r9dfcE9Qz8ZjN 9vYwqq4Bv6pxpfwGARA79hEadJgRnLZhdYkkE5livlDTNupsti6sevUasOFq8r1HkL/8 z3yQlxBOGLCUPDMWmgM7OLszkXBJ+BKCTkSZ6rSkP8rOc6hVU95LdJ4cioBGt+ilefWX N3gHQwuaKK7LlFvWAGw6BgNwjVU2gxTGuzYDeSFQEVUX98SZP6SqqF/Q41snuveSTL/s X1eg== X-Gm-Message-State: AOUpUlHKnKIbyCKW0G/ByvGXF+gsAaMitE3P6m7Oh77mJ17PDqXpiHXj nIZB8LoKx9KQZmUxna0L8XNx/j0JKcPHB282WHiWKg== X-Received: by 2002:a1c:4c0e:: with SMTP id z14-v6mr16270819wmf.89.1534397988526; Wed, 15 Aug 2018 22:39:48 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:adf:9dd2:0:0:0:0:0 with HTTP; Wed, 15 Aug 2018 22:39:48 -0700 (PDT) In-Reply-To: <7bc075fc-7039-62d8-c708-1c36233b7126@wdc.com> References: <1534377377-70108-1-git-send-email-atish.patra@wdc.com> <1534377377-70108-2-git-send-email-atish.patra@wdc.com> <7bc075fc-7039-62d8-c708-1c36233b7126@wdc.com> From: Anup Patel Date: Thu, 16 Aug 2018 11:09:48 +0530 Message-ID: Subject: Re: [RFC PATCH 1/5] RISC-V: Add logical CPU indexing for RISC-V To: Atish Patra Cc: "palmer@sifive.com" , "linux-riscv@lists.infradead.org" , Mark Rutland , Christoph Hellwig , Thomas Gleixner , "linux-kernel@vger.kernel.org List" , Damien Le Moal Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 16, 2018 at 10:47 AM, Atish Patra wrote: > On 8/15/18 9:06 PM, Anup Patel wrote: >> >> On Thu, Aug 16, 2018 at 5:26 AM, Atish Patra wrote: >>> >>> Currently, both linux cpu id and hardware cpu id are same. >>> This is not recommended as it will lead to discontinuous cpu >>> indexing in Linux. Moreover, kdump kernel will run from CPU0 >>> which would be absent if we follow existing scheme. >>> >>> Implement a logical mapping between Linux cpu id and hardware >>> cpuid to decouple these two. Always mark the boot processor as >>> cpu0 and all other cpus get the logical cpu id based on their >>> booting order. >>> >>> Signed-off-by: Atish Patra >>> --- >>> arch/riscv/include/asm/smp.h | 17 ++++++++++++++++- >>> arch/riscv/kernel/setup.c | 2 ++ >>> arch/riscv/kernel/smp.c | 19 +++++++++++++++++++ >>> 3 files changed, 37 insertions(+), 1 deletion(-) >>> >>> diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h >>> index 36016845..0763337b 100644 >>> --- a/arch/riscv/include/asm/smp.h >>> +++ b/arch/riscv/include/asm/smp.h >>> @@ -22,6 +22,12 @@ >>> #include >>> #include >>> >>> +/* >>> + * Mapping between linux logical cpu index and hartid. >>> + */ >>> +extern u64 __cpu_logical_map[NR_CPUS]; >>> +#define cpu_logical_map(cpu) __cpu_logical_map[cpu] >>> + >>> #ifdef CONFIG_SMP >>> >>> /* SMP initialization hook for setup_arch */ >>> @@ -33,6 +39,8 @@ void arch_send_call_function_ipi_mask(struct cpumask >>> *mask); >>> /* Hook for the generic smp_call_function_single() routine. */ >>> void arch_send_call_function_single_ipi(int cpu); >>> >>> +int riscv_hartid_to_cpuid(int hartid); >>> +void cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask >>> *out); >>> /* >>> * This is particularly ugly: it appears we can't actually get the >>> definition >>> * of task_struct here, but we need access to the CPU this task is >>> running on. >>> @@ -41,6 +49,13 @@ void arch_send_call_function_single_ipi(int cpu); >>> */ >>> #define raw_smp_processor_id() (*((int*)((char*)get_current() + >>> TASK_TI_CPU))) >>> >>> -#endif /* CONFIG_SMP */ >>> +#else >>> + >>> +static inline int riscv_hartid_to_cpuid(int hartid) { return 0 ; } >>> +static inline void cpuid_to_hartid_mask(const struct cpumask *in, >>> + struct cpumask *out) { >>> + cpumask_set_cpu(cpu_logical_map(0), out); >>> +} >>> >>> +#endif /* CONFIG_SMP */ >>> #endif /* _ASM_RISCV_SMP_H */ >>> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c >>> index db20dc63..e21ed481 100644 >>> --- a/arch/riscv/kernel/setup.c >>> +++ b/arch/riscv/kernel/setup.c >>> @@ -82,6 +82,8 @@ EXPORT_SYMBOL(empty_zero_page); >>> /* The lucky hart to first increment this variable will boot the other >>> cores */ >>> atomic_t hart_lottery; >>> >>> +u64 __cpu_logical_map[NR_CPUS]; >> >> >> If hardware IDs are always machine word size then its better to use >> "unsigned long" in-place of u64. >> > > Good point. Thanks. > >> The __cpu_logical_map[] should be zero initially because zero is a >> valid hardware ID. Better set all entries to -1 by assigning { -1 } to the >> array. >> > > ok. I will introduce INVALID_HART_ID (=-1) and initialize with that. > >> Also, I feel __cpu_logical_map[] should be part of smp.c instead of >> setup.c. Any particular reason for having it in setup.c? >> > > currently smp.c is only compiled in if CONFIG_SMP. That's why I kept it in > setup.c Ahh, got it. For now let it be here till we figure better place for it. Regards, Anup