From patchwork Tue Feb 7 13:54:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 53916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2864923wrn; Tue, 7 Feb 2023 06:02:21 -0800 (PST) X-Google-Smtp-Source: AK7set+Yy8UCRSC2+eA36VnF+0AoJtTlmlyhLkeh1wxzKzJqG0fc7OdrmNX4S5tHiAaT/KoW1rvj X-Received: by 2002:a05:6402:5383:b0:4a3:43c1:843c with SMTP id ew3-20020a056402538300b004a343c1843cmr18914615edb.16.1675778541479; Tue, 07 Feb 2023 06:02:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1675778541; cv=pass; d=google.com; s=arc-20160816; b=rQujzHSSfYNn0V9V1ehMGBtQbKXvcPrdCfSafieQrejK+sPixh3XsXoiXOukQk49Sm VW6aOq4WH4Y+13rY+gAcKjMC5dBYc87Fr6BozCbXyvSmK/AffZABu3cD8dPYXHZkBy/b lgztvs/PUvua7Hki5bG6193fkg5NpNyC1IyL66PxMq46uBfYpUxzDTYtvpdrpKDuLo9w WnepWyzYNrhHX7dQdDSCEieVVHIhkLpMcF5nEc90pk85LslM4dWWJhoCfjfupH7NcMW7 1yyeustjwHfrLAQKS/2enzksmUWJFmm5ykScUZX2Wpqnh17IJjDI8xv53X6QQuTodSBe MPCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u6Fr4Rdqpr4JQviI55Ygp77iGJtasSXSwdbN3XXp8d4=; b=H7hK4T1pc/sUXA9IcHHfw9I0DVnx1YUKsEaV7f8OUIovrFBaKxZIjCeGz7Ir8poMls kMFUBkg0X5Ookg+SHYqnEoPkNbGiuOo/qZMguPcM2LvQaZHCmKBI7JgTiDvIetquYytJ hjT0SUCQ3xHUiAnfdrJ/vcQCx1mVle8IwZMKHoVXUczPYzfOY9JvqSA2h5Qs91RMEjE6 jDwvCCNTvm5v2/K3zCcjLSQIlOB78ekFX8YrkSPirnFEFDywTo/cJV8Uu3GcFn5sFGF5 NNJr0Wpvw/up9sbwScZtc4UUqrSgWyQgMmnA1G0bfXQKqBCy9ATNK5ayJfb5DmcuK57q +t3Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=b7SHpFXU; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020aa7cd41000000b004aab3450a00si6336989edw.498.2023.02.07.06.01.55; Tue, 07 Feb 2023 06:02:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=b7SHpFXU; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjBGOAC (ORCPT + 99 others); Tue, 7 Feb 2023 09:00:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232301AbjBGN7o (ORCPT ); Tue, 7 Feb 2023 08:59:44 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0624.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::624]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA9C33D0B5; Tue, 7 Feb 2023 05:59:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k3REPI6fRYeKrNa2BwSE/zagkI5fxIJz9O0ut3eGYgLcbijLZrNWEPb7cpmrnDIOXQwIUW4DEzVZsmcwFI1681GyBR+Sz80AgNS1SSB+gbPZ3sJLQM8sl39RUGrqguHPMCInHNQM+c+oafGq682pR9wyu2I+dd4LC4DpFYZkyvXPdhkwCXElJ0orVDJqFFJkJRv7EcyF9XihxY1SoGlJrs2l0lSIRECZRLJhs9xsAN2wVgfufcNMPIELoRzlpvV2oQsLqTlxr8wX0OL6xk/GWDi8Ay+r6C0nqkF89I4QpxrDdRTa1y+dJHHCwqlGNIzz8CfnsacWxiKUkCa6AEesUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=u6Fr4Rdqpr4JQviI55Ygp77iGJtasSXSwdbN3XXp8d4=; b=AuteZoyYeDncA8EgM3vDHBR8RdySJBJMgxaySf25qQd6T5QAQ5Oey2BjALpsUDUGO7z6HcwCtn175gv1lf0jLzdmibR+k5sOa6bA/02QNyp0mMaD2eeNtrEW4hCvz3/PNI1itDJf1LaHLDlWRCSe7uNOpDM68B/xZxD+QuRRhVVPuu4Q+SXDsbd8ZeHItH48LA9+ucDa9fdGDUhYuZBcImfqS96FTWR5082Rh19uV3OUs8upE7zxGvgbEXRN2sb6A52Sno2iZxTybjQE23UKMMsBvUyJNfvUpqpucofDL+AVbanjvskZ8P2RnjiXl2NMhbyzqE1YfeaVXSPUdJWKlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=u6Fr4Rdqpr4JQviI55Ygp77iGJtasSXSwdbN3XXp8d4=; b=b7SHpFXUkbv2BkpVjLbtqbPR6qPecnTezIgyyHME1GcAiPsD72YQyVxzJq7TjthxFLjEnm3KYoo7X+4DmtOMarm5Y9evjdMi3D7v0KyPcHkGdwSJoHLODKMVI/iQIq3yoQjo225RzjFMle/FwBZnFxrXknOioRTCuaPTAhvjpCM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AM9PR04MB8115.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.36; Tue, 7 Feb 2023 13:55:15 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%5]) with mapi id 15.20.6064.034; Tue, 7 Feb 2023 13:55:15 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , Kurt Kanzenbach , Jacob Keller , Gerhard Engleder , Jesse Brandeburg , Tony Nguyen , intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 net-next 06/15] net/sched: taprio: calculate tc gate durations Date: Tue, 7 Feb 2023 15:54:31 +0200 Message-Id: <20230207135440.1482856-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230207135440.1482856-1-vladimir.oltean@nxp.com> References: <20230207135440.1482856-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AS4PR10CA0023.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5d8::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AM9PR04MB8115:EE_ X-MS-Office365-Filtering-Correlation-Id: a74c2a09-2596-415d-c2b0-08db0912f019 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ubJS1OF6HQMBYJlGfj1YGGJp/vRT3a3fUjaDLT3qWyNegwroSSZdY2uv88bMdeVAU3KUywGqkFZxxBrDO50gBmF5/fdiuavwb58B7kl8QIvu9IuHEwbGnsTTOsmJBJ0iFH3+N2MQvukSV2c0n45zfLb9ur8fXTkiwNuU+LpPSocWWmJfVxTNnS31yxZbtaNiNjxMulN1Xdm0s8NKIewX5W6fxeYTvfBd5gxugaaEvkzpIycG/BOXoaWT6/vr2zo1d2qjQ2M02gnqcsVvwl6qhJpIfjrtC5VMeb9C0cgg2XDAKnnnlYR/ziHtGS3lel7xJypI4vGdFNgcu8e+jEjVSC3obL+GklrNJppghM+7XhTkFAAfQgXZJiGk2GO9E+Zb50kRWRKDvtdiPGj2+XUxaLRMkvFex2MK65SDj9tSZG/fV+hq22lo38amHIgXwtuuuyI5FDp1z1Huq/NTC180ia+ATvbV9IDQ/rIkCQ28hJJz7fZvg82WlF38C+X4iYdF9u1OCDNa4RmyyIgwiYMubXaf/+6vrhoWl1SGf8ZUJYkADxKwqoYOtl0S+f4VGMuNtVP4manZATMdOIUPyXsqh7bJkTpCAdaUdbs3IX9wtnP8KBd6tvzYmnFeEtMtp9S6jLZ1sQF9teYr/xv4nS72XoUBKMgylbG/7IJG+S31K8MpJ6jQqMgXgRltKYUlOjnFFmL3RGtU3fuISkzgmGWzZg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(396003)(346002)(366004)(136003)(376002)(451199018)(2906002)(8676002)(38350700002)(38100700002)(316002)(83380400001)(6916009)(66556008)(66476007)(8936002)(4326008)(41300700001)(44832011)(5660300002)(7416002)(66946007)(2616005)(6666004)(1076003)(6506007)(478600001)(6486002)(186003)(26005)(6512007)(86362001)(54906003)(52116002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MjicDT4IJHk8QZCBgAHlnJUTeqsStLllOeYiCHu9FB3alLr7mrTM1BPedi3RPwR3Kk3nDxMJDpDz2g0GSo8Pwq3OOvHw9GD0SEmnRb0TqzG0ba76yuvQNmfM4+i6j50CHea0TyJLDrJub/N9bjVsZ69HxkFtS9tYVKDlm+y3i0pMA7EgJn+v7r5Zd0ieBQuUm3uZvRloW8l/UrQRbbOP4YPP2pm8TCHrp0aS//4s3b1YM8FN0JCLY9PD40WaxWiO3yyDTeLHa0h6OwP9qknwrV/72i/VUEP1blFRVAaU+mc3Yb4sBsMIY2f+tWuRbzIQ3uCXRbXC8bD3w59wU0d+puPmsa3KCANO76l1tlgY58UXV7gEL3B7ThYKCCuWQ7J9U+dmPs/byfTXZHag7iICtIxyaSfuvjwZSWlkgrPvb+dS4gwFU6C9b67ZIDyWItv6k54rs595dC/NX3Z871BH3YCgXwsceiJx2D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t9B5qFEiVhdxBnk9lxQFlYeurVbHO24aX47FBT31PEUb+pEzA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a74c2a09-2596-415d-c2b0-08db0912f019 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2023 13:55:15.0806 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1VFoOv6hbqakzEWnyhITby6R8W/enJKg6OEb/3we2ptNT52OsnFvU09SLg9mof6oELzoGoq+N1/BXtQ8u+nbPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8115 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,SPF_HELO_PASS, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757181159690565532?= X-GMAIL-MSGID: =?utf-8?q?1757181159690565532?= Current taprio code operates on a very simplistic (and incorrect) assumption: that egress scheduling for a traffic class can only take place for the duration of the current interval, or i.o.w., it assumes that at the end of each schedule entry, there is a "gate close" event for all traffic classes. As an example, traffic sent with the schedule below will be jumpy, even though all 8 TC gates are open, so there is absolutely no "gate close" event (effectively a transition from BIT(tc)==1 to BIT(tc)==0 in consecutive schedule entries): tc qdisc replace dev veth0 parent root taprio \ num_tc 2 \ map 0 1 \ queues 1@0 1@1 \ base-time 0 \ sched-entry S 0xff 4000000000 \ clockid CLOCK_TAI \ flags 0x0 This qdisc simply does not have what it takes in terms of logic to *actually* compute the durations of traffic classes. Also, it does not recognize the need to use this information on a per-traffic-class basis: it always looks at entry->interval and entry->close_time. This change proposes that each schedule entry has an array called tc_gate_duration[tc]. This holds the information: "for how long will this traffic class gate remain open, starting from *this* schedule entry". If the traffic class gate is always open, that value is equal to the cycle time of the schedule. We'll also need to keep track, for the purpose of queueMaxSDU[tc] calculation, what is the maximum time duration for a traffic class having an open gate. This gives us directly what is the maximum sized packet that this traffic class will have to accept. For everything else it has to qdisc_drop() it in qdisc_enqueue(). Signed-off-by: Vladimir Oltean Reviewed-by: Kurt Kanzenbach --- v1->v2: rename "tc_gate" to just "gate" to reduce line length net/sched/sch_taprio.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 5f57dcfafffd..7d897bbd48ca 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -39,6 +39,10 @@ static struct static_key_false taprio_have_working_mqprio; #define TAPRIO_FLAGS_INVALID U32_MAX struct sched_entry { + /* Durations between this GCL entry and the GCL entry where the + * respective traffic class gate closes + */ + u64 gate_duration[TC_MAX_QUEUE]; struct list_head list; /* The instant that this entry "closes" and the next one @@ -55,6 +59,10 @@ struct sched_entry { }; struct sched_gate_list { + /* Longest non-zero contiguous gate durations per traffic class, + * or 0 if a traffic class gate never opens during the schedule. + */ + u64 max_open_gate_duration[TC_MAX_QUEUE]; struct rcu_head rcu; struct list_head entries; size_t num_entries; @@ -95,6 +103,51 @@ struct __tc_taprio_qopt_offload { struct tc_taprio_qopt_offload offload; }; +static void taprio_calculate_gate_durations(struct taprio_sched *q, + struct sched_gate_list *sched) +{ + struct net_device *dev = qdisc_dev(q->root); + int num_tc = netdev_get_num_tc(dev); + struct sched_entry *entry, *cur; + int tc; + + list_for_each_entry(entry, &sched->entries, list) { + u32 gates_still_open = entry->gate_mask; + + /* For each traffic class, calculate each open gate duration, + * starting at this schedule entry and ending at the schedule + * entry containing a gate close event for that TC. + */ + cur = entry; + + do { + if (!gates_still_open) + break; + + for (tc = 0; tc < num_tc; tc++) { + if (!(gates_still_open & BIT(tc))) + continue; + + if (cur->gate_mask & BIT(tc)) + entry->gate_duration[tc] += cur->interval; + else + gates_still_open &= ~BIT(tc); + } + + cur = list_next_entry_circular(cur, &sched->entries, list); + } while (cur != entry); + + /* Keep track of the maximum gate duration for each traffic + * class, taking care to not confuse a traffic class which is + * temporarily closed with one that is always closed. + */ + for (tc = 0; tc < num_tc; tc++) + if (entry->gate_duration[tc] && + sched->max_open_gate_duration[tc] < entry->gate_duration[tc]) + sched->max_open_gate_duration[tc] = entry->gate_duration[tc]; + } +} + static ktime_t sched_base_time(const struct sched_gate_list *sched) { if (!sched) @@ -953,6 +1006,8 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb, new->cycle_time = cycle; } + taprio_calculate_gate_durations(q, new); + return 0; }