Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1748393imm; Thu, 16 Aug 2018 01:46:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx5dvky+xySj48jm/BF7Dm49T6WWr0Qpch/9ungIZmq80wNUh8ftvnu4FJVdn3PvDand8FV X-Received: by 2002:a62:3952:: with SMTP id g79-v6mr31280740pfa.133.1534409207493; Thu, 16 Aug 2018 01:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534409207; cv=none; d=google.com; s=arc-20160816; b=q4SRagYJCSAI4I4xfe6FWqbYJaaG76YY2mA1NVTzU8rfO/0a8oU3EFVbbag7W1F9w0 zSoLuk/Fcezuf+becR9r4OYnPBzR4GySFHW/CLVMWiA6TKuttKKexh4BDfmXmOGeKaFn imYEBIplj3aAy8oynQ6fEfeWq8X+iEpn4sA1c3dO4bUNq2LV7RRKM7S3yWVgwuYjfR2Z SxaoB18T2MEWybKHDb9zqHTMyya3XAOHy31m9eQ/w3PoCkqvccCG2C+U5S5XYrCCoHSC 99xFYNpe8o/DE0T1yL3veYrjFhcl11Rh/Qpw3yg7L6hkIUjoVPSkR1MIQPt9d1ydeQcI RqIg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=3HyoBXZxVtw86Sm8Bk1GIgzFwf8cr26VuEU/7oMdqMY=; b=0k0zC3LltGa88RrMXi4DZE+te7sI+QkAPZr++6nsKyDeE5DgyXH9gX7FpcawVVren8 IXHdLSQ2cAuOphSrPx0d/+eAoKClUKAgdA5+nVXBIPLqxPdX5ldTowlnzp/W/fZZxC04 WwXcsSsjxTFZWcJg9InWoEm9Xp/uiQL7pW33UliK6dRe7EpVtkMc6xact/AHHx7EVzIN f6GMdl59LstgSD0c5UDxilnMDS/GAZk2gyATpuoTZi5Lv4HhSeOhNfyLdKP1rldbFGNb 3lmqFRGwp5+r79fX+OA9/bVEhY9XGKEWFCXa1M9QKGpPt7vedXJwbWJy+jG485BCeIce ktyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Xclg4pJQ; 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 n7-v6si21473232pgp.411.2018.08.16.01.46.31; Thu, 16 Aug 2018 01:46:47 -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=Xclg4pJQ; 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 S2388180AbeHPINt (ORCPT + 99 others); Thu, 16 Aug 2018 04:13:49 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:41004 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbeHPINt (ORCPT ); Thu, 16 Aug 2018 04:13: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=1534396682; x=1565932682; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=+A3Tp9CZjFjVC1BMc+dlztRpvUnYD33l+lEXaluQXrA=; b=Xclg4pJQkhp6+dWFnovBSyg8Ud+kF7DLLHuBEoRWCL99X5QjXmF5ev3l b42CQnDdZmRYhBLJBcKni7FbFEcZdO4Sg8+1LFnlDyd9OED6iYqo3RFo7 6urJFg1StWGjnMktRC+qBTlZhiOdi0g4KjKSibT+uF68ZCr9BBbJfPBqI DADJVMO+B9N+y4Ig22ATkUvKqGPK5uDB9/8HrVnzrvUqin1fN8HqKPkNQ UnXU1Jdiw30BUODiV5LvafytW+8dQNDK+Ey6i8twrzQ1kZUvGLteUU5Gw cOKpvwwe5q8PSNrN/73aySXeEq5zD3IxXT2Aj0b3RXEhDS+tuJXiIAhad Q==; X-IronPort-AV: E=Sophos;i="5.53,246,1531756800"; d="scan'208";a="89191687" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Aug 2018 13:18:02 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 15 Aug 2018 22:05:24 -0700 Received: from 570dpc2.ad.shared (HELO [10.86.59.225]) ([10.86.59.225]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Aug 2018 22:18:02 -0700 Subject: Re: [RFC PATCH 1/5] RISC-V: Add logical CPU indexing for RISC-V To: Anup Patel Cc: "palmer@sifive.com" , "linux-riscv@lists.infradead.org" , Mark Rutland , Christoph Hellwig , Thomas Gleixner , "linux-kernel@vger.kernel.org List" , Damien Le Moal References: <1534377377-70108-1-git-send-email-atish.patra@wdc.com> <1534377377-70108-2-git-send-email-atish.patra@wdc.com> From: Atish Patra Message-ID: <7bc075fc-7039-62d8-c708-1c36233b7126@wdc.com> Date: Wed, 15 Aug 2018 22:17:58 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Regards, Atish >> + >> #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 >> >