Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1707817imm; Thu, 16 Aug 2018 00:54:56 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxl17UNPMH5nRbmIt0kKLuIAVJFsMVIv4etJbnBB8jSbcVy8kBJLsHRTZZqQJQmPoA99QjN X-Received: by 2002:a63:9b19:: with SMTP id r25-v6mr28020003pgd.44.1534406096901; Thu, 16 Aug 2018 00:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534406096; cv=none; d=google.com; s=arc-20160816; b=MHYY4Eb9BS3zCQiBleMcHFzZsa84u/g5aW7bSCN+6h9dkMDW7IieCIqUgGZxTwqrJ+ fohT4dg6lOv089t8p8PiUkNQwPWk6q+CTUdyR8NkJEdXDqmw5YUl7DS9rizOsLLwTxil 851OvNjkU1lvbdlxEJVXT57RkZxb2Gc5bzyJIYC8hkqzZBNQBTEYIWNi0obT4xByzxfz eFzis8MjahB52a44nGqxk2MYRVWFSgEi0X/yOcUFHFFAjdPYN5FYozIy2uUtya2qXpdg vikXLCL4koOj0F1j2FDqFznW0bZzBf9bepBe7WZ/qU0sow53y3btZkIVyhDhEWSe+zBZ x/wg== 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=I7uxka0u1jLTlIWbBxTQjzk5UHp9i68gBytUNKwzkww=; b=kir1L0O7nexrDEA/+4gUVqkng6dZ2XfaZzeDisuaGhA5klreIbE0VO04IAB3CtqtlE tg2rxEtHPQekMPrtfav1815gWeGivrAJeGMFqscUlU+ww5dkTdsfiwQ525uXw27LTcot /Uv92pVYDyyPZ3NVIMHlofJBbRNd4aKx2gQhOO/h00VhnNLm3PYbWVFJ1zSKE/QTr6ND bZUZjDlnYvX4zuJ1tXhX2jqIoNQfJiDf69IUyXHM24ZTx2WO+MUU3JB8zQTR9OGMVYOH ZINCZP8QjMlBAunUYhmFt03OkpDe3nt/7Tc6wv0b0ty3OFtXDvENYi/dzUV22GVDgbeD xmmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=XS9deY6S; 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 w21-v6si24075920pgk.206.2018.08.16.00.54.41; Thu, 16 Aug 2018 00:54:56 -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=XS9deY6S; 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 S2387675AbeHPHBi (ORCPT + 99 others); Thu, 16 Aug 2018 03:01:38 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38991 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387501AbeHPHBi (ORCPT ); Thu, 16 Aug 2018 03:01:38 -0400 Received: by mail-wm0-f65.google.com with SMTP id q8-v6so3026602wmq.4 for ; Wed, 15 Aug 2018 21:06:06 -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=I7uxka0u1jLTlIWbBxTQjzk5UHp9i68gBytUNKwzkww=; b=XS9deY6Ss69c+bGM/stH9ymwbyNLF15GA4wcUMqZECbL2Ylp6y+TS6qQsjAqSUGp+k BH4DEVZT1eF4ZxjuOatd3MYaeBa7Q4k8tmkQ4GHPOl6m7K3bWfqQR6c9avj8/X8mNlRA VW/OipCCOBx9FbTIsD+XVcVD8QWXwg8mnbtR3vjF1hBOT5NG8nUXm0+QX5XB/xbgNH1L 3bRtxsWTcFTFF1IRD22NHF983K56t4luAygyi9WQ7pkZVizAq9eQhrzd6Lpn3v0LzBpr /ZPrqn1IrogXbFQLhC/Zz2xcUpQqp/RFKPB3KWN2dsLS/vOX0vBfP0q6Q5lRR7J+Glhw X+Bw== 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=I7uxka0u1jLTlIWbBxTQjzk5UHp9i68gBytUNKwzkww=; b=h319iBH2KJaPev+5v1WHiA9m1qlOjYJGTFMjQoSGV1IdplPZ+2Bmt2hKPgSx1c8oY2 llYqrGwwWN5lgnQ9WveifkUT/m4IKgqFo5eP2pJLxr81VeKZlyKBH4r4iirn5fMMBPk9 Uq2mAOYzvkX8NbWHMK/W7/VcmW8eGen0q7Ie4IvclLllIVIIJBXfdHkoJX1I21bKOm7Y 1Anvhx9Fz/OQVkL5AHyLQJ8ix/5mWHggJUBYpauIWn7ja39R8m10qW+C7xM6bAYSKApX 1VlA/goI1Y/zeAEJm1pO8QX3STAsG019GDnukuQJIybR2kNZ2c5TPfBRb1n/3VQ4q0ny BekA== X-Gm-Message-State: AOUpUlHvaqrqJJwmGxkAMBvXjZLfEeQ6JU5xoU3WUiLQlsQPu3SgHjCF L3LoHUnwtYooT9y6K7NthGv3vXkHIHfcgr+uWu7nYw== X-Received: by 2002:a1c:8a04:: with SMTP id m4-v6mr14465873wmd.137.1534392365170; Wed, 15 Aug 2018 21:06:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:adf:9dd2:0:0:0:0:0 with HTTP; Wed, 15 Aug 2018 21:06:04 -0700 (PDT) In-Reply-To: <1534377377-70108-2-git-send-email-atish.patra@wdc.com> References: <1534377377-70108-1-git-send-email-atish.patra@wdc.com> <1534377377-70108-2-git-send-email-atish.patra@wdc.com> From: Anup Patel Date: Thu, 16 Aug 2018 09:36:04 +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 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. 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. 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? > + > #ifdef CONFIG_BLK_DEV_INITRD > static void __init setup_initrd(void) > { > diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c > index 906fe21e..d55379ee 100644 > --- a/arch/riscv/kernel/smp.c > +++ b/arch/riscv/kernel/smp.c > @@ -38,7 +38,26 @@ enum ipi_message_type { > IPI_MAX > }; > > +int riscv_hartid_to_cpuid(int hartid) > +{ > + int i = -1; > + > + for (i = 0; i < NR_CPUS; i++) > + if (cpu_logical_map(i) == hartid) > + return i; > + > + pr_err("Couldn't find cpu id for hartid [%d]\n", hartid); > + BUG(); > + return i; > +} > > +void cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out) May be rename cpuid_to_hartid_mask() to riscv_cpuid_to_hartid_mask() for consistency. > +{ > + int cpu; > + > + for_each_cpu(cpu, in) > + cpumask_set_cpu(cpu_logical_map(cpu), out); > +} > /* Unsupported */ > int setup_profiling_timer(unsigned int multiplier) > { > -- > 2.7.4 >