From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by dpdk.org (Postfix) with ESMTP id 930E5377A for ; Thu, 9 Apr 2015 00:24:25 +0200 (CEST) Received: by pabsx10 with SMTP id sx10so128212528pab.3 for ; Wed, 08 Apr 2015 15:24:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=p34/FXd5Y2WVOw4YwnsdQ95ek891AfzKVHgjuFEeKkA=; b=UWEi2hr3YLqumB+tQL1C/wbgsuxIMhYKSGabgsRE+ckVsgfR+RpnUPedD+PJykiBV+ Vn5pSDa9cEmSvT5JEpMiFyH4lLrU8mlw5zwnx5o9HnecBzED0CtZ0t8O+hsbSDViAx/L PT/LsrrYcIVfyw7V0y0W0VXPvLKNBHg16ebwuuhTjWFvXyq/WF+/Mo33C6qi3U9OLqWJ N1W+CDySBG9teFiyh5pKOmbwoDZsHA3rnwxO+CnvUCKegXixCpOa+Lohfb+YD3Sdvrwe rDUjtlzFefszI8ew/t7vJhAba7uknx+oEQG/BpRyvNzJOkDMfetEFMzU7Z4MV8gs1C7z TVNw== X-Gm-Message-State: ALoCoQl3FWAV34cBStEgcPjPBlaqlwdpueTedjDWEdvW0rQJekYKCwtqixYmNdEy2WmxvuwBkHH4 X-Received: by 10.68.129.72 with SMTP id nu8mr28601356pbb.145.1428531864975; Wed, 08 Apr 2015 15:24:24 -0700 (PDT) Received: from urahara (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id n5sm12326864pdh.27.2015.04.08.15.24.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 15:24:24 -0700 (PDT) Date: Wed, 8 Apr 2015 15:24:30 -0700 From: Stephen Hemminger To: Vladimir Medvedkin Message-ID: <20150408152430.0bdedfd6@urahara> In-Reply-To: <1428519973-10550-1-git-send-email-medvedkinv@gmail.com> References: <1428519973-10550-1-git-send-email-medvedkinv@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH] Add toeplitz hash algorithm X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Apr 2015 22:24:26 -0000 On Wed, 8 Apr 2015 15:06:13 -0400 Vladimir Medvedkin wrote: > Software implementation of the Toeplitz hash function used by RSS. > Can be used either for packet distribution on single queue NIC > or for simulating of RSS computation on specific NIC (for example > after GRE header decapsulating). > > Signed-off-by: Vladimir Medvedkin > +enum rte_thash_flag { > + RTE_THASH_L3 = 0, //calculate hash tacking into account only l3 header > + RTE_THASH_L4 //calculate hash tacking into account l4 + l4 headers > +}; > + > +/** > + * Prepare special converted key to use with rte_softrss_be() > + * @param orig > + * pointer to original RSS key > + * @param targ > + * pointer to target RSS key > + */ > + > +static inline void > +rte_convert_rss_key(uint32_t *orig, uint32_t *targ) orig should be const > +{ > + int i; > + for (i = 0; i < 10; i++) { > + targ[i] = rte_be_to_cpu_32(orig[i]); > + } > +} > +static inline uint32_t > +rte_softrss(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum rte_thash_flag flag, uint32_t *rss_key) rss_key should be const > +{ > + uint32_t ret = 0; > + int i; > + for (i = 0; i < 32; i++) { blank line after declaration please > + if (sip & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); Long expression > 80 characters. Repeated multiple times (should be inline) Extra parens () Extension to 64 bits is only to avoid compiler warning? > + } > + } > + rss_key++; > + for (i = 0; i < 32; i++) { > + if (dip & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); > + } > + } > + if (flag == RTE_THASH_L4) { > + rss_key++; > + for (i = 0; i < 32; i++) { > + if (((sp<<16)|dp) & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); > + } > + } > + } > + return ret; > +} > + > +/** > + * Optimized implementation. > + * If you want the calculated hash value matches NIC RSS value > + * you have to use special converted key. > + * All ip's and ports have to be CPU byte order. > + * @param sip > + * Source ip address. > + * @param dip > + * Destination ip address. > + * @param sp > + * Source TCP|UDP port. > + * @param dp > + * Destination TCP|UDP port. > + * @param flag > + * RTE_THASH_L3: calculate hash tacking into account only sip and dip > + * RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp > + * @param *rss_key > + * Pointer to 40-byte RSS hash key. > + * @return > + * Calculated hash value. > + */ > + > +static inline uint32_t > +rte_softrss_be(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum rte_thash_flag flag, uint32_t *rss_key) > +{ Same problems as previous code. Also lots of copy paste (see Do Not Repeat Yourself principle).