b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation
       [not found] <1356315256-6572-1-git-send-email-akinobu.mita@gmail.com>
@ 2012-12-24  2:14 ` Akinobu Mita
  2012-12-25 11:26   ` Antonio Quartulli
  2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32() Akinobu Mita
  1 sibling, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2012-12-24  2:14 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: netdev, b.a.t.m.a.n, Akinobu Mita, Simon Wunderlich,
	Marek Lindner, David S. Miller

batadv_iv_ogm_emit_send_time() attempts to calculates a random integer
in the range of 'orig_interval +- BATADV_JITTER' by the below lines.

        msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
        msecs += (random32() % 2 * BATADV_JITTER);

But it actually gets 'orig_interval' or 'orig_interval - BATADV_JITTER'
because '%' and '*' have same precedence and associativity is
left-to-right.

This adds the parentheses at the appropriate position so that it matches
original intension.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Marek Lindner <lindner_marek@yahoo.de>
Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Cc: Antonio Quartulli <ordex@autistici.org>
Cc: b.a.t.m.a.n@lists.open-mesh.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
---
 net/batman-adv/bat_iv_ogm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 9f3925a..7d02ebd 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -123,7 +123,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
 	unsigned int msecs;
 
 	msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
-	msecs += (random32() % 2 * BATADV_JITTER);
+	msecs += random32() % (2 * BATADV_JITTER);
 
 	return jiffies + msecs_to_jiffies(msecs);
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32()
       [not found] <1356315256-6572-1-git-send-email-akinobu.mita@gmail.com>
  2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation Akinobu Mita
@ 2012-12-24  2:14 ` Akinobu Mita
  2012-12-25 11:30   ` Antonio Quartulli
  1 sibling, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2012-12-24  2:14 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: netdev, b.a.t.m.a.n, Akinobu Mita, Simon Wunderlich,
	Marek Lindner, David S. Miller

Use more preferable function name which implies using a pseudo-random
number generator.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Marek Lindner <lindner_marek@yahoo.de>
Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Cc: Antonio Quartulli <ordex@autistici.org>
Cc: b.a.t.m.a.n@lists.open-mesh.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
---
 net/batman-adv/bat_iv_ogm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 7d02ebd..bc434c4 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -123,7 +123,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
 	unsigned int msecs;
 
 	msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
-	msecs += random32() % (2 * BATADV_JITTER);
+	msecs += prandom_u32() % (2 * BATADV_JITTER);
 
 	return jiffies + msecs_to_jiffies(msecs);
 }
@@ -131,7 +131,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
 /* when do we schedule a ogm packet to be sent */
 static unsigned long batadv_iv_ogm_fwd_send_time(void)
 {
-	return jiffies + msecs_to_jiffies(random32() % (BATADV_JITTER / 2));
+	return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2));
 }
 
 /* apply hop penalty for a normal link */
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation
  2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation Akinobu Mita
@ 2012-12-25 11:26   ` Antonio Quartulli
  2012-12-25 21:35     ` Akinobu Mita
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2012-12-25 11:26 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: netdev, b.a.t.m.a.n, linux-kernel, Simon Wunderlich, akpm,
	Marek Lindner, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 1159 bytes --]

On Mon, Dec 24, 2012 at 11:14:06AM +0900, Akinobu Mita wrote:
> batadv_iv_ogm_emit_send_time() attempts to calculates a random integer
> in the range of 'orig_interval +- BATADV_JITTER' by the below lines.
> 
>         msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
>         msecs += (random32() % 2 * BATADV_JITTER);
> 
> But it actually gets 'orig_interval' or 'orig_interval - BATADV_JITTER'
> because '%' and '*' have same precedence and associativity is
> left-to-right.
> 
> This adds the parentheses at the appropriate position so that it matches
> original intension.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Marek Lindner <lindner_marek@yahoo.de>
> Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> Cc: Antonio Quartulli <ordex@autistici.org>
> Cc: b.a.t.m.a.n@lists.open-mesh.org
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: netdev@vger.kernel.org
> ---

Acked-by: Antonio Quartulli <ordex@autistici.org>

But I would suggest to apply this change to net, since it is a fix.

Cheers,


-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32()
  2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32() Akinobu Mita
@ 2012-12-25 11:30   ` Antonio Quartulli
  2013-01-02 11:52     ` Marek Lindner
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2012-12-25 11:30 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: netdev, b.a.t.m.a.n, linux-kernel, Simon Wunderlich, akpm,
	Marek Lindner, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

On Mon, Dec 24, 2012 at 11:14:07AM +0900, Akinobu Mita wrote:
> Use more preferable function name which implies using a pseudo-random
> number generator.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Marek Lindner <lindner_marek@yahoo.de>
> Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> Cc: Antonio Quartulli <ordex@autistici.org>
> Cc: b.a.t.m.a.n@lists.open-mesh.org
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: netdev@vger.kernel.org

