diff --git a/wd_cipher.c b/wd_cipher.c index 7d7525e2..413734c2 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -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 @@ -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; } @@ -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; } diff --git a/wd_comp.c b/wd_comp.c index 9d4de40a..826fc2ac 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -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 @@ -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; } @@ -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; } diff --git a/wd_digest.c b/wd_digest.c index c2d0fcca..7d45e41b 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -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; @@ -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; } @@ -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; }