From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Andreas Dilger <adilger@clusterfs.com>
Cc: Jean-Luc Cooke <jlcooke@certainkey.com>,
Stephen Hemminger <shemminger@osdl.org>,
"David S. Miller" <davem@redhat.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
netdev@oss.sgi.com, Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] enhanced version of net_random()
Date: Fri, 20 Aug 2004 15:22:09 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.53.0408201518250.25319@chaos> (raw)
In-Reply-To: <20040820185956.GV8967@schnapps.adilger.int>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1186 bytes --]
On Fri, 20 Aug 2004, Andreas Dilger wrote:
> On Aug 20, 2004 13:59 -0400, Jean-Luc Cooke wrote:
> > Is there a reason why get_random_bytes() is unsuitable?
> >
> > Keeping the number of PRNGs in the kernel to a minimum should a goal we can
> > all share.
>
> For some uses a decent PRNG is enough, and the overhead of get_random_bytes()
> is much too high. We've needed something like this for a long time (something
> that gives decenly uniform numbers) and hacks to use useconds/cycles/etc do
> not cut it. I for one welcome a simple in-kernel interface to
> e.g. get_urandom_bytes() (or net_random() as this is maybe inappropriately
> called) that is only pseudo-random but fast and efficient.
>
> Cheers, Andreas
> --
> Andreas Dilger
The attached code will certainly work on Intel machines. It is
in the public domain, having been modified by myself to produce
a very long sequence...
I wouldn't suggest converting it to 'C' because the rotation
takes many CPU instructions when one tries to do the test, shift,
and OR in 'C',
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1530 bytes --]
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# File rnd.S Created 04-FEB-1999 Richard B. Johnson
#
# Simple random number generator. Based upon Alan R. Miller's
# algorithm. Professor of Metallurgy, University of New Mexico
# Institute of Mining and Technology, circa 1980. Published
# In the 8080/Z-80 Assembly Language manual he wrote.
#
# unsigned size_t rnd((size_t *) seed);
#
# The seed can be initialized with time(&seed); on each boot.
#
MAGIC = 0x72b6078b
INTPTR = 0x08
DIVISR = 0x0c
.section .text
.global rnd
.type rnd,@function
.align 0x04
rnd: pushl %ebx
movl INTPTR(%esp), %ebx
movl (%ebx), %eax
rorl $3, %eax
addl $MAGIC, %eax
movl %eax, (%ebx)
popl %ebx
ret
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This returns a random number between 0 and one less than the
# input divisor, i.e. n mod rand(x).
#
# size_t modrnd((size_t *) seed, size_t divisor);
#
.type modrnd,@function
.global modrnd
.align 0x04
modrnd: pushl %ebx
movl INTPTR(%esp), %ebx
movl (%ebx), %eax
rorl $3, %eax
addl $MAGIC, %eax
movl %eax, (%ebx)
xorl %edx, %edx
divl DIVISR(%esp)
movl %edx, %eax
popl %ebx
ret
.end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2004-08-20 19:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-12 17:48 [RFC] enhanced version of net_random() Stephen Hemminger
2004-08-12 19:48 ` David S. Miller
2004-08-13 18:51 ` Stephen Hemminger
2004-08-13 19:28 ` Andi Kleen
2004-08-16 6:27 ` David S. Miller
2004-08-12 20:02 ` Ben Greear
2004-08-20 17:59 ` Jean-Luc Cooke
2004-08-20 18:47 ` David S. Miller
2004-08-20 18:59 ` Andreas Dilger
2004-08-20 19:22 ` Richard B. Johnson [this message]
2004-08-20 19:48 ` David S. Miller
2004-08-20 19:53 ` Jean-Luc Cooke
2004-08-22 15:04 ` Andi Kleen
2004-08-23 17:05 ` Stephen Hemminger
2004-08-23 18:09 ` Richard B. Johnson
2004-08-20 21:24 ` Lee Revell
2004-08-20 23:55 ` Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.53.0408201518250.25319@chaos \
--to=root@chaos.analogic.com \
--cc=adilger@clusterfs.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@redhat.com \
--cc=jlcooke@certainkey.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@oss.sgi.com \
--cc=shemminger@osdl.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox