Switch API optimizations
Subsystems (3)
v2 cover Switch API optimizations
Optimize the process of creating a recipe in the switch block by removing duplicate switch ID words and changing how result indexes are fitted into recipes. In many cases this can decrease the number of recipes required to add a certain set of rules, potentially allowing a more varied set of rules to be created. Total rule count will also increase, since less words will be left unused/wasted. There are only 64 rules available in total, so every one counts.
After this modification, many fields and some structs became unused or were simplified, resulting in overall simpler implementation.
Marcin Szycik (4):
ice: Remove unused struct ice_prot_lkup_ext members
ice: Optimize switch recipe creation
ice: Remove unused members from switch API
ice: Add tracepoint for adding and removing switch rules
Michal Swiatkowski (3):
ice: Remove reading all recipes before adding a new one
ice: Simplify bitmap setting in adding recipe
ice: remove unused recipe bookkeeping data
drivers/net/ethernet/intel/ice/ice_common.c | 11 +- .../ethernet/intel/ice/ice_protocol_type.h | 43 +- drivers/net/ethernet/intel/ice/ice_switch.c | 674 ++++++------------ drivers/net/ethernet/intel/ice/ice_switch.h | 20 +- drivers/net/ethernet/intel/ice/ice_trace.h | 18 + drivers/net/ethernet/intel/ice/ice_type.h | 2 + 6 files changed, 272 insertions(+), 496 deletions(-)
---
v2:
* Nicify checking sizeof struct field
* Add a tracepoint for tracking recipe/rule utilization (patch 7)
v1: [1]
[1] https://lore.kernel.org/intel-wired-lan/[email protected]/T/#t
Signature · 1 line
2.45.0
PATCH v2 1/7 ice: Remove unused struct ice_prot_lkup_ext members
Remove field_off as it's never used.
Remove done bitmap, as its value is only checked and never assigned. Reusing sub-recipes while creating new root recipes is currently not supported in the driver.
--- .../ethernet/intel/ice/ice_protocol_type.h | 4 -- drivers/net/ethernet/intel/ice/ice_switch.c | 44 ++++++++----------- 2 files changed, 19 insertions(+), 29 deletions(-)
drivers/net/ethernet/intel/ice/ice_protocol_type.h +0 -4
@@ -452,13 +452,9 @@ struct ice_prot_lkup_ext {u16 prot_type;u8 n_val_words;/* create a buffer to hold max words per recipe */ -u16 field_off[ICE_MAX_CHAIN_WORDS ];u16 field_mask[ICE_MAX_CHAIN_WORDS ];struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS ]; - -/* Indicate field offsets that have field vector indices assigned */ -DECLARE_BITMAP (done,ICE_MAX_CHAIN_WORDS ); };struct ice_pref_recipe_group {
drivers/net/ethernet/intel/ice/ice_switch.c +19 -25
52 lines not on this page · raw message
Signature · 1 line
2.45.0
PATCH v2 2/7 ice: Remove reading all recipes before adding a new one
In reply to Marcin SzycikFrom: Michal Swiatkowski <[email protected]>
The content of the first read recipe is used as a template when adding a recipe. It isn't needed - only prune index is directly set from there. Set it in the code instead. Also, now there's no need to set rid and lookup indexes to 0, as the whole recipe buffer is initialized to 0.
--- drivers/net/ethernet/intel/ice/ice_switch.c | 29 ++------------------- 1 file changed, 2 insertions(+), 27 deletions(-)
drivers/net/ethernet/intel/ice/ice_switch.c +2 -27
@@ -5079,11 +5079,9 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, {DECLARE_BITMAP (result_idx_bm,ICE_MAX_FV_WORDS );struct ice_aqc_recipe_content *content; -struct ice_aqc_recipe_data_elem *tmp;struct ice_aqc_recipe_data_elem *buf;struct ice_recp_grp_entry *entry;u16 free_res_idx; -u16 recipe_count;u8 chain_idx;u8 recps =0 ;int status;
@@ -5110,10 +5108,6 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm,if (rm->n_grp_count >ICE_MAX_CHAIN_RECIPE )return -ENOSPC ; - tmp =kcalloc (ICE_MAX_NUM_RECIPES ,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; - buf =devm_kcalloc (ice_hw_to_dev (hw), rm->n_grp_count,sizeof (*buf),GFP_KERNEL );if (!buf) {
@@ -5122,11 +5116,6 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, }bitmap_zero (rm->r_bitmap,ICE_MAX_NUM_RECIPES ); - recipe_count =ICE_MAX_NUM_RECIPES ; - status =ice_aq_get_recipe (hw, tmp, &recipe_count,ICE_SW_LKUP_MAC , -NULL ); -if (status || recipe_count ==0 ) - goto err_unroll;/* Allocate the recipe resources, and configure them according to the * match fields from protocol headers and extracted field vectors.
@@ -5141,19 +5130,9 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, content = &buf[recps].content; -/* Clear the result index of the located recipe, as this will be -* updated, if needed, later in the recipe creation process. -*/ - tmp[0 ].content.result_indx =0 ; - - buf[recps] = tmp[0 ]; buf[recps].recipe_indx = (u8 )entry->rid; -/* if the recipe is a non-root recipe RID should be programmed -* as 0 for the rules to be applied correctly. -*/ - content->rid =0 ; -memset (&content->lkup_indx,0 , -sizeof (content->lkup_indx)); + + buf[recps].content.act_ctrl |=ICE_AQ_RECIPE_ACT_PRUNE_INDX_M ;/* All recipes use look-up index 0 to match switch ID. */ content->lkup_indx[0 ] =ICE_AQ_SW_ID_LKUP_IDX ;
@@ -5192,8 +5171,6 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, }/* fill recipe dependencies */ -bitmap_zero ((unsigned long *)buf[recps].recipe_bitmap, -ICE_MAX_NUM_RECIPES );set_bit (buf[recps].recipe_indx, (unsigned long *)buf[recps].recipe_bitmap); content->act_ctrl_fwd_priority = rm->priority;
@@ -5357,12 +5334,10 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, recp->recp_created = true; } rm->root_buf = buf; -kfree (tmp);return status; err_unroll: err_mem: -kfree (tmp);devm_kfree (ice_hw_to_dev (hw), buf);return status; }
Signature · 1 line
2.45.0
PATCH v2 3/7 ice: Simplify bitmap setting in adding recipe
In reply to Marcin SzycikFrom: Michal Swiatkowski <[email protected]>
Remove unnecessary size checks when copying bitmaps in ice_add_sw_recipe() and replace them with compile time assert. Check if the bitmaps are equal size, as they are copied both ways.
---
v2: Replace sizeof(((struct s*)0)->f with sizeof_field() (thanks Alex!)
--- drivers/net/ethernet/intel/ice/ice_switch.c | 24 ++++++++------------- 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/ice/ice_switch.c +9 -15
@@ -5067,6 +5067,10 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const unsigned long *profiles,return (u16 )bitmap_weight (free_idx,ICE_MAX_FV_WORDS ); } +/* For memcpy in ice_add_sw_recipe. */ +static_assert(sizeof_field(struct ice_aqc_recipe_data_elem, recipe_bitmap) == + sizeof_field(struct ice_sw_recipe, r_bitmap)); +/** * ice_add_sw_recipe - function to call AQ calls to create switch recipe * @hw: pointer to hardware structure
@@ -5187,13 +5191,9 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm, rm->root_rid = buf[0 ].recipe_indx;set_bit (buf[0 ].recipe_indx, rm->r_bitmap); buf[0 ].content.rid = rm->root_rid |ICE_AQ_RECIPE_ID_IS_ROOT ; -if (sizeof (buf[0 ].recipe_bitmap) >=sizeof (rm->r_bitmap)) { -memcpy (buf[0 ].recipe_bitmap, rm->r_bitmap, -sizeof (buf[0 ].recipe_bitmap)); - }else { - status = -EINVAL ; - goto err_unroll; - } +memcpy (buf[0 ].recipe_bitmap, rm->r_bitmap, +sizeof (buf[0 ].recipe_bitmap)); +/* Applicable only for ROOT_RECIPE, set the fwd_priority for * the recipe which is getting created if specified * by user. Usually any advanced switch filter, which results
@@ -5256,14 +5256,8 @@ ice_add_sw_recipe(struct ice_hw *hw, struct ice_sw_recipe *rm,set_bit (entry->rid, rm->r_bitmap); }list_add (&last_chain_entry->l_entry, &rm->rg_list); -if (sizeof (buf[recps].recipe_bitmap) >= -sizeof (rm->r_bitmap)) { -memcpy (buf[recps].recipe_bitmap, rm->r_bitmap, -sizeof (buf[recps].recipe_bitmap)); - }else { - status = -EINVAL ; - goto err_unroll; - } +memcpy (buf[recps].recipe_bitmap, rm->r_bitmap, +sizeof (buf[recps].recipe_bitmap)); content->act_ctrl_fwd_priority = rm->priority; recps++;
Signature · 1 line
2.45.0
PATCH v2 4/7 ice: remove unused recipe bookkeeping data
In reply to Marcin SzycikFrom: Michal Swiatkowski <[email protected]>
Remove root_buf from recipe struct. Its only usage was in ice_find_recp(), where if recipe had an inverse action, it was skipped, but actually the driver never adds inverse actions, so effectively it was pointless.
Without root_buf, the recipe data element in ice_add_sw_recipe() does not need to be persistent and can also be automatically deallocated with __free, which nicely simplifies unroll.
--- drivers/net/ethernet/intel/ice/ice_common.c | 1 - drivers/net/ethernet/intel/ice/ice_switch.c | 55 ++++++--------------- drivers/net/ethernet/intel/ice/ice_switch.h | 2 - 3 files changed, 15 insertions(+), 43 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +0 -1
@@ -993,7 +993,6 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)devm_kfree (ice_hw_to_dev (hw), lst_itr); } } -devm_kfree (ice_hw_to_dev (hw), recps[i].root_buf); }ice_rm_all_sw_replay_rule_info (hw);devm_kfree (ice_hw_to_dev (hw), sw->recp_list);
drivers/net/ethernet/intel/ice/ice_switch.c +15 -40
134 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_switch.h +0 -2
@@ -274,8 +274,6 @@ struct ice_sw_recipe {struct list_head rg_list; -/* AQ buffer associated with this recipe */ -struct ice_aqc_recipe_data_elem *root_buf;/* This struct saves the fv_words for a given lookup */ struct ice_prot_lkup_ext lkup_exts; };
Signature · 1 line
2.45.0
PATCH v2 6/7 ice: Remove unused members from switch API
In reply to Marcin SzycikRemove several members of struct ice_sw_recipe and struct ice_prot_lkup_ext. Remove struct ice_recp_grp_entry and struct ice_pref_recipe_group, since they are now unused as well.
All of the deleted members were only written to and never read, so it's pointless to keep them.
--- drivers/net/ethernet/intel/ice/ice_common.c | 7 --- .../ethernet/intel/ice/ice_protocol_type.h | 17 ------- drivers/net/ethernet/intel/ice/ice_switch.c | 51 ++++--------------- drivers/net/ethernet/intel/ice/ice_switch.h | 16 ------ 4 files changed, 10 insertions(+), 81 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +0 -7
@@ -961,14 +961,7 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw) } recps = sw->recp_list;for (i =0 ; i <ICE_MAX_NUM_RECIPES ; i++) { -struct ice_recp_grp_entry *rg_entry, *tmprg_entry; - recps[i].root_rid = i; -list_for_each_entry_safe (rg_entry, tmprg_entry, - &recps[i].rg_list, l_entry) { -list_del (&rg_entry->l_entry); -devm_kfree (ice_hw_to_dev (hw), rg_entry); - }if (recps[i].adv_rule) {struct ice_adv_fltr_mgmt_list_entry *tmp_entry;
drivers/net/ethernet/intel/ice/ice_protocol_type.h +0 -17
@@ -455,7 +455,6 @@ struct ice_prot_ext_tbl_entry {/* Extractions to be looked up for a given recipe */ struct ice_prot_lkup_ext { -u16 prot_type;u8 n_val_words;/* create a buffer to hold max words per recipe */ u16 field_mask[ICE_MAX_CHAIN_WORDS ];
@@ -463,20 +462,4 @@ struct ice_prot_lkup_ext { struct ice_fv_word fv_words[ICE_MAX_CHAIN_WORDS]; }; -struct ice_pref_recipe_group { -u8 n_val_pairs;/* Number of valid pairs */ -struct ice_fv_word pairs[ICE_NUM_WORDS_RECIPE ]; -u16 mask[ICE_NUM_WORDS_RECIPE ]; -}; - -struct ice_recp_grp_entry { -struct list_head l_entry; - -#define ICE_INVAL_CHAIN_IND 0xFF -u16 rid; -u8 chain_idx; -u16 fv_idx[ICE_NUM_WORDS_RECIPE ]; -u16 fv_mask[ICE_NUM_WORDS_RECIPE ]; -struct ice_pref_recipe_group r_group; -};#endif /* _ICE_PROTOCOL_TYPE_H_ */
drivers/net/ethernet/intel/ice/ice_switch.c +10 -41
124 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_switch.h +0 -16
@@ -216,7 +216,6 @@ struct ice_sw_recipe {/* For a chained recipe the root recipe is what should be used for * programming rules */ -u8 is_root;u8 root_rid;u8 recp_created;
@@ -230,19 +229,6 @@ struct ice_sw_recipe {u16 fv_idx[ICE_MAX_CHAIN_WORDS ];u16 fv_mask[ICE_MAX_CHAIN_WORDS ]; -/* if this recipe is a collection of other recipe */ -u8 big_recp; - -/* if this recipe is part of another bigger recipe then chain index -* corresponding to this recipe -*/ -u8 chain_idx; - -/* if this recipe is a collection of other recipe then count of other -* recipes and recipe IDs of those recipes -*/ -u8 n_grp_count; -/* Bit map specifying the IDs associated with this group of recipe */ DECLARE_BITMAP (r_bitmap,ICE_MAX_NUM_RECIPES );
@@ -274,8 +260,6 @@ struct ice_sw_recipe { u8 need_pass_l2:1; u8 allow_pass_l2:1; -struct list_head rg_list; -/* This struct saves the fv_words for a given lookup */ struct ice_prot_lkup_ext lkup_exts; };
Signature · 1 line
2.45.0
PATCH v2 5/7 ice: Optimize switch recipe creation
In reply to Marcin SzycikCurrently when creating switch recipes, switch ID is always added as the first word in every recipe. There are only 5 words in a recipe, so one word is always wasted. This is also true for the last recipe, which stores result indexes (in case of chain recipes). Therefore the maximum usable length of a chain recipe is 4 * 4 = 16 words. 4 words in a recipe, 4 recipes that can be chained (using a 5th one for result indexes).
Current max size chained recipe:
0: smmmm
1: smmmm
2: smmmm
3: smmmm
4: srrrr
Where:
s - switch ID
m - regular match (e.g. ipv4 src addr, udp dst port, etc.) r - result index
Switch ID does not actually need to be present in every recipe, only in one of them (in case of chained recipe). This frees up to 8 extra words:
3 from recipes in the middle (because first recipe still needs to have switch ID), and 5 from one extra recipe (because now the last recipe also does not have switch ID, so it can chain 1 more recipe).
Max size chained recipe after changes:
0: smmmm
1: Mmmmm
2: Mmmmm
3: Mmmmm
4: MMMMM
5: Rrrrr
Extra usable words available after this change are highlighted with capital letters.
Changing how switch ID is added is not straightforward, because it's not a regular lookup. Its FV index and mask can't be determined based on protocol
+ offset pair read from package and instead need to be added manually.
Additionally, change how result indexes are added. Currently they are always inserted in a new recipe at the end. Example for 13 words, (with above optimization, switch ID being one of the words):
0: smmmm
1: mmmmm
2: mmmxx
3: rrrxx
Where:
x - unused word
In this and some other cases, the result indexes can be moved just after last matches because there are unused words, saving one recipe. Example for 13 words after both optimizations:
0: smmmm
1: mmmmm
2: mmmrr
Note how one less result index is needed in this case, because the last recipe does not need to "link" to itself.
There are cases when adding an additional recipe for result indexes cannot be avoided. In that cases result indexes are all put in the last recipe. Example for 14 words after both optimizations:
0: smmmm
1: mmmmm
2: mmmmx
3: rrrxx
With these two changes, recipes/rules are more space efficient, allowing more to be created in total.
--- .../ethernet/intel/ice/ice_protocol_type.h | 22 +- drivers/net/ethernet/intel/ice/ice_switch.c | 525 +++++++----------- drivers/net/ethernet/intel/ice/ice_switch.h | 2 + 3 files changed, 212 insertions(+), 337 deletions(-)
drivers/net/ethernet/intel/ice/ice_protocol_type.h +14 -8
@@ -7,18 +7,24 @@/* Each recipe can match up to 5 different fields. Fields to match can be meta- * data, values extracted from packet headers, or results from other recipes. -* One of the 5 fields is reserved for matching the switch ID. So, up to 4 -* recipes can provide intermediate results to another one through chaining, -* e.g. recipes 0, 1, 2, and 3 can provide intermediate results to recipe 4. +* Therefore, up to 5 recipes can provide intermediate results to another one +* through chaining, e.g. recipes 0, 1, 2, 3 and 4 can provide intermediate +* results to recipe 5. Note that one of the fields in one of the recipes must +* always be reserved for matching the switch ID. */ -#define ICE_NUM_WORDS_RECIPE 4 +#define ICE_NUM_WORDS_RECIPE 5 -/* Max recipes that can be chained */ +/* Max recipes that can be chained, not including the last one, which combines +* intermediate results. +*/ #define ICE_MAX_CHAIN_RECIPE 5 -/* 1 word reserved for switch ID from allowed 5 words. -* So a recipe can have max 4 words. And you can chain 5 such recipes -* together. So maximum words that can be programmed for look up is 5 * 4. +/* Total max recipes in chain recipe (including intermediate results) */ +#define ICE_MAX_CHAIN_RECIPE_RES (ICE_MAX_CHAIN_RECIPE + 1) + +/* A recipe can have max 5 words, and 5 recipes can be chained together (using +* the 6th one, which would contain only result indexes). So maximum words that +* can be programmed for lookup is 5 * 5 (not including intermediate results). */ #define ICE_MAX_CHAIN_WORDS (ICE_NUM_WORDS_RECIPE * ICE_MAX_CHAIN_RECIPE)
drivers/net/ethernet/intel/ice/ice_switch.c +196 -329
636 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_switch.h +2 -0
@@ -227,6 +227,8 @@ struct ice_sw_recipe {*/ struct ice_fv_word ext_words[ICE_MAX_CHAIN_WORDS ];u16 word_masks[ICE_MAX_CHAIN_WORDS ]; +u16 fv_idx[ICE_MAX_CHAIN_WORDS ]; +u16 fv_mask[ICE_MAX_CHAIN_WORDS ];/* if this recipe is a collection of other recipe */ u8 big_recp;
Signature · 1 line
2.45.0
PATCH v2 7/7 ice: Add tracepoint for adding and removing switch rules
In reply to Marcin SzycikTrack the number of rules and recipes added to switch. Add a tracepoint to ice_aq_sw_rules(), which shows both rule and recipe count. This information can be helpful when designing a set of rules to program to the hardware, as it shows where the practical limit is. Actual limits are known (64 recipes, 32k rules), but it's hard to translate these values to how many rules the *user* can actually create, because of extra metadata being implicitly added, and recipe/rule chaining. Chaining combines several recipes/rules to create a larger recipe/rule, so one large rule added by the user might actually consume multiple rules from hardware perspective.
Rule counter is simply incremented/decremented in ice_aq_sw_rules(), since all rules are added or removed via it.
Counting recipes is harder, as recipes can't be removed (only overwritten). Recipes added via ice_aq_add_recipe() could end up being unused, when there is an error in later stages of rule creation. Instead, track the allocation and freeing of recipes, which should reflect the actual usage of recipes (if something fails after recipe(s) were created, caller should free them). Also, a number of recipes are loaded from NVM by default - initialize the recipe counter with the number of these recipes on switch initialization.
--- drivers/net/ethernet/intel/ice/ice_common.c | 3 +++ drivers/net/ethernet/intel/ice/ice_switch.c | 22 +++++++++++++++++++-- drivers/net/ethernet/intel/ice/ice_trace.h | 18 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 2 ++ 4 files changed, 43 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +3 -0
@@ -934,6 +934,9 @@ static int ice_init_fltr_mgmt_struct(struct ice_hw *hw)INIT_LIST_HEAD (&sw->vsi_list_map_head); sw->prof_res_bm_init =0 ; +/* Initialize recipe count with default recipes read from NVM */ + sw->recp_cnt =ICE_SW_LKUP_LAST ; + status =ice_init_def_sw_recp (hw);if (status) {devm_kfree (ice_hw_to_dev (hw), hw->switch_info);
drivers/net/ethernet/intel/ice/ice_switch.c +20 -2
@@ -3,6 +3,7 @@#include "ice_lib.h" #include "ice_switch.h" +#include "ice_trace.h" #define ICE_ETH_DA_OFFSET 0#define ICE_ETH_ETHTYPE_OFFSET 12
@@ -1961,6 +1962,15 @@ ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz, hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) status = -ENOENT ; +if (!status) { +if (opc == ice_aqc_opc_add_sw_rules) + hw->switch_info->rule_cnt += num_rules; +else if (opc == ice_aqc_opc_remove_sw_rules) + hw->switch_info->rule_cnt -= num_rules; + } + +trace_ice_aq_sw_rules (hw->switch_info); +return status; }
@@ -2181,8 +2191,10 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid) sw_buf->res_type =cpu_to_le16 (res_type); status =ice_aq_alloc_free_res (hw, sw_buf, buf_len, ice_aqc_opc_alloc_res); -if (!status) +if (!status) { *rid =le16_to_cpu (sw_buf->elem[0 ].e.sw_resp); + hw->switch_info->recp_cnt++; + }return status; }
@@ -2196,7 +2208,13 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid)*/ static int ice_free_recipe_res (struct ice_hw *hw,u16 rid) { -return ice_free_hw_res (hw,ICE_AQC_RES_TYPE_RECIPE ,1 , &rid); +int status; + + status =ice_free_hw_res (hw,ICE_AQC_RES_TYPE_RECIPE ,1 , &rid); +if (!status) + hw->switch_info->recp_cnt--; + +return status; }/**
drivers/net/ethernet/intel/ice/ice_trace.h +18 -0
@@ -330,6 +330,24 @@ DEFINE_EVENT(ice_esw_br_port_template,TP_ARGS (port) ); +DECLARE_EVENT_CLASS (ice_switch_stats_template, + TP_PROTO(struct ice_switch_info *sw_info), +TP_ARGS (sw_info), + TP_STRUCT__entry(__field(u16, rule_cnt) +__field (u8, recp_cnt)), + TP_fast_assign(__entry->rule_cnt = sw_info->rule_cnt; + __entry->recp_cnt = sw_info->recp_cnt;), +TP_printk ("rules=%u recipes=%u" , + __entry->rule_cnt, + __entry->recp_cnt) +); + +DEFINE_EVENT (ice_switch_stats_template, + ice_aq_sw_rules, + TP_PROTO(struct ice_switch_info *sw_info), +TP_ARGS (sw_info) +); +/* End tracepoints */ #endif /* _ICE_TRACE_H_ */
drivers/net/ethernet/intel/ice/ice_type.h +2 -0
@@ -764,6 +764,8 @@ struct ice_switch_info {struct ice_sw_recipe *recp_list;u16 prof_res_bm_init;u16 max_used_prof_index; +u16 rule_cnt; +u8 recp_cnt;DECLARE_BITMAP (prof_res_bm[ICE_MAX_NUM_PROFILES ],ICE_MAX_FV_WORDS ); };
Signature · 1 line
2.45.0
Re: [PATCH iwl-next v2 7/7] ice: Add tracepoint for adding and removing switch rules
Quoted 22 lines · Marcin Szycik
Track the number of rules and recipes added to switch. Add a tracepoint to
ice_aq_sw_rules(), which shows both rule and recipe count. This information can be helpful when designing a set of rules to program to the hardware, as it shows where the practical limit is. Actual limits are known (64 recipes, 32k rules), but it's hard to translate these values to how many rules the *user* can actually create, because of extra metadata being implicitly added, and recipe/rule chaining. Chaining combines several recipes/rules to create a larger recipe/rule, so one large rule added by the user might actually consume multiple rules from hardware perspective.Rule counter is simply incremented/decremented in
ice_aq_sw_rules(), since all rules are added or removed via it.Counting recipes is harder, as recipes can't be removed (only overwritten). Recipes added via
ice_aq_add_recipe()could end up being unused, when there is an error in later stages of rule creation. Instead, track the allocation and freeing of recipes, which should reflect the actual usage of recipes (if something fails after recipe(s) were created, caller should free them). Also, a number of recipes are loaded from NVM by default - initialize the recipe counter with the number of these recipes on switch initialization.
Quoted 9 lines
Reviewed-by Michal Swiatkowski <[email protected]>Signed-off-by Marcin Szycik <[email protected]>--- drivers/net/ethernet/intel/ice/ice_common.c | 3 +++ drivers/net/ethernet/intel/ice/ice_switch.c | 22 +++++++++++++++++++-- drivers/net/ethernet/intel/ice/ice_trace.h | 18 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 2 ++ 4 files changed, 43 insertions(+), 2 deletions(-)
Re: [Intel-wired-lan] [PATCH iwl-next v2 7/7] ice: Add tracepoint for adding and removing switch rules
In reply to Marcin SzycikDear Marcin,
Thank you for your patch.
Am 24.06.24 um 16:45 schrieb Marcin Szycik:
Quoted 13 lines
Track the number of rules and recipes added to switch. Add a tracepoint to
ice_aq_sw_rules(), which shows both rule and recipe count. This information can be helpful when designing a set of rules to program to the hardware, as it shows where the practical limit is. Actual limits are known (64 recipes, 32k rules), but it's hard to translate these values to how many rules the *user* can actually create, because of extra metadata being implicitly added, and recipe/rule chaining. Chaining combines several recipes/rules to create a larger recipe/rule, so one large rule added by the user might actually consume multiple rules from hardware perspective.Rule counter is simply incremented/decremented in
ice_aq_sw_rules(), since all rules are added or removed via it.
Quoted 8 lines
Counting recipes is harder, as recipes can't be removed (only overwritten). Recipes added via
ice_aq_add_recipe()could end up being unused, when there is an error in later stages of rule creation. Instead, track the allocation and freeing of recipes, which should reflect the actual usage of recipes (if something fails after recipe(s) were created, caller should free them). Also, a number of recipes are loaded from NVM by default - initialize the recipe counter with the number of these recipes on switch initialization.
Can you please add an example how to use the tracepoint?
Quoted 112 lines
Reviewed-by Michal Swiatkowski <[email protected]>Signed-off-by Marcin Szycik <[email protected]>--- drivers/net/ethernet/intel/ice/ice_common.c | 3 +++ drivers/net/ethernet/intel/ice/ice_switch.c | 22 +++++++++++++++++++-- drivers/net/ethernet/intel/ice/ice_trace.h | 18 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 2 ++ 4 files changed, 43 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/ice/ice_common.c +3
-0@@ -934,6 +934,9 @@ static int ice_init_fltr_mgmt_struct(struct ice_hw *hw)INIT_LIST_HEAD (&sw->vsi_list_map_head); sw->prof_res_bm_init =0 ; +/* Initialize recipe count with default recipes read from NVM */ + sw->recp_cnt =ICE_SW_LKUP_LAST ; + status =ice_init_def_sw_recp (hw);if (status) {devm_kfree (ice_hw_to_dev (hw), hw->switch_info);drivers/net/ethernet/intel/ice/ice_switch.c +20
-2@@ -3,6 +3,7 @@#include "ice_lib.h" #include "ice_switch.h" +#include "ice_trace.h" #define ICE_ETH_DA_OFFSET 0#define ICE_ETH_ETHTYPE_OFFSET 12@@ -1961,6 +1962,15 @@ ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz, hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) status = -ENOENT ; +if (!status) { +if (opc == ice_aqc_opc_add_sw_rules) + hw->switch_info->rule_cnt += num_rules; +else if (opc == ice_aqc_opc_remove_sw_rules) + hw->switch_info->rule_cnt -= num_rules; + } + +trace_ice_aq_sw_rules (hw->switch_info); +return status; }@@ -2181,8 +2191,10 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid) sw_buf->res_type =cpu_to_le16 (res_type); status =ice_aq_alloc_free_res (hw, sw_buf, buf_len, ice_aqc_opc_alloc_res); -if (!status) +if (!status) { *rid =le16_to_cpu (sw_buf->elem[0 ].e.sw_resp); + hw->switch_info->recp_cnt++; + }return status; }@@ -2196,7 +2208,13 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid)*/ static int ice_free_recipe_res (struct ice_hw *hw,u16 rid) { -return ice_free_hw_res (hw,ICE_AQC_RES_TYPE_RECIPE ,1 , &rid); +int status; + + status =ice_free_hw_res (hw,ICE_AQC_RES_TYPE_RECIPE ,1 , &rid); +if (!status) + hw->switch_info->recp_cnt--; + +return status; }/** drivers/net/ethernet/intel/ice/ice_trace.h +18
-0@@ -330,6 +330,24 @@ DEFINE_EVENT(ice_esw_br_port_template,TP_ARGS (port) ); +DECLARE_EVENT_CLASS (ice_switch_stats_template, + TP_PROTO(struct ice_switch_info *sw_info), +TP_ARGS (sw_info), + TP_STRUCT__entry(__field(u16, rule_cnt) +__field (u8, recp_cnt)), + TP_fast_assign(__entry->rule_cnt = sw_info->rule_cnt; + __entry->recp_cnt = sw_info->recp_cnt;), +TP_printk ("rules=%u recipes=%u" , + __entry->rule_cnt, + __entry->recp_cnt) +); + +DEFINE_EVENT (ice_switch_stats_template, + ice_aq_sw_rules, + TP_PROTO(struct ice_switch_info *sw_info), +TP_ARGS (sw_info) +); +/* End tracepoints */ #endif /* _ICE_TRACE_H_ */ drivers/net/ethernet/intel/ice/ice_type.h +0
-0
drivers/net/ethernet/intel/ice/ice_type.h struct ice_switch_info { · line 771
Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_type.h +2
-0@@ -764,6 +764,8 @@ struct ice_switch_info {struct ice_sw_recipe *recp_list;u16 prof_res_bm_init;u16 max_used_prof_index; +u16 rule_cnt; +u8 recp_cnt;DECLARE_BITMAP (prof_res_bm[ICE_MAX_NUM_PROFILES ],ICE_MAX_FV_WORDS ); };
Kind regards,
Paul
Re: [Intel-wired-lan] [PATCH iwl-next v2 7/7] ice: Add tracepoint for adding and removing switch rules
Quoted 28 lines · Paul Menzel
Dear Marcin,
Thank you for your patch.
Am 24.06.24 um 16:45 schrieb Marcin Szycik:
Quoted 13 lines
Track the number of rules and recipes added to switch. Add a tracepoint to
ice_aq_sw_rules(), which shows both rule and recipe count. This information can be helpful when designing a set of rules to program to the hardware, as it shows where the practical limit is. Actual limits are known (64 recipes, 32k rules), but it's hard to translate these values to how many rules the *user* can actually create, because of extra metadata being implicitly added, and recipe/rule chaining. Chaining combines several recipes/rules to create a larger recipe/rule, so one large rule added by the user might actually consume multiple rules from hardware perspective.Rule counter is simply incremented/decremented in
ice_aq_sw_rules(), since all rules are added or removed via it.Quoted 8 lines
Counting recipes is harder, as recipes can't be removed (only overwritten). Recipes added via
ice_aq_add_recipe()could end up being unused, when there is an error in later stages of rule creation. Instead, track the allocation and freeing of recipes, which should reflect the actual usage of recipes (if something fails after recipe(s) were created, caller should free them). Also, a number of recipes are loaded from NVM by default - initialize the recipe counter with the number of these recipes on switch initialization.
Quoted 1 line
Can you please add an example how to use the tracepoint?
Sure, will add to next version.
Example configuration:
cd /sys/kernel/tracing
echo function > current_tracer
echo ice_aq_sw_rules > set_ftrace_filter
echo ice_aq_sw_rules > set_event
echo 1 > tracing_on
cat trace
Sample output:
tc-4097 [069] ...1. 787.595536: ice_aq_sw_rules <-ice_rem_adv_rule tc-4097 [069] ..... 787.595705: ice_aq_sw_rules: rules=9 recipes=15 tc-4098 [057] ...1. 787.652033: ice_aq_sw_rules <-ice_add_adv_rule tc-4098 [057] ..... 787.652201: ice_aq_sw_rules: rules=10 recipes=16
Thanks,
Marcin
Quoted 115 lines
Quoted 103 lines
Reviewed-by Michal Swiatkowski <[email protected]>Signed-off-by Marcin Szycik <[email protected]>---
drivers/net/ethernet/intel/ice/ice_common.c| 3 +++drivers/net/ethernet/intel/ice/ice_switch.c| 22 +++++++++++++++++++-- drivers/net/ethernet/intel/ice/ice_trace.h | 18 +++++++++++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 2 ++4 files changed, 43 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/ice/ice_common.c +0
-0@@ -934,6 +934,9 @@ static int ice_init_fltr_mgmt_struct(struct ice_hw *hw) INIT_LIST_HEAD(&sw->vsi_list_map_head); sw->prof_res_bm_init = 0;+ /* Initialize recipe count with default recipes read from NVM */ +
sw->recp_cnt=ICE_SW_LKUP_LAST;
+
status =ice_init_def_sw_recp(hw);
if (status) {
devm_kfree(ice_hw_to_dev(hw), hw->switch_info);drivers/net/ethernet/intel/ice/ice_switch.c +9
-0@@ -3,6 +3,7 @@ #include "ice_lib.h" #include "ice_switch.h" +#include "ice_trace.h" #define ICE_ETH_DA_OFFSET 0 #define ICE_ETH_ETHTYPE_OFFSET 12@@ -1961,6 +1962,15 @@ ice_aq_sw_rules(struct ice_hw *hw, void *rule_list, u16 rule_list_sz, hw->adminq.sq_last_status == ICE_AQ_RC_ENOENT) status = -ENOENT; + if (!status) { + if (opc == ice_aqc_opc_add_sw_rules) + hw->switch_info->rule_cnt += num_rules; + else if (opc == ice_aqc_opc_remove_sw_rules) + hw->switch_info->rule_cnt -= num_rules; + } + + trace_ice_aq_sw_rules(hw->switch_info); + return status; } @@ -2181,8 +2191,10 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid)
sw_buf->res_type=cpu_to_le16(res_type); status =ice_aq_alloc_free_res(hw, sw_buf, buf_len, ice_aqc_opc_alloc_res); - if (!status)
+ if (!status) {
*rid =le16_to_cpu(sw_buf->elem[0].e.sw_resp); + hw->switch_info->recp_cnt++;
+ }
return status;
}drivers/net/ethernet/intel/ice/ice_switch.c +7
-1@@ -2196,7 +2208,13 @@ int ice_alloc_recipe(struct ice_hw *hw, u16 *rid)*/ static int ice_free_recipe_res(struct ice_hw *hw, u16 rid) { - return ice_free_hw_res(hw, ICE_AQC_RES_TYPE_RECIPE, 1, &rid); + int status; + + status = ice_free_hw_res(hw, ICE_AQC_RES_TYPE_RECIPE, 1, &rid); + if (!status) + hw->switch_info->recp_cnt--; + + return status; } /**drivers/net/ethernet/intel/ice/ice_trace.h +17
-0@@ -330,6 +330,24 @@ DEFINE_EVENT(ice_esw_br_port_template, TP_ARGS(port) ); +DECLARE_EVENT_CLASS(ice_switch_stats_template, + TP_PROTO(struct ice_switch_info *sw_info), + TP_ARGS(sw_info), + TP_STRUCT__entry(__field(u16, rule_cnt) + __field(u8, recp_cnt)), + TP_fast_assign(__entry->rule_cnt = sw_info->rule_cnt; + __entry->recp_cnt = sw_info->recp_cnt;), + TP_printk("rules=%u recipes=%u", + __entry->rule_cnt, + __entry->recp_cnt) +); + +DEFINE_EVENT (ice_switch_stats_template, + ice_aq_sw_rules, + TP_PROTO(struct ice_switch_info *sw_info), + TP_ARGS(sw_info) +); + /* End tracepoints */ #endif /* _ICE_TRACE_H_ */drivers/net/ethernet/intel/ice/ice_type.h +0
-0drivers/net/ethernet/intel/ice/ice_type.h struct ice_switch_info { · line 770
Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_type.h +2
-0@@ -764,6 +764,8 @@ struct ice_switch_info { struct ice_sw_recipe *recp_list; u16 prof_res_bm_init; u16 max_used_prof_index; + u16 rule_cnt; + u8 recp_cnt; DECLARE_BITMAP(prof_res_bm[ICE_MAX_NUM_PROFILES], ICE_MAX_FV_WORDS); };Kind regards,
Paul