net: ipv4: route.c: add likely() statements
Subsystems (3)
PATCH 1/2 net: ipv4: route.c: add likely() statements
Add likely() statements in ipv4_confirm_neigh() for 'rt->rt_gw_family == AF_INET'.
--- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/route.c +1 -1
@@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)struct net_device *dev = dst->dev;const __be32 *pkey = daddr; -if (rt->rt_gw_family ==AF_INET ) { +if (likely (rt->rt_gw_family ==AF_INET )) { pkey = (const __be32 *)&rt->rt_gw4; }else if (rt->rt_gw_family ==AF_INET6 ) {return __ipv6_confirm_neigh_stub (dev, &rt->rt_gw6);
Signature · 1 line
2.29.0
Quoted 2 lines · Yejune Deng
Add
likely()statements inipv4_confirm_neigh()for 'rt->rt_gw_family==AF_INET'.
Why? Such macros are beneficial in only specific cases, most of the time, likely/unlikely is cargo cult.
Quoted 22 lines
Signed-off-by Yejune Deng <[email protected]>--- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/route.c +1
-1@@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)struct net_device *dev = dst->dev;const __be32 *pkey = daddr; -if (rt->rt_gw_family ==AF_INET ) { +if (likely (rt->rt_gw_family ==AF_INET )) { pkey = (const __be32 *)&rt->rt_gw4; }else if (rt->rt_gw_family ==AF_INET6 ) {return __ipv6_confirm_neigh_stub (dev, &rt->rt_gw6);Signature · 1 line
2.29.0
My reasons are as following: ipv4_confirm_neigh() belongs to ipv4_dst_ops that family is AF_INET, and ipv4_neigh_lookup() is also added likely() when rt->rt_gw_family is equal to AF_INET.
Quoted 30 lines · Leon Romanovsky
Quoted 2 lines · Yejune Deng
Add
likely()statements inipv4_confirm_neigh()for 'rt->rt_gw_family==AF_INET'.Why? Such macros are beneficial in only specific cases, most of the time, likely/unlikely is cargo cult.
Quoted 22 lines
Signed-off-by Yejune Deng <[email protected]>--- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/route.c +1
-2@@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)struct net_device *dev = dst->dev;const __be32 *pkey = daddr; -if (rt->rt_gw_family ==AF_INET ) { +if (likely (rt->rt_gw_family ==AF_INET )) { pkey = (const __be32 *)&rt->rt_gw4; }else if (rt->rt_gw_family ==AF_INET6 ) {return __ipv6_confirm_neigh_stub (dev, &rt->rt_gw6); --2.29.0
Quoted 3 lines · Yejune Deng
My reasons are as following:
ipv4_confirm_neigh()belongs toipv4_dst_opsthat family isAF_INET, andipv4_neigh_lookup()is also addedlikely()whenrt->rt_gw_familyis equal toAF_INET.
It is part of that cargo cult. Please support your claim with performance numbers when this likely/unlikely will give any difference.
Thanks
Quoted 32 lines · Leon Romanovsky
Quoted 30 lines · Yejune Deng
Quoted 2 lines
Add
likely()statements inipv4_confirm_neigh()for 'rt->rt_gw_family==AF_INET'.Why? Such macros are beneficial in only specific cases, most of the time, likely/unlikely is cargo cult.
Quoted 22 lines
Signed-off-by Yejune Deng <[email protected]>--- net/ipv4/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/route.c +1
-2@@ -440,7 +440,7 @@ static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)struct net_device *dev = dst->dev;const __be32 *pkey = daddr; -if (rt->rt_gw_family ==AF_INET ) { +if (likely (rt->rt_gw_family ==AF_INET )) { pkey = (const __be32 *)&rt->rt_gw4; }else if (rt->rt_gw_family ==AF_INET6 ) {return __ipv6_confirm_neigh_stub (dev, &rt->rt_gw6); --2.29.0