Skip to content

Commit

Permalink
lib: objagg: implement optimization hints assembly and use hints for …
Browse files Browse the repository at this point in the history
…object creation

Implement simple greedy algo to find more optimized root-delta tree for
a given objagg instance. This "hints" can be used by a driver to:
1) check if the hints are better (driver's choice) than the original
   objagg tree. Driver does comparison of objagg stats and hints stats.
2) use the hints to create a new objagg instance which will construct
   the root-delta tree according to the passed hints. Currently, only a
   simple greedy algorithm is implemented. Basically it finds the roots
   according to the maximal possible user count including deltas.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
jpirko authored and davem330 committed Feb 8, 2019
1 parent bb72e68 commit 9069a38
Show file tree
Hide file tree
Showing 4 changed files with 802 additions and 22 deletions.
37 changes: 35 additions & 2 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,32 @@ mlxsw_sp_acl_erp_delta_fill(const struct mlxsw_sp_acl_erp_key *parent_key,
return 0;
}

static bool mlxsw_sp_acl_erp_delta_check(void *priv, const void *parent_obj,
const void *obj)
{
const struct mlxsw_sp_acl_erp_key *parent_key = parent_obj;
const struct mlxsw_sp_acl_erp_key *key = obj;
u16 delta_start;
u8 delta_mask;
int err;

err = mlxsw_sp_acl_erp_delta_fill(parent_key, key,
&delta_start, &delta_mask);
return err ? false : true;
}

static int mlxsw_sp_acl_erp_hints_obj_cmp(const void *obj1, const void *obj2)
{
const struct mlxsw_sp_acl_erp_key *key1 = obj1;
const struct mlxsw_sp_acl_erp_key *key2 = obj2;

/* For hints purposes, two objects are considered equal
* in case the masks are the same. Does not matter what
* the "ctcam" value is.
*/
return memcmp(key1->mask, key2->mask, sizeof(key1->mask));
}

static void *mlxsw_sp_acl_erp_delta_create(void *priv, void *parent_obj,
void *obj)
{
Expand Down Expand Up @@ -1254,12 +1280,17 @@ static void mlxsw_sp_acl_erp_delta_destroy(void *priv, void *delta_priv)
kfree(delta);
}

static void *mlxsw_sp_acl_erp_root_create(void *priv, void *obj)
static void *mlxsw_sp_acl_erp_root_create(void *priv, void *obj,
unsigned int root_id)
{
struct mlxsw_sp_acl_atcam_region *aregion = priv;
struct mlxsw_sp_acl_erp_table *erp_table = aregion->erp_table;
struct mlxsw_sp_acl_erp_key *key = obj;

if (!key->ctcam &&
root_id != OBJAGG_OBJ_ROOT_ID_INVALID &&
root_id >= MLXSW_SP_ACL_ERP_MAX_PER_REGION)
return ERR_PTR(-ENOBUFS);
return erp_table->ops->erp_create(erp_table, key);
}

Expand All @@ -1273,6 +1304,8 @@ static void mlxsw_sp_acl_erp_root_destroy(void *priv, void *root_priv)

static const struct objagg_ops mlxsw_sp_acl_erp_objagg_ops = {
.obj_size = sizeof(struct mlxsw_sp_acl_erp_key),
.delta_check = mlxsw_sp_acl_erp_delta_check,
.hints_obj_cmp = mlxsw_sp_acl_erp_hints_obj_cmp,
.delta_create = mlxsw_sp_acl_erp_delta_create,
.delta_destroy = mlxsw_sp_acl_erp_delta_destroy,
.root_create = mlxsw_sp_acl_erp_root_create,
Expand All @@ -1290,7 +1323,7 @@ mlxsw_sp_acl_erp_table_create(struct mlxsw_sp_acl_atcam_region *aregion)
return ERR_PTR(-ENOMEM);

erp_table->objagg = objagg_create(&mlxsw_sp_acl_erp_objagg_ops,
aregion);
NULL, aregion);
if (IS_ERR(erp_table->objagg)) {
err = PTR_ERR(erp_table->objagg);
goto err_objagg_create;
Expand Down
20 changes: 18 additions & 2 deletions include/linux/objagg.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@

struct objagg_ops {
size_t obj_size;
bool (*delta_check)(void *priv, const void *parent_obj,
const void *obj);
int (*hints_obj_cmp)(const void *obj1, const void *obj2);
void * (*delta_create)(void *priv, void *parent_obj, void *obj);
void (*delta_destroy)(void *priv, void *delta_priv);
void * (*root_create)(void *priv, void *obj);
void * (*root_create)(void *priv, void *obj, unsigned int root_id);
#define OBJAGG_OBJ_ROOT_ID_INVALID UINT_MAX
void (*root_destroy)(void *priv, void *root_priv);
};

struct objagg;
struct objagg_obj;
struct objagg_hints;

const void *objagg_obj_root_priv(const struct objagg_obj *objagg_obj);
const void *objagg_obj_delta_priv(const struct objagg_obj *objagg_obj);
const void *objagg_obj_raw(const struct objagg_obj *objagg_obj);

struct objagg_obj *objagg_obj_get(struct objagg *objagg, void *obj);
void objagg_obj_put(struct objagg *objagg, struct objagg_obj *objagg_obj);
struct objagg *objagg_create(const struct objagg_ops *ops, void *priv);
struct objagg *objagg_create(const struct objagg_ops *ops,
struct objagg_hints *hints, void *priv);
void objagg_destroy(struct objagg *objagg);

struct objagg_obj_stats {
Expand All @@ -43,4 +49,14 @@ struct objagg_stats {
const struct objagg_stats *objagg_stats_get(struct objagg *objagg);
void objagg_stats_put(const struct objagg_stats *objagg_stats);

enum objagg_opt_algo_type {
OBJAGG_OPT_ALGO_SIMPLE_GREEDY,
};

struct objagg_hints *objagg_hints_get(struct objagg *objagg,
enum objagg_opt_algo_type opt_algo_type);
void objagg_hints_put(struct objagg_hints *objagg_hints);
const struct objagg_stats *
objagg_hints_stats_get(struct objagg_hints *objagg_hints);

#endif
Loading

0 comments on commit 9069a38

Please sign in to comment.