Skip to contentSkip to conversation

misc riscv cleanups

PATCH In review Christoph Hellwig 3 participants 26 messages Aug 21, 2019 – Sep 5, 2019

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/6 riscv: refactor the IPI code

This prepares for adding native non-SBI IPI code.

---
 arch/riscv/kernel/smp.c | 55 +++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 24 deletions(-)
arch/riscv/kernel/smp.c +31 -24
index 5a9834503a2f..8cd730239613 100644
@@ -78,13 +78,38 @@ static void ipi_stop(void)
 		wait_for_interrupt();
 }
 
+static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op)
+{
+	int cpuid, hartid;
+	struct cpumask hartid_mask;
+
+	cpumask_clear(&hartid_mask);
+	mb();
+	for_each_cpu(cpuid, mask) {
+		set_bit(op, &ipi_data[cpuid].bits);
+		hartid = cpuid_to_hartid_map(cpuid);
+		cpumask_set_cpu(hartid, &hartid_mask);
+	}
+	mb();
+	sbi_send_ipi(cpumask_bits(&hartid_mask));
+}
+
+static void send_ipi_single(int cpu, enum ipi_message_type op)
+{
+	send_ipi_mask(cpumask_of(cpu), op);
+}
+
+static inline void clear_ipi(void)
+{
+	csr_clear(CSR_SIP, SIE_SSIE);
+}
+
 void riscv_software_interrupt(void)
 {
 	unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
 	unsigned long *stats = ipi_data[smp_processor_id()].stats;
 
-	/* Clear pending IPI */
-	csr_clear(CSR_SIP, SIE_SSIE);
+	clear_ipi();
 
 	while (true) {
 		unsigned long ops;
@@ -118,23 +143,6 @@ void riscv_software_interrupt(void)
 	}
 }
 
-static void
-send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
-{
-	int cpuid, hartid;
-	struct cpumask hartid_mask;
-
-	cpumask_clear(&hartid_mask);
-	mb();
-	for_each_cpu(cpuid, to_whom) {
-		set_bit(operation, &ipi_data[cpuid].bits);
-		hartid = cpuid_to_hartid_map(cpuid);
-		cpumask_set_cpu(hartid, &hartid_mask);
-	}
-	mb();
-	sbi_send_ipi(cpumask_bits(&hartid_mask));
-}
-
 static const char * const ipi_names[] = {
 	[IPI_RESCHEDULE]	= "Rescheduling interrupts",
 	[IPI_CALL_FUNC]		= "Function call interrupts",
@@ -156,12 +164,12 @@ void show_ipi_stats(struct seq_file *p, int prec)
 
 void arch_send_call_function_ipi_mask(struct cpumask *mask)
 {
-	send_ipi_message(mask, IPI_CALL_FUNC);
+	send_ipi_mask(mask, IPI_CALL_FUNC);
 }
 
 void arch_send_call_function_single_ipi(int cpu)
 {
-	send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
+	send_ipi_single(cpu, IPI_CALL_FUNC);
 }
 
 void smp_send_stop(void)
@@ -176,7 +184,7 @@ void smp_send_stop(void)
 
 		if (system_state <= SYSTEM_RUNNING)
 			pr_crit("SMP: stopping secondary CPUs\n");
-		send_ipi_message(&mask, IPI_CPU_STOP);
+		send_ipi_mask(&mask, IPI_CPU_STOP);
 	}
 
 	/* Wait up to one second for other CPUs to stop */
@@ -191,6 +199,5 @@ void smp_send_stop(void)
 
 void smp_send_reschedule(int cpu)
 {
-	send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
+	send_ipi_single(cpu, IPI_RESCHEDULE);
 }
-
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] riscv: refactor the IPI code

Quoted 106 lines · Christoph Hellwig

This prepares for adding native non-SBI IPI code.

---
 arch/riscv/kernel/smp.c | 55 +++++++++++++++++++++++--------------
----
 1 file changed, 31 insertions(+), 24 deletions(-)
arch/riscv/kernel/smp.c +27 -2
index 5a9834503a2f..8cd730239613 100644
@@ -78,13 +78,38 @@ static void ipi_stop(void)
 		wait_for_interrupt();
 }
 
+static void send_ipi_mask(const struct cpumask *mask, enum
 ipi_message_type op)
+{
+	int cpuid, hartid;
+	struct cpumask hartid_mask;
+
+	cpumask_clear(&hartid_mask);
+	mb();
+	for_each_cpu(cpuid, mask) {
+		set_bit(op, &ipi_data[cpuid].bits);
+		hartid = cpuid_to_hartid_map(cpuid);
+		cpumask_set_cpu(hartid, &hartid_mask);
+	}
+	mb();
+	sbi_send_ipi(cpumask_bits(&hartid_mask));
+}
+
+static void send_ipi_single(int cpu, enum ipi_message_type op)
+{
+	send_ipi_mask(cpumask_of(cpu), op);
+}
+
+static inline void clear_ipi(void)
+{
+	csr_clear(CSR_SIP, SIE_SSIE);
+}
+
 void riscv_software_interrupt(void)
 {
 	unsigned long *pending_ipis =
 &ipi_data[smp_processor_id()].bits;
 	unsigned long *stats = ipi_data[smp_processor_id()].stats;
 
-	/* Clear pending IPI */
-	csr_clear(CSR_SIP, SIE_SSIE);
+	clear_ipi();
 
arch/riscv/kernel/smp.c +0 -17
 	while (true) {
 		unsigned long ops;
@@ -118,23 +143,6 @@ void riscv_software_interrupt(void)
 	}
 }
 
-static void
-send_ipi_message(const struct cpumask *to_whom, enum
 ipi_message_type operation)
