Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1497048imm; Wed, 15 Aug 2018 19:44:48 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw3FrmuVGVqPTqsMTzJEeKGW+aGPXHbBUCpSpYv7/ciWrEbJCcNibHvpOYojfxPmsi7p5gA X-Received: by 2002:a63:f751:: with SMTP id f17-v6mr27874712pgk.410.1534387488711; Wed, 15 Aug 2018 19:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534387488; cv=none; d=google.com; s=arc-20160816; b=Q/XDq3d+JyQaj1j1b9xMKAPqpL9QrpVvRz99AX3EbRHYg8ntITDDiIIezX4uNwJITL TBIh5Jjse6UJTCF4MEklJfCBHKHW8OtYIS8xLQslJu8SN42pijcSmWI48/O5WuE78bKi Whu2VUld9NzPoOe7bULEE8D28S0EDrarPtU+ExjLh2IoJUR0WnSsv3zNXYryj9xeVwfP u/YUeXzDE+gG4PG+W9p6Y3PbLlWWKZXSR1AoYra7wcwKNjiJQtOuv1oNbRHrHyeW3vzu 3HSUJMU1kbxBWJXGkPei9N5DgczzZzfcmb2KtMFe1kWUo0GEKa6z58G3IwTMLUX46NOi +nvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=y4OE5e2NRZohYVP3ZNT/1NB/A0QcmMe98Xof8A52U4E=; b=v1S2Arlx4PIfQ1dAA8VVRLd7cZovLB9qUaoCT1yRCvqC3FGlBeU/ESpUqpvLiDf7us pWP7E/xsBN/VB7fvF2YLkJu7rCZ+tgcipbR0FqX7l8rxcG8lFGsxfv2eePl9/f8S1Ns+ 5h4hgwPNDkF8Vhxal4PnGDeiQM2Oo2zqWDF1DGDPOU6/iMYxptg6LyEb8Vno3qJTMQSx TeTMwSyU+QaWfK8LekuhQQexX9w4sQE5LL6JaagSXxVq29+9Kbra2QKSUGCnZ/qvcMkI MrzmoD4Ee4p25RNuf0VgMUsAxtRHAu996nP4SipAsEK4iEoBT9ompdeQEg3nEdA8yZW0 R3yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hspqTmmt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l190-v6si25026720pgd.626.2018.08.15.19.44.18; Wed, 15 Aug 2018 19:44:48 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hspqTmmt; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731305AbeHPCuu (ORCPT + 99 others); Wed, 15 Aug 2018 22:50:50 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:25856 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbeHPCut (ORCPT ); Wed, 15 Aug 2018 22:50:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1534377379; x=1565913379; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=8SV0JD9xISdUkBeOHHNwOfZqNF36VPqj1Rts7EPD3lU=; b=hspqTmmtEBVDGGj+vMNB8TWikkYoz9EfwtFb4iIgwygcuCU5/L3EAgHU 8AXIDs/kzt3n2SMlg1vGBmyPt+dzgQfqp/sutVlFOSMUxzi6SrqdSJAq6 DPT3bq3MmAlLL/fDGLhuXf2wYkYHnkrKE7b1OTz0N+rzTy87330gDp/GI EmvGaOpm2unwHTMYmhZP5yuMT0NkX3oYmavQxfxDOSBHoFGj2c/s2h0ex RWJTrNNQwV07XVfYSgBQ27xnumWfTMCSGCsOqx7OFby6ukMzZu7JJPbQ8 9dZL/bqo+/8E1RU+d1uHD9h7FPGfiynWrJ8b5uoB5dYBSTvTLjk9L2mhZ A==; X-IronPort-AV: E=Sophos;i="5.53,245,1531756800"; d="scan'208";a="88557062" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Aug 2018 07:56:18 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 15 Aug 2018 16:44:16 -0700 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Aug 2018 16:56:18 -0700 From: Atish Patra To: palmer@sifive.com, linux-riscv@lists.infradead.org, mark.rutland@arm.com, anup@brainfault.org, hch@infradead.org Cc: atish.patra@wdc.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, Damien.LeMoal@wdc.com Subject: [RFC PATCH 1/5] RISC-V: Add logical CPU indexing for RISC-V Date: Wed, 15 Aug 2018 16:56:13 -0700 Message-Id: <1534377377-70108-2-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534377377-70108-1-git-send-email-atish.patra@wdc.com> References: <1534377377-70108-1-git-send-email-atish.patra@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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]; + #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) +{ + 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