Received: by 10.223.185.116 with SMTP id b49csp1115356wrg; Sat, 3 Mar 2018 16:02:11 -0800 (PST) X-Google-Smtp-Source: AG47ELtD9PXyb2imbRdLGSoaI6/weFK27aRx8xLOiM0aF7me99H2FOi8voZab6L+ATo9gdUq5YwJ X-Received: by 10.98.233.3 with SMTP id j3mr10596967pfh.38.1520121731105; Sat, 03 Mar 2018 16:02:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520121731; cv=none; d=google.com; s=arc-20160816; b=ksRGZH0GMto6kFLfbU6OOnWDf+cUK7JLrREqkFPMOyh0Kmr6QHPm+RwsPmlZP+ezte cyTGLidi+8Kmv1gN5CSwAdfkShWdoKPV3yIJijXDr1glw8Mm+sh6j/d9ec45Pf6ZXRQb e3UA20LQMhUZEAHaO3H7zvi1XhWqANnkQ2Rrg82AT4AH1mnAp5V/hctq0/AoXiGSEwgg RE2ft3NcePiZ0avU/ywLWqwi+xNxZIBGX/8R1y/Cbiu9yMhZj7IO0NvmYsQk8cFXsSHb axrrhpllSGiB7O4EWpgGV/PQWO4VgjajsSUn2ljCOPM3kRuLlWHmSRAUdIh1zS8+y0I/ 6zJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=afBHyZdRLhuxIVAElCJef1ULEDtzttveC2c40bXYvb8=; b=kgQDbZgYYfgpG3aynacAqoCv/MPtFxp9DWs2IAYLM2G8Gimz1bm/pmTy6mZF1NTQOp byKUVY7OHLCMnjSxb1GpmZ3xA72j+JfrV3gA4wVAmwwt0aUxcpbDUCmDfCeWgB2S7G/j IyBppOPY7ZT7KrK59/OZ614b3ksc3iWf7Ecjk0ho9ZVIUKMVcCMzMaa1l3ZEX1bm1+G/ 9+7+LdTnutO5JIDTgXHtTwg1AJ/mrqDnBPqo42b3CRVq8GcFLtfZaZMVYTcmFncuGjpj wGf6kfmQF3/5wyvvd4g75F9HDFHUbW/sM7YI8rsjGkweLuj9bDKX2X1jODXH8biJW7YR 0+GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=C7XtpSyM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x22si7435113pfm.321.2018.03.03.16.01.57; Sat, 03 Mar 2018 16:02:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=C7XtpSyM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933795AbeCDABY (ORCPT + 99 others); Sat, 3 Mar 2018 19:01:24 -0500 Received: from mail-co1nam03on0109.outbound.protection.outlook.com ([104.47.40.109]:6764 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933209AbeCCWcE (ORCPT ); Sat, 3 Mar 2018 17:32:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=afBHyZdRLhuxIVAElCJef1ULEDtzttveC2c40bXYvb8=; b=C7XtpSyMwnaxZhNSakTS/foL/QhlWkOaGhkJbqh4ATrdsZYwNn1f417dPei02mIFWgKW/LR/RsQPJHi2VH5RziqO6eb3zPPkJKLroT1B1n+BQVTRCYBU63YV47zTR/uBz9YimLhrc8/yvPsJfPzH51gCDlIrxk9dH9NHgtztvZg= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1083.namprd21.prod.outlook.com (52.132.149.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.1; Sat, 3 Mar 2018 22:32:02 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:32:02 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Nik Unger , Stephen Hemminger , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 040/219] netem: apply correct delay when rate throttling Thread-Topic: [PATCH AUTOSEL for 4.9 040/219] netem: apply correct delay when rate throttling Thread-Index: AQHTsz7uSkt6dlUfVkWu3BbZ80Utqg== Date: Sat, 3 Mar 2018 22:28:18 +0000 Message-ID: <20180303222716.26640-40-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1083;7:uk5DclBlCJ1AyceLQcfTI25teXAGATF2XoLDWv8bjnRl71D4miyrafSc0wx+f7AhUpzc9grwUjr71PyG8WpFqxZedS5SSbvl0gu0ItkN85JRtn6LFEsgmodGG9tydJGb2th9K7yy+UOUOsMpej7Zcp+McqXfDzT4bF1oIF2UGALH6M3JofUINDXBSCyrif9t+vFuaBow5I0wrhHeW1gZFv/L+PLEDif8hSRIEWZpMgCEdxF0kVfRG0jAeaHvsYlk x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 9e0ea0d2-14a0-4b48-a143-08d5815695a2 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020);SRVR:MW2PR2101MB1083; x-ms-traffictypediagnostic: MW2PR2101MB1083: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(157189615257929); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231220)(944501244)(52105095)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:MW2PR2101MB1083;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1083; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39860400002)(39380400002)(396003)(346002)(366004)(189003)(199004)(33974003)(31014005)(106356001)(53936002)(316002)(305945005)(7736002)(3280700002)(107886003)(2906002)(6512007)(6436002)(97736004)(3660700001)(6306002)(6486002)(99286004)(81166006)(8936002)(81156014)(76176011)(8676002)(25786009)(2950100002)(6506007)(4326008)(110136005)(5250100002)(54906003)(36756003)(575784001)(105586002)(6116002)(6666003)(22452003)(86612001)(10090500001)(186003)(68736007)(26005)(2900100001)(86362001)(66066001)(102836004)(3846002)(14454004)(478600001)(72206003)(10290500003)(5660300001)(59450400001)(1076002)(966005)(2501003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1083;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: qbBwIQxRkqy/ZDSVlcHkPqEflGCjmkIo3rt3Kk4SqIwui10ZCIZnRCv5Wqdcc+jJoTuW9Wm/Oy48qoufjOCfmLhSgbscbLtgl5i/kfidlIf+cTurX5gi6a/qOppvP4cbYkAc7MizEtPUVy6WBgz4K0DM4ok3CFX/+rPazDrS7IQ= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e0ea0d2-14a0-4b48-a143-08d5815695a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:28:18.9787 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1083 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nik Unger [ Upstream commit 5080f39e8c72e01cf37e8359023e7018e2a4901e ] I recently reported on the netem list that iperf network benchmarks show unexpected results when a bandwidth throttling rate has been configured for netem. Specifically: 1) The measured link bandwidth *increases* when a higher delay is added 2) The measured link bandwidth appears higher than the specified limit 3) The measured link bandwidth for the same very slow settings varies signi= ficantly across machines The issue can be reproduced by using tc to configure netem with a 512kbit rate and various (none, 1us, 50ms, 100ms, 200ms) delays on a veth pair between network namespaces, and then using iperf (or any other network benchmarking tool) to test throughput. Complete detailed instructions are in the original email chain here: https://lists.linuxfoundation.org/pipermail/netem/2017-February/001672.html There appear to be two underlying bugs causing these effects: - The first issue causes long delays when the rate is slow and no delay is configured (e.g., "rate 512kbit"). This is because SKBs are not orphaned when no delay is configured, so orphaning does not occur until *after* the rate-induced delay has been applied. For this reason, adding a tiny delay (e.g., "rate 512kbit delay 1us") dramatically increases the measured bandwidth. - The second issue is that rate-induced delays are not correctly applied, allowing SKB delays to occur in parallel. The indended approach is to compute the delay for an SKB and to add this delay to the end of the current queue. However, the code does not detect existing SKBs in the queue due to improperly testing sch->q.qlen, which is nonzero even when packets exist only in the rbtree. Consequently, new SKBs do not wait for the current queue to empty. When packet delays vary significantly (e.g., if packet sizes are different), then this also causes unintended reordering. I modified the code to expect a delay (and orphan the SKB) when a rate is configured. I also added some defensive tests that correctly find the latest scheduled delivery time, even if it is (unexpectedly) for a packet in sch->q. I have tested these changes on the latest kernel (4.11.0-rc1+) and the iperf / ping test results are as expected. Signed-off-by: Nik Unger Signed-off-by: Stephen Hemminger Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/sch_netem.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 9f7b380cf0a3..c73d58872cf8 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -462,7 +462,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qd= isc *sch, /* If a delay is expected, orphan the skb. (orphaning usually takes * place at TX completion time, so _before_ the link transit delay) */ - if (q->latency || q->jitter) + if (q->latency || q->jitter || q->rate) skb_orphan_partial(skb); =20 /* @@ -530,21 +530,31 @@ static int netem_enqueue(struct sk_buff *skb, struct = Qdisc *sch, now =3D psched_get_time(); =20 if (q->rate) { - struct sk_buff *last; + struct netem_skb_cb *last =3D NULL; + + if (sch->q.tail) + last =3D netem_skb_cb(sch->q.tail); + if (q->t_root.rb_node) { + struct sk_buff *t_skb; + struct netem_skb_cb *t_last; + + t_skb =3D netem_rb_to_skb(rb_last(&q->t_root)); + t_last =3D netem_skb_cb(t_skb); + if (!last || + t_last->time_to_send > last->time_to_send) { + last =3D t_last; + } + } =20 - if (sch->q.qlen) - last =3D sch->q.tail; - else - last =3D netem_rb_to_skb(rb_last(&q->t_root)); if (last) { /* * Last packet in queue is reference point (now), * calculate this time bonus and subtract * from delay. */ - delay -=3D netem_skb_cb(last)->time_to_send - now; + delay -=3D last->time_to_send - now; delay =3D max_t(psched_tdiff_t, 0, delay); - now =3D netem_skb_cb(last)->time_to_send; + now =3D last->time_to_send; } =20 delay +=3D packet_len_2_sched_time(qdisc_pkt_len(skb), q); --=20 2.14.1