-{
-	int cpuid, hartid;
-	struct cpumask hartid_mask;
-
-	cpumask_clear(&hartid_mask);
-	mb();
-	for_each_cpu(cpuid, to_whom) {
-		set_bit(operation, &ipi_data[cpuid].bits);
-		hartid = cpuid_to_hartid_map(cpuid);
-		cpumask_set_cpu(hartid, &hartid_mask);
-	}
-	mb();
-	sbi_send_ipi(cpumask_bits(&hartid_mask));
-}
-
 static const char * const ipi_names[] = {
 	[IPI_RESCHEDULE]	= "Rescheduling interrupts",
arch/riscv/kernel/smp.c +2 -2
 	[IPI_CALL_FUNC]		= "Function call interrupts",
@@ -156,12 +164,12 @@ void show_ipi_stats(struct seq_file *p, int
 prec)
 
 void arch_send_call_function_ipi_mask(struct cpumask *mask)
 {
-	send_ipi_message(mask, IPI_CALL_FUNC);
+	send_ipi_mask(mask, IPI_CALL_FUNC);
 }
 
 void arch_send_call_function_single_ipi(int cpu)
 {
-	send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
+	send_ipi_single(cpu, IPI_CALL_FUNC);
 }
 

void smp_send_stop(void)

arch/riscv/kernel/smp.c +1 -1
@@ -176,7 +184,7 @@ void smp_send_stop(void)
 
 		if (system_state <= SYSTEM_RUNNING)
 			pr_crit("SMP: stopping secondary CPUs\n");
-		send_ipi_message(&mask, IPI_CPU_STOP);
+		send_ipi_mask(&mask, IPI_CPU_STOP);
 	}
 
 	/* Wait up to one second for other CPUs to stop */

arch/riscv/kernel/smp.c void smp_send_stop(void) · line 196

Quoted 7 lines
arch/riscv/kernel/smp.c +1 -2
@@ -191,6 +199,5 @@ void smp_send_stop(void)
 
 void smp_send_reschedule(int cpu)
 {
-	send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
+	send_ipi_single(cpu, IPI_RESCHEDULE);
 }
-
Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

Re: [PATCH 1/6] riscv: refactor the IPI code

In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

This prepares for adding native non-SBI IPI code.

Thanks - dropped the previous version from the v5.4-rc1 queue, and queued this one in its place, with Atish's Reviewed-by:.

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw

PATCH 2/6 riscv: cleanup send_ipi_mask

In reply to Christoph Hellwig

Use the special barriers for atomic bitops to make the intention a little more clear, and use riscv_cpuid_to_hartid_mask instead of open coding it.

---
 arch/riscv/kernel/smp.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
arch/riscv/kernel/smp.c +7 -9
index 8cd730239613..2e21669aa068 100644
@@ -80,17 +80,15 @@ static void ipi_stop(void)
 
 static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op)
 {
-	int cpuid, hartid;
 	struct cpumask hartid_mask;
+	int cpu;
 
-	cpumask_clear(&hartid_mask);
-	mb();
-	for_each_cpu(cpuid, mask) {
-		set_bit(op, &ipi_data[cpuid].bits);
-		hartid = cpuid_to_hartid_map(cpuid);
-		cpumask_set_cpu(hartid, &hartid_mask);
-	}
-	mb();
+	smp_mb__before_atomic();
+	for_each_cpu(cpu, mask)
+		set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	riscv_cpuid_to_hartid_mask(mask, &hartid_mask);
 	sbi_send_ipi(cpumask_bits(&hartid_mask));
 }
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#5 lore raw

Re: [PATCH 2/6] riscv: cleanup send_ipi_mask

Quoted 26 lines · Christoph Hellwig

Use the special barriers for atomic bitops to make the intention a little more clear, and use riscv_cpuid_to_hartid_mask instead of open coding it.

---
 arch/riscv/kernel/smp.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
arch/riscv/kernel/smp.c +1 -5
index 8cd730239613..2e21669aa068 100644
@@ -80,17 +80,15 @@ static void ipi_stop(void)
 
 static void send_ipi_mask(const struct cpumask *mask, enum
 ipi_message_type op)
 {
-	int cpuid, hartid;
 	struct cpumask hartid_mask;
+	int cpu;
 
-	cpumask_clear(&hartid_mask);
-	mb();
-	for_each_cpu(cpuid, mask) {
-		set_bit(op, &ipi_data[cpuid].bits);

arch/riscv/kernel/smp.c static void ipi_stop(void) · line 92

Quoted 10 lines
arch/riscv/kernel/smp.c +6 -4
-		hartid = cpuid_to_hartid_map(cpuid);
-		cpumask_set_cpu(hartid, &hartid_mask);
-	}
-	mb();
+	smp_mb__before_atomic();
+	for_each_cpu(cpu, mask)
+		set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	riscv_cpuid_to_hartid_mask(mask, &hartid_mask);

Isn't that less optimized than previous one ?

This will iterate all the cpus set in mask twice during every ipi sent. For now, we won't see any different. As we have more number of cpus in RISC-V (hopefully one day ;) ;)), this may affect the performance.

Quoted 3 lines
arch/riscv/kernel/smp.c +0 -0
 	sbi_send_ipi(cpumask_bits(&hartid_mask));
 }
Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#6 lore raw

Re: [PATCH 2/6] riscv: cleanup send_ipi_mask

Quoted 5 lines · Atish Patra

Isn't that less optimized than previous one ?

This will iterate all the cpus set in mask twice during every ipi sent. For now, we won't see any different. As we have more number of cpus in RISC-V (hopefully one day ;) ;)), this may affect the performance.

By then we are hopefully done with using the SBI IPI code :) The native IPI code this refactor is preparing for won't need the hartid translation for example. The point of this patch isn't really to micro-optimize, but to make the code clear and obvious.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by
#7 lore raw

Re: [PATCH 2/6] riscv: cleanup send_ipi_mask

Quoted 9 lines · On Mon, 2019-08-26 at 13:28 +0200, [email protected] wrote:
Quoted 7 lines · Atish Patra

Isn't that less optimized than previous one ?

This will iterate all the cpus set in mask twice during every ipi sent.
For now, we won't see any different. As we have more number of cpus in
RISC-V (hopefully one day ;) ;)), this may affect the performance.

Quoted 5 lines

By then we are hopefully done with using the SBI IPI code :) The native
IPI code this refactor is preparing for won't need the hartid translation for example. The point of this patch isn't really to micro-optimize, but to make the code clear and obvious.

ok. Sounds good to me.

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#8 lore raw

Re: [PATCH 2/6] riscv: cleanup send_ipi_mask

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

Use the special barriers for atomic bitops to make the intention a little more clear, and use riscv_cpuid_to_hartid_mask instead of open coding it.

Thanks, queued for v5.4-rc1 with Atish's Reviewed-by:.

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#9 lore raw

