Skip to contentSkip to conversation

Add carta_random32() library routine

PATCH In review Jeff Garzik 7 participants 12 messages Oct 11, 2006 – Oct 28, 2006 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · Linux Kernel Mailing List

commit e0ab2928cc2202f13f0574d4c6f567f166d307eb
tree 3df0b8e340b1a98cd8a2daa19672ff008e8fb7f9
parent b611967de4dc5c52049676c4369dcac622a7cdfe
author Stephane Eranian <[email protected]> 1160554905 -0700 committer Linus Torvalds <[email protected]> 1160590461 -0700

Quoted 8 lines

[PATCH] Add carta_random32() library routine

This is a follow-up patch based on the review for perfmon2. This patch adds the carta_random32() library routine + carta_random32.h header file.

This is fast, simple, and efficient pseudo number generator algorithm. We use it in perfmon2 to randomize the sampling periods. In this context, we do not need any fancy randomizer.

hrm, does this really warrant inclusion into every kernel build, on every platform?

Jeff

#2 lore raw
Quoted 12 lines · On Wed, 11 Oct 2006 15:22:57 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 11 lines · Linux Kernel Mailing List

commit e0ab2928cc2202f13f0574d4c6f567f166d307eb
tree 3df0b8e340b1a98cd8a2daa19672ff008e8fb7f9
parent b611967de4dc5c52049676c4369dcac622a7cdfe
author Stephane Eranian <[email protected]> 1160554905 -0700 committer Linus Torvalds <[email protected]> 1160590461 -0700

[PATCH] Add carta_random32() library routine

This is a follow-up patch based on the review for perfmon2. This patch adds the carta_random32() library routine + carta_random32.h header file.

Quoted 9 lines
Quoted 3 lines

This is fast, simple, and efficient pseudo number generator algorithm. We use it in perfmon2 to randomize the sampling periods. In this context, we do not need any fancy randomizer.

hrm, does this really warrant inclusion into every kernel build, on every platform?

Jeff

Wouldn't existing net_random() work?

Signature · 1 line
Stephen Hemminger <[email protected]>
#3 lore raw
Quoted 19 lines · On Wed, 11 Oct 2006 12:29:38 -0700 Stephen Hemminger <[email protected]>…
Quoted 16 lines · On Wed, 11 Oct 2006 15:22:57 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 14 lines · Linux Kernel Mailing List

commit e0ab2928cc2202f13f0574d4c6f567f166d307eb
tree 3df0b8e340b1a98cd8a2daa19672ff008e8fb7f9
parent b611967de4dc5c52049676c4369dcac622a7cdfe
author Stephane Eranian <[email protected]> 1160554905 -0700 committer Linus Torvalds <[email protected]> 1160590461 -0700

[PATCH] Add carta_random32() library routine

This is a follow-up patch based on the review for perfmon2. This patch adds the carta_random32() library routine + carta_random32.h header file.

This is fast, simple, and efficient pseudo number generator algorithm. We use it in perfmon2 to randomize the sampling periods. In this context, we do not need any fancy randomizer.

Quoted 8 lines
Quoted 5 lines

hrm, does this really warrant inclusion into every kernel build, on every platform?

Jeff

Wouldn't existing net_random() work?

It might do, but someone went and hid it in networking and nobody knew about it.

Stephane?

#4 lore raw

PATCH 1/1 rename net_random to random32

Make net_random() more widely available by calling it random32

---
 include/linux/net.h    |    5 +-
 include/linux/random.h |    3 +
 lib/Makefile           |    2 -
 lib/random32.c         |  135 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/core/dev.c         |    2 -
 net/core/utils.c       |  116 -----------------------------------------
 6 files changed, 141 insertions(+), 122 deletions(-)
