2019-04-10 23:08:22

by Atish Patra

[permalink] [raw]
Subject: [PATCH v2 0/4] Miscellaneous kernel command line fixes

Assorted command line option fixes for RISC-V.

Changes from v1->v2.
1. Update pr_err string in patch (4/4) as per review.

Atish Patra (4):
RISC-V: Add RISC-V specific arch_match_cpu_phys_id
RISC-V: Fix of_get_cpu_node usage
RISC-V: Implement nosmp commandline option.
RISC-V: Support nr_cpus command line option.

arch/riscv/kernel/cpu.c | 3 +--
arch/riscv/kernel/smp.c | 5 +++++
arch/riscv/kernel/smpboot. | 0
arch/riscv/kernel/smpboot.c | 22 ++++++++++++++++++++--
4 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 arch/riscv/kernel/smpboot.

--
2.21.0


2019-04-10 23:05:56

by Atish Patra

[permalink] [raw]
Subject: [PATCH v2 4/4] RISC-V: Support nr_cpus command line option.

If nr_cpus command line option is set, maximum possible cpu should be
set to that value.

Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/kernel/smpboot. | 0
arch/riscv/kernel/smpboot.c | 10 +++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/smpboot.

diff --git a/arch/riscv/kernel/smpboot. b/arch/riscv/kernel/smpboot.
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index a8ad200581aa..7a0b62252524 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -84,11 +84,19 @@ void __init setup_smp(void)
}

cpuid_to_hartid_map(cpuid) = hart;
- set_cpu_possible(cpuid, true);
cpuid++;
}

BUG_ON(!found_boot_cpu);
+
+ if (cpuid > nr_cpu_ids)
+ pr_warn("Total number of cpus [%d] is greater than nr_cpus option value [%d]\n",
+ cpuid, nr_cpu_ids);
+
+ for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
+ if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID)
+ set_cpu_possible(cpuid, true);
+ }
}

int __cpu_up(unsigned int cpu, struct task_struct *tidle)
--
2.21.0

2019-04-10 23:06:01

by Atish Patra

[permalink] [raw]
Subject: [PATCH v2 1/4] RISC-V: Add RISC-V specific arch_match_cpu_phys_id

OF/DT core has a hook for architecture specific logical cpuid to hartid
mapping. By implementing this, we can pass the logical cpu id to cpu
node parsing functions.

Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/kernel/smp.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c
index 0c41d07ec281..94db72662f60 100644
--- a/arch/riscv/kernel/smp.c
+++ b/arch/riscv/kernel/smp.c
@@ -70,6 +70,11 @@ void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
for_each_cpu(cpu, in)
cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
}
+
+bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
+{
+ return phys_id == cpuid_to_hartid_map(cpu);
+}
/* Unsupported */
int setup_profiling_timer(unsigned int multiplier)
{
--
2.21.0

2019-04-10 23:06:07

by Atish Patra

[permalink] [raw]
Subject: [PATCH v2 2/4] RISC-V: Fix of_get_cpu_node usage

of_get_cpu_node expects a logical cpu id not a hartid.

Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/kernel/cpu.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index cf2fca12414a..c8d2a3223099 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -136,8 +136,7 @@ static void c_stop(struct seq_file *m, void *v)
static int c_show(struct seq_file *m, void *v)
{
unsigned long cpu_id = (unsigned long)v - 1;
- struct device_node *node = of_get_cpu_node(cpuid_to_hartid_map(cpu_id),
- NULL);
+ struct device_node *node = of_get_cpu_node(cpu_id, NULL);
const char *compat, *isa, *mmu;

seq_printf(m, "processor\t: %lu\n", cpu_id);
--
2.21.0

2019-04-10 23:06:43

by Atish Patra

[permalink] [raw]
Subject: [PATCH v2 3/4] RISC-V: Implement nosmp commandline option.

nosmp command line option sets max_cpus to zero. No secondary harts
will boot if this is enabled. But present cpu mask will still point to
all possible masks.

Fix present cpu mask for nosmp usecase.

Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/kernel/smpboot.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index eb533b5c2c8c..a8ad200581aa 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -47,6 +47,17 @@ void __init smp_prepare_boot_cpu(void)

void __init smp_prepare_cpus(unsigned int max_cpus)
{
+ int cpuid;
+
+ /* This covers non-smp usecase mandated by "nosmp" option */
+ if (max_cpus == 0)
+ return;
+
+ for_each_possible_cpu(cpuid) {
+ if (cpuid == smp_processor_id())
+ continue;
+ set_cpu_present(cpuid, true);
+ }
}

void __init setup_smp(void)
@@ -74,7 +85,6 @@ void __init setup_smp(void)

cpuid_to_hartid_map(cpuid) = hart;
set_cpu_possible(cpuid, true);
- set_cpu_present(cpuid, true);
cpuid++;
}

--
2.21.0

2019-04-11 06:59:13

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v2 1/4] RISC-V: Add RISC-V specific arch_match_cpu_phys_id