PATCH 3/6 riscv: optimize send_ipi_single

In reply to Christoph Hellwig

Don't go through send_ipi_mask, but just set the op bit an then pass a simple generate hartid mask directly to sbi_send_ipi.

---
 arch/riscv/kernel/smp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/riscv/kernel/smp.c +7 -1
index 2e21669aa068..a3715d621f60 100644
@@ -94,7 +94,13 @@ static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op)
 
 static void send_ipi_single(int cpu, enum ipi_message_type op)
 {
-	send_ipi_mask(cpumask_of(cpu), op);
+	int hartid = cpuid_to_hartid_map(cpu);
+
+	smp_mb__before_atomic();
+	set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	sbi_send_ipi(cpumask_bits(cpumask_of(hartid)));
 }
 
 static inline void clear_ipi(void)
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#10 lore raw

Re: [PATCH 3/6] riscv: optimize send_ipi_single

Quoted 16 lines · Christoph Hellwig

Don't go through send_ipi_mask, but just set the op bit an then pass a
simple generate hartid mask directly to sbi_send_ipi.

---
 arch/riscv/kernel/smp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/riscv/kernel/smp.c +0 -0
index 2e21669aa068..a3715d621f60 100644
@@ -94,7 +94,13 @@ static void send_ipi_mask(const struct cpumask
 *mask, enum ipi_message_type op)
 

arch/riscv/kernel/smp.c static void send_ipi_mask(const struct cpumask · line 104

Quoted 10 lines
arch/riscv/kernel/smp.c +7 -1
 static void send_ipi_single(int cpu, enum ipi_message_type op)
 {
-	send_ipi_mask(cpumask_of(cpu), op);
+	int hartid = cpuid_to_hartid_map(cpu);
+
+	smp_mb__before_atomic();
+	set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	sbi_send_ipi(cpumask_bits(cpumask_of(hartid)));

The only cost save I see is you don't have to cpumask_clear anymore. Is there any other cost save ? If not is it worth duplicating the code ?

May be I am being too pedantic here.. :) :)

Quoted 3 lines
arch/riscv/kernel/smp.c +0 -0
 }
 

static inline void clear_ipi(void)

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#11 lore raw

Re: [PATCH 3/6] riscv: optimize send_ipi_single

Quoted 15 lines · Atish Patra

arch/riscv/kernel/smp.c static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op) · line 103

Quoted 10 lines

static void send_ipi_single(int cpu, enum ipi_message_type op) {

arch/riscv/kernel/smp.c +7 -1
-	send_ipi_mask(cpumask_of(cpu), op);
+	int hartid = cpuid_to_hartid_map(cpu);
+
+	smp_mb__before_atomic();
+	set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	sbi_send_ipi(cpumask_bits(cpumask_of(hartid)));

The only cost save I see is you don't have to cpumask_clear anymore. Is there any other cost save ? If not is it worth duplicating the code ?

Quoted 1 line

May be I am being too pedantic here.. :) :)

It avoids the additional potentially huge cpumask, and generally makes the code a lot more obvious. This might not really be needed, but helps with sharing the code nicely with the native IPI path.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by
#12 lore raw

Re: [PATCH 3/6] riscv: optimize send_ipi_single

Quoted 18 lines · On Mon, 2019-08-26 at 13:29 +0200, [email protected] wrote:
Quoted 17 lines · Atish Patra

arch/riscv/kernel/smp.c static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op) · line 103

Quoted 10 lines

static void send_ipi_single(int cpu, enum ipi_message_type op) {

arch/riscv/kernel/smp.c +7 -1
-	send_ipi_mask(cpumask_of(cpu), op);
+	int hartid = cpuid_to_hartid_map(cpu);
+
+	smp_mb__before_atomic();
+	set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	sbi_send_ipi(cpumask_bits(cpumask_of(hartid)));

The only cost save I see is you don't have to cpumask_clear anymore.
Is there any other cost save ? If not is it worth duplicating the code
?

Quoted 6 lines
Quoted 1 line

May be I am being too pedantic here.. :) :)

It avoids the additional potentially huge cpumask, and generally makes
the code a lot more obvious. This might not really be needed, but helps with sharing the code nicely with the native IPI path.

ok.

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by Atish Patra on v1 3/6
#13 lore raw

Re: [PATCH 3/6] riscv: optimize send_ipi_single

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Don't go through send_ipi_mask, but just set the op bit an then pass a simple generate hartid mask directly to sbi_send_ipi.

Thanks, I fixed some minor issues in the patch description and queued the following for v5.4-rc1.

- Paul

From: Christoph Hellwig <[email protected]>
Date: Wed, 21 Aug 2019 23:58:34 +0900
Subject: [PATCH] riscv: optimize send_ipi_single

Don't go through send_ipi_mask, but just set the op bit and then pass a simple generated hartid mask directly to sbi_send_ipi.

---
 arch/riscv/kernel/smp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/riscv/kernel/smp.c +7 -1
index 2e21669aa068..a3715d621f60 100644
@@ -94,7 +94,13 @@ static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op)
 
 static void send_ipi_single(int cpu, enum ipi_message_type op)
 {
-	send_ipi_mask(cpumask_of(cpu), op);
+	int hartid = cpuid_to_hartid_map(cpu);
+
+	smp_mb__before_atomic();
+	set_bit(op, &ipi_data[cpu].bits);
+	smp_mb__after_atomic();
+
+	sbi_send_ipi(cpumask_bits(cpumask_of(hartid)));
 }
 
 static inline void clear_ipi(void)
Signature · 7 lines
2.23.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#14 lore raw

PATCH 4/6 riscv: cleanup riscv_cpuid_to_hartid_mask

In reply to Christoph Hellwig

Move the initial clearing of the mask from the callers to riscv_cpuid_to_hartid_mask, and remove the unused !CONFIG_SMP stub.

---
 arch/riscv/include/asm/smp.h      | 6 ------
 arch/riscv/include/asm/tlbflush.h | 1 -
 arch/riscv/kernel/smp.c           | 1 +
 arch/riscv/mm/cacheflush.c        | 1 -
 4 files changed, 1 insertion(+), 8 deletions(-)
