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@xxxxxxxxxxxxxxx> --- riscv/kvm-cpu.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/riscv/kvm-cpu.c b/riscv/kvm-cpu.c index 0c171da..84d35f7 100644 --- a/riscv/kvm-cpu.c +++ b/riscv/kvm-cpu.c @@ -172,21 +172,23 @@ static bool kvm_cpu_riscv_sbi(struct kvm_cpu *vcpu) str_start = guest_flat_to_host(vcpu->kvm, addr); addr += vcpu->kvm_run->riscv_sbi.args[0] - 1; str_end = guest_flat_to_host(vcpu->kvm, addr); - if (!str_start || !str_end) { + if (!str_start || !str_end || str_start > str_end) { vcpu->kvm_run->riscv_sbi.ret[0] = SBI_ERR_INVALID_PARAM; break; } + if (vcpu->kvm_run->riscv_sbi.function_id == + SBI_EXT_DBCN_CONSOLE_WRITE) { + int length = (str_end - str_start) + 1; + + length = term_putc(str_start, length, 0); + vcpu->kvm_run->riscv_sbi.ret[1] = length; + break; + } + /* This will be SBI_EXT_DBCN_CONSOLE_READ */ 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); - } + while (str_start <= str_end && term_readable(0)) { + *str_start = term_getc(vcpu->kvm, 0); vcpu->kvm_run->riscv_sbi.ret[1]++; str_start++; } -- 2.34.1