From patchwork Tue Feb 7 13:54:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1738956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=focW+9pC; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PB4R54Lndz23hX for ; Wed, 8 Feb 2023 00:56:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id F3FC5417D6; Tue, 7 Feb 2023 13:55:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org F3FC5417D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1675778160; bh=BmKO8+yvmDq95/lR5FxlzRPopUOqflvAxVXHl9Nu1ko=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=focW+9pC/NFiNukHYVD3E9bpcGsgTbt1xvXKrYS0IJA0dfk5PFwyjMbNFcnubv9XW F2edxe66mGagR4UZztVwfhTA9C8l26D/+ejvRuBMiY5ymjvVNptlOM3xh91AYr0ypv qOp1q+UT5HYeqpz33uc6GwsW2R6ooSJ2rmR3xpzrio9N4Iu3qB+HRO2/CLJHemAX2T AjCZ6iNloAtRFeUhwlyUPzSs+YjrpUKmh8ym/VmhHg3uXlTygeBGhS4UksEWGzLkk2 o2wJYySxp2TyXsmfhtu0nBTS/bjniYEm/SpWP2uwas0F3ITk95Wp1A0gdAp2aAlliK awYoXYT+zWJ/g== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CN7ln2HkU5V6; Tue, 7 Feb 2023 13:55:56 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp4.osuosl.org (Postfix) with ESMTP id 9BB69417E1; Tue, 7 Feb 2023 13:55:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 9BB69417E1 X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id BC1C81BF376 for ; Tue, 7 Feb 2023 13:55:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A0C9E417D7 for ; Tue, 7 Feb 2023 13:55:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A0C9E417D7 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x8QNCgTbCXrM for ; Tue, 7 Feb 2023 13:55:22 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2E65F417D6 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2070.outbound.protection.outlook.com [40.107.7.70]) by smtp4.osuosl.org (Postfix) with ESMTPS id 2E65F417D6 for ; Tue, 7 Feb 2023 13:55:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZhOctSsSn1rh/5cSX5yJZFhlQTFKdRs3f7qFKwhP4pVE7Vm/Ye2bSeWxm5QfxMCWpF5wWR1URFb3Z8vkvDFnjQf6Pz3T28KDZOECDWgMZtajPvE9JYIUklnFZDkc/Dx7iiSMTTolmVEJrfBHvAbj5n+3TKI1+1iSj4msSzLhQ5sxT2Ks6xikW7Inq5Y/pQ67TAKKClhXYpklOOVAPme1yvoy08Rm+UX5p03vu89odsOc9UnqQKHXOX3K/hWlVl4/xxFam6dzJBTQ0JPU7lpYwEp5G86sCxPBQOpO1OKIArvALkWNyPS9ghvP5iJHpIJ3owjUH0FpV8hjh/ELXNmPqg== 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=DMmFt6mlpFfnnPitylfG+Ez+lWXNDlzRbLVDgli5hm4=; b=QgIj5RCPSY794wGKsZdQGYK3R+BV+kxCsmiZBEanQxPIdgyqpNUzBgA9v2WrncXsckk9/yN7vZW9YAStRCWSHczh2Frbg4M3bohvXon9FxauylOBtFhlQ/tvr1kHkCD0TALStCjxq8efzqrumq6d+malok6oRgfJxuTIUngNKPoCTySeqEYl9CB6o4hHb7BCtK3zIVviqVlOb4Vak1FCmcTHxLAz+vwhwVn32IZfRqzSyFG+Vg0qU4TH/urG6QAiyKapU+X7lUDjHv7FIlriEHY6CmRMaJU3O8BaUe+S2+KaoRZWKUk5e1RYeq2w+Gcz8scytC1/s3xhRkpgJn/nSQ== 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 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:19 +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:19 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Date: Tue, 7 Feb 2023 15:54:33 +0200 Message-Id: <20230207135440.1482856-9-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: 71294eea-7e93-4f8e-eab5-08db0912f274 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gE6BvCboGs/nNslhr6ZHOxfhvwgxHICJYdzBjdHrxHedw2WRcRqGW1bMz3CR4w8Oja0SB8qUpTeNTT1IpH9aKqnK7e68x6yF//mayw1O8F1zNE4B/+XE95Xj38DNIfNeLtm0K7/Vq93Qt2fhEqlLpC35z16oA2nau8uNBhj30sokIOQhR/RcxDqSAoImzQdi9NzmrYmZrhVUFkv7cRQWmEWeA3qAIXFNZ1NwWWK96ARyS7PVkTEqdEmqr5u/EC6410Q6yu1rzYMoRaxBBR01Bg0P18GioHZLjL3WrhQkjJE41pY70EgaQ+O7/LjPskuxz3Aw4nOWATZh0Ms1Drt6KsA5r+yGiYe37VKMe2PgKbPDFTNV4zhuxjCTVcJMhjcfawz1l/EDtN0rif0jHAEXPvs7yewkC91tGYg7/VG3gVORStdVZ7Q29s/zWBgL1EGiPhVm42mfyEQavMMxWOWOSg4mwyOFglgJqT8JG1VTazv0D/+O9N3JBpbKuoFYSRPJVMfh1KmNPlOvHLIA56t6JnB3OICju8Nohtyqn4Kb1t9EN1BNAKVBz6KjoBVCqiaKwfoCqzfcJN3thvYmjmJkDGtFC8rX/TR1L1Bl4YOgOohLjIw5x1/P160UPmItWXnTJi7Tcz7GtCPv27HlHgsSVoDjTI0eH7vxwFDEBhg6+MDYdY2vWmBfEOxFK45bMvbYxSaVerxc2+9rvoUc/iq4SA== 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: td58KToSpLsRlhFz8tQcW+DIix2M//3idArY3i5BTjW/ADgh8Mgn3gZDVwLbg7Amv2f5fHrJBozqMifK8aFu6mmVb3vnHdCCOXdwYZJWXma7q6dMreLq0G3qlvjVM0xDlQPJW/cSD/kZm3EfiBw76t74deh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egaw/n+hhnRMWewyJPN2z0qUmrJsZ/4oaaFQtwRKDiE52cYRLKzNludl7VH8ciV70tneOmaeueNU4OWXrrLvVVB5SPDcIjUT72dGFqoMrLTEjkj0OFTqi3IdIbVHZYSIvUr8JlNiCP5+asG2FnKsLjzyQlvXxsPWoKd6rdLUD7BUfbg4GQdG9ggAvcuLhOXp2SVorWsyBmNc31XhyGiPYr7PBiB+9NHoeOIr7ZtdLNJ2WlZzxWgXg+7pHfdfCcZ9xyRGCOF8XYGNf+KZJqbjFOJeatf4Wt/4P+kDotFE7HpZvJCtMuMS9rR4FpJJ6zUEnz1eV2j4q6R3jp+UP2EHXWjizR9mraPe4fQcG6uGEe2IFusg5qmb49CpegdAxtXiEiogOLoTMg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71294eea-7e93-4f8e-eab5-08db0912f274 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:19.0335 (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: Uhp2jhmKryxD3k5makB0ajgfovMDKe/CMJ6+ZjeW+PjLuy41ugUdPjrm1trquyfyFVy1cszEpXxka6SBE1A4YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8115 X-Mailman-Original-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=DMmFt6mlpFfnnPitylfG+Ez+lWXNDlzRbLVDgli5hm4=; b=hzBPlSA4PMGgAMrXft48trUik6mxEAlKlk4n7YUVpZlIoWGDYHelAevqboGLIFFUaVD6w8e48J+zpvstRzAjv2ddSOr/Dy2of5dCbNBcnKJPq2fSZ/3VnNIgtZQ69v0C5+xdEtWzG+Hxq0yZru0VlNS0LXhMNNB+NvVuObIKWR8= X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=nxp.com header.i=@nxp.com header.a=rsa-sha256 header.s=selector2 header.b=hzBPlSA4 X-Mailman-Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Subject: [Intel-wired-lan] [PATCH v2 net-next 08/15] net/sched: taprio: calculate budgets per traffic class X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiri Pirko , intel-wired-lan@lists.osuosl.org, Kurt Kanzenbach , Jamal Hadi Salim , Jesse Brandeburg , Gerhard Engleder , Eric Dumazet , Tony Nguyen , Cong Wang , Jakub Kicinski , Paolo Abeni , "David S. Miller" , linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" Currently taprio assumes that the budget for a traffic class expires at the end of the current interval as if the next interval contains a "gate close" event for this traffic class. This is, however, an unfounded assumption. Allow schedule entry intervals to be fused together for a particular traffic class by calculating the budget until the gate *actually* closes. This means we need to keep budgets per traffic class, and we also need to update the budget consumption procedure. Signed-off-by: Vladimir Oltean Reviewed-by: Kurt Kanzenbach --- v1->v2: none net/sched/sch_taprio.c | 54 +++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 3e798c8406ae..08099c1747cc 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -43,6 +43,7 @@ struct sched_entry { * respective traffic class gate closes */ u64 gate_duration[TC_MAX_QUEUE]; + atomic_t budget[TC_MAX_QUEUE]; struct list_head list; /* The instant that this entry ends and the next one @@ -51,7 +52,6 @@ struct sched_entry { */ ktime_t end_time; ktime_t next_txtime; - atomic_t budget; int index; u32 gate_mask; u32 interval; @@ -563,11 +563,48 @@ static struct sk_buff *taprio_peek(struct Qdisc *sch) return NULL; } -static void taprio_set_budget(struct taprio_sched *q, struct sched_entry *entry) +static void taprio_set_budgets(struct taprio_sched *q, + struct sched_gate_list *sched, + struct sched_entry *entry) { - atomic_set(&entry->budget, - div64_u64((u64)entry->interval * PSEC_PER_NSEC, - atomic64_read(&q->picos_per_byte))); + struct net_device *dev = qdisc_dev(q->root); + int num_tc = netdev_get_num_tc(dev); + int tc, budget; + + for (tc = 0; tc < num_tc; tc++) { + /* Traffic classes which never close have infinite budget */ + if (entry->gate_duration[tc] == sched->cycle_time) + budget = INT_MAX; + else + budget = div64_u64((u64)entry->gate_duration[tc] * PSEC_PER_NSEC, + atomic64_read(&q->picos_per_byte)); + + atomic_set(&entry->budget[tc], budget); + } +} + +/* When an skb is sent, it consumes from the budget of all traffic classes */ +static int taprio_update_budgets(struct sched_entry *entry, size_t len, + int tc_consumed, int num_tc) +{ + int tc, budget, new_budget = 0; + + for (tc = 0; tc < num_tc; tc++) { + budget = atomic_read(&entry->budget[tc]); + /* Don't consume from infinite budget */ + if (budget == INT_MAX) { + if (tc == tc_consumed) + new_budget = budget; + continue; + } + + if (tc == tc_consumed) + new_budget = atomic_sub_return(len, &entry->budget[tc]); + else + atomic_sub(len, &entry->budget[tc]); + } + + return new_budget; } static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, @@ -577,6 +614,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, struct taprio_sched *q = qdisc_priv(sch); struct net_device *dev = qdisc_dev(sch); struct Qdisc *child = q->qdiscs[txq]; + int num_tc = netdev_get_num_tc(dev); struct sk_buff *skb; ktime_t guard; int prio; @@ -611,7 +649,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq, /* ... and no budget. */ if (gate_mask != TAPRIO_ALL_GATES_OPEN && - atomic_sub_return(len, &entry->budget) < 0) + taprio_update_budgets(entry, len, tc, num_tc) < 0) return NULL; skip_peek_checks: @@ -832,7 +870,7 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer) } next->end_time = end_time; - taprio_set_budget(q, next); + taprio_set_budgets(q, oper, next); first_run: rcu_assign_pointer(q->current_entry, next); @@ -1091,7 +1129,7 @@ static void setup_first_end_time(struct taprio_sched *q, sched->cycle_end_time = ktime_add_ns(base, cycle); first->end_time = ktime_add_ns(base, first->interval); - taprio_set_budget(q, first); + taprio_set_budgets(q, sched, first); rcu_assign_pointer(q->current_entry, NULL); }