From patchwork Wed Feb 14 11:43:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10218489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3762D6055C for ; Wed, 14 Feb 2018 11:43:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1937B28F55 for ; Wed, 14 Feb 2018 11:43:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C98D28F5B; Wed, 14 Feb 2018 11:43:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 944A828F55 for ; Wed, 14 Feb 2018 11:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967386AbeBNLnn (ORCPT ); Wed, 14 Feb 2018 06:43:43 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59984 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967360AbeBNLnn (ORCPT ); Wed, 14 Feb 2018 06:43:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 955004023141 for ; Wed, 14 Feb 2018 11:43:42 +0000 (UTC) Received: from [10.36.118.14] (unknown [10.36.118.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B097F20A846E; Wed, 14 Feb 2018 11:43:41 +0000 (UTC) Subject: Re: [PATCH kvm-unit-tests 4/8] powerpc: Introduce getchar To: Andrew Jones , Thomas Huth Cc: kvm@vger.kernel.org, rkrcmar@redhat.com References: <20180207190334.16516-1-drjones@redhat.com> <20180207190334.16516-5-drjones@redhat.com> <11627054-40fd-d9c8-408f-754a833fe60c@redhat.com> <20180208125903.7uhndkr3k6uad7jy@kamzik.brq.redhat.com> From: Paolo Bonzini Message-ID: <465ef721-a220-74cf-70dd-9b65fa523b1b@redhat.com> Date: Wed, 14 Feb 2018 12:43:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180208125903.7uhndkr3k6uad7jy@kamzik.brq.redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 14 Feb 2018 11:43:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 14 Feb 2018 11:43:42 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 08/02/2018 13:59, Andrew Jones wrote: > On Thu, Feb 08, 2018 at 12:06:07PM +0100, Thomas Huth wrote: >> On 07.02.2018 20:03, Andrew Jones wrote: >>> Move the unit test specific h_get_term_char() to powerpc common code >>> and call it getchar(). Other architectures may want to implement >>> getchar() too (ARM will in a coming patch), so put the prototype in >>> libcflat.h >> >> Using the libc name getchar() here sounds wrong. h_get_term_char() >> behaves differently compared to the libc getchar(), e.g. it does not >> block if there are no characters available. >> I think you should either name this function differently, or implement a >> behavior that is more close to the libc getchar() to avoid future confusion. > > Good point. I guess I should rename it, because we'd need to anyway in > order to share getchar()'s implementation among other architectures, > unless we duplicated the looping and EOF returning. Any suggestion for > the name? __getchar() or stdin_readb()? Like this? Paolo diff --git a/lib/getchar.c b/lib/getchar.c new file mode 100644 index 0000000..26f6b6b --- /dev/null +++ b/lib/getchar.c @@ -0,0 +1,11 @@ +#include "libcflat.h" +#include "asm/barrier.h" + +int getchar(void) +{ + int c; + + while ((c = __getchar()) == -1) + cpu_relax(); + return c; +} diff --git a/lib/libcflat.h b/lib/libcflat.h index c680b69..cc56553 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -82,6 +82,7 @@ typedef u64 phys_addr_t; #define INVALID_PHYS_ADDR (~(phys_addr_t)0) extern void puts(const char *s); +extern int __getchar(void); extern int getchar(void); extern void exit(int code); extern void abort(void); diff --git a/lib/powerpc/hcall.c b/lib/powerpc/hcall.c index d65af93..7b05265 100644 --- a/lib/powerpc/hcall.c +++ b/lib/powerpc/hcall.c @@ -32,7 +32,7 @@ void putchar(int c) hcall(H_PUT_TERM_CHAR, vty, nr_chars, chars); } -int getchar(void) +int __getchar(void) { register unsigned long r3 asm("r3") = H_GET_TERM_CHAR; register unsigned long r4 asm("r4") = 0; /* 0 == default vty */ @@ -41,5 +41,5 @@ int getchar(void) asm volatile (" sc 1 " : "+r"(r3), "+r"(r4), "=r"(r5) : "r"(r3), "r"(r4)); - return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : 0; + return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : -1; } diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 21dea40..63dc166 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -30,6 +30,7 @@ asm-offsets = lib/$(ARCH)/asm-offsets.h include $(SRCDIR)/scripts/asm-offsets.mak cflatobjs += lib/util.o +cflatobjs += lib/getchar.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc.o cflatobjs += lib/devicetree.o diff --git a/powerpc/sprs.c b/powerpc/sprs.c index 5b5a540..6744bd8 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -285,8 +285,7 @@ int main(int argc, char **argv) if (pause) { puts("Now migrate the VM, then press a key to continue...\n"); - while (getchar() == 0) - cpu_relax(); + (void) getchar(); } else { puts("Sleeping...\n"); handle_exception(0x900, &dec_except_handler, NULL);