include/linux/net.h +2 -3
index c257f71..5d4240e 100644
@@ -193,9 +193,8 @@ extern int 	     sock_map_fd(struct sock
 extern struct socket *sockfd_lookup(int fd, int *err);
 #define		     sockfd_put(sock) fput(sock->file)
 extern int	     net_ratelimit(void);
-extern unsigned long net_random(void);
-extern void	     net_srandom(unsigned long);
-extern void	     net_random_init(void);
+
+#define net_random()	random32()
 
 extern int   	     kernel_sendmsg(struct socket *sock, struct msghdr *msg,
 				    struct kvec *vec, size_t num, size_t len);
include/linux/random.h +3 -0
index 5d6456b..0248b30 100644
@@ -69,6 +69,9 @@ #endif
 unsigned int get_random_int(void);
 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
 
+u32 random32(void);
+void srandom32(u32 seed);
+
 #endif /* __KERNEL___ */
 
 #endif /* _LINUX_RANDOM_H */
lib/Makefile +1 -1
index 59070db..bffdc82 100644
@@ -5,7 +5,7 @@ #
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o irq_regs.o carta_random32.o
+	 sha1.o irq_regs.o random32.o carta_random32.o
 
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
lib/random32.c new file +135 -0

135 lines not on this page · raw message

net/core/dev.c +0 -2
index 4d891be..81c426a 100644
@@ -3502,8 +3502,6 @@ static int __init net_dev_init(void)
 
 	BUG_ON(!dev_boot_phase);
 
-	net_random_init();
-
 	if (dev_proc_init())
 		goto out;
 
net/core/utils.c +0 -116

129 lines not on this page · raw message

Signature · 1 line
1.4.1
#6 lore raw

Re: [PATCH] rename net_random to random32

In reply to Stephen Hemminger
Quoted 14 lines · Stephen Hemminger

Make net_random() more widely available by calling it random32
...

lib/Makefile +1 -1
@@ -5,7 +5,7 @@ #
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o irq_regs.o carta_random32.o
+	 sha1.o irq_regs.o random32.o carta_random32.o
...

lib/random32.c line 101

Quoted 5 lines
lib/random32.c new file +2 -0
...
+EXPORT_SYMBOL(random32);
...
+EXPORT_SYMBOL(srandom32);
...

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

The problem is that if only modules use these functions, they will be omitted from the kernel image.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#7 lore raw

Re: [PATCH] rename net_random to random32

Quoted 24 lines · On Fri, 13 Oct 2006 20:19:22 +0200 Adrian Bunk <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

Make net_random() more widely available by calling it random32
...

lib/Makefile +1 -1
@@ -5,7 +5,7 @@ #
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o irq_regs.o carta_random32.o
+	 sha1.o irq_regs.o random32.o carta_random32.o
...

lib/random32.c line 101

Quoted 5 lines
lib/random32.c new file +2 -0
...
+EXPORT_SYMBOL(random32);
...
+EXPORT_SYMBOL(srandom32);
...

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

Quoted 6 lines

The problem is that if only modules use these functions, they will be omitted from the kernel image.

cu
Adrian

The main net code uses the code so it isn't really an issue in this case.

#8 lore raw

Re: [PATCH] rename net_random to random32

In reply to Adrian Bunk
Quoted 24 lines · On Fri, 13 Oct 2006 20:19:22 +0200 Adrian Bunk <[email protected]> wrote:
Quoted 14 lines · Stephen Hemminger

Make net_random() more widely available by calling it random32
...

lib/Makefile +1 -1
@@ -5,7 +5,7 @@ #
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
 	 idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \
-	 sha1.o irq_regs.o carta_random32.o
+	 sha1.o irq_regs.o random32.o carta_random32.o
...

lib/random32.c line 101

Quoted 5 lines
lib/random32.c new file +2 -0
...
+EXPORT_SYMBOL(random32);
...
+EXPORT_SYMBOL(srandom32);
...

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

Quoted 3 lines

The problem is that if only modules use these functions, they will be omitted from the kernel image.

Yeah, I always get those two confused. I moved it to obj-y, thanks.

maintainer
#9 lore raw

Re: [PATCH] rename net_random to random32

From: Andrew Morton <[email protected]>
Date: Fri, 13 Oct 2006 12:09:56 -0700

Quoted 10 lines
Quoted 6 lines · On Fri, 13 Oct 2006 20:19:22 +0200 Adrian Bunk <[email protected]> wrote:

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

The problem is that if only modules use these functions, they will be omitted from the kernel image.

Yeah, I always get those two confused. I moved it to obj-y, thanks.

Yep, good catch Adrian. I've been burned by this one oto.

#10 lore raw

Re: [PATCH] rename net_random to random32

In reply to Adrian Bunk
Quoted 2 lines

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

In practice module will not load becasue it cannot resolve symbol - right?

That aside we should not export symbols from lib-y. But I have not any good idea how to catch this during build time unles doing some ugly grep magic.

One thing that could be done would be to check for a specific section (__ksymtab_strings) in the .o file only for lib-y .o files.

The check could be something like:
objdump -h <file.o> | grep __ksymtab_strings

If grep give error code '0' then we exported a symbol. I may try to cook up later this weekend.

Sam

#11 lore raw

Re: [PATCH] rename net_random to random32

In reply to Adrian Bunk
Quoted 11 lines · Adrian Bunk

lib/random32.c line 101

Quoted 7 lines
lib/random32.c new file +2 -0
...
+EXPORT_SYMBOL(random32);
...
+EXPORT_SYMBOL(srandom32);
...

EXPORT_SYMBOL's in lib-y are latent bugs (IMHO kbuild should error on them):

Quoted 2 lines

The problem is that if only modules use these functions, they will be omitted from the kernel image.

In fact we should really really just kill lib-y completely. Leaving the control of what gets built in to the linker shound like a really bad idea in our enviroment.

#12 lore raw
In reply to Jeff Garzik
Quoted 12 lines · On Wed, 11 Oct 2006 15:22:57 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 11 lines · Linux Kernel Mailing List

commit e0ab2928cc2202f13f0574d4c6f567f166d307eb
tree 3df0b8e340b1a98cd8a2daa19672ff008e8fb7f9
parent b611967de4dc5c52049676c4369dcac622a7cdfe
author Stephane Eranian <[email protected]> 1160554905 -0700 committer Linus Torvalds <[email protected]> 1160590461 -0700

[PATCH] Add carta_random32() library routine

This is a follow-up patch based on the review for perfmon2. This patch adds the carta_random32() library routine + carta_random32.h header file.

Quoted 7 lines
Quoted 3 lines

This is fast, simple, and efficient pseudo number generator algorithm. We use it in perfmon2 to randomize the sampling periods. In this context, we do not need any fancy randomizer.

hrm, does this really warrant inclusion into every kernel build, on every platform?

probly not really. But putting it into lib.a has problems, and making it a loadable module has problems, and making it Kconfigurable has problems. And it's only 150-odd bytes.

It'd be better to just start to use it. There are a number of callers of get_random_bytes() who just don't need such fanciness (and degradation or /dev/urandom), such as ext2/3/4's Orlov allocator.