All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
	Janosch Frank <frankja@linux.ibm.com>
Subject: [kvm-unit-tests PULL 13/17] s390x: Add linemode buffer to fix newline on every print
Date: Wed, 25 Sep 2019 18:37:10 +0200	[thread overview]
Message-ID: <20190925163714.27519-14-thuth@redhat.com> (raw)
In-Reply-To: <20190925163714.27519-1-thuth@redhat.com>

From: Janosch Frank <frankja@linux.ibm.com>

Linemode seems to add a newline for each sent message which makes
reading rather hard. Hence we add a small buffer and only print if
it's full or a newline is encountered.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Message-Id: <20190920112345.2359-1-frankja@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 lib/s390x/sclp-console.c | 43 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
index 19416b5..6067a1a 100644
--- a/lib/s390x/sclp-console.c
+++ b/lib/s390x/sclp-console.c
@@ -13,6 +13,7 @@
 #include <asm/page.h>
 #include <asm/arch_def.h>
 #include <asm/io.h>
+#include <asm/spinlock.h>
 #include "sclp.h"
 
 /*
@@ -87,6 +88,10 @@ static uint8_t _ascebc[256] = {
      0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF
 };
 
+static char lm_buff[120];
+static unsigned char lm_buff_off;
+static struct spinlock lm_buff_lock;
+
 static void sclp_print_ascii(const char *str)
 {
 	int len = strlen(str);
@@ -103,10 +108,10 @@ static void sclp_print_ascii(const char *str)
 	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 }
 
-static void sclp_print_lm(const char *str)
+static void lm_print(const char *buff, int len)
 {
 	unsigned char *ptr, *end, ch;
-	unsigned int count, offset, len;
+	unsigned int count, offset;
 	struct WriteEventData *sccb;
 	struct mdb *mdb;
 	struct mto *mto;
@@ -117,11 +122,10 @@ static void sclp_print_lm(const char *str)
 	end = (unsigned char *) sccb + 4096 - 1;
 	memset(sccb, 0, sizeof(*sccb));
 	ptr = (unsigned char *) &sccb->msg.mdb.mto;
-	len = strlen(str);
 	offset = 0;
 	do {
 		for (count = sizeof(*mto); offset < len; count++) {
-			ch = str[offset++];
+			ch = buff[offset++];
 			if (ch == 0x0a || ptr + count > end)
 				break;
 			ptr[count] = _ascebc[ch];
@@ -148,6 +152,37 @@ static void sclp_print_lm(const char *str)
 	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 }
 
+
+/*
+ * In contrast to the ascii console, linemode produces a new
+ * line with every write of data. The report() function uses
+ * several printf() calls to generate a line of data which
+ * would all end up on different lines.
+ *
+ * Hence we buffer here until we encounter a \n or the buffer
+ * is full. That means that linemode output can look a bit
+ * different from ascii and that it takes a bit longer for
+ * lines to appear.
+ */
+static void sclp_print_lm(const char *str)
+{
+	int i;
+	const int len = strlen(str);
+
+	spin_lock(&lm_buff_lock);
+
+	for (i = 0; i < len; i++) {
+		lm_buff[lm_buff_off++] = str[i];
+
+		/* Buffer full or newline? */
+		if (str[i] == '\n' || lm_buff_off == (ARRAY_SIZE(lm_buff) - 1)) {
+			lm_print(lm_buff, lm_buff_off);
+			lm_buff_off = 0;
+		}
+	}
+	spin_unlock(&lm_buff_lock);
+}
+
 /*
  * SCLP needs to be initialized by setting a send and receive mask,
  * indicating which messages the control program (we) want(s) to
-- 
2.18.1


  parent reply	other threads:[~2019-09-25 16:38 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 16:36 [kvm-unit-tests PULL 00/17] New s390x kvm-unit-tests and some fixes Thomas Huth
2019-09-25 16:36 ` [kvm-unit-tests PULL 01/17] s390x: Support PSW restart boot Thomas Huth
2019-09-25 16:36 ` [kvm-unit-tests PULL 02/17] s390x: Diag288 test Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 03/17] s390x: Move stsi to library Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 04/17] s390x: STSI tests Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 05/17] s390x: Add diag308 subcode 0 testing Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 06/17] s390x: Move pfmf to lib and make address void Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 07/17] s390x: Storage key library functions now take void ptr addresses Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 08/17] s390x: Bump march to zEC12 Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 09/17] s390x: Add storage key removal facility Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 10/17] s390x: Fix stsi unaligned test and add selector tests Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 11/17] s390x: Use interrupts in SCLP and add locking Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 12/17] s390x: Add linemode console Thomas Huth
2019-09-25 16:37 ` Thomas Huth [this message]
2019-09-25 16:37 ` [kvm-unit-tests PULL 14/17] s390x: Add initial smp code Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 15/17] s390x: Prepare for external calls Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 16/17] s390x: SMP test Thomas Huth
2019-09-25 16:37 ` [kvm-unit-tests PULL 17/17] s390x: Free allocated page in iep test Thomas Huth
2019-09-25 16:39 ` [kvm-unit-tests PULL 00/17] New s390x kvm-unit-tests and some fixes 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=20190925163714.27519-14-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.