From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 234F3C43219 for ; Fri, 26 Apr 2019 12:13:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0011B2084F for ; Fri, 26 Apr 2019 12:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726394AbfDZMNt (ORCPT ); Fri, 26 Apr 2019 08:13:49 -0400 Received: from dispatch1-us1.ppe-hosted.com ([148.163.129.52]:49024 "EHLO dispatch1-us1.ppe-hosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbfDZMNs (ORCPT ); Fri, 26 Apr 2019 08:13:48 -0400 X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 8FAC8A80081; Fri, 26 Apr 2019 12:13:46 +0000 (UTC) Received: from [10.17.20.203] (10.17.20.203) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 26 Apr 2019 05:13:42 -0700 Subject: Re: TC stats / hw offload question To: Pablo Neira Ayuso CC: Jamal Hadi Salim , netdev , "Jiri Pirko" , Cong Wang References: <26f0cfc9-3bef-8579-72cc-aa6c5ccecd43@solarflare.com> <4cb765dd-453f-3139-bce6-6e0b31167aec@mojatatu.com> <20190424141139.5c5vhihie5mryxlt@salvia> <26afcaaf-abdf-42ad-1715-5af9c6f3c2ef@solarflare.com> <58c74d0f-b92e-31f9-9828-24fb04129534@solarflare.com> <20190425223346.zqfadtphmhuj7ohp@salvia> From: Edward Cree Message-ID: Date: Fri, 26 Apr 2019 13:13:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.0 MIME-Version: 1.0 In-Reply-To: <20190425223346.zqfadtphmhuj7ohp@salvia> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-GB X-Originating-IP: [10.17.20.203] X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-24574.005 X-TM-AS-Result: No-12.922400-4.000000-10 X-TMASE-MatchedRID: 6otD/cJAac0bF9xF7zzuNSa1MaKuob8PC/ExpXrHizwKogmGusPLb4Ba Mqh3jZTTkiint03Mwb2xjhHDzLoapEMpVZZsZyZG4NAJeq9IDSzk1ikmy0JzSJh8u7mojKy+Le1 /wNzmw07gTGfgubR6iED8qutfZX9JsznIV04I19GZroPNdqiG8xLXa2P1m93zM7O6Mb+qTwGQpa 1uTVqtkJfADchIQaCbQoRCxxvfa52kdfApK0hImtOEZs/2oH3cbtUOg4wiVGBUjspoiX02F4iLO GSrOVCj3B7VN6V4TxpsbYIYyS5fFHpsxhuKgz2pwrUhv0kAAvF9LQinZ4QefNQdB5NUNSsi1GcR AJRT6PP3FLeZXNZS4KBkcgGnJ4WmYKNHxA8YEPqaNd+fP+DX6lFf98uvehvbNuGTDn3U+pt+3Bn dfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--12.922400-4.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-24574.005 X-MDID: 1556280827-eZKd4MNKfRSU Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 25/04/2019 23:33, Pablo Neira Ayuso wrote: > On Thu, Apr 25, 2019 at 02:23:08PM +0100, Edward Cree wrote: >> On 24/04/2019 16:03, Edward Cree wrote: >>> static int efx_tc_flower_replace(struct efx_nic *efx, >>>                                  struct net_device *net_dev, >>>                                  struct tc_cls_flower_offload *tc) >>> { >>>     struct efx_tc_action_set *act; >>> >>>     /* parse the match */ >>> >>>     tcf_exts_for_each_action(i, a, tc->exts) { >>>         if (a->ops && a->ops->stats_update) { >>>             /* act is the hw action we're building */ >>>             act->count = allocate_a_counter(); >> Also, this was actually taking a->tcfa_index, allowing multiple rules to >>  share a counter.  The action index doesn't seem to be available in the >>  new flow_offload API. > Could you show a bit more code to see how you use a->tcfa_index from > your efx_tc_flower_replace()? > > Thanks. Sure; this block is (still slightly abridged) if (a->ops && a->ops->stats_update) {     struct efx_tc_counter_index *ctr;     ctr = efx_tc_flower_get_counter_by_index(efx, a->tcfa_index);     if (IS_ERR(ctr)) {         rc = PTR_ERR(ctr);         goto release;     }     act->count = ctr;     act->count_action_idx = i;     efx_tc_calculate_count_delta(act); } and we have struct efx_tc_counter_index {     u32 tcfa_index;     struct rhash_head linkage;     refcount_t ref;     u32 fw_id; }; const static struct rhashtable_params efx_tc_counter_ht_params = {     .key_len        = offsetof(struct efx_tc_counter_index, linkage),     .key_offset     = 0,     .head_offset    = offsetof(struct efx_tc_counter_index, linkage), }; static struct efx_tc_counter_index *efx_tc_flower_get_counter_by_index(                 struct efx_nic *efx, u32 idx) {     struct efx_tc_counter_index *ctr, *old;     long rc;     ctr = kzalloc(sizeof(*ctr), GFP_USER);     if (!ctr)         return ERR_PTR(-ENOMEM);     ctr->tcfa_index = idx;     old = rhashtable_lookup_get_insert_fast(&efx->tc->counter_ht,                                             &ctr->linkage,                                             efx_tc_counter_ht_params);     if (old) {         /* don't need our new entry */         kfree(ctr);         if (!refcount_inc_not_zero(&old->ref))             return ERR_PTR(-EAGAIN);         /* existing entry found */         ctr = old;     } else {         rc = efx_tc_flower_allocate_counter(efx);         if (rc < 0) {             rhashtable_remove_fast(&efx->tc->counter_ht,                                    &ctr->linkage,                                    efx_tc_counter_ht_params);             kfree(ctr);             return ERR_PTR(rc);         }         ctr->fw_id = rc;         refcount_inc(&ctr->ref);     }     return ctr; } Thus if (and only if) two TC actions have the same tcfa_index, they will  share a single counter in the HW. I gathered from a previous conversation with Jamal[1] that that was the  correct behaviour: > Note, your counters should also be shareable; example, count all > the drops in one counter across multiple flows as in the following > case where counter index 1 is used. > > tc flower match foo action drop index 1 > tc flower match bar action drop index 1 -Ed [1]: https://www.spinics.net/lists/netdev/msg551448.html