arch/riscv/include/asm/smp.h +0 -6
index c6ed4d691def..a83451d73a4e 100644
@@ -61,11 +61,5 @@ static inline unsigned long cpuid_to_hartid_map(int cpu)
 	return boot_cpu_hartid;
 }
 
-static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
-					      struct cpumask *out)
-{
-	cpumask_set_cpu(cpuid_to_hartid_map(0), out);
-}
-
 #endif /* CONFIG_SMP */
 #endif /* _ASM_RISCV_SMP_H */
arch/riscv/include/asm/tlbflush.h +0 -1
index 4d9bbe8438bf..df31fe2ed09c 100644
@@ -47,7 +47,6 @@ static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start,
 {
 	struct cpumask hmask;
 
-	cpumask_clear(&hmask);
 	riscv_cpuid_to_hartid_mask(cmask, &hmask);
 	sbi_remote_sfence_vma(hmask.bits, start, size);
 }
arch/riscv/kernel/smp.c +1 -0
index a3715d621f60..3836760d7aaf 100644
@@ -56,6 +56,7 @@ void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out)
 {
 	int cpu;
 
+	cpumask_clear(out);
 	for_each_cpu(cpu, in)
 		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);
 }
arch/riscv/mm/cacheflush.c +0 -1
index 9ebcff8ba263..3f15938dec89 100644
@@ -47,7 +47,6 @@ void flush_icache_mm(struct mm_struct *mm, bool local)
 	cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu));
 	local |= cpumask_empty(&others);
 	if (mm != current->active_mm || !local) {
-		cpumask_clear(&hmask);
 		riscv_cpuid_to_hartid_mask(&others, &hmask);
 		sbi_remote_fence_i(hmask.bits);
 	} else {
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 4/6
#15 lore raw

Re: [PATCH 4/6] riscv: cleanup riscv_cpuid_to_hartid_mask

Quoted 69 lines · Christoph Hellwig

Move the initial clearing of the mask from the callers to riscv_cpuid_to_hartid_mask, and remove the unused !CONFIG_SMP stub.

---
 arch/riscv/include/asm/smp.h      | 6 ------
 arch/riscv/include/asm/tlbflush.h | 1 -
 arch/riscv/kernel/smp.c           | 1 +
 arch/riscv/mm/cacheflush.c        | 1 -
 4 files changed, 1 insertion(+), 8 deletions(-)
arch/riscv/include/asm/smp.h +0 -6
index c6ed4d691def..a83451d73a4e 100644
@@ -61,11 +61,5 @@ static inline unsigned long
 cpuid_to_hartid_map(int cpu)
 	return boot_cpu_hartid;
 }
 
-static inline void riscv_cpuid_to_hartid_mask(const struct cpumask
 *in,
-					      struct cpumask *out)
-{
-	cpumask_set_cpu(cpuid_to_hartid_map(0), out);
-}
-

#endif /* CONFIG_SMP */
#endif /* _ASM_RISCV_SMP_H */