Acked-by: Antonio Quartulli <ordex@autistici.org>

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation
  2012-12-25 11:26   ` Antonio Quartulli
@ 2012-12-25 21:35     ` Akinobu Mita
  2012-12-25 21:37       ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Akinobu Mita @ 2012-12-25 21:35 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: netdev, b.a.t.m.a.n, linux-kernel, Simon Wunderlich, akpm,
	Marek Lindner, David S. Miller

2012/12/25 Antonio Quartulli <ordex@autistici.org>:
> On Mon, Dec 24, 2012 at 11:14:06AM +0900, Akinobu Mita wrote:
>> batadv_iv_ogm_emit_send_time() attempts to calculates a random integer
>> in the range of 'orig_interval +- BATADV_JITTER' by the below lines.
>>
>>         msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
>>         msecs += (random32() % 2 * BATADV_JITTER);
>>
>> But it actually gets 'orig_interval' or 'orig_interval - BATADV_JITTER'
>> because '%' and '*' have same precedence and associativity is
>> left-to-right.
>>
>> This adds the parentheses at the appropriate position so that it matches
>> original intension.
>>
>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>> Cc: Marek Lindner <lindner_marek@yahoo.de>
>> Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
>> Cc: Antonio Quartulli <ordex@autistici.org>
>> Cc: b.a.t.m.a.n@lists.open-mesh.org
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: netdev@vger.kernel.org
>> ---
>
> Acked-by: Antonio Quartulli <ordex@autistici.org>
>
> But I would suggest to apply this change to net, since it is a fix.

I agree.
David, please consider to apply this patch for 3.8-rc*.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation
  2012-12-25 21:35     ` Akinobu Mita
@ 2012-12-25 21:37       ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2012-12-25 21:37 UTC (permalink / raw)
  To: akinobu.mita; +Cc: netdev, b.a.t.m.a.n, linux-kernel, siwu, akpm, lindner_marek

From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Wed, 26 Dec 2012 06:35:37 +0900

> 2012/12/25 Antonio Quartulli <ordex@autistici.org>:
>> On Mon, Dec 24, 2012 at 11:14:06AM +0900, Akinobu Mita wrote:
>>> batadv_iv_ogm_emit_send_time() attempts to calculates a random integer
>>> in the range of 'orig_interval +- BATADV_JITTER' by the below lines.
>>>
>>>         msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
>>>         msecs += (random32() % 2 * BATADV_JITTER);
>>>
>>> But it actually gets 'orig_interval' or 'orig_interval - BATADV_JITTER'
>>> because '%' and '*' have same precedence and associativity is
>>> left-to-right.
>>>
>>> This adds the parentheses at the appropriate position so that it matches
>>> original intension.
>>>
>>> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
>>> Cc: Marek Lindner <lindner_marek@yahoo.de>
>>> Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
>>> Cc: Antonio Quartulli <ordex@autistici.org>
>>> Cc: b.a.t.m.a.n@lists.open-mesh.org
>>> Cc: "David S. Miller" <davem@davemloft.net>
>>> Cc: netdev@vger.kernel.org
>>> ---
>>
>> Acked-by: Antonio Quartulli <ordex@autistici.org>
>>
>> But I would suggest to apply this change to net, since it is a fix.
> 
> I agree.
> David, please consider to apply this patch for 3.8-rc*.
> 

All patches I should consider seriously should be properly
reposted for review and inclusion.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32()
  2012-12-25 11:30   ` Antonio Quartulli
@ 2013-01-02 11:52     ` Marek Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Lindner @ 2013-01-02 11:52 UTC (permalink / raw)
  To: b.a.t.m.a.n
  Cc: netdev, Akinobu Mita, Simon Wunderlich, linux-kernel, akpm,
	David S. Miller

On Tuesday, December 25, 2012 19:30:36 Antonio Quartulli wrote:
> On Mon, Dec 24, 2012 at 11:14:07AM +0900, Akinobu Mita wrote:
> > Use more preferable function name which implies using a pseudo-random
> > number generator.
> > 
> > Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> > Cc: Marek Lindner <lindner_marek@yahoo.de>
> > Cc: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> > Cc: Antonio Quartulli <ordex@autistici.org>
> > Cc: b.a.t.m.a.n@lists.open-mesh.org
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: netdev@vger.kernel.org
> 
> Acked-by: Antonio Quartulli <ordex@autistici.org>

Applied in revision 02c5591.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-01-02 11:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1356315256-6572-1-git-send-email-akinobu.mita@gmail.com>
2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 19/29] batman-adv: fix random jitter calculation Akinobu Mita
2012-12-25 11:26   ` Antonio Quartulli
2012-12-25 21:35     ` Akinobu Mita
2012-12-25 21:37       ` David Miller
2012-12-24  2:14 ` [B.A.T.M.A.N.] [PATCH 20/29] batman-adv: rename random32() to prandom_u32() Akinobu Mita
2012-12-25 11:30   ` Antonio Quartulli
2013-01-02 11:52     ` Marek Lindner

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).