From patchwork Thu Dec 9 09:28:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12666217 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 713E9C433EF for ; Thu, 9 Dec 2021 09:29:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236300AbhLIJcc (ORCPT ); Thu, 9 Dec 2021 04:32:32 -0500 Received: from mail-bn8nam08on2090.outbound.protection.outlook.com ([40.107.100.90]:64096 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236244AbhLIJc0 (ORCPT ); Thu, 9 Dec 2021 04:32:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FsaDsUO8piu3xiGv4sY/KVPmNNh0oPqSF7Rk8QSzstsV437FOQOvlQNf2282zZzckrzO2Xg4IaHaTlIejRMnxjEnFbG68Dcy15aY+IQGVunNqo64UO1rbR9HeDx/q3vL5bGzR02gQRUkE5AjY4iU4W8MwCSI5OzjNz6lBfMV/TPoYSk7Gd8vS3rC5+2bzOYyH1nezc565Jr9VzyCbZ8E2ZtOguzJJnNMUx+MtgbHsEWTNBdz7RJ3dgB/gxBxA0VKBRcIXa0GMuQkljLb1iiqgYyFZsUzA30xEXBUELv01bSow78Ux7wyAUtQzhtgED1std84jF0d7opU8zCYzIeqfQ== 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=YK04thQSIKcMbJnQL2ZpOwKD9hwAAD3KhRtWiyq6MSU=; b=iUOuDffqeZLIOaCVZJgkQsJbS71H/QALXb39jjx6EnFUEpiwhcDRQ7jgu8fGJlVjSxipsRzyvjKnQUZTHi4xOo0GnNqJXgqcYGdlAu+tO7FzbtXYg5B0tqF5RQvwW8JeW8D7qquwUhE3sA5jfpV3A2PVpC/GE2XZAsQHudzXPworkxKECFJDyVY5CWjI3zJ0/7X/UpbvzBiXicqY5kEfqWEqJrx6pUW+X7SoZ2acDC+3xZuRYGbyfWgtC1sZsEWqVEwUjgAEKoJV5Ng4vQ6jAPQUD7+oGOuVIh9yooXP/Izt1iHg06vrqchoquymmsrJia8u7UAStWCS4X9EEVAnqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YK04thQSIKcMbJnQL2ZpOwKD9hwAAD3KhRtWiyq6MSU=; b=hPrROG2O9zIgp3Cuuw6ap+p1NMQKKDsGER2p88SoNor/h772lskkogPPoBpxLVHlhowp1lH1/iZdr7J135vNGxLwVVqwiRhk/rU6qpxwWvHkWdBKqousuMbTTmuXLmFIQ1EI+n5l9NCaMU6R0ABevsRCM9vGxGu30BKL6tnbyIA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5494.namprd13.prod.outlook.com (2603:10b6:510:128::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.10; Thu, 9 Dec 2021 09:28:47 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a01a:4940:c69a:e04c]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::a01a:4940:c69a:e04c%9]) with mapi id 15.20.4778.012; Thu, 9 Dec 2021 09:28:47 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Cong Wang , Dan Carpenter , Ido Schimmel , Jamal Hadi Salim , Jiri Pirko , Oz Shlomo , Roi Dayan , Vlad Buslov , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Simon Horman Subject: [PATCH v6 net-next 08/12] flow_offload: add process to update action stats from hardware Date: Thu, 9 Dec 2021 10:28:02 +0100 Message-Id: <20211209092806.12336-9-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211209092806.12336-1-simon.horman@corigine.com> References: <20211209092806.12336-1-simon.horman@corigine.com> X-ClientProxiedBy: AM3PR03CA0068.eurprd03.prod.outlook.com (2603:10a6:207:5::26) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9824fbbc-8d8d-474c-0c1e-08d9baf64d5b X-MS-TrafficTypeDiagnostic: PH0PR13MB5494:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:363; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VXOcZGP7Ds9abEk9AOG+15bJZL87XA39XSeb5CSIrt4pN7sdef7Stbrxz5YMYTc9SZf3XlTu3RNYujfbzeL0iedV77e7NN99QXdFloAC6LZgPXkmjqdYskkKsCjIJ3YGzU/9eZfcCr7QZpfns+OxPvtxMbpbrWcbhCdmfhH2rzEC4Y59K+E/7eYI4FOkA/dpUwPoUyDVbm0SmzhAbSuWWIyfP1hl/+9KOpq19dWB4FTtsGf0bMXqpUrRD1qdfgXJPudxTL/F9AfZRAdRrJu/z5M7qx9dz9QKGqSUeG8OVrrgYIamTauen9p4aF0XCrfIksL3rEvLrjHlUWDTf2zJFr8V0EAqui7Ax8FmJBgH1L4nVYLWVq9NroYIM1a/qI/dpVXs6gUzd9Sah0TPaLVayx6ImPZSQeyu93I3kxJ1NUBQvGAaIqGphePvE+I+57KAb7p6Q/SlKZfk4ZNU2B7OLWoOFBHj92kJBIpCsCLFNv5vtpg75sNBr+L3jubFi9j5orBMnwiVneB7xa16pwbShfGjRfd6dQtkcMMU2vXLSP5pqUOKVEZUVnp+/N8ovwlvBCE8DEr4L7h5AQZbeMA9vCyIQXh2FBlMnBKX4K9sJ511oF3lXFBTltFza8odGhgqwDDoLss0AcWa/Rs2JQtrhA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR13MB4842.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(39840400004)(396003)(346002)(136003)(376002)(366004)(6666004)(6512007)(44832011)(38100700002)(6916009)(66556008)(86362001)(15650500001)(52116002)(316002)(1076003)(6506007)(8936002)(8676002)(4326008)(36756003)(2906002)(6486002)(5660300002)(186003)(66476007)(2616005)(83380400001)(508600001)(54906003)(66946007)(107886003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hHop6kytSUTokZZhS3tRnGQAG+d1MQon1oR6U1DdDwFBw5DMcH4knce3i/YsMwREyhGeYxTR1Q+8Nbn3nlkXeKeq9h6k2K/qK4Lhrc84Nllg9sE4kM2cD+hWoroqUy/qpLsxatHdMhBXJLdBu230tcCAn2di0ppe1jx8PUHoGXmjnNaUK8aU87yXXsCkoxMudgPBqg3p4JHghqT711AUrbr8hbtMNyGqBDFVqIaqVvFXHIsyW8oNbvICOzEuYyeYivEh9r1ZbKZTuoZNNH4LmtegoKHY1aQn7R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8GatX0llITqCDWZjKapuu7jsjCHI/8glN2+EEvdqvLcg/Gs03GxNnqKGBeWCRX7ejUlz9KJqb9qGc2Cy40nT7n//j+doI1yHrp8Mxt012vLrd6cQFldDuwQ6olJgCn4vb6dq+vWjAjXuFMHMDCD6Ebgi4apLefzaetbHN4S/HPDHoRSFFM4I3mZqemZDq/2hv3eyPP7jwQRHty7623u7OxSFqu6+2Hy9rq7a8IVTWBu19SEMRUNZt5pF0ANjcjynnQ+2bsLM85buCN2kHn9/6JQYyHBJ/TlfrUA9BzZGIsEtFOGslq9lDT2UACG2nbGZ64Z746tIfuyz2yrE445a6YaYNnlMMZB4ggyFT+RIlf3MX9yIMvbk= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9824fbbc-8d8d-474c-0c1e-08d9baf64d5b X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 09:28:47.4857 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9mxNfpsAgqMYv5NEKdjpcpHa8Q1WmcdwyPc8epZ1ZqkOifm1qgrQjjjg2fBmcCoOafCywo+0Hi0Np+4+9FxPMMRCkMbWIbrffJHxjQaq1dI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5494 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Baowen Zheng When collecting stats for actions update them using both hardware and software counters. Stats update process should not run in context of preempt_disable. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/act_api.h | 1 + include/net/pkt_cls.h | 18 ++++++++++-------- net/sched/act_api.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 7e4e79b50216..ce094e79f722 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -253,6 +253,7 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets, u64 drops, bool hw); int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); +int tcf_action_update_hw_stats(struct tc_action *action); int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct tcf_chain **handle, struct netlink_ext_ack *newchain); diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 13f0e4a3a136..1942fe72b3e3 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -269,18 +269,20 @@ tcf_exts_stats_update(const struct tcf_exts *exts, #ifdef CONFIG_NET_CLS_ACT int i; - preempt_disable(); - for (i = 0; i < exts->nr_actions; i++) { struct tc_action *a = exts->actions[i]; - tcf_action_stats_update(a, bytes, packets, drops, - lastuse, true); - a->used_hw_stats = used_hw_stats; - a->used_hw_stats_valid = used_hw_stats_valid; - } + /* if stats from hw, just skip */ + if (tcf_action_update_hw_stats(a)) { + preempt_disable(); + tcf_action_stats_update(a, bytes, packets, drops, + lastuse, true); + preempt_enable(); - preempt_enable(); + a->used_hw_stats = used_hw_stats; + a->used_hw_stats_valid = used_hw_stats_valid; + } + } #endif } diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 1d469029f2cd..4e309b8e49bb 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -245,6 +245,37 @@ static int tcf_action_offload_add(struct tc_action *action, return err; } +int tcf_action_update_hw_stats(struct tc_action *action) +{ + struct flow_offload_action fl_act = {}; + int err; + + if (!tc_act_in_hw(action)) + return -EOPNOTSUPP; + + err = flow_action_init(&fl_act, action, FLOW_ACT_STATS, NULL); + if (err) + return err; + + err = tcf_action_offload_cmd(&fl_act, NULL, NULL); + if (!err) { + preempt_disable(); + tcf_action_stats_update(action, fl_act.stats.bytes, + fl_act.stats.pkts, + fl_act.stats.drops, + fl_act.stats.lastused, + true); + preempt_enable(); + action->used_hw_stats = fl_act.stats.used_hw_stats; + action->used_hw_stats_valid = true; + } else { + return -EOPNOTSUPP; + } + + return 0; +} +EXPORT_SYMBOL(tcf_action_update_hw_stats); + static int tcf_action_offload_del(struct tc_action *action) { struct flow_offload_action fl_act = {}; @@ -1317,6 +1348,9 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p, if (p == NULL) goto errout; + /* update hw stats for this action */ + tcf_action_update_hw_stats(p); + /* compat_mode being true specifies a call that is supposed * to add additional backward compatibility statistic TLVs. */