Skip to content

Commit 0f4146f

Browse files
Hui Tangherbertx
authored andcommitted
crypto: hisilicon/hpre - Optimize finding hpre device process
Optimize finding hpre device process according to priority of numa distance. Signed-off-by: Hui Tang <[email protected]> Signed-off-by: Shukun Tan <[email protected]> Reviewed-by: Zhou Wang <[email protected]> Reviewed-by: Zaibo Xu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 18f1ab3 commit 0f4146f

File tree

3 files changed

+20
-55
lines changed

3 files changed

+20
-55
lines changed

drivers/crypto/hisilicon/hpre/hpre.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct hpre_debug {
4646

4747
struct hpre {
4848
struct hisi_qm qm;
49-
struct list_head list;
5049
struct hpre_debug debug;
5150
u32 num_vfs;
5251
unsigned long status;
@@ -76,7 +75,7 @@ struct hpre_sqe {
7675
__le32 rsvd1[_HPRE_SQE_ALIGN_EXT];
7776
};
7877

79-
struct hpre *hpre_find_device(int node);
78+
struct hisi_qp *hpre_create_qp(void);
8079
int hpre_algs_register(void);
8180
void hpre_algs_unregister(void);
8281

drivers/crypto/hisilicon/hpre/hpre_crypto.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,18 @@ static void hpre_rm_req_from_ctx(struct hpre_asym_request *hpre_req)
147147
static struct hisi_qp *hpre_get_qp_and_start(void)
148148
{
149149
struct hisi_qp *qp;
150-
struct hpre *hpre;
151150
int ret;
152151

153-
/* find the proper hpre device, which is near the current CPU core */
154-
hpre = hpre_find_device(cpu_to_node(smp_processor_id()));
155-
if (!hpre) {
156-
pr_err("Can not find proper hpre device!\n");
157-
return ERR_PTR(-ENODEV);
158-
}
159-
160-
qp = hisi_qm_create_qp(&hpre->qm, 0);
161-
if (IS_ERR(qp)) {
162-
pci_err(hpre->qm.pdev, "Can not create qp!\n");
152+
qp = hpre_create_qp();
153+
if (!qp) {
154+
pr_err("Can not create hpre qp!\n");
163155
return ERR_PTR(-ENODEV);
164156
}
165157

166158
ret = hisi_qm_start_qp(qp, 0);
167159
if (ret < 0) {
168-
hisi_qm_release_qp(qp);
169-
pci_err(hpre->qm.pdev, "Can not start qp!\n");
160+
hisi_qm_free_qps(&qp, 1);
161+
pci_err(qp->qm->pdev, "Can not start qp!\n");
170162
return ERR_PTR(-EINVAL);
171163
}
172164

@@ -338,7 +330,7 @@ static void hpre_ctx_clear(struct hpre_ctx *ctx, bool is_clear_all)
338330
if (is_clear_all) {
339331
idr_destroy(&ctx->req_idr);
340332
kfree(ctx->req_list);
341-
hisi_qm_release_qp(ctx->qp);
333+
hisi_qm_free_qps(&ctx->qp, 1);
342334
}
343335

344336
ctx->crt_g2_mode = false;

drivers/crypto/hisilicon/hpre/hpre_main.c

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282

8383
#define HPRE_VIA_MSI_DSM 1
8484

85-
static LIST_HEAD(hpre_list);
86-
static DEFINE_MUTEX(hpre_list_lock);
85+
static struct hisi_qm_list hpre_devices;
8786
static const char hpre_name[] = "hisi_hpre";
8887
static struct dentry *hpre_debugfs_root;
8988
static const struct pci_device_id hpre_dev_ids[] = {
@@ -196,43 +195,17 @@ static u32 hpre_pf_q_num = HPRE_PF_DEF_Q_NUM;
196195
module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444);
197196
MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)");
198197

199-
static inline void hpre_add_to_list(struct hpre *hpre)
198+
struct hisi_qp *hpre_create_qp(void)
200199
{
201-
mutex_lock(&hpre_list_lock);
202-
list_add_tail(&hpre->list, &hpre_list);
203-
mutex_unlock(&hpre_list_lock);
204-
}
205-
206-
static inline void hpre_remove_from_list(struct hpre *hpre)
207-
{
208-
mutex_lock(&hpre_list_lock);
209-
list_del(&hpre->list);
210-
mutex_unlock(&hpre_list_lock);
211-
}
212-
213-
struct hpre *hpre_find_device(int node)
214-
{
215-
struct hpre *hpre, *ret = NULL;
216-
int min_distance = INT_MAX;
217-
struct device *dev;
218-
int dev_node = 0;
200+
int node = cpu_to_node(smp_processor_id());
201+
struct hisi_qp *qp = NULL;
202+
int ret;
219203

220-
mutex_lock(&hpre_list_lock);
221-
list_for_each_entry(hpre, &hpre_list, list) {
222-
dev = &hpre->qm.pdev->dev;
223-
#ifdef CONFIG_NUMA
224-
dev_node = dev->numa_node;
225-
if (dev_node < 0)
226-
dev_node = 0;
227-
#endif
228-
if (node_distance(dev_node, node) < min_distance) {
229-
ret = hpre;
230-
min_distance = node_distance(dev_node, node);
231-
}
232-
}
233-
mutex_unlock(&hpre_list_lock);
204+
ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp);
205+
if (!ret)
206+
return qp;
234207

235-
return ret;
208+
return NULL;
236209
}
237210

238211
static int hpre_cfg_by_dsm(struct hisi_qm *qm)
@@ -799,17 +772,17 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
799772
if (ret)
800773
dev_warn(&pdev->dev, "init debugfs fail!\n");
801774

802-
hpre_add_to_list(hpre);
775+
hisi_qm_add_to_list(qm, &hpre_devices);
803776

804777
ret = hpre_algs_register();
805778
if (ret < 0) {
806-
hpre_remove_from_list(hpre);
807779
pci_err(pdev, "fail to register algs to crypto!\n");
808780
goto err_with_qm_start;
809781
}
810782
return 0;
811783

812784
err_with_qm_start:
785+
hisi_qm_del_from_list(qm, &hpre_devices);
813786
hisi_qm_stop(qm);
814787

815788
err_with_err_init:
@@ -929,7 +902,7 @@ static void hpre_remove(struct pci_dev *pdev)
929902
int ret;
930903

931904
hpre_algs_unregister();
932-
hpre_remove_from_list(hpre);
905+
hisi_qm_del_from_list(qm, &hpre_devices);
933906
if (qm->fun_type == QM_HW_PF && hpre->num_vfs != 0) {
934907
ret = hpre_sriov_disable(pdev);
935908
if (ret) {
@@ -979,6 +952,7 @@ static int __init hpre_init(void)
979952
{
980953
int ret;
981954

955+
hisi_qm_init_list(&hpre_devices);
982956
hpre_register_debugfs();
983957

984958
ret = pci_register_driver(&hpre_pci_driver);

0 commit comments

Comments
 (0)