9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] devlpt optimization
@ 2009-02-04 11:28 cinap_lenrek
  0 siblings, 0 replies; only message in thread
From: cinap_lenrek @ 2009-02-04 11:28 UTC (permalink / raw)
  To: 9fans

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-04 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-04 11:28 [9fans] devlpt optimization cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).