Skip to content

Commit

Permalink
uadk: support switch between hw and sw
Browse files Browse the repository at this point in the history
case 1: sync or async error, switch worker
case 2: roundrobin mode, switch worker after worker->looptime (10)

Signed-off-by: Zhangfei Gao <[email protected]>
  • Loading branch information
zhangfeigao committed Dec 26, 2024
1 parent 744cf24 commit f4fc058
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
36 changes: 36 additions & 0 deletions wd_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ struct wd_cipher_sess {
struct wd_env_config wd_cipher_env_config;
static struct wd_init_attrs wd_cipher_init_attrs;

void wd_cipher_switch_worker(struct wd_cipher_sess *sess, int para)
{
struct uadk_adapter_worker *worker;

pthread_spin_lock(&sess->worker_lock);
worker = uadk_adapter_switch_worker(wd_cipher_setting.adapter,
sess->worker, para);
if (worker)
sess->worker = worker;
sess->worker_looptime = 0;
pthread_spin_unlock(&sess->worker_lock);
}

static void wd_cipher_close_driver(int init_type)
{
#ifndef WD_STATIC_DRV
Expand Down Expand Up @@ -742,6 +755,20 @@ int wd_do_cipher_sync(handle_t h_sess, struct wd_cipher_req *req)
ret = send_recv_sync(worker, ctx, &msg);
req->state = msg.result;

if (ret) {
wd_cipher_switch_worker(sess, 1);
sess->worker_looptime++;
return ret;
}

if ((sess->worker_looptime != 0) ||
(wd_cipher_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN)) {
sess->worker_looptime++;
}

if (sess->worker_looptime >= wd_cipher_setting.adapter->looptime)
wd_cipher_switch_worker(sess, 0);

return ret;
}

Expand Down Expand Up @@ -795,10 +822,19 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
if (ret)
goto fail_with_msg;

if ((sess->worker_looptime != 0) ||
(wd_cipher_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN))
sess->worker_looptime++;

if (sess->worker_looptime >= wd_cipher_setting.adapter->looptime)
wd_cipher_switch_worker(sess, 0);

return 0;

fail_with_msg:
wd_put_msg_to_pool(&worker->pool, idx, msg->tag);
wd_cipher_switch_worker(sess, 1);
sess->worker_looptime++;
return ret;
}

Expand Down
37 changes: 36 additions & 1 deletion wd_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ struct wd_comp_setting {
struct wd_env_config wd_comp_env_config;
static struct wd_init_attrs wd_comp_init_attrs;

void wd_comp_switch_worker(struct wd_comp_sess *sess, int para)
{
struct uadk_adapter_worker *worker;

pthread_spin_lock(&sess->worker_lock);
worker = uadk_adapter_switch_worker(wd_comp_setting.adapter,
sess->worker, para);
if (worker)
sess->worker = worker;
sess->worker_looptime = 0;
pthread_spin_unlock(&sess->worker_lock);
}

static void wd_comp_close_driver(int init_type)
{
#ifndef WD_STATIC_DRV
Expand Down Expand Up @@ -639,6 +652,20 @@ static int wd_comp_sync_job(struct wd_comp_sess *sess,
msg, NULL, worker->config.epoll_en);
pthread_spin_unlock(&ctx->lock);

if (ret) {
wd_comp_switch_worker(sess, 1);
sess->worker_looptime++;
return ret;
}

if ((sess->worker_looptime != 0) ||
(wd_comp_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN)) {
sess->worker_looptime++;
}

if (sess->worker_looptime >= wd_comp_setting.adapter->looptime)
wd_comp_switch_worker(sess, 0);

return ret;
}

Expand Down Expand Up @@ -904,11 +931,19 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
if (unlikely(ret))
goto fail_with_msg;

if ((sess->worker_looptime != 0) ||
(wd_comp_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN))
sess->worker_looptime++;

if (sess->worker_looptime >= wd_comp_setting.adapter->looptime)
wd_comp_switch_worker(sess, 0);

return 0;

fail_with_msg:
wd_put_msg_to_pool(&worker->pool, idx, msg->tag);

wd_comp_switch_worker(sess, 1);
sess->worker_looptime++;
return ret;
}

Expand Down
35 changes: 35 additions & 0 deletions wd_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ struct wd_digest_sess {
int worker_looptime;
};

void wd_digest_switch_worker(struct wd_digest_sess *sess, int para)
{
struct uadk_adapter_worker *worker;

pthread_spin_lock(&sess->worker_lock);
worker = uadk_adapter_switch_worker(wd_digest_setting.adapter,
sess->worker, para);
if (worker)
sess->worker = worker;
sess->worker_looptime = 0;
pthread_spin_unlock(&sess->worker_lock);
}

struct wd_env_config wd_digest_env_config;
static struct wd_init_attrs wd_digest_init_attrs;

Expand Down Expand Up @@ -694,6 +707,19 @@ int wd_do_digest_sync(handle_t h_sess, struct wd_digest_req *req)
ret = send_recv_sync(worker, ctx, dsess, &msg);
req->state = msg.result;

if (ret) {
wd_digest_switch_worker(dsess, 1);
dsess->worker_looptime++;
return ret;
}

if ((dsess->worker_looptime != 0) ||
(wd_digest_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN))
dsess->worker_looptime++;

if (dsess->worker_looptime >= wd_digest_setting.adapter->looptime)
wd_digest_switch_worker(dsess, 0);

return ret;
}

Expand Down Expand Up @@ -751,10 +777,19 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
if (ret)
goto fail_with_msg;

if ((dsess->worker_looptime != 0) ||
(wd_digest_setting.adapter->mode == UADK_ADAPT_MODE_ROUNDROBIN))
dsess->worker_looptime++;

if (dsess->worker_looptime >= wd_digest_setting.adapter->looptime)
wd_digest_switch_worker(dsess, 0);

return 0;

fail_with_msg:
wd_put_msg_to_pool(&worker->pool, idx, msg->tag);
wd_digest_switch_worker(dsess, 1);
dsess->worker_looptime++;
return ret;
}

Expand Down

0 comments on commit f4fc058

Please sign in to comment.