arch/riscv/include/asm/tlbflush.h +0 -1
index 4d9bbe8438bf..df31fe2ed09c 100644
@@ -47,7 +47,6 @@ static inline void remote_sfence_vma(struct cpumask
 *cmask, unsigned long start,
 {
 	struct cpumask hmask;
 
-	cpumask_clear(&hmask);
 	riscv_cpuid_to_hartid_mask(cmask, &hmask);
 	sbi_remote_sfence_vma(hmask.bits, start, size);

}

arch/riscv/kernel/smp.c +1 -0
index a3715d621f60..3836760d7aaf 100644
@@ -56,6 +56,7 @@ void riscv_cpuid_to_hartid_mask(const struct
 cpumask *in, struct cpumask *out)
 {
 	int cpu;
 
+	cpumask_clear(out);
 	for_each_cpu(cpu, in)
 		cpumask_set_cpu(cpuid_to_hartid_map(cpu), out);

}

arch/riscv/mm/cacheflush.c +0 -1
index 9ebcff8ba263..3f15938dec89 100644
@@ -47,7 +47,6 @@ void flush_icache_mm(struct mm_struct *mm, bool
 local)
 	cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu));
 	local |= cpumask_empty(&others);
 	if (mm != current->active_mm || !local) {
-		cpumask_clear(&hmask);
 		riscv_cpuid_to_hartid_mask(&others, &hmask);
 		sbi_remote_fence_i(hmask.bits);
Quoted 1 line

} else {

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#16 lore raw

Re: [PATCH 4/6] riscv: cleanup riscv_cpuid_to_hartid_mask

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Move the initial clearing of the mask from the callers to riscv_cpuid_to_hartid_mask, and remove the unused !CONFIG_SMP stub.

Thanks, queued for v5.4-rc1 with Atish's Reviewed-by:.

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#17 lore raw

PATCH 5/6 riscv: don't use the rdtime(h) pseudo-instructions

In reply to Christoph Hellwig

If we just use the CSRs that these map to directly the code is simpler and doesn't require extra inline assembly code. Also fix up the top-level comment in timer-riscv.c to not talk about the cycle count or mention details of the clocksource interface, of which this file is just a consumer.

---
 arch/riscv/include/asm/timex.h    | 44 +++++++++++++++----------------
 drivers/clocksource/timer-riscv.c | 17 +++---------
 2 files changed, 25 insertions(+), 36 deletions(-)
arch/riscv/include/asm/timex.h +21 -23
index 6a703ec9d796..c7ef131b9e4c 100644
@@ -6,43 +6,41 @@
 #ifndef _ASM_RISCV_TIMEX_H
 #define _ASM_RISCV_TIMEX_H
 
-#include <asm/param.h>
+#include <asm/csr.h>
 
 typedef unsigned long cycles_t;
 
-static inline cycles_t get_cycles_inline(void)
+static inline cycles_t get_cycles(void)
 {
-	cycles_t n;
-
-	__asm__ __volatile__ (
-		"rdtime %0"
-		: "=r" (n));
-	return n;
+	return csr_read(CSR_TIME);
 }
-#define get_cycles get_cycles_inline
+#define get_cycles get_cycles
 
 #ifdef CONFIG_64BIT
-static inline uint64_t get_cycles64(void)
+static inline u64 get_cycles64(void)
+{
+	return get_cycles();
+}
+#else /* CONFIG_64BIT */
+static inline u32 get_cycles_hi(void)
 {
-        return get_cycles();
+	return csr_read(CSR_TIMEH);
 }
-#else
-static inline uint64_t get_cycles64(void)
+
+static inline u64 get_cycles64(void)
 {
-	u32 lo, hi, tmp;
-	__asm__ __volatile__ (
-		"1:\n"
-		"rdtimeh %0\n"
-		"rdtime %1\n"
-		"rdtimeh %2\n"
-		"bne %0, %2, 1b"
-		: "=&r" (hi), "=&r" (lo), "=&r" (tmp));
+	u32 hi, lo;
+
+	do {
+		hi = get_cycles_hi();
+		lo = get_cycles();
+	} while (hi != get_cycles_hi());
+
 	return ((u64)hi << 32) | lo;
 }
-#endif
+#endif /* CONFIG_64BIT */
 
 #define ARCH_HAS_READ_CURRENT_TIMER
-
 static inline int read_current_timer(unsigned long *timer_val)
 {
 	*timer_val = get_cycles();
drivers/clocksource/timer-riscv.c +4 -13
index 09e031176bc6..470c7ef02ea4 100644
@@ -2,6 +2,10 @@
 /*
  * Copyright (C) 2012 Regents of the University of California
  * Copyright (C) 2017 SiFive
+ *
+ * All RISC-V systems have a timer attached to every hart.  These timers can be
+ * read from the "time" and "timeh" CSRs, and can use the SBI to setup
+ * events.
  */
 #include <linux/clocksource.h>
 #include <linux/clockchips.h>
@@ -12,19 +16,6 @@
 #include <asm/smp.h>
 #include <asm/sbi.h>
 
-/*
- * All RISC-V systems have a timer attached to every hart.  These timers can be
- * read by the 'rdcycle' pseudo instruction, and can use the SBI to setup
- * events.  In order to abstract the architecture-specific timer reading and
- * setting functions away from the clock event insertion code, we provide
- * function pointers to the clockevent subsystem that perform two basic
- * operations: rdtime() reads the timer on the current CPU, and
- * next_event(delta) sets the next timer event to 'delta' cycles in the future.
- * As the timers are inherently a per-cpu resource, these callbacks perform
- * operations on the current hart.  There is guaranteed to be exactly one timer
- * per hart on all RISC-V systems.
- */
-
 static int riscv_clock_next_event(unsigned long delta,
 		struct clock_event_device *ce)
 {
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#18 lore raw

Re: [PATCH 5/6] riscv: don't use the rdtime(h) pseudo-instructions

Quoted 29 lines · Christoph Hellwig

If we just use the CSRs that these map to directly the code is simpler
and doesn't require extra inline assembly code. Also fix up the top- level
comment in timer-riscv.c to not talk about the cycle count or mention details of the clocksource interface, of which this file is just a consumer.

---
 arch/riscv/include/asm/timex.h    | 44 +++++++++++++++------------
----
 drivers/clocksource/timer-riscv.c | 17 +++---------
 2 files changed, 25 insertions(+), 36 deletions(-)
arch/riscv/include/asm/timex.h +1 -1
index 6a703ec9d796..c7ef131b9e4c 100644
@@ -6,43 +6,41 @@
 #ifndef _ASM_RISCV_TIMEX_H
 #define _ASM_RISCV_TIMEX_H
 
-#include <asm/param.h>
+#include <asm/csr.h>
 
 typedef unsigned long cycles_t;
 

arch/riscv/include/asm/timex.h line 15

Quoted 10 lines
arch/riscv/include/asm/timex.h +2 -7
-static inline cycles_t get_cycles_inline(void)
+static inline cycles_t get_cycles(void)
 {
-	cycles_t n;
-
-	__asm__ __volatile__ (
-		"rdtime %0"
-		: "=r" (n));
-	return n;
+	return csr_read(CSR_TIME);

Does this work correctly in QEMU ? I was looking at the qemu code and it looks like it returns cpu_get_host_ticks which seems wrong to me.

https://github.com/qemu/qemu/blob/master/target/riscv/csr.c#L213

Quoted 92 lines
arch/riscv/include/asm/timex.h +18 -15
 }
-#define get_cycles get_cycles_inline
+#define get_cycles get_cycles
 
 #ifdef CONFIG_64BIT
-static inline uint64_t get_cycles64(void)
+static inline u64 get_cycles64(void)
+{
+	return get_cycles();
+}
+#else /* CONFIG_64BIT */
+static inline u32 get_cycles_hi(void)
 {
-        return get_cycles();
+	return csr_read(CSR_TIMEH);
 }
-#else
-static inline uint64_t get_cycles64(void)
+
+static inline u64 get_cycles64(void)
 {
-	u32 lo, hi, tmp;
-	__asm__ __volatile__ (
-		"1:\n"
-		"rdtimeh %0\n"
-		"rdtime %1\n"
-		"rdtimeh %2\n"
-		"bne %0, %2, 1b"
-		: "=&r" (hi), "=&r" (lo), "=&r" (tmp));
+	u32 hi, lo;
+
+	do {
+		hi = get_cycles_hi();
+		lo = get_cycles();
+	} while (hi != get_cycles_hi());
+
 	return ((u64)hi << 32) | lo;
 }
-#endif
+#endif /* CONFIG_64BIT */
 
 #define ARCH_HAS_READ_CURRENT_TIMER
-
 static inline int read_current_timer(unsigned long *timer_val)
 {
 	*timer_val = get_cycles();
drivers/clocksource/timer-riscv.c +2 -0
index 09e031176bc6..470c7ef02ea4 100644
@@ -2,6 +2,10 @@
 /*
  * Copyright (C) 2012 Regents of the University of California
  * Copyright (C) 2017 SiFive
+ *
+ * All RISC-V systems have a timer attached to every hart.  These

timers can be
+ * read from the "time" and "timeh" CSRs, and can use the SBI to setup
+ * events.
*/
#include <linux/clocksource.h>
#include <linux/clockchips.h>

drivers/clocksource/timer-riscv.c +0 -2
@@ -12,19 +16,6 @@
 #include <asm/smp.h>
 #include <asm/sbi.h>
 
-/*
- * All RISC-V systems have a timer attached to every hart.  These

timers can be
- * read by the 'rdcycle' pseudo instruction, and can use the SBI to setup
- * events. In order to abstract the architecture-specific timer reading and
- * setting functions away from the clock event insertion code, we provide
- * function pointers to the clockevent subsystem that perform two basic
- * operations: rdtime() reads the timer on the current CPU, and
- * next_event(delta) sets the next timer event to 'delta' cycles in the future.
- * As the timers are inherently a per-cpu resource, these callbacks perform
- * operations on the current hart. There is guaranteed to be exactly one timer
- * per hart on all RISC-V systems.
- */

drivers/clocksource/timer-riscv.c +0 -1
-
 static int riscv_clock_next_event(unsigned long delta,
 		struct clock_event_device *ce)
 {
Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#19 lore raw

Re: [PATCH 5/6] riscv: don't use the rdtime(h) pseudo-instructions

Quoted 46 lines · Atish Patra
Quoted 31 lines · Christoph Hellwig

If we just use the CSRs that these map to directly the code is simpler
and doesn't require extra inline assembly code. Also fix up the top-
level
comment in timer-riscv.c to not talk about the cycle count or mention
details of the clocksource interface, of which this file is just a consumer.

---
 arch/riscv/include/asm/timex.h    | 44 +++++++++++++++------------
----
 drivers/clocksource/timer-riscv.c | 17 +++---------
 2 files changed, 25 insertions(+), 36 deletions(-)
arch/riscv/include/asm/timex.h +1 -1
index 6a703ec9d796..c7ef131b9e4c 100644
@@ -6,43 +6,41 @@
 #ifndef _ASM_RISCV_TIMEX_H
 #define _ASM_RISCV_TIMEX_H
 
-#include <asm/param.h>
+#include <asm/csr.h>
 
 typedef unsigned long cycles_t;
 

arch/riscv/include/asm/timex.h line 15

Quoted 10 lines
arch/riscv/include/asm/timex.h +2 -7
-static inline cycles_t get_cycles_inline(void)
+static inline cycles_t get_cycles(void)
 {
-	cycles_t n;
-
-	__asm__ __volatile__ (
-		"rdtime %0"
-		: "=r" (n));
-	return n;
+	return csr_read(CSR_TIME);

Does this work correctly in QEMU ? I was looking at the qemu code and it looks like it returns cpu_get_host_ticks which seems wrong to me.

Quoted 3 lines

https://github.com/qemu/qemu/blob/master/target/riscv/csr.c#L213

Nevermind. I missed the CONFIG_USER_ONLY and got confused. csr_read will also trap and get the correct value.

Regards,
Atish

Quoted 95 lines
Quoted 95 lines
arch/riscv/include/asm/timex.h +18 -15
 }
-#define get_cycles get_cycles_inline
+#define get_cycles get_cycles
 
 #ifdef CONFIG_64BIT
-static inline uint64_t get_cycles64(void)
+static inline u64 get_cycles64(void)
+{
+	return get_cycles();
+}
+#else /* CONFIG_64BIT */
+static inline u32 get_cycles_hi(void)
 {
-        return get_cycles();
+	return csr_read(CSR_TIMEH);
 }
-#else
-static inline uint64_t get_cycles64(void)
+
+static inline u64 get_cycles64(void)
 {
-	u32 lo, hi, tmp;
-	__asm__ __volatile__ (
-		"1:\n"
-		"rdtimeh %0\n"
-		"rdtime %1\n"
-		"rdtimeh %2\n"
-		"bne %0, %2, 1b"
-		: "=&r" (hi), "=&r" (lo), "=&r" (tmp));
+	u32 hi, lo;
+
+	do {
+		hi = get_cycles_hi();
+		lo = get_cycles();
+	} while (hi != get_cycles_hi());
+
 	return ((u64)hi << 32) | lo;
 }
-#endif
+#endif /* CONFIG_64BIT */
 
 #define ARCH_HAS_READ_CURRENT_TIMER
-
 static inline int read_current_timer(unsigned long *timer_val)
 {
 	*timer_val = get_cycles();
drivers/clocksource/timer-riscv.c +2 -0
index 09e031176bc6..470c7ef02ea4 100644
@@ -2,6 +2,10 @@
 /*
  * Copyright (C) 2012 Regents of the University of California
  * Copyright (C) 2017 SiFive
+ *
+ * All RISC-V systems have a timer attached to every hart.  These

timers can be
+ * read from the "time" and "timeh" CSRs, and can use the SBI to setup
+ * events.
*/
#include <linux/clocksource.h>
#include <linux/clockchips.h>

drivers/clocksource/timer-riscv.c +0 -2
@@ -12,19 +16,6 @@
 #include <asm/smp.h>
 #include <asm/sbi.h>
 
-/*
- * All RISC-V systems have a timer attached to every hart.  These

timers can be
- * read by the 'rdcycle' pseudo instruction, and can use the SBI to
setup
- * events. In order to abstract the architecture-specific timer reading and
- * setting functions away from the clock event insertion code, we provide
- * function pointers to the clockevent subsystem that perform two basic
- * operations: rdtime() reads the timer on the current CPU, and
- * next_event(delta) sets the next timer event to 'delta' cycles in
the future.
- * As the timers are inherently a per-cpu resource, these callbacks
perform
- * operations on the current hart. There is guaranteed to be exactly one timer
- * per hart on all RISC-V systems.
- */

drivers/clocksource/timer-riscv.c +0 -1
-
 static int riscv_clock_next_event(unsigned long delta,
 		struct clock_event_device *ce)
 {
Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#20 lore raw

Re: [PATCH 5/6] riscv: don't use the rdtime(h) pseudo-instructions

In reply to Atish Patra
Quoted 5 lines · Atish Patra
Quoted 5 lines
arch/riscv/include/asm/timex.h +1 -3
-static inline cycles_t get_cycles_inline(void)
+static inline cycles_t get_cycles(void)
 {
-	cycles_t n;
-
Quoted 8 lines

arch/riscv/include/asm/timex.h line 15

Quoted 5 lines
arch/riscv/include/asm/timex.h +1 -4
-	__asm__ __volatile__ (
-		"rdtime %0"
-		: "=r" (n));
-	return n;
+	return csr_read(CSR_TIME);

Does this work correctly in QEMU ? I was looking at the qemu code and it looks like it returns cpu_get_host_ticks which seems wrong to me.

It better should. rdtime is just a pseudo-instruction that the assembler translates to a CSR read. (in other words something totally pointless, no idea why it even is in the spec).

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by
#21 lore raw

Re: [PATCH 5/6] riscv: don't use the rdtime(h) pseudo-instructions

Quoted 17 lines · On Mon, 2019-08-26 at 13:30 +0200, [email protected] wrote:
Quoted 7 lines · Atish Patra
Quoted 7 lines
arch/riscv/include/asm/timex.h +1 -5
-static inline cycles_t get_cycles_inline(void)
+static inline cycles_t get_cycles(void)
 {
-	cycles_t n;
-
-	__asm__ __volatile__ (
-		"rdtime %0"
Quoted 8 lines

arch/riscv/include/asm/timex.h line 15

Quoted 3 lines
arch/riscv/include/asm/timex.h +1 -2
-		: "=r" (n));
-	return n;
+	return csr_read(CSR_TIME);

Does this work correctly in QEMU ? I was looking at the qemu code and
it looks like it returns cpu_get_host_ticks which seems wrong to me.

Quoted 4 lines

It better should. rdtime is just a pseudo-instruction that the assembler translates to a CSR read. (in other words something totally
pointless, no idea why it even is in the spec).

Yes. I did not see the usermode macro carefully in qemu code.

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#22 lore raw

Re: [PATCH 5/6] riscv: don't use the rdtime(h) pseudo-instructions

In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

If we just use the CSRs that these map to directly the code is simpler and doesn't require extra inline assembly code. Also fix up the top-level comment in timer-riscv.c to not talk about the cycle count or mention details of the clocksource interface, of which this file is just a consumer.

Thanks, queued for v5.4-rc1 with Atish's Reviewed-by:.

- Paul

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#23 lore raw

PATCH 6/6 riscv: move the TLB flush logic out of line

In reply to Christoph Hellwig

The TLB flush logic is going to become more complex. Start moving it out of line.

---
 arch/riscv/include/asm/tlbflush.h | 37 ++++++-------------------------
 arch/riscv/mm/Makefile            |  3 +++
 arch/riscv/mm/tlbflush.c          | 35 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 30 deletions(-)
 create mode 100644 arch/riscv/mm/tlbflush.c
arch/riscv/include/asm/tlbflush.h +7 -30
index df31fe2ed09c..075a784c66c5 100644
@@ -25,8 +25,13 @@ static inline void local_flush_tlb_page(unsigned long addr)
 	__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
 }
 
-#ifndef CONFIG_SMP
-
+#ifdef CONFIG_SMP
+void flush_tlb_all(void);
+void flush_tlb_mm(struct mm_struct *mm);
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+		unsigned long end);
+#else /* CONFIG_SMP */
 #define flush_tlb_all() local_flush_tlb_all()
 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
 
@@ -37,34 +42,6 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
 }
 
 #define flush_tlb_mm(mm) flush_tlb_all()
-
-#else /* CONFIG_SMP */
-
-#include <asm/sbi.h>
-
-static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start,
-				     unsigned long size)
-{
-	struct cpumask hmask;
-
-	riscv_cpuid_to_hartid_mask(cmask, &hmask);
-	sbi_remote_sfence_vma(hmask.bits, start, size);
-}
-
-#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
-
-#define flush_tlb_range(vma, start, end) \
-	remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start))
-
-static inline void flush_tlb_page(struct vm_area_struct *vma,
-				  unsigned long addr)
-{
-	flush_tlb_range(vma, addr, addr + PAGE_SIZE);
-}
-
-#define flush_tlb_mm(mm)				\
-	remote_sfence_vma(mm_cpumask(mm), 0, -1)
-
 #endif /* CONFIG_SMP */
 
 /* Flush a range of kernel pages */
arch/riscv/mm/Makefile +3 -0
index 74055e1d6f21..9d9a17335686 100644
@@ -13,4 +13,7 @@ obj-y += cacheflush.o
 obj-y += context.o
 obj-y += sifive_l2_cache.o
 
+ifeq ($(CONFIG_MMU),y)
+obj-$(CONFIG_SMP) += tlbflush.o
+endif
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
arch/riscv/mm/tlbflush.c new file +35 -0
new file mode 100644
index 000000000000..df93b26f1b9d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <asm/sbi.h>
+
+void flush_tlb_all(void)
+{
+	sbi_remote_sfence_vma(NULL, 0, -1);
+}
+
+static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start,
+		unsigned long size)
+{
+	struct cpumask hmask;
+
+	riscv_cpuid_to_hartid_mask(cmask, &hmask);
+	sbi_remote_sfence_vma(hmask.bits, start, size);
+}
+
+void flush_tlb_mm(struct mm_struct *mm)
+{
+	__sbi_tlb_flush_range(mm_cpumask(mm), 0, -1);
+}
+
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), addr, PAGE_SIZE);
+}
+
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+		unsigned long end)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), start, end - start);
+}
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 6/6
#24 lore raw

