From patchwork Wed Sep 25 16:37:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5D24112B for ; Wed, 25 Sep 2019 16:38:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE70221D7B for ; Wed, 25 Sep 2019 16:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391715AbfIYQi3 (ORCPT ); Wed, 25 Sep 2019 12:38:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57278 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390948AbfIYQi2 (ORCPT ); Wed, 25 Sep 2019 12:38:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F93A368CF; Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16E2260BF1; Wed, 25 Sep 2019 16:38:26 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank 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 Message-Id: <20190925163714.27519-14-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank 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 Reviewed-by: Thomas Huth Acked-by: David Hildenbrand Message-Id: <20190920112345.2359-1-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- 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 #include #include +#include #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