Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4513359imm; Tue, 11 Sep 2018 13:06:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYXvbcJi2/Jhh83Q/DNBpun51BUOFCH0MIn6F3uMlHMiL3G2UtrSUDO4yxP3u4ND6dcjGLa X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr29850058pgc.344.1536696408358; Tue, 11 Sep 2018 13:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536696408; cv=none; d=google.com; s=arc-20160816; b=neL14vynJnTOFZ1bJe5nmmK0Am4HcaPwoLw+RkkzKP8ce/Ojt9lG74smAPQ2AXrc+E GcHcOo8hLg9fN9y+7MJzb2NYi/774RJjWQ17ceIodUPhUszEaxcij82nPdk1Fjsy8arR cWXH+BKTj9ebc1hbaHhuxflCCnSZjD0sdq6FgWgLxovCyIZ6x7GNo8ILlXMvgcZ5oIx6 rBgTWP1H3eBbvhdjkF2CttDoaC2EhbbK1ncjiYFjFVFO7GHMOQgfOyo/o8GWeSCNFp9X 39pi1JzQundljtE0VjTxk/EKfsu2WeW4xtxQgUfnfJXmMUTxuuYWHuY+4k7XrK9NudOD n8jA== 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; bh=M+uiu+dmCyiNKn+1UekeKwvA8CEQleghkHCDN7tf9U0=; b=g3NzMY5sunijVTrKoRqSRloiJHT9+yGWdfWtB4hfLrj0xYFlCbqjnTz92oiBjvWEqu OVMuttjTaRY06BYbsEBV8D6adjIQFJJLRbMa+Iy2Y0dvdRyaj2NqvzT2i0knXkkAQhI/ y7DeLitAUmZSfh6EXHfYQOi4N/dU0Px6IY1xNaspL9entvwhDeyyXs1pDeg5BxEFQkDz mjnQ6kf5qUF752FLZsW/ZFV3XRzB90Y92bpIT8EAWTt8B74DW+GlfqAyQ/W6N3AQTsjT azgpa9xy791Wv794sEkjZI4rADLjVHF5r08m/qTj/oVvBThzJ3fPhy/n0BG1dBQCM7i0 OH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=rV2QE7OG; 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 m10-v6si19607885pgv.374.2018.09.11.13.06.33; Tue, 11 Sep 2018 13:06: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=rV2QE7OG; 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 S1728087AbeILBGj (ORCPT + 99 others); Tue, 11 Sep 2018 21:06:39 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:52878 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbeILBGi (ORCPT ); Tue, 11 Sep 2018 21:06:38 -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=1536696345; x=1568232345; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=jaKLdazmjO0K+7+KaCwU2B2Uf9dqvFXChtdpvPBBLj8=; b=rV2QE7OGJeCaQ2LnjP5ri07T8jrUu/0Z+DEdwbI9nRcS+NsHwXN4eVUb jyUSXZmweWNr9h9J7MOtO9lGALBfAm5mYnWUEiP4TTlZsvf1S0QhDFWPi D+rA8RCvoEO4p+J2fwTUKJ232mpCfz1VNlBZ3M1JNuv/o9wiw7IiFbCUX IGnI1ta4YoKjuL95lH8UjAxdHGKdxuL8Ekn1oX7DWjDvCp+aehjclZqTJ fM0/K4lpXqklRrIr7RRICrG4V7hfQ1JFKrbMk3H76F6ToHwf8/QJYPy/R a0AbBH7asVqf8Ftuaxji6iAwiRAOlZH+CjebtQ4HJX9CA9Qsg4I+quLBe A==; X-IronPort-AV: E=Sophos;i="5.53,361,1531756800"; d="scan'208";a="193728841" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Sep 2018 04:05:43 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 11 Sep 2018 12:52:18 -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; 11 Sep 2018 13:05:44 -0700 From: Atish Patra To: palmer@sifive.com, linux-riscv@lists.infradead.org Cc: mark.rutland@arm.com, hch@infradead.org, anup@brainfault.org, atish.patra@wdc.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, Damien.LeMoal@wdc.com, marc.zyngier@arm.com, jeremy.linton@arm.com, gregkh@linuxfoundation.org, jason@lakedaemon.net, catalin.marinas@arm.com, dmitriy@oss-tech.org, ard.biesheuvel@linaro.org Subject: [PATCH v4 11/12] RISC-V: Add logical CPU indexing for RISC-V Date: Tue, 11 Sep 2018 13:05:38 -0700 Message-Id: <1536696339-15204-12-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536696339-15204-1-git-send-email-atish.patra@wdc.com> References: <1536696339-15204-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 Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- arch/riscv/include/asm/smp.h | 24 +++++++++++++++++++++++- arch/riscv/kernel/setup.c | 4 ++++ arch/riscv/kernel/smp.c | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 85d7619e..fce312ce 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -18,6 +18,13 @@ #include #include +#define INVALID_HARTID ULONG_MAX +/* + * Mapping between linux logical cpu index and hartid. + */ +extern unsigned long __cpuid_to_hardid_map[NR_CPUS]; +#define cpuid_to_hardid_map(cpu) __cpuid_to_hardid_map[cpu] + #ifdef CONFIG_SMP /* SMP initialization hook for setup_arch */ @@ -29,12 +36,27 @@ 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 riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out); + /* * Obtains the hart ID of the currently executing task. This relies on * THREAD_INFO_IN_TASK, but we define that unconditionally. */ #define raw_smp_processor_id() (current_thread_info()->cpu) -#endif /* CONFIG_SMP */ +#else + +static inline int riscv_hartid_to_cpuid(int hartid) +{ + return 0; +} +static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in, + struct cpumask *out) +{ + cpumask_set_cpu(cpuid_to_hardid_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..eef1b1a6 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -82,6 +82,10 @@ EXPORT_SYMBOL(empty_zero_page); /* The lucky hart to first increment this variable will boot the other cores */ atomic_t hart_lottery; +unsigned long __cpuid_to_hardid_map[NR_CPUS] = { + [0 ... NR_CPUS-1] = INVALID_HARTID +}; + #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..5aba0107 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 (cpuid_to_hardid_map(i) == hartid) + return i; + + pr_err("Couldn't find cpu id for hartid [%d]\n", hartid); + BUG(); + return i; +} +void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out) +{ + int cpu; + + for_each_cpu(cpu, in) + cpumask_set_cpu(cpuid_to_hardid_map(cpu), out); +} /* Unsupported */ int setup_profiling_timer(unsigned int multiplier) { -- 2.7.4