[kvm-unit-tests,RFC,v3,10/13] s390x: Add linemode buffer to fix newline on every print
diff mbox series

Message ID 20181218092657.46466-11-frankja@linux.ibm.com
State New
Headers show
Series
  • 390x: Add cross hypervisor and disk boot
Related show

Commit Message

Janosch Frank Dec. 18, 2018, 9:26 a.m. UTC
Linemode seems to add a newline for each sent message which makes
reading rather hard. Hence we add a small buffer that and only print
if it's full or a newline is encountered.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/sclp-console.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Thomas Huth Dec. 18, 2018, 12:41 p.m. UTC | #1
On 2018-12-18 10:26, Janosch Frank wrote:
> Linemode seems to add a newline for each sent message which makes
> reading rather hard. Hence we add a small buffer that and only print
> if it's full or a newline is encountered.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  lib/s390x/sclp-console.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
> index f0ce6a0..34edae5 100644
> --- a/lib/s390x/sclp-console.c
> +++ b/lib/s390x/sclp-console.c
> @@ -88,6 +88,9 @@ static uint8_t _ascebc[256] = {
>  };
>  
>  static bool initialized;
> +static char lm_buff[120];
> +static unsigned char lm_buff_off;
> +
>  
>  static void sclp_print_ascii(const char *str)
>  {
> @@ -116,6 +119,18 @@ static void sclp_print_lm(const char *str)
>  	struct mdb *mdb;
>  	struct mto *mto;
>  	struct go *go;
> +	char *nl;
> +
> +	len = strlen(str);
> +	len = len < (sizeof(lm_buff) - lm_buff_off) ? len : (sizeof(lm_buff) - lm_buff_off);
> +	nl = strchr(str, '\n');
> +	if ((lm_buff_off < sizeof(lm_buff) - 1)) {
> +		memcpy(&lm_buff[lm_buff_off], str, len);
> +		lm_buff_off += len;
> +	}
> +	/* Buffer not full and no newline */
> +	if (lm_buff_off != sizeof(lm_buff) - 1 && !nl)
> +		return;
>  
>  	sclp_wait_busy();
>  	sclp_busy = true;
> @@ -123,11 +138,11 @@ 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);
> +	len = strlen(lm_buff);
>  	offset = 0;
>  	do {
>  		for (count = sizeof(*mto); offset < len; count++) {
> -			ch = str[offset++];
> +			ch = lm_buff[offset++];
>  			if ((ch == 0x0a) || (ptr + count > end))
>  				break;
>  			ptr[count] = _ascebc[ch];
> @@ -154,6 +169,8 @@ static void sclp_print_lm(const char *str)
>  	go->type = 1;
>  	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
>  	sclp_wait_busy();
> +	memset(lm_buff, 0 , sizeof(lm_buff));
> +	lm_buff_off = 0;
>  }
>  
>  /*
> 

That likely does not work as expected when someone is printing with the
'\n' not being at the end (printf("Hello\nWor"); printf("ld\n");) ...
but it's certainly better than before, so fine for me if you resend this
the next time without RFC.

 Thomas
Janosch Frank Dec. 19, 2018, 10:11 a.m. UTC | #2
On 18.12.18 13:41, Thomas Huth wrote:
> On 2018-12-18 10:26, Janosch Frank wrote:
>> Linemode seems to add a newline for each sent message which makes
>> reading rather hard. Hence we add a small buffer that and only print
>> if it's full or a newline is encountered.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
[...]
>>  /*
>>
> 
> That likely does not work as expected when someone is printing with the
> '\n' not being at the end (printf("Hello\nWor"); printf("ld\n");) ...
> but it's certainly better than before, so fine for me if you resend this
> the next time without RFC.
> 
>  Thomas
> 

It seems to print \n on a new line, at least it does on the SE operation
message consoles I work with. If not I would have gone mad by now, as I
print a lot of data with newlines for some new tests with "%lx\n %lx\n...".

I'll add a comment to the new function, to make clear why that's here.

Patch
diff mbox series

diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c
index f0ce6a0..34edae5 100644
--- a/lib/s390x/sclp-console.c
+++ b/lib/s390x/sclp-console.c
@@ -88,6 +88,9 @@  static uint8_t _ascebc[256] = {
 };
 
 static bool initialized;
+static char lm_buff[120];
+static unsigned char lm_buff_off;
+
 
 static void sclp_print_ascii(const char *str)
 {
@@ -116,6 +119,18 @@  static void sclp_print_lm(const char *str)
 	struct mdb *mdb;
 	struct mto *mto;
 	struct go *go;
+	char *nl;
+
+	len = strlen(str);
+	len = len < (sizeof(lm_buff) - lm_buff_off) ? len : (sizeof(lm_buff) - lm_buff_off);
+	nl = strchr(str, '\n');
+	if ((lm_buff_off < sizeof(lm_buff) - 1)) {
+		memcpy(&lm_buff[lm_buff_off], str, len);
+		lm_buff_off += len;
+	}
+	/* Buffer not full and no newline */
+	if (lm_buff_off != sizeof(lm_buff) - 1 && !nl)
+		return;
 
 	sclp_wait_busy();
 	sclp_busy = true;
@@ -123,11 +138,11 @@  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);
+	len = strlen(lm_buff);
 	offset = 0;
 	do {
 		for (count = sizeof(*mto); offset < len; count++) {
-			ch = str[offset++];
+			ch = lm_buff[offset++];
 			if ((ch == 0x0a) || (ptr + count > end))
 				break;
 			ptr[count] = _ascebc[ch];
@@ -154,6 +169,8 @@  static void sclp_print_lm(const char *str)
 	go->type = 1;
 	sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 	sclp_wait_busy();
+	memset(lm_buff, 0 , sizeof(lm_buff));
+	lm_buff_off = 0;
 }
 
 /*