]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
opa_vnic: Just use skb_get_hash instead of skb_tx_hash
authorAlexander Duyck <alexander.h.duyck@intel.com>
Fri, 27 Apr 2018 18:06:35 +0000 (14:06 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 30 Apr 2018 02:01:32 +0000 (22:01 -0400)
This patch is meant to clean up how the opa_vnic is obtaining entropy from
Tx packets.

The code as it was written was claiming to get 16 bits of hash, but from
what I can tell it was only ever actually getting 14 bits as it was limited
to 0 - (2^15 - 1). It then was folding the result to get a 8 bit value for
entropy.

Instead of throwing away all that input I am cutting out the middle man and
instead having the code call skb_get_hash directly and then folding the 32
bit value into a 8 bit value using a pair of shifts and XOR operations.

Execution wise this new approach should provide more entropy and be faster
since we are bypassing the reciprocal multiplication to reduce the 32b
value to 16b and instead just using a shift/XOR combination.

In addition we can drop the unneeded adapter value from the call to get the
entropy since the netdev itself isn't even needed.

Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/infiniband/ulp/opa_vnic/opa_vnic_encap.c
drivers/infiniband/ulp/opa_vnic/opa_vnic_internal.h
drivers/infiniband/ulp/opa_vnic/opa_vnic_netdev.c

index 4be3aef40bd2ebea81f337c93d6a4752d4c35f9c..267da8215e08fe71b9d4920e1accf851d7723538 100644 (file)
@@ -443,17 +443,16 @@ static u8 opa_vnic_get_rc(struct __opa_veswport_info *info,
 }
 
 /* opa_vnic_calc_entropy - calculate the packet entropy */
-u8 opa_vnic_calc_entropy(struct opa_vnic_adapter *adapter, struct sk_buff *skb)
+u8 opa_vnic_calc_entropy(struct sk_buff *skb)
 {
-       u16 hash16;
-
-       /*
-        * Get flow based 16-bit hash and then XOR the upper and lower bytes
-        * to get the entropy.
-        * __skb_tx_hash limits qcount to 16 bits. Hence, get 15-bit hash.
-        */
-       hash16 = __skb_tx_hash(adapter->netdev, skb, BIT(15));
-       return (u8)((hash16 >> 8) ^ (hash16 & 0xff));
+       u32 hash = skb_get_hash(skb);
+
+       /* store XOR of all bytes in lower 8 bits */
+       hash ^= hash >> 8;
+       hash ^= hash >> 16;
+
+       /* return lower 8 bits as entropy */
+       return (u8)(hash & 0xFF);
 }
 
 /* opa_vnic_get_def_port - get default port based on entropy */
@@ -490,7 +489,7 @@ void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb)
 
        hdr = skb_push(skb, OPA_VNIC_HDR_LEN);
 
-       entropy = opa_vnic_calc_entropy(adapter, skb);
+       entropy = opa_vnic_calc_entropy(skb);
        def_port = opa_vnic_get_def_port(adapter, entropy);
        len = opa_vnic_wire_length(skb);
        dlid = opa_vnic_get_dlid(adapter, skb, def_port);
index afd95f4322620789415ad15194259945093ae452..43ac61ffef4a9e6aa60dfad55538afb878fb1e86 100644 (file)
@@ -299,7 +299,7 @@ struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
 void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter);
 void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
 u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
-u8 opa_vnic_calc_entropy(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
+u8 opa_vnic_calc_entropy(struct sk_buff *skb);
 void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter);
 void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter);
 void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter,
index ce57e0f10289c6249b6a7f48cca42b5d0a6f482a..0c8aec62a42539fc90d67000361653fbf846ae3b 100644 (file)
@@ -104,7 +104,7 @@ static u16 opa_vnic_select_queue(struct net_device *netdev, struct sk_buff *skb,
 
        /* pass entropy and vl as metadata in skb */
        mdata = skb_push(skb, sizeof(*mdata));
-       mdata->entropy =  opa_vnic_calc_entropy(adapter, skb);
+       mdata->entropy = opa_vnic_calc_entropy(skb);
        mdata->vl = opa_vnic_get_vl(adapter, skb);
        rc = adapter->rn_ops->ndo_select_queue(netdev, skb,
                                               accel_priv, fallback);