Re: [PATCH 6/6] riscv: move the TLB flush logic out of line

Quoted 128 lines · Christoph Hellwig

The TLB flush logic is going to become more complex. Start moving it out of line.

---
 arch/riscv/include/asm/tlbflush.h | 37 ++++++-----------------------
--
 arch/riscv/mm/Makefile            |  3 +++
 arch/riscv/mm/tlbflush.c          | 35 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 30 deletions(-)
 create mode 100644 arch/riscv/mm/tlbflush.c
arch/riscv/include/asm/tlbflush.h +7 -2
index df31fe2ed09c..075a784c66c5 100644
@@ -25,8 +25,13 @@ static inline void local_flush_tlb_page(unsigned
 long addr)
 	__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) :
 "memory");
 }
 
-#ifndef CONFIG_SMP
-
+#ifdef CONFIG_SMP
+void flush_tlb_all(void);
+void flush_tlb_mm(struct mm_struct *mm);
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long
 start,
+		unsigned long end);
+#else /* CONFIG_SMP */

#define flush_tlb_all() local_flush_tlb_all() #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)

arch/riscv/include/asm/tlbflush.h +0 -28
@@ -37,34 +42,6 @@ static inline void flush_tlb_range(struct
 vm_area_struct *vma,
 }
 
 #define flush_tlb_mm(mm) flush_tlb_all()
