[PATCH] IPoIB: fix static rate calculation
authorRoland Dreier <roland@topspin.com>
Sat, 16 Apr 2005 22:26:06 +0000 (15:26 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 16 Apr 2005 22:26:06 +0000 (15:26 -0700)
Correct and simplify calculation of static rate.  We need to round up the
quotient of (local_rate - path_rate) / path_rate.  To round up we add
(path_rate - 1) to the numerator, so the quotient simplifies to (local_rate -
1) / path_rate.

No idea how I came up with the old formula.

Signed-off-by: Roland Dreier <roland@topspin.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/infiniband/ulp/ipoib/ipoib_multicast.c

index 5a3b5c6a4494027932f67f6087257dc60018841b..8d35475a1d568b9cee517fcc7f25432a6fea819c 100644 (file)
@@ -302,11 +302,10 @@ static void path_rec_completion(int status,
                        .sl            = pathrec->sl,
                        .port_num      = priv->port
                };
+               int path_rate = ib_sa_rate_enum_to_int(pathrec->rate);
 
-               if (ib_sa_rate_enum_to_int(pathrec->rate) > 0)
-                       av.static_rate = (2 * priv->local_rate -
-                                         ib_sa_rate_enum_to_int(pathrec->rate) - 1) /
-                               (priv->local_rate ? priv->local_rate : 1);
+               if (path_rate > 0 && priv->local_rate > path_rate)
+                       av.static_rate = (priv->local_rate - 1) / path_rate;
 
                ipoib_dbg(priv, "static_rate %d for local port %dX, path %dX\n",
                          av.static_rate, priv->local_rate,
index f46932dc81c94385550e5d4534c332a9b0cb0b51..70208c3d21e28d415a8f9a82f886e62b64c4590d 100644 (file)
@@ -258,13 +258,12 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
                                .traffic_class = mcast->mcmember.traffic_class
                        }
                };
+               int path_rate = ib_sa_rate_enum_to_int(mcast->mcmember.rate);
 
                av.grh.dgid = mcast->mcmember.mgid;
 
-               if (ib_sa_rate_enum_to_int(mcast->mcmember.rate) > 0)
-                       av.static_rate = (2 * priv->local_rate -
-                                         ib_sa_rate_enum_to_int(mcast->mcmember.rate) - 1) /
-                               (priv->local_rate ? priv->local_rate : 1);
+               if (path_rate > 0 && priv->local_rate > path_rate)
+                       av.static_rate = (priv->local_rate - 1) / path_rate;
 
                ipoib_dbg_mcast(priv, "static_rate %d for local port %dX, mcmember %dX\n",
                                av.static_rate, priv->local_rate,