From patchwork Tue Nov 1 18:28:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zoltan Balogh X-Patchwork-Id: 690086 X-Patchwork-Delegate: diproiettod@vmware.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3t7fsT5G01z9s1h for ; Wed, 2 Nov 2016 05:29:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.onmicrosoft.com header.i=@ericsson.onmicrosoft.com header.b=ihPlu4aT; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id E74D81068A; Tue, 1 Nov 2016 11:29:46 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 2CE0C10689 for ; Tue, 1 Nov 2016 11:29:45 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 8F69F4201CB for ; Tue, 1 Nov 2016 12:29:44 -0600 (MDT) X-ASG-Debug-ID: 1478024982-09eadd0f95556990001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id qX5hL1ifmYZIjB2m (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 01 Nov 2016 12:29:42 -0600 (MDT) X-Barracuda-Envelope-From: zoltan.balogh@ericsson.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO sesbmg23.ericsson.net) (193.180.251.37) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 1 Nov 2016 18:29:42 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at ericsson.com designates 193.180.251.37 as permitted sender) X-Barracuda-Apparent-Source-IP: 193.180.251.37 X-Barracuda-RBL-IP: 193.180.251.37 X-AuditID: c1b4fb25-d35ee98000001e3e-3f-5818df131a63 Received: from ESESSHC021.ericsson.se (Unknown_Domain [153.88.183.81]) by (Symantec Mail Security) with SMTP id 18.FE.07742.31FD8185; Tue, 1 Nov 2016 19:29:39 +0100 (CET) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.81) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 1 Nov 2016 19:28:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.onmicrosoft.com; s=selector1-ericsson-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VH3P65b0FH+1PoIf7gpGs+dPfbNOFYdPD7JY3gvsJgQ=; b=ihPlu4aTBmncicX5YZmpF4ntc3muIuES/B3ldftzIqqduwsJb4F1hOvT5BkaVYGLXNR8e6DxGgyoxu7/9D3wAlAPjjtMzskI4ToHS2VDuggCyxpYjThnRf3xkAqHXMAGr+WHSdPRXEoyZlUgouc3cpGvfUEmUIFkBoXXzMttedo= Received: from AM2PR07MB1042.eurprd07.prod.outlook.com (10.162.37.27) by AM2PR07MB1043.eurprd07.prod.outlook.com (10.162.37.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.707.1; Tue, 1 Nov 2016 18:28:37 +0000 Received: from AM2PR07MB1042.eurprd07.prod.outlook.com ([10.162.37.27]) by AM2PR07MB1042.eurprd07.prod.outlook.com ([10.162.37.27]) with mapi id 15.01.0707.004; Tue, 1 Nov 2016 18:28:37 +0000 X-CudaMail-Envelope-Sender: zoltan.balogh@ericsson.com From: =?iso-8859-1?Q?Zolt=E1n_Balogh?= To: "dev@openvswitch.org" X-CudaMail-MID: CM-E2-1031059176 X-CudaMail-DTE: 110116 X-CudaMail-Originating-IP: 193.180.251.37 Thread-Topic: [PATCH] odp-execute: Optimize IP header modification in OVS datapath X-ASG-Orig-Subj: [##CM-E2-1031059176##][PATCH] odp-execute: Optimize IP header modification in OVS datapath Thread-Index: AdIuz3FCLwGq+zIDRqmiC0UnSmvMwQ== Date: Tue, 1 Nov 2016 18:28:36 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=zoltan.balogh@ericsson.com; x-originating-ip: [192.176.1.87] x-ms-office365-filtering-correlation-id: 0039e200-ec5e-415d-bca1-08d40284e541 x-microsoft-exchange-diagnostics: 1; AM2PR07MB1043; 7:B5Zkccf8AM17icu3nWpKwAtJzDB9+Pcqzt5yCi+oWG+irSwFk+JGZRAevqwcc++bP0980vu6A0xNeq6UAX0uLwd5bmVeo35+xx4IxdKYONgn7PxmLiN+R2W2O2R5dCIBR+epLIgg2ioo4za6Bd2oIJzC9tV5vP3VHmIgAR4hIFYaanVY+ccp09MVBRHeIb9Cdl6Rf/yJnO11gHdx2r7skycji+ywXkvwK7EWNuiAk3TN8Z1yRDgGEx2NYm9G13IX4/SuKWIXdCQPQI1Og3gaJbX+w3N+UIQvhnGA5A4C9fXFA2jgvMZRJe1P1IZixnLFokEnlBjyhmE/ktQhacsqt8SiaH3YN/9i61DAuhlFcV0= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR07MB1043; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(37575265505322); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:AM2PR07MB1043; BCL:0; PCL:0; RULEID:; SRVR:AM2PR07MB1043; x-forefront-prvs: 01136D2D90 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(199003)(189002)(9686002)(7736002)(305945005)(7846002)(5640700001)(1730700003)(110136003)(8936002)(74316002)(6916009)(19580395003)(19580405001)(97736004)(7696004)(107886002)(6116002)(122556002)(3280700002)(2906002)(68736007)(5002640100001)(102836003)(3846002)(92566002)(2501003)(87936001)(81166006)(586003)(81156014)(3660700001)(54356999)(189998001)(76576001)(105586002)(8676002)(50986999)(33656002)(10400500002)(101416001)(77096005)(86362001)(5660300001)(2900100001)(450100001)(229853001)(66066001)(106356001)(11100500001)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR07MB1043; H:AM2PR07MB1042.eurprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Nov 2016 18:28:36.8719 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR07MB1043 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJIsWRmVeSWpSXmKPExsUyM2J7oK7wfYkIg9ud/BZHT+9hdmD0eHbz P2MAYxSXTUpqTmZZapG+XQJXxuZFq1kLWg0qWqZvZ2xgvK3cxcjBISFgIrH5pFEXIxeHkMA6 RolLJzeyQDjHGSXWvH7BCOKwCPQySzS9bmaDyExikpj9eTkjhHOYUaJp8XTWLkZODjYBZ4nr u1+ygdgiAvoSh3rOsoDYwgK+EsebNrFAxEMk+q4uZ4aw9SS+Pb0EZrMIqEg8nrQRzOYViJFY fXU5WD2jgJjE91NrmEBsZgFxiVtP5oPZEgICEkv2nGeGsEUlXj7+xwpRHysxvbWbDeI3BYkl fyUhTF+JxoXmICdLCCxglti0/B1Uq5vE+wtbGSHsbImG682sEPVWEvPOxELU72CUuLd1GdRa GYneT2uZIRIPWCXe3H8KdqeQQKrE8rWtjBD/SkncvdIJZctIvLizlxXifj2JG1OnsEHY2hLL Fr5mnsCoPgvJa7OQlM1CUjYLHCyCEidnPmFZwMiyilG0OLU4KTfdyFgvtSgzubg4P08vL7Vk EyMwQRzc8lt1B+PlN46HGAU4GJV4eD+slYgQYk0sK67MPcQowcGsJML79A5QiDclsbIqtSg/ vqg0J7X4EKM0B4uSOK/ZyvvhQgLpiSWp2ampBalFMFkmDk6pBsZ+SXX1vmmZm7/fuP0zVSPM T3HZ1rvGJvPjb6pqFp/sTljplOO37xifpI+8v/qUo+/eaXbXpzPOnf20bsoj/6mNs/78YXsr Yt8T6hJsrl0y9/ihrk9WZx/8T+u/yj1zsv7LlMQpNrM5xOLs7jx0K5fiOPXUZfIP78yMY4cX W/ZIHg9xW5vx+6USS3FGoqEWc1FxIgBWwQKSDAMAAA== X-GBUdb-Analysis: 0, 193.180.251.37, Ugly c=0.313739 p=-0.142857 Source Normal X-MessageSniffer-Rules: 0-0-0-16765-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1478024982 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.10 X-Barracuda-Spam-Status: No, SCORE=0.10 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=DKIM_SIGNED, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34194 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS Subject: [ovs-dev] [PATCH] odp-execute: Optimize IP header modification in OVS datapath X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" Hi, I measured the packet processing cost of OVS DPDK datapath for different OpenFlow actions. I configured OVS to use a single pmd thread and measured the packet throughput in a phy-to-phy setup. I used 10G interfaces bounded to DPDK driver and overloaded the vSwitch with 64 byte packets through one of the 10G interfaces. The processing cost of the dec_ttl action seemed to be gratuitously high compared with other actions. I looked into the code and saw that dec_ttl is encoded as a masked nested attribute in OVS_ACTION_ATTR_SET_MASKED(OVS_KEY_ATTR_IPV4). That way, OVS datapath can modify several IP header fields (TTL, TOS, source and destination IP addresses) by a single invocation of packet_set_ipv4() in the odp_set_ipv4() function in the lib/odp-execute.c file. The packet_set_ipv4() function takes the new TOS, TTL and IP addresses as arguments, compares them with the actual ones and updates the fields if needed. This means, that even if only TTL needs to be updated, each of the four IP header fields is passed to the callee and is compared to the actual field for each packet. The odp_set_ipv4() caller function possesses information about the fields that need to be updated in the 'mask' structure. The idea is to spare invocation of thepacket_set_ipv4() function but use its code parts directly. So the 'mask' can be used to decide which IP header fields need to be updated. In addition, a faster packet processing can be achieved if the values of local variables are calculated right before their usage. These are the results of my measurements. | T | T | I | I | | T | O | P | P | Vanilla OVS | OVS + patch | L | S | s | d | (nsec/packet) | (nsec/packet) -------+---+---+---+---+---------------+--------------- output | | | | | 67.20 | 67.20 | X | | | | 74.34 | 70.03 | | X | | | 74.20 | 71.06 | | | X | | 83.14 | 78.67 | | | | X | 83.27 | 78.00 | | | X | X | 96.68 | 91.81 | X | | X | X | 99.58 | 96.00 | X | X | X | X | 103.31 | 100.73 The table shows the average processing cost of packets in nanoseconds for the following actions: output; output + dec_ttl; output + mod_nw_tos; output + mod_nw_src; output + mod_nw_dst and some of their combinations. I added OVS_LIKELY to the 'if' condition for the TTL field, since as far as I know, this field will typically be decremented when any field of the IP header is modified. Please find the patch below. Signed-off-by: Zoltán Balogh diff --git a/lib/odp-execute.c b/lib/odp-execute.c index 65a6fcd..131532d 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -33,6 +33,7 @@ #include "flow.h" #include "unaligned.h" #include "util.h" +#include "csum.h" /* Masked copy of an ethernet address. 'src' is already properly masked. */ static void @@ -68,13 +69,42 @@ odp_set_ipv4(struct dp_packet *packet, const struct ovs_key_ipv4 *key, const struct ovs_key_ipv4 *mask) { struct ip_header *nh = dp_packet_l3(packet); + ovs_be32 ip_src_nh; + ovs_be32 ip_dst_nh; + ovs_be32 new_ip_src; + ovs_be32 new_ip_dst; + uint8_t new_tos; + uint8_t new_ttl; + + ip_src_nh = get_16aligned_be32(&nh->ip_src); + new_ip_src = key->ipv4_src | (ip_src_nh & ~mask->ipv4_src); + + if (mask->ipv4_src && ip_src_nh != new_ip_src) { + packet_set_ipv4_addr(packet, &nh->ip_src, new_ip_src); + } - packet_set_ipv4( - packet, - key->ipv4_src | (get_16aligned_be32(&nh->ip_src) & ~mask->ipv4_src), - key->ipv4_dst | (get_16aligned_be32(&nh->ip_dst) & ~mask->ipv4_dst), - key->ipv4_tos | (nh->ip_tos & ~mask->ipv4_tos), - key->ipv4_ttl | (nh->ip_ttl & ~mask->ipv4_ttl)); + ip_dst_nh = get_16aligned_be32(&nh->ip_dst); + new_ip_dst = key->ipv4_dst | (ip_dst_nh & ~mask->ipv4_dst); + + if (mask->ipv4_dst && ip_dst_nh != new_ip_dst) { + packet_set_ipv4_addr(packet, &nh->ip_dst, new_ip_dst); + } + + new_tos = key->ipv4_tos | (nh->ip_tos & ~mask->ipv4_tos); + + if (mask->ipv4_tos && nh->ip_tos != new_tos) { + nh->ip_csum = recalc_csum16(nh->ip_csum, htons((uint16_t) nh->ip_tos), + htons((uint16_t) new_tos)); + nh->ip_tos = new_tos; + } + + new_ttl = key->ipv4_ttl | (nh->ip_ttl & ~mask->ipv4_ttl); + + if (OVS_LIKELY(mask->ipv4_ttl && nh->ip_ttl != new_ttl)) { + nh->ip_csum = recalc_csum16(nh->ip_csum, htons(nh->ip_ttl << 8), + htons(new_ttl << 8)); + nh->ip_ttl = new_ttl; + } } static const ovs_be32 * diff --git a/lib/packets.c b/lib/packets.c index 990c407..179841a 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -849,7 +849,7 @@ eth_compose(struct dp_packet *b, const struct eth_addr eth_dst, return data; } -static void +void packet_set_ipv4_addr(struct dp_packet *packet, ovs_16aligned_be32 *addr, ovs_be32 new_addr) { diff --git a/lib/packets.h b/lib/packets.h index 21bd35c..97d1b38 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -1093,6 +1093,8 @@ void *snap_compose(struct dp_packet *, const struct eth_addr eth_dst, unsigned int oui, uint16_t snap_type, size_t size); void packet_set_ipv4(struct dp_packet *, ovs_be32 src, ovs_be32 dst, uint8_t tos, uint8_t ttl); +void packet_set_ipv4_addr(struct dp_packet *packet, ovs_16aligned_be32 *addr, + ovs_be32 new_addr); void packet_set_ipv6(struct dp_packet *, const ovs_be32 src[4], const ovs_be32 dst[4], uint8_t tc, ovs_be32 fl, uint8_t hlmit);