-
-#else /* CONFIG_SMP */
-
-#include <asm/sbi.h>
-
-static inline void remote_sfence_vma(struct cpumask *cmask, unsigned
 long start,
-				     unsigned long size)
-{
-	struct cpumask hmask;
-
-	riscv_cpuid_to_hartid_mask(cmask, &hmask);
-	sbi_remote_sfence_vma(hmask.bits, start, size);
-}
-
-#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
-
-#define flush_tlb_range(vma, start, end) \
-	remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) -
 (start))
-
-static inline void flush_tlb_page(struct vm_area_struct *vma,
-				  unsigned long addr)
-{
-	flush_tlb_range(vma, addr, addr + PAGE_SIZE);
-}
-
-#define flush_tlb_mm(mm)				\
-	remote_sfence_vma(mm_cpumask(mm), 0, -1)
-

#endif /* CONFIG_SMP */

/* Flush a range of kernel pages */

arch/riscv/mm/Makefile +3 -0
index 74055e1d6f21..9d9a17335686 100644
@@ -13,4 +13,7 @@ obj-y += cacheflush.o
 obj-y += context.o
 obj-y += sifive_l2_cache.o
 
+ifeq ($(CONFIG_MMU),y)
+obj-$(CONFIG_SMP) += tlbflush.o
+endif
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
arch/riscv/mm/tlbflush.c new file +12 -0
new file mode 100644
index 000000000000..df93b26f1b9d
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <asm/sbi.h>
+
+void flush_tlb_all(void)
+{
+	sbi_remote_sfence_vma(NULL, 0, -1);
+}
+
+static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned

