From owner-freebsd-hackers Thu Oct 19 23:44:43 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id XAA17895 for hackers-outgoing; Thu, 19 Oct 1995 23:44:43 -0700 Received: from grunt.grondar.za (grunt.grondar.za [196.7.18.129]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id XAA17886 for ; Thu, 19 Oct 1995 23:44:04 -0700 Received: from grumble.grondar.za (grumble.grondar.za [196.7.18.130]) by grunt.grondar.za (8.6.12/8.6.9) with ESMTP id IAA28575; Fri, 20 Oct 1995 08:43:11 +0200 Received: from localhost (localhost [127.0.0.1]) by grumble.grondar.za (8.6.12/8.6.9) with SMTP id IAA01491; Fri, 20 Oct 1995 08:43:10 +0200 Message-Id: <199510200643.IAA01491@grumble.grondar.za> X-Authentication-Warning: grumble.grondar.za: Host localhost didn't use HELO protocol To: Bruce Evans cc: hackers@FreeBSD.org Subject: Re: Creating a /dev/random Date: Fri, 20 Oct 1995 08:43:10 +0200 From: Mark Murray Sender: owner-hackers@FreeBSD.org Precedence: bulk > > o I thought it best to place my interrupt hooks where I did, instead > > of where you suggested, as I decided I wanted to be as close to > > the interrupt code as I could get. Also the `unit' you suggested I > > use to fiddle the irq passing would not work - it did not have the > > right range of values (it would typically obly be 0, wth the occaisional > > 1 or 2) > > My method avoids extra overhead for the interrupts that aren't hooked. > I said to replace the `unit' number by the interrupt number in intr_unit[] > and load the original unit number in the dispatch function before calling > the interrupt handler. There is a problem with this. The interrupt handler is called with a unit number, which is non-unique. There is no way to get back to the original interrupt handler. (you suggested:) > I think you will need to hook selected interrupt handlers to get dynamic > interrupt information. INTR() is too static. The following would almost > work: > > void init_interrupt_randomness(void) { > for (each irq of interest) { > prev_intr_handler[irq] = intr_handler[irq]; > prev_intr_unit[irq] = intr_unit[irq]; > disable_intr(); > intr_handler[irq] = add_interrupt_randomness; > intr_unit[irq] = irq; > enable_intr(); > } > } > > void add_interrupt_randomness(int irq) { <-- units, not irq's > static u_char busy; > > disable_intr(); > if (busy) > enable_intr(); > else { > busy = TRUE; > enable_intr(); > do_things(irq); > busy = FALSE; > } > (*prev_intr_handler[irq])(prev_intr_unit[irq]); <=== won't work as units are mostly small numbers > } > > o I have yet to write some kind of IOCTL to set this interrupt selector. > > (Would an ioctl be the right way? Is there some precedent I could > > follow? > > Yes. spkr.c: spkrioctl() would be a good example if it was written right. > Correct the following stylistic and real bugs in it to get a good example: Great! Thanks.. [I like the example - "except for this list of bugs, this is the route to follow" ;-)] > >diff -udr --exclude=compile sys.ORG/i386/conf/files.i386 sys/i386/conf/files .i386 > > ... > >+i386/isa/random.c standard > > Should be optional. Perhaps `optional random device-driver'. I would rather make it a permanent fixture. When random.c is compiled the object file is about 5k, not much for the bloatists to complain about ;-). If software developers like Netscrape could count on this device being present, then they would use it. If it is optional, it may as well be not there. These are Ts'o's sentiments as well. Right now there are #ifdef DEVRANDOM constructs around the code, which I would like to remove when it is stable. > >diff -udr --exclude=compile sys.ORG/i386/i386/machdep.c sys/i386/i386/machde p.c > >--- sys.ORG/i386/i386/machdep.c Thu Oct 12 12:34:03 1995 > >+++ sys/i386/i386/machdep.c Thu Oct 19 20:44:13 1995 > >@@ -126,6 +126,7 @@ > > #include > > #include > > #include > >+#include > > Does it really have isa dependencies? The other isa includes in machdep.c > are bogus too. is this the wrong place to put this header? It is a short file containing necessary function prototypes. > >diff -udr --exclude=compile sys.ORG/i386/isa/vector.s sys/i386/isa/vector.s > >... > >@@ -195,6 +205,8 @@ > > outb %al,$icu+1 ; \ > > sti ; /* XXX _doreti repeats the cli/sti */ \ > > MEXITCOUNT ; \ > >+ /* Add this interrupt to the pool of entropy */ \ > >+ ADDENTROPY(irq_num) ; \ > > /* We could usually avoid the following jmp by inlining some of */ \ > > /* _doreti, but it's probably better to use less cache. */ \ > > jmp _doreti ; \ > > The addition should be before the MEXITCOUNT for correct profiling (in my > version of profiling, MEXITCOUNT is non-null and must be placed immediately > before all jmps). It should probably be even earlier, immediately after > the call to the interrupt handler, so that it is called while interrupts > for the device are still masked in the ICU. Placing it later doesn't > improve latency, because device interrupts are still masked in software. Will do. M -- Mark Murray 46 Harvey Rd, Claremont, Cape Town 7700, South Africa +27 21 61-3768 GMT+0200 Finger mark@grumble.grondar.za for PGP key