diff mbox series

[kvmtool,v2] riscv: Use the count parameter of term_putc in SBI_EXT_DBCN_CONSOLE_WRITE

Message ID 20241129045926.2961198-1-cyrilbur@tenstorrent.com (mailing list archive)
State New
Headers show
Series [kvmtool,v2] riscv: Use the count parameter of term_putc in SBI_EXT_DBCN_CONSOLE_WRITE | expand

Commit Message

Cyril Bur Nov. 29, 2024, 4:59 a.m. UTC
Currently each character of a string is term_putc()ed individually. This
causes a round trip into opensbi for each char. Very inefficient
especially since the interface term_putc() does accept a count.

This patch passes a count to term_putc() in the
SBI_EXT_DBCN_CONSOLE_WRITE path.

Signed-off-by: Cyril Bur <cyrilbur@tenstorrent.com>
---
V2: Reworked the calculation of length as a variable. No significant
change

 riscv/kvm-cpu.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c
index 0c171da..8f55c8e 100644
--- a/riscv/kvm-cpu.c
+++ b/riscv/kvm-cpu.c
@@ -178,15 +178,16 @@  static bool kvm_cpu_riscv_sbi(struct kvm_cpu *vcpu)
 				break;
 			}
 			vcpu->kvm_run->riscv_sbi.ret[1] = 0;
-			while (str_start <= str_end) {
-				if (vcpu->kvm_run->riscv_sbi.function_id ==
-				    SBI_EXT_DBCN_CONSOLE_WRITE) {
-					term_putc(str_start, 1, 0);
-				} else {
-					if (!term_readable(0))
-						break;
-					*str_start = term_getc(vcpu->kvm, 0);
-				}
+			if (vcpu->kvm_run->riscv_sbi.function_id ==
+			    SBI_EXT_DBCN_CONSOLE_WRITE) {
+				int length = (str_end - str_start) + 1;
+
+				term_putc(str_start, length, 0);
+				vcpu->kvm_run->riscv_sbi.ret[1] += length;
+				break;
+			}
+			while (str_start <= str_end && term_readable(0)) {
+				*str_start = term_getc(vcpu->kvm, 0);
 				vcpu->kvm_run->riscv_sbi.ret[1]++;
 				str_start++;
 			}