From: Paolo Bonzini <pbonzini@redhat.com>
To: Andrew Jones <drjones@redhat.com>, Thomas Huth <thuth@redhat.com>
Cc: kvm@vger.kernel.org, rkrcmar@redhat.com
Subject: Re: [PATCH kvm-unit-tests 4/8] powerpc: Introduce getchar
Date: Wed, 14 Feb 2018 12:43:40 +0100 [thread overview]
Message-ID: <465ef721-a220-74cf-70dd-9b65fa523b1b@redhat.com> (raw)
In-Reply-To: <20180208125903.7uhndkr3k6uad7jy@kamzik.brq.redhat.com>
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?
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);
Paolo
next prev parent reply other threads:[~2018-02-14 11:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-07 19:03 [PATCH kvm-unit-tests 0/8] arm/arm64: extend psci tests Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 1/8] virtio-mmio: fix queue allocation Andrew Jones
2018-02-07 19:32 ` Andrew Jones
2018-02-07 19:34 ` [PATCH kvm-unit-tests v2 " Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 2/8] scripts/arch-run: run_migration improvements Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 3/8] powerpc: don't use NMI's to signal end of migration Andrew Jones
2018-02-08 10:58 ` Thomas Huth
2018-02-07 19:03 ` [PATCH kvm-unit-tests 4/8] powerpc: Introduce getchar Andrew Jones
2018-02-08 11:06 ` Thomas Huth
2018-02-08 12:59 ` Andrew Jones
2018-02-14 11:43 ` Paolo Bonzini [this message]
2018-02-14 12:38 ` Andrew Jones
2018-02-14 13:25 ` Paolo Bonzini
2018-02-14 14:38 ` Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 5/8] lib: Introduce do_migration Andrew Jones
2018-02-14 11:45 ` Paolo Bonzini
2018-02-14 12:44 ` Andrew Jones
2018-02-14 13:24 ` Paolo Bonzini
2018-02-07 19:03 ` [PATCH kvm-unit-tests 6/8] arm/arm64: Add support for migration tests Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 7/8] arm/arm64: psci: add migration test Andrew Jones
2018-02-07 19:03 ` [PATCH kvm-unit-tests 8/8] arm/psci: add smccc 1.1 tests Andrew Jones
2018-02-14 11:46 ` [PATCH kvm-unit-tests 0/8] arm/arm64: extend psci tests Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=465ef721-a220-74cf-70dd-9b65fa523b1b@redhat.com \
--to=pbonzini@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=rkrcmar@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).