From: Ido Schimmel <idosch@mellanox.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
Jiri Pirko <jiri@mellanox.com>, mlxsw <mlxsw@mellanox.com>,
Ido Schimmel <idosch@mellanox.com>
Subject: [PATCH net-next 12/14] mlxsw: spectrum_acl: Allow to interrupt/continue rehash work
Date: Thu, 28 Feb 2019 06:59:25 +0000 [thread overview]
Message-ID: <20190228065850.7471-13-idosch@mellanox.com> (raw)
In-Reply-To: <20190228065850.7471-1-idosch@mellanox.com>
From: Jiri Pirko <jiri@mellanox.com>
Currently, migration of vregions with many entries may take long time
during which insertions and removals of the rules are blocked
due to wait to acquire vregion->lock.
To overcome this, allow to interrupt and continue rehash work according
to the set credits - number of rules to migrate.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
.../mellanox/mlxsw/spectrum_acl_tcam.c | 82 ++++++++++++++-----
1 file changed, 62 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
index 9dc83815644e..cfd05af3f0f6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c
@@ -27,6 +27,7 @@ size_t mlxsw_sp_acl_tcam_priv_size(struct mlxsw_sp *mlxsw_sp)
#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT 5000 /* ms */
#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN 3000 /* ms */
+#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS 100 /* number of entries */
int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam *tcam)
@@ -732,16 +733,26 @@ mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(struct mlxsw_sp_acl_tcam_vregion
static int
mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,
- struct mlxsw_sp_acl_tcam_vregion *vregion);
+ struct mlxsw_sp_acl_tcam_vregion *vregion,
+ int *credits);
static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work)
{
struct mlxsw_sp_acl_tcam_vregion *vregion =
container_of(work, struct mlxsw_sp_acl_tcam_vregion,
rehash.dw.work);
+ int credits = MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS;
+ int err;
- mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, vregion);
- mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion);
+ err = mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp,
+ vregion, &credits);
+ if (credits < 0)
+ /* Rehash gone out of credits so it was interrupted.
+ * Schedule the work as soon as possible to continue.
+ */
+ mlxsw_core_schedule_dw(&vregion->rehash.dw, 0);
+ else
+ mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion);
}
static struct mlxsw_sp_acl_tcam_vregion *
@@ -1176,7 +1187,8 @@ mlxsw_sp_acl_tcam_ventry_activity_get(struct mlxsw_sp *mlxsw_sp,
static int
mlxsw_sp_acl_tcam_ventry_migrate(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_ventry *ventry,
- struct mlxsw_sp_acl_tcam_chunk *chunk)
+ struct mlxsw_sp_acl_tcam_chunk *chunk,
+ int *credits)
{
struct mlxsw_sp_acl_tcam_entry *new_entry;
@@ -1184,6 +1196,9 @@ mlxsw_sp_acl_tcam_ventry_migrate(struct mlxsw_sp *mlxsw_sp,
if (ventry->entry->chunk == chunk)
return 0;
+ if (--(*credits) < 0)
+ return 0;
+
new_entry = mlxsw_sp_acl_tcam_entry_create(mlxsw_sp, ventry, chunk);
if (IS_ERR(new_entry))
return PTR_ERR(new_entry);
@@ -1223,7 +1238,8 @@ static int
mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_vchunk *vchunk,
struct mlxsw_sp_acl_tcam_region *region,
- struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
+ struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
+ int *credits)
{
struct mlxsw_sp_acl_tcam_ventry *ventry;
int err;
@@ -1240,7 +1256,7 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp,
list_for_each_entry(ventry, &vchunk->ventry_list, list) {
err = mlxsw_sp_acl_tcam_ventry_migrate(mlxsw_sp, ventry,
- vchunk->chunk);
+ vchunk->chunk, credits);
if (err) {
if (ctx->this_is_rollback)
return err;
@@ -1250,6 +1266,11 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp,
*/
swap(vchunk->chunk, vchunk->chunk2);
return err;
+ } else if (*credits < 0) {
+ /* We are out of credits, the rest of the ventries
+ * will be migrated later.
+ */
+ return 0;
}
}
@@ -1260,7 +1281,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp,
static int
mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_vregion *vregion,
- struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
+ struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
+ int *credits)
{
struct mlxsw_sp_acl_tcam_vchunk *vchunk;
int err;
@@ -1268,8 +1290,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp,
list_for_each_entry(vchunk, &vregion->vchunk_list, list) {
err = mlxsw_sp_acl_tcam_vchunk_migrate_one(mlxsw_sp, vchunk,
vregion->region,
- ctx);
- if (err)
+ ctx, credits);
+ if (err || *credits < 0)
return err;
}
return 0;
@@ -1278,13 +1300,15 @@ mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp,
static int
mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_vregion *vregion,
- struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
+ struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
+ int *credits)
{
int err, err2;
trace_mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion);
mutex_lock(&vregion->lock);
- err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx);
+ err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion,
+ ctx, credits);
if (err) {
/* In case migration was not successful, we need to swap
* so the original region pointer is assigned again
@@ -1292,7 +1316,8 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
*/
swap(vregion->region, vregion->region2);
ctx->this_is_rollback = true;
- err2 = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx);
+ err2 = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion,
+ ctx, credits);
if (err2)
vregion->failed_rollback = true;
}
@@ -1301,6 +1326,12 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
return err;
}
+static bool
+mlxsw_sp_acl_tcam_vregion_rehash_in_progress(const struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
+{
+ return ctx->hints_priv;
+}
+
static int
mlxsw_sp_acl_tcam_vregion_rehash_start(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_tcam_vregion *vregion,
@@ -1372,19 +1403,28 @@ mlxsw_sp_acl_tcam_vregion_rehash_end(struct mlxsw_sp *mlxsw_sp,
static int
mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,
- struct mlxsw_sp_acl_tcam_vregion *vregion)
+ struct mlxsw_sp_acl_tcam_vregion *vregion,
+ int *credits)
{
struct mlxsw_sp_acl_tcam_rehash_ctx *ctx = &vregion->rehash.ctx;
int err;
- err = mlxsw_sp_acl_tcam_vregion_rehash_start(mlxsw_sp, vregion, ctx);
- if (err) {
- if (err != -EAGAIN)
- dev_err(mlxsw_sp->bus_info->dev, "Failed get rehash hints\n");
- return err;
+ /* Check if the previous rehash work was interrupted
+ * which means we have to continue it now.
+ * If not, start a new rehash.
+ */
+ if (!mlxsw_sp_acl_tcam_vregion_rehash_in_progress(ctx)) {
+ err = mlxsw_sp_acl_tcam_vregion_rehash_start(mlxsw_sp,
+ vregion, ctx);
+ if (err) {
+ if (err != -EAGAIN)
+ dev_err(mlxsw_sp->bus_info->dev, "Failed get rehash hints\n");
+ return err;
+ }
}
- err = mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion, ctx);
+ err = mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion,
+ ctx, credits);
if (err) {
dev_err(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n");
if (vregion->failed_rollback) {
@@ -1394,7 +1434,9 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,
}
}
- mlxsw_sp_acl_tcam_vregion_rehash_end(mlxsw_sp, vregion, ctx);
+ if (*credits >= 0)
+ mlxsw_sp_acl_tcam_vregion_rehash_end(mlxsw_sp, vregion, ctx);
+
return err;
}
--
2.20.1
next prev parent reply other threads:[~2019-02-28 6:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 6:59 [PATCH net-next 00/14] mlxsw: spectrum_acl: Split rehash work into chunks Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 01/14] mlxsw: spectrum_acl: Push rehash dw struct into rehash sub-struct Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 02/14] mlxsw: spectrum_acl: Don't migrate already migrated entry Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 03/14] mlxsw: spectrum_acl: Introduce new rehash context struct and save hint_priv there Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 05/14] mlxsw: spectrum_acl: Push code start/end from mlxsw_sp_acl_tcam_vregion_migrate() Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 04/14] mlxsw: spectrum_acl: Push rehash start/end code into separate functions Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 06/14] mlxsw: spectrum_acl: assign vregion->region by the newly created region Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 07/14] mlxsw: spectrum_acl: assign vchunk->chunk by the newly created chunk Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 08/14] mlxsw: spectrum_acl: Rename variables in mlxsw_sp_acl_tcam_ventry_migrate() Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 09/14] mlxsw: spectrum_acl: Put this_is_rollback to rehash context struct Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 10/14] mlxsw: spectrum_acl: Put vchunk migrate start/end code into separate functions Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 11/14] mlxsw: spectrum_acl: Do rollback as another call to mlxsw_sp_acl_tcam_vchunk_migrate_all() Ido Schimmel
2019-02-28 6:59 ` Ido Schimmel [this message]
2019-02-28 6:59 ` [PATCH net-next 13/14] mlxsw: spectrum_acl: Remember where to continue rehash migration Ido Schimmel
2019-02-28 6:59 ` [PATCH net-next 14/14] mlxsw: spectrum_acl: Make mlxsw_sp_acl_tcam_vregion_rehash() return void Ido Schimmel
2019-03-02 5:44 ` [PATCH net-next 00/14] mlxsw: spectrum_acl: Split rehash work into chunks David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190228065850.7471-13-idosch@mellanox.com \
--to=idosch@mellanox.com \
--cc=davem@davemloft.net \
--cc=jiri@mellanox.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox