Skip to content

Commit

Permalink
uadk: simulate async mode for driver only support sync
Browse files Browse the repository at this point in the history
There may driver does not support async mode.
The operation is finished when send is over.
So we can simulate async mode just return the correct number

Signed-off-by: Zhangfei Gao <[email protected]>
  • Loading branch information
zhangfeigao committed Jan 4, 2025
1 parent 3fc0fc5 commit f1779e9
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 5 deletions.
9 changes: 9 additions & 0 deletions adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static void read_config_entries(char *conf, struct uadk_adapter *adapter, char *
worker = &adapter->workers[i];
worker->driver = drv;
worker->idx = i;
pthread_mutex_init(&worker->mutex, NULL);
adapter->workers_nb++;
if (drv_name) {
free(drv_name);
Expand Down Expand Up @@ -133,6 +134,7 @@ int uadk_adapter_add_workers(struct uadk_adapter *adapter, char *alg)
adapter->workers[i].driver = workers[i].driver;
adapter->workers[i].idx = i;
adapter->workers_nb++;
pthread_mutex_init(&adapter->workers[i].mutex, NULL);

if (adapter->workers_nb >= UADK_MAX_NB_WORKERS)
break;
Expand Down Expand Up @@ -179,3 +181,10 @@ struct uadk_adapter_worker *uadk_adapter_switch_worker(

return new_worker;
}

void uadk_adapter_free(struct uadk_adapter *adapter)
{
for (int i = 0; i < adapter->workers_nb; i++)
pthread_mutex_destroy(&adapter->workers[i].mutex);
free(adapter);
}
1 change: 1 addition & 0 deletions drv/isa_ce_sm3.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static struct wd_alg_driver sm3_ce_alg_driver = {
.drv_name = "isa_ce_sm3",
.alg_name = "sm3",
.calc_type = UADK_ALG_CE_INSTR,
.mode = UADK_DRV_SYNCONLY,
.priority = 200,
.queue_num = 1,
.op_type_num = 1,
Expand Down
1 change: 1 addition & 0 deletions drv/isa_ce_sm4.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg)
.drv_name = "isa_ce_sm4",\
.alg_name = (ce_alg_name),\
.calc_type = UADK_ALG_CE_INSTR,\
.mode = UADK_DRV_SYNCONLY,\
.priority = 200,\
.op_type_num = 1,\
.fallback = 0,\
Expand Down
5 changes: 5 additions & 0 deletions include/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct uadk_adapter_worker {
struct wd_async_msg_pool pool;
bool valid;
int idx;
__u64 async_recv;
__u64 poll_recv;
pthread_mutex_t mutex;
};

struct uadk_adapter {
Expand All @@ -47,4 +50,6 @@ struct uadk_adapter_worker *uadk_adapter_switch_worker(
struct uadk_adapter_worker *worker,
int para
);

void uadk_adapter_free(struct uadk_adapter *adapter);
#endif
6 changes: 6 additions & 0 deletions include/wd_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ enum alg_dev_type {
UADK_ALG_HW = 0x3
};

enum alg_drv_mode {
UADK_DRV_NORMAL = 0x0,
UADK_DRV_SYNCONLY = 0x1,
};

/*
* @drv_name: name of the current device driver
* @alg_name: name of the algorithm supported by the driver
Expand Down Expand Up @@ -102,6 +107,7 @@ struct wd_alg_driver {
const char *alg_name;
int priority;
int calc_type;
int mode;
int queue_num;
int op_type_num;
void *priv;
Expand Down
1 change: 1 addition & 0 deletions libwd.map
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ global:
uadk_adapter_add_workers;
uadk_adapter_choose_worker;
uadk_adapter_switch_worker;
uadk_adapter_free;
local: *;
};
23 changes: 23 additions & 0 deletions wd_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,17 @@ int wd_do_cipher_async(handle_t h_sess, struct wd_cipher_req *req)
worker = sess->worker;
pthread_spin_unlock(&sess->worker_lock);

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
ret = wd_do_cipher_sync(h_sess, req);
if (!ret) {
pthread_mutex_lock(&worker->mutex);
worker->async_recv++;
pthread_mutex_unlock(&worker->mutex);
req->cb(req, req->cb_param);
}
return ret;
}

idx = worker->sched->pick_next_ctx(
worker->sched->h_sched_ctx,
sess->sched_key[worker->idx], CTX_MODE_ASYNC);
Expand Down Expand Up @@ -861,6 +872,18 @@ int wd_cipher_poll_ctx_(struct wd_sched *sched, __u32 idx, __u32 expt, __u32 *co

*count = 0;

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
pthread_mutex_lock(&worker->mutex);
recv_count = worker->async_recv - worker->poll_recv;
if (recv_count >= expt)
*count = expt;
else
*count = recv_count;
worker->poll_recv += *count;
pthread_mutex_unlock(&worker->mutex);
return 0;
}

ret = wd_check_ctx(&worker->config, CTX_MODE_ASYNC, idx);
if (ret)
return ret;
Expand Down
27 changes: 22 additions & 5 deletions wd_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ int wd_comp_poll_ctx_(struct wd_sched *sched, __u32 idx, __u32 expt, __u32 *coun

*count = 0;

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
pthread_mutex_lock(&worker->mutex);
recv_count = worker->async_recv - worker->poll_recv;
if (recv_count >= expt)
*count = expt;
else
*count = recv_count;
worker->poll_recv += *count;
pthread_mutex_unlock(&worker->mutex);
return 0;
}

ret = wd_check_ctx(&worker->config, CTX_MODE_ASYNC, idx);
if (unlikely(ret))
return ret;
Expand Down Expand Up @@ -612,11 +624,6 @@ static int wd_comp_check_params(struct wd_comp_sess *sess,
return -WD_EINVAL;
}

if (unlikely(mode == CTX_MODE_SYNC && req->cb)) {
WD_ERR("invalid: sync comp cb should be NULL!\n");
return -WD_EINVAL;
}

return 0;
}

Expand Down Expand Up @@ -902,6 +909,16 @@ int wd_do_comp_async(handle_t h_sess, struct wd_comp_req *req)
worker = sess->worker;
pthread_spin_unlock(&sess->worker_lock);

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
ret = wd_do_comp_sync(h_sess, req);
if (!ret) {
pthread_mutex_lock(&worker->mutex);
worker->async_recv++;
pthread_mutex_unlock(&worker->mutex);
req->cb(req, req->cb_param);
}
return ret;
}
idx = worker->sched->pick_next_ctx(
worker->sched->h_sched_ctx,
sess->sched_key[worker->idx], CTX_MODE_ASYNC);
Expand Down
23 changes: 23 additions & 0 deletions wd_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ int wd_do_digest_async(handle_t h_sess, struct wd_digest_req *req)
worker = dsess->worker;
pthread_spin_unlock(&dsess->worker_lock);

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
ret = wd_do_digest_sync(h_sess, req);
if (!ret) {
pthread_mutex_lock(&worker->mutex);
worker->async_recv++;
pthread_mutex_unlock(&worker->mutex);
req->cb(req);
}
return ret;
}

idx = worker->sched->pick_next_ctx(
worker->sched->h_sched_ctx,
dsess->sched_key[worker->idx], CTX_MODE_ASYNC);
Expand Down Expand Up @@ -816,6 +827,18 @@ int wd_digest_poll_ctx_(struct wd_sched *sched, __u32 idx, __u32 expt, __u32 *co

*count = 0;

if (worker->driver->mode == UADK_DRV_SYNCONLY) {
pthread_mutex_lock(&worker->mutex);
recv_cnt = worker->async_recv - worker->poll_recv;
if (recv_cnt >= expt)
*count = expt;
else
*count = recv_cnt;
worker->poll_recv += *count;
pthread_mutex_unlock(&worker->mutex);
return 0;
}

ret = wd_check_ctx(&worker->config, CTX_MODE_ASYNC, idx);
if (ret)
return ret;
Expand Down

0 comments on commit f1779e9

Please sign in to comment.