On Wed, Apr 10, 2019 at 04:04:40PM -0700, Atish Patra wrote:
> OF/DT core has a hook for architecture specific logical cpuid to hartid
> mapping. By implementing this, we can pass the logical cpu id to cpu
> node parsing functions.

But that also means we must pass it that way. So as-is this would
break existing setups, wouldn't it?

2019-04-11 07:00:11

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] RISC-V: Fix of_get_cpu_node usage

On Wed, Apr 10, 2019 at 04:04:41PM -0700, Atish Patra wrote:
> of_get_cpu_node expects a logical cpu id not a hartid.

But only because you changed that with your patch 1, so it should
be folded into that.

2019-04-11 07:03:52

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] RISC-V: Implement nosmp commandline option.

On Wed, Apr 10, 2019 at 04:04:42PM -0700, Atish Patra wrote:
> nosmp command line option sets max_cpus to zero. No secondary harts
> will boot if this is enabled. But present cpu mask will still point to
> all possible masks.
>
> Fix present cpu mask for nosmp usecase.
>
> Signed-off-by: Atish Patra <[email protected]>
> ---
> arch/riscv/kernel/smpboot.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index eb533b5c2c8c..a8ad200581aa 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -47,6 +47,17 @@ void __init smp_prepare_boot_cpu(void)
>
> void __init smp_prepare_cpus(unsigned int max_cpus)
> {
> + int cpuid;
> +
> + /* This covers non-smp usecase mandated by "nosmp" option */
> + if (max_cpus == 0)
> + return;
> +
> + for_each_possible_cpu(cpuid) {
> + if (cpuid == smp_processor_id())
> + continue;
> + set_cpu_present(cpuid, true);
> + }

Most other architectures seem to use init_cpu_present() here.

Otherwise this looks fine to me.

2019-04-11 18:15:33

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] RISC-V: Fix of_get_cpu_node usage

On 4/10/19 11:59 PM, Christoph Hellwig wrote:
> On Wed, Apr 10, 2019 at 04:04:41PM -0700, Atish Patra wrote:
>> of_get_cpu_node expects a logical cpu id not a hartid.
>
> But only because you changed that with your patch 1, so it should
> be folded into that.
>

Yes. I should merge this to patch 1. Otherwise, git bisect will have
issues later with patch 1.

Regards,
Atish

2019-04-11 18:44:47

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH v2 3/4] RISC-V: Implement nosmp commandline option.

On 4/11/19 12:01 AM, Christoph Hellwig wrote:
> On Wed, Apr 10, 2019 at 04:04:42PM -0700, Atish Patra wrote:
>> nosmp command line option sets max_cpus to zero. No secondary harts
>> will boot if this is enabled. But present cpu mask will still point to
>> all possible masks.
>>
>> Fix present cpu mask for nosmp usecase.
>>
>> Signed-off-by: Atish Patra <[email protected]>
>> ---
>> arch/riscv/kernel/smpboot.c | 12 +++++++++++-
>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
>> index eb533b5c2c8c..a8ad200581aa 100644
>> --- a/arch/riscv/kernel/smpboot.c
>> +++ b/arch/riscv/kernel/smpboot.c
>> @@ -47,6 +47,17 @@ void __init smp_prepare_boot_cpu(void)
>>
>> void __init smp_prepare_cpus(unsigned int max_cpus)
>> {
>> + int cpuid;
>> +
>> + /* This covers non-smp usecase mandated by "nosmp" option */
>> + if (max_cpus == 0)
>> + return;
>> +
>> + for_each_possible_cpu(cpuid) {
>> + if (cpuid == smp_processor_id())
>> + continue;
>> + set_cpu_present(cpuid, true);
>> + }
>
> Most other architectures seem to use init_cpu_present() here.
>

I did a quick grep through other archs. Mostly, init_cpu_present is
preferred when you update a entire cpumask or cpu 0.
We can just use cpu_possible_mask and init_cpu_present together to avoid
the loop. It will just set the current boot cpu bit once more.

But looking at ARM64 code, we may have to bring back the loop when we
have some implementation similar cpu_ops.

Regards,
Atish

> Otherwise this looks fine to me.
>