Skip to content

Commit 7d62713

Browse files
dtatuleamstsirkin
authored andcommitted
net/mlx5: Support throttled commands from async API
Currently, commands that qualify as throttled can't be used via the async API. That's due to the fact that the throttle semaphore can sleep but the async API can't. This patch allows throttling in the async API by using the tentative variant of the semaphore and upon failure (semaphore at 0) returns EBUSY to signal to the caller that they need to wait for the completion of previously issued commands. Furthermore, make sure that the semaphore is released in the callback. Signed-off-by: Dragos Tatulea <[email protected]> Cc: Leon Romanovsky <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent 6d17035 commit 7d62713

File tree

1 file changed

+16
-5
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+16
-5
lines changed

drivers/net/ethernet/mellanox/mlx5/core/cmd.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,10 +1882,12 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
18821882

18831883
throttle_op = mlx5_cmd_is_throttle_opcode(opcode);
18841884
if (throttle_op) {
1885-
/* atomic context may not sleep */
1886-
if (callback)
1887-
return -EINVAL;
1888-
down(&dev->cmd.vars.throttle_sem);
1885+
if (callback) {
1886+
if (down_trylock(&dev->cmd.vars.throttle_sem))
1887+
return -EBUSY;
1888+
} else {
1889+
down(&dev->cmd.vars.throttle_sem);
1890+
}
18891891
}
18901892

18911893
pages_queue = is_manage_pages(in);
@@ -2091,10 +2093,19 @@ static void mlx5_cmd_exec_cb_handler(int status, void *_work)
20912093
{
20922094
struct mlx5_async_work *work = _work;
20932095
struct mlx5_async_ctx *ctx;
2096+
struct mlx5_core_dev *dev;
2097+
u16 opcode;
20942098

20952099
ctx = work->ctx;
2096-
status = cmd_status_err(ctx->dev, status, work->opcode, work->op_mod, work->out);
2100+
dev = ctx->dev;
2101+
opcode = work->opcode;
2102+
status = cmd_status_err(dev, status, work->opcode, work->op_mod, work->out);
20972103
work->user_callback(status, work);
2104+
/* Can't access "work" from this point on. It could have been freed in
2105+
* the callback.
2106+
*/
2107+
if (mlx5_cmd_is_throttle_opcode(opcode))
2108+
up(&dev->cmd.vars.throttle_sem);
20982109
if (atomic_dec_and_test(&ctx->num_inflight))
20992110
complete(&ctx->inflight_done);
21002111
}

0 commit comments

Comments
 (0)