NetBSD Problem Report #53444

From www@NetBSD.org  Thu Jul 12 16:40:08 2018
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4E8657A1CE
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 12 Jul 2018 16:40:08 +0000 (UTC)
Message-Id: <20180712164007.299AA7A262@mollari.NetBSD.org>
Date: Thu, 12 Jul 2018 16:40:07 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: extended W mode enabling makes vt-switching very slow
X-Send-Pr-Version: www-1.0

>Number:         53444
>Category:       kern
>Synopsis:       extended W mode enabling makes vt-switching very slow
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    uwe
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 12 16:45:00 +0000 2018
>Closed-Date:    Sat Jul 14 00:48:08 +0000 2018
>Last-Modified:  Sat Jul 14 00:48:08 +0000 2018
>Originator:     coypu
>Release:        NetBSD 8.99.19
>Organization:
>Environment:
NetBSD localhost 8.99.19 NetBSD 8.99.19 (GENERIC2) #9: Thu Jul 12 19:28:39 IDT 2018  fly@:/home/fly/obj/sys/arch/amd64/compile/GENERIC2 amd64

>Description:
VT-switching used to be nearly instant.
Now it takes like 5-10 seconds.

My machine:
Full dmesg here: http://dmesgd.nycbug.org/index.cgi?do=view&id=3574

Excerpt:
pms0 at pckbc1 (aux slot)
pms0: Synaptics touchpad version 8.2
pms0: Extended W mode, Palm detect, One button click pad, Multi-finger Report, Multi-finger
pckbc1: using irq 12 for aux slot
wsmouse0 at pms0 mux 0

I found out that the following diff is sufficient to make vt-switching as fast as before:

--- a/sys/dev/pckbport/synaptics.c
+++ b/sys/dev/pckbport/synaptics.c 
 void
 pms_synaptics_enable(void *vsc)
 {
        struct pms_softc *psc = vsc;
        struct synaptics_softc *sc = &psc->u.synaptics;
        u_char enable_modes;
        int res;
-       u_char cmd[1], resp[3];

        if (sc->flags & SYN_FLAG_HAS_PASSTHROUGH) {
                /*
                 * Extended capability probes can confuse the passthrough
                 * device; reset the touchpad now to cure that.
                 */
                res = synaptics_poll_reset(psc);
        }

        /*
         * Enable Absolute mode with W (width) reporting, and set
         * the packet rate to maximum (80 packets per second). Enable
         * extended W mode if supported so we can report second finger
         * position.
         */
@@ -448,43 +447,44 @@ pms_synaptics_enable(void *vsc)

        synaptics_poll_cmd(psc, PMS_SET_SAMPLE, SYNAPTICS_CMD_SET_MODE2, 0);

        /* a couple of set scales to clear out pending commands */
        for (int i = 0; i < 2; i++)
                synaptics_poll_cmd(psc, PMS_SET_SCALE11, 0);

        /*
         * Enable multi-finger capability in cold boot case with
         * undocumented sequence.
         * Parameters from
         * https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller/
         * VoodooPS2Trackpad/VoodooPS2SynapticsTouchPad.cpp
         * setTouchPadModeByte function.
         */
+#if 0
        if (sc->flags & SYN_FLAG_HAS_EXTENDED_WMODE) {
                static const uint8_t seq[] = {
                    0xe6, 0xe8, 0x00, 0xe8, 0x00,
                    0xe8, 0x00, 0xe8, 0x03, 0xf3,
                    0xc8,
                };
                for (size_t s = 0; s < __arraycount(seq); s++) {
                        cmd[0] = seq[s];
                        (void)pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
                                cmd, 1, 3, resp, 0);
                }
        }
-
+#endif

>How-To-Repeat:

>Fix:
No idea.

>Release-Note:

>Audit-Trail:
From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/53444: extended W mode enabling makes vt-switching very slow
Date: Thu, 12 Jul 2018 21:08:01 +0000

 So, it appears that if you send a pcbkport command and it doesn't get
 ACK'd, we could be waiting a long time. that does appear to be what's
 happening here.

