From patchwork Sun Dec 25 11:39:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Blakey X-Patchwork-Id: 708706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tmgYp1qxxz9t1F for ; Sun, 25 Dec 2016 22:55:42 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 33834BCD; Sun, 25 Dec 2016 11:48:50 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id C4C54B8F for ; Sun, 25 Dec 2016 11:48:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 02C49141 for ; Sun, 25 Dec 2016 11:48:44 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from paulb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 25 Dec 2016 13:40:36 +0200 Received: from dev-r-vrt-176.mtr.labs.mlnx (dev-r-vrt-176.mtr.labs.mlnx [10.212.176.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id uBPBeXbD029898; Sun, 25 Dec 2016 13:40:35 +0200 From: Paul Blakey To: dev@openvswitch.org, Andy Gospodarek , Simon Horman , Jiri Pirko , John Fastabend , Lance Richardson , Marcelo Ricardo Leitner , Joe Stringer Date: Sun, 25 Dec 2016 13:39:41 +0200 Message-Id: <1482665989-791-14-git-send-email-paulb@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1482665989-791-1-git-send-email-paulb@mellanox.com> References: <1482665989-791-1-git-send-email-paulb@mellanox.com> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Shahar Klein , Mark Bloch , Hadar Hen Zion , Rony Efraim , Or Gerlitz Subject: [ovs-dev] [PATCH ovs V2 13/21] netdev-tc-offloads: Add flower mask to priority map X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Flower classifer requires a different priority per mask, so we hash the mask and generate a new priority for each new mask used. Signed-off-by: Paul Blakey Reviewed-by: Roi Dayan --- lib/netdev-tc-offloads.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 7729cfc..b4eee98 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -173,6 +173,43 @@ add_ufid_tc_mapping(ovs_u128 *ufid, int prio, int handle, struct netdev *netdev) return replace; } +struct prio_map_data { + struct hmap_node node; + struct tc_flow_key mask; + uint16_t protocol; + uint16_t prio; +}; + +static uint16_t +get_prio_for_tc_flow(struct tc_flow *tc_flow) +{ + static struct hmap prios = HMAP_INITIALIZER(&prios); + static struct ovs_mutex prios_lock = OVS_MUTEX_INITIALIZER; + static int last_prio = 0; + size_t key_len = sizeof(struct tc_flow_key); + size_t hash = hash_bytes(&tc_flow->mask, key_len, tc_flow->key.eth_type); + struct prio_map_data *data; + struct prio_map_data *new_data; + + ovs_mutex_lock(&prios_lock); + HMAP_FOR_EACH_WITH_HASH(data, node, hash, &prios) { + if (!memcmp(&tc_flow->mask, &data->mask, key_len) + && data->protocol == tc_flow->key.eth_type) { + ovs_mutex_unlock(&prios_lock); + return data->prio; + } + } + + new_data = xzalloc(sizeof *new_data); + memcpy(&new_data->mask, &tc_flow->mask, key_len); + new_data->prio = ++last_prio; + new_data->protocol = tc_flow->key.eth_type; + hmap_insert(&prios, &new_data->node, hash); + ovs_mutex_unlock(&prios_lock); + + return new_data->prio; +} + int netdev_tc_flow_flush(struct netdev *netdev) {