[IPV4]: Use random32() in net/ipv4/multipath
Removed local random number generator function Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
269def7c50
commit
4c3ae4d7e7
|
@ -32,6 +32,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/mroute.h>
|
#include <linux/mroute.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
#include <linux/random.h>
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
#include <net/protocol.h>
|
#include <net/protocol.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
|
@ -48,21 +49,6 @@
|
||||||
|
|
||||||
#define MULTIPATH_MAX_CANDIDATES 40
|
#define MULTIPATH_MAX_CANDIDATES 40
|
||||||
|
|
||||||
/* interface to random number generation */
|
|
||||||
static unsigned int RANDOM_SEED = 93186752;
|
|
||||||
|
|
||||||
static inline unsigned int random(unsigned int ubound)
|
|
||||||
{
|
|
||||||
static unsigned int a = 1588635695,
|
|
||||||
q = 2,
|
|
||||||
r = 1117695901;
|
|
||||||
|
|
||||||
RANDOM_SEED = a*(RANDOM_SEED % q) - r*(RANDOM_SEED / q);
|
|
||||||
|
|
||||||
return RANDOM_SEED % ubound;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void random_select_route(const struct flowi *flp,
|
static void random_select_route(const struct flowi *flp,
|
||||||
struct rtable *first,
|
struct rtable *first,
|
||||||
struct rtable **rp)
|
struct rtable **rp)
|
||||||
|
@ -84,7 +70,7 @@ static void random_select_route(const struct flowi *flp,
|
||||||
if (candidate_count > 1) {
|
if (candidate_count > 1) {
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
unsigned char candidate_no = (unsigned char)
|
unsigned char candidate_no = (unsigned char)
|
||||||
random(candidate_count);
|
(random32() % candidate_count);
|
||||||
|
|
||||||
/* find chosen candidate and adjust GC data for all candidates
|
/* find chosen candidate and adjust GC data for all candidates
|
||||||
* to ensure they stay in cache
|
* to ensure they stay in cache
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/mroute.h>
|
#include <linux/mroute.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
#include <linux/random.h>
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
#include <net/protocol.h>
|
#include <net/protocol.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
|
@ -84,18 +85,6 @@ struct multipath_route {
|
||||||
/* state: primarily weight per route information */
|
/* state: primarily weight per route information */
|
||||||
static struct multipath_bucket state[MULTIPATH_STATE_SIZE];
|
static struct multipath_bucket state[MULTIPATH_STATE_SIZE];
|
||||||
|
|
||||||
/* interface to random number generation */
|
|
||||||
static unsigned int RANDOM_SEED = 93186752;
|
|
||||||
|
|
||||||
static inline unsigned int random(unsigned int ubound)
|
|
||||||
{
|
|
||||||
static unsigned int a = 1588635695,
|
|
||||||
q = 2,
|
|
||||||
r = 1117695901;
|
|
||||||
RANDOM_SEED = a*(RANDOM_SEED % q) - r*(RANDOM_SEED / q);
|
|
||||||
return RANDOM_SEED % ubound;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned char __multipath_lookup_weight(const struct flowi *fl,
|
static unsigned char __multipath_lookup_weight(const struct flowi *fl,
|
||||||
const struct rtable *rt)
|
const struct rtable *rt)
|
||||||
{
|
{
|
||||||
|
@ -193,7 +182,7 @@ static void wrandom_select_route(const struct flowi *flp,
|
||||||
|
|
||||||
/* choose a weighted random candidate */
|
/* choose a weighted random candidate */
|
||||||
decision = first;
|
decision = first;
|
||||||
selector = random(power);
|
selector = random32() % power;
|
||||||
last_power = 0;
|
last_power = 0;
|
||||||
|
|
||||||
/* select candidate, adjust GC data and cleanup local state */
|
/* select candidate, adjust GC data and cleanup local state */
|
||||||
|
|
Loading…
Reference in New Issue