From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/53444: extended W mode enabling makes vt-switching very slow
Date: Thu, 12 Jul 2018 21:18:26 +0000

 uwe mentions this:

                     0xe6, 0xe8, 0x00, 0xe8, 0x00,
                     0xe8, 0x00, 0xe8, 0x03, 0xf3,
                     0xc8,

 effectively hard-codes the 'psmouse sliced command' which multiple
 things use (and then some).

 In the words of otherOS:

  * psmouse_sliced_command() sends an extended PS/2 command to the mouse
  * using sliced syntax, understood by advanced devices, such as Logitech
  * or Synaptics touchpads. The command is encoded as:
  * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu

 The documentation/other drivers use sliced commands.

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/53444: extended W mode enabling makes vt-switching very slow
Date: Fri, 13 Jul 2018 01:27:32 +0300

 On Thu, Jul 12, 2018 at 21:20:00 +0000, coypu@sdf.org wrote:

 >  uwe mentions this:
 >  
 >                      0xe6, 0xe8, 0x00, 0xe8, 0x00,
 >                      0xe8, 0x00, 0xe8, 0x03, 0xf3,
 >                      0xc8,
 >  
 >  effectively hard-codes the 'psmouse sliced command' which multiple
 >  things use (and then some).
 >  
 >  In the words of otherOS:
 >  
 >   * psmouse_sliced_command() sends an extended PS/2 command to the mouse
 >   * using sliced syntax, understood by advanced devices, such as Logitech
 >   * or Synaptics touchpads. The command is encoded as:
 >   * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
 >  
 >  The documentation/other drivers use sliced commands.

 - E6 makes sure we are in a known state (just in case previous command was E8)
 - E8 xx ... sends the argument for the extended command in slices
 - F3 xx is the command

 FWIW, the docs I have say that F3 C8 sets Deluxe Mode Byte 3 but they
 are rather old and that byte is unused/undocumented in them.

 I wonder if the device is unhappy b/c you send that extended command
 byte by byte instead of using pms_sliced_command() that will send it
 in meaningful chunks.

 -uwe

Responsible-Changed-From-To: kern-bug-people->ryoon
Responsible-Changed-By: maya@NetBSD.org
Responsible-Changed-When: Fri, 13 Jul 2018 21:02:45 +0000
Responsible-Changed-Why:
This patch works for me (with uwe improving the driver): http://coypu.sdf.org/synaptics6.diff
Does it still work with the extended W mode for you?


State-Changed-From-To: open->feedback
State-Changed-By: maya@NetBSD.org
State-Changed-When: Fri, 13 Jul 2018 21:02:45 +0000
State-Changed-Why:
Index: synaptics.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/synaptics.c,v
retrieving revision 1.41
diff -u -r1.41 synaptics.c
--- synaptics.c	3 Jun 2018 15:10:12 -0000	1.41
+++ synaptics.c	13 Jul 2018 20:59:33 -0000
@@ -179,7 +179,7 @@
 }

 static int
-synaptics_poll_status(struct pms_softc *psc, u_char slice, u_char resp[3])
+synaptics_special_read(struct pms_softc *psc, u_char slice, u_char resp[3])
 {
 	u_char cmd[1] = { PMS_SEND_DEV_STATUS };
 	int res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot, slice);
@@ -188,6 +188,21 @@
 	    cmd, 1, 3, resp, 0);
 }

+static int
+synaptics_special_write(struct pms_softc *psc, u_char command, u_char arg)
+{
+	int res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot, arg);
+	if (res)
+		return res;
+
+	u_char cmd[2];
+	cmd[0] = PMS_SET_SAMPLE;
+	cmd[1] = command;
+	res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+	    cmd, 2, 0, NULL, 0);
+	return res;
+}
+
 static void
 pms_synaptics_probe_extended(struct pms_softc *psc)
 {
@@ -213,7 +228,7 @@
 	if (((sc->caps & SYNAPTICS_CAP_EXTNUM) + 0x08)
 	    >= SYNAPTICS_EXTENDED_QUERY)
 	{
-		res = synaptics_poll_status(psc, SYNAPTICS_EXTENDED_QUERY, resp);
+		res = synaptics_special_read(psc, SYNAPTICS_EXTENDED_QUERY, resp);
 		if (res == 0) {
 			int buttons = (resp[1] >> 4);
 			aprint_debug_dev(psc->sc_dev,
@@ -245,7 +260,7 @@
 	if (((sc->caps & SYNAPTICS_CAP_EXTNUM) + 0x08) >=
 	    SYNAPTICS_CONTINUED_CAPABILITIES)
 	{
-		res = synaptics_poll_status(psc,
+		res = synaptics_special_read(psc,
 		    SYNAPTICS_CONTINUED_CAPABILITIES, resp);

 /*
@@ -362,7 +377,7 @@


 	/* Query the hardware capabilities. */
-	res = synaptics_poll_status(psc, SYNAPTICS_READ_CAPABILITIES, resp);
+	res = synaptics_special_read(psc, SYNAPTICS_READ_CAPABILITIES, resp);
 	if (res) {
 		/* Hmm, failed to get capabilites. */
 		aprint_error_dev(psc->sc_dev,
@@ -410,7 +425,6 @@
 	struct synaptics_softc *sc = &psc->u.synaptics;
 	u_char enable_modes;
 	int res;
-	u_char cmd[1], resp[3];

 	if (sc->flags & SYN_FLAG_HAS_PASSTHROUGH) {
 		/*
@@ -441,37 +455,17 @@
 	for (int i = 0; i < 2; i++)
 		synaptics_poll_cmd(psc, PMS_SET_SCALE11, 0);

-	res = pms_sliced_command(psc->sc_kbctag, psc->sc_kbcslot,
-	    enable_modes);
+	res = synaptics_special_write(psc, SYNAPTICS_CMD_SET_MODE2, enable_modes);
 	if (res)
 		aprint_error("synaptics: set mode error\n");

-	synaptics_poll_cmd(psc, PMS_SET_SAMPLE, SYNAPTICS_CMD_SET_MODE2, 0);
-
 	/* a couple of set scales to clear out pending commands */
 	for (int i = 0; i < 2; i++)
 		synaptics_poll_cmd(psc, PMS_SET_SCALE11, 0);

-	/*
-	 * Enable multi-finger capability in cold boot case with
-	 * undocumented sequence.
-	 * Parameters from
-	 * https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller/
-	 * VoodooPS2Trackpad/VoodooPS2SynapticsTouchPad.cpp
-	 * setTouchPadModeByte function.
-	 */
-	if (sc->flags & SYN_FLAG_HAS_EXTENDED_WMODE) {
-		static const uint8_t seq[] = {
-		    0xe6, 0xe8, 0x00, 0xe8, 0x00,
-		    0xe8, 0x00, 0xe8, 0x03, 0xf3,
-		    0xc8,
-		};
-		for (size_t s = 0; s < __arraycount(seq); s++) {
-			cmd[0] = seq[s];
-			(void)pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
-				cmd, 1, 3, resp, 0);
-		}
-	}
+	/* Set advanced gesture mode */
+	if (sc->flags & SYN_FLAG_HAS_EXTENDED_WMODE)
+		synaptics_special_write(psc, SYNAPTICS_WRITE_DELUXE_3, 0x3); 

 	synaptics_poll_cmd(psc, PMS_DEV_ENABLE, 0);

Index: synapticsreg.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pckbport/synapticsreg.h,v
retrieving revision 1.9
diff -u -r1.9 synapticsreg.h
--- synapticsreg.h	6 Nov 2017 21:07:17 -0000	1.9
+++ synapticsreg.h	13 Jul 2018 20:59:33 -0000
@@ -45,6 +45,7 @@
 #define	SYNAPTICS_READ_MODEL_ID		0x3
 #define	SYNAPTICS_EXTENDED_QUERY	0x9
 #define	SYNAPTICS_CONTINUED_CAPABILITIES 0x0c
+#define	SYNAPTICS_WRITE_DELUXE_3	0xc8 /* 6.2.3. Deluxe mode setting sequence */

 /* Synaptics special commands */
 #define	SYNAPTICS_CMD_SET_MODE2		0x14



Responsible-Changed-From-To: ryoon->uwe
Responsible-Changed-By: maya@NetBSD.org
Responsible-Changed-When: Sat, 14 Jul 2018 00:48:08 +0000
Responsible-Changed-Why:
You feexed eet.


State-Changed-From-To: feedback->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sat, 14 Jul 2018 00:48:08 +0000
State-Changed-Why:
Fixed. thanks.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.