I just solderd a paralel printer cable and together to get an old
canon bjc250 to work, finding that printing on plan9 was
horribly slow compared to ghostscript on linux :-(. The printer
paused up to 5 seconds after each a row. It takes minutes to print
the first page of /sys/doc/lp.ps...

I compared the plan9 code with the openbsd driver and found
that they use an optimization to make the busy waiting faster
by using a adaptive spin loop first and then reverting to
sleeping.

Hacking a similar thing in the plan9 driver makes printing
speed acceptable again for me :-)

/sys/src/9/pc/devlpt.c:

static void
outch(int base, int c)
{
        int status, tries;
+       int spin;
+       static int maxspin = 0;

        spin = 0;
        for(tries=0;; tries++) {
                status = inb(base+Qpsr);
                if(status&Fnotbusy)
                        break;
                if((status&Fpe)==0 && (status&(Fselect|Fnoerror)) != 
(Fselect|Fnoerror))
                        error(Eio);
+               if(++spin < maxspin)
+                       continue;
+               maxspin++;
                if(tries < 10)
                        tsleep(&lptrendez, return0, nil, 1);
                else {
                        outb(base+Qpcr, Finitbar|Fie);
                        tsleep(&lptrendez, lptready, (void *)base, 100);
                }
        }
        outb(base+Qdlr, c);
        outb(base+Qpcr, Finitbar|Fstrobe);
        outb(base+Qpcr, Finitbar);
+       if(spin*2 + 16 < maxspin)
+               maxspin--;
}

The static maxspin may cause problems with multiple paralel ports
or multiprocessor machines.

Another timesaver is to know that one needs set the Parport
configuration in the PC BIOS to "Normal" or "Standard"! 
Not "Bi-Directional", "EPP" or "ECP"! Then anything works as
expected. :-)

--
cinap


Reply via email to