long start,

arch/riscv/mm/tlbflush.c new file +19 -0
+		unsigned long size)
+{
+	struct cpumask hmask;
+
+	riscv_cpuid_to_hartid_mask(cmask, &hmask);
+	sbi_remote_sfence_vma(hmask.bits, start, size);
+}
+
+void flush_tlb_mm(struct mm_struct *mm)
+{
+	__sbi_tlb_flush_range(mm_cpumask(mm), 0, -1);
+}
+
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), addr, PAGE_SIZE);
+}
+
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long

start,

arch/riscv/mm/tlbflush.c new file +3 -0
+		unsigned long end)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), start, end -
Quoted 2 lines

start);
+}

Signature · 6 lines
Regards,
Atish
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by Atish Patra on v1 6/6
#25 lore raw

Re: [PATCH 6/6] riscv: move the TLB flush logic out of line

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

The TLB flush logic is going to become more complex. Start moving it out of line.

Thanks. "checkpatch.pl --strict" reported several whitespace issues with this patch. I fixed those up here and queued the following for v5.4-rc1.

- Paul

From: Christoph Hellwig <[email protected]>
Date: Wed, 21 Aug 2019 23:58:37 +0900
Subject: [PATCH] riscv: move the TLB flush logic out of line

The TLB flush logic is going to become more complex. Start moving it out of line.

---
 arch/riscv/include/asm/tlbflush.h | 37 ++++++-------------------------
 arch/riscv/mm/Makefile            |  3 +++
 arch/riscv/mm/tlbflush.c          | 35 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 30 deletions(-)
 create mode 100644 arch/riscv/mm/tlbflush.c
arch/riscv/include/asm/tlbflush.h +7 -30
index df31fe2ed09c..37ae4e367ad2 100644
@@ -25,8 +25,13 @@ static inline void local_flush_tlb_page(unsigned long addr)
 	__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
 }
 
-#ifndef CONFIG_SMP
-
+#ifdef CONFIG_SMP
+void flush_tlb_all(void);
+void flush_tlb_mm(struct mm_struct *mm);
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+		     unsigned long end);
+#else /* CONFIG_SMP */
 #define flush_tlb_all() local_flush_tlb_all()
 #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
 
@@ -37,34 +42,6 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
 }
 
 #define flush_tlb_mm(mm) flush_tlb_all()
-
-#else /* CONFIG_SMP */
-
-#include <asm/sbi.h>
-
-static inline void remote_sfence_vma(struct cpumask *cmask, unsigned long start,
-				     unsigned long size)
-{
-	struct cpumask hmask;
-
-	riscv_cpuid_to_hartid_mask(cmask, &hmask);
-	sbi_remote_sfence_vma(hmask.bits, start, size);
-}
-
-#define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
-
-#define flush_tlb_range(vma, start, end) \
-	remote_sfence_vma(mm_cpumask((vma)->vm_mm), start, (end) - (start))
-
-static inline void flush_tlb_page(struct vm_area_struct *vma,
-				  unsigned long addr)
-{
-	flush_tlb_range(vma, addr, addr + PAGE_SIZE);
-}
-
-#define flush_tlb_mm(mm)				\
-	remote_sfence_vma(mm_cpumask(mm), 0, -1)
-
 #endif /* CONFIG_SMP */
 
 /* Flush a range of kernel pages */
arch/riscv/mm/Makefile +3 -0
index 74055e1d6f21..9d9a17335686 100644
@@ -13,4 +13,7 @@ obj-y += cacheflush.o
 obj-y += context.o
 obj-y += sifive_l2_cache.o
 
+ifeq ($(CONFIG_MMU),y)
+obj-$(CONFIG_SMP) += tlbflush.o
+endif
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
arch/riscv/mm/tlbflush.c new file +35 -0
new file mode 100644
index 000000000000..24cd33d2c48f
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <asm/sbi.h>
+
+void flush_tlb_all(void)
+{
+	sbi_remote_sfence_vma(NULL, 0, -1);
+}
+
+static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start,
+				  unsigned long size)
+{
+	struct cpumask hmask;
+
+	riscv_cpuid_to_hartid_mask(cmask, &hmask);
+	sbi_remote_sfence_vma(hmask.bits, start, size);
+}
+
+void flush_tlb_mm(struct mm_struct *mm)
+{
+	__sbi_tlb_flush_range(mm_cpumask(mm), 0, -1);
+}
+
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), addr, PAGE_SIZE);
+}
+
+void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
+		     unsigned long end)
+{
+	__sbi_tlb_flush_range(mm_cpumask(vma->vm_mm), start, end - start);
+}
Signature · 7 lines
2.23.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv