Skip to content

Commit 700f7d0

Browse files
Zhou Wangherbertx
authored andcommitted
crypto: hisilicon - fix to return sub-optimal device when best device has no qps
Currently find_zip_device() finds zip device which has the min NUMA distance with current CPU. This patch modifies find_zip_device to return sub-optimal device when best device has no qps. This patch sorts all devices by NUMA distance, then finds the best zip device which has free qp. Signed-off-by: Zhou Wang <wangzhou1@hisilicon.com> Signed-off-by: Shukun Tan <tanshukun1@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f0c8b6a commit 700f7d0

3 files changed

Lines changed: 77 additions & 20 deletions

File tree

‎drivers/crypto/hisilicon/qm.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ struct hisi_qp *hisi_qm_create_qp(struct hisi_qm *qm, u8 alg_type)
11271127
}
11281128
set_bit(qp_id, qm->qp_bitmap);
11291129
qm->qp_array[qp_id] = qp;
1130+
qm->qp_in_used++;
11301131

11311132
write_unlock(&qm->qps_lock);
11321133

@@ -1191,6 +1192,7 @@ void hisi_qm_release_qp(struct hisi_qp *qp)
11911192
write_lock(&qm->qps_lock);
11921193
qm->qp_array[qp->qp_id] = NULL;
11931194
clear_bit(qp->qp_id, qm->qp_bitmap);
1195+
qm->qp_in_used--;
11941196
write_unlock(&qm->qps_lock);
11951197

11961198
kfree(qp);
@@ -1395,6 +1397,24 @@ static void hisi_qm_cache_wb(struct hisi_qm *qm)
13951397
}
13961398
}
13971399

1400+
/**
1401+
* hisi_qm_get_free_qp_num() - Get free number of qp in qm.
1402+
* @qm: The qm which want to get free qp.
1403+
*
1404+
* This function return free number of qp in qm.
1405+
*/
1406+
int hisi_qm_get_free_qp_num(struct hisi_qm *qm)
1407+
{
1408+
int ret;
1409+
1410+
read_lock(&qm->qps_lock);
1411+
ret = qm->qp_num - qm->qp_in_used;
1412+
read_unlock(&qm->qps_lock);
1413+
1414+
return ret;
1415+
}
1416+
EXPORT_SYMBOL_GPL(hisi_qm_get_free_qp_num);
1417+
13981418
/**
13991419
* hisi_qm_init() - Initialize configures about qm.
14001420
* @qm: The qm needing init.
@@ -1458,6 +1478,7 @@ int hisi_qm_init(struct hisi_qm *qm)
14581478
if (ret)
14591479
goto err_free_irq_vectors;
14601480

1481+
qm->qp_in_used = 0;
14611482
mutex_init(&qm->mailbox_lock);
14621483
rwlock_init(&qm->qps_lock);
14631484

‎drivers/crypto/hisilicon/qm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct hisi_qm {
134134
u32 sqe_size;
135135
u32 qp_base;
136136
u32 qp_num;
137+
u32 qp_in_used;
137138
u32 ctrl_qp_num;
138139

139140
struct qm_dma qdma;
@@ -206,6 +207,7 @@ int hisi_qm_start_qp(struct hisi_qp *qp, unsigned long arg);
206207
int hisi_qm_stop_qp(struct hisi_qp *qp);
207208
void hisi_qm_release_qp(struct hisi_qp *qp);
208209
int hisi_qp_send(struct hisi_qp *qp, const void *msg);
210+
int hisi_qm_get_free_qp_num(struct hisi_qm *qm);
209211
int hisi_qm_get_vft(struct hisi_qm *qm, u32 *base, u32 *number);
210212
int hisi_qm_set_vft(struct hisi_qm *qm, u32 fun_num, u32 base, u32 number);
211213
int hisi_qm_debug_init(struct hisi_qm *qm);

‎drivers/crypto/hisilicon/zip/zip_main.c‎

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,47 +79,81 @@
7979
#define HZIP_SOFT_CTRL_CNT_CLR_CE 0x301000
8080
#define SOFT_CTRL_CNT_CLR_CE_BIT BIT(0)
8181

82-
#define HZIP_NUMA_DISTANCE 100
8382
#define HZIP_BUF_SIZE 22
8483

8584
static const char hisi_zip_name[] = "hisi_zip";
8685
static struct dentry *hzip_debugfs_root;
8786
static LIST_HEAD(hisi_zip_list);
8887
static DEFINE_MUTEX(hisi_zip_list_lock);
8988

90-
#ifdef CONFIG_NUMA
91-
static struct hisi_zip *find_zip_device_numa(int node)
89+
struct hisi_zip_resource {
90+
struct hisi_zip *hzip;
91+
int distance;
92+
struct list_head list;
93+
};
94+
95+
static void free_list(struct list_head *head)
9296
{
93-
struct hisi_zip *zip = NULL;
97+
struct hisi_zip_resource *res, *tmp;
98+
99+
list_for_each_entry_safe(res, tmp, head, list) {
100+
list_del(&res->list);
101+
kfree(res);
102+
}
103+
}
104+
105+
struct hisi_zip *find_zip_device(int node)
106+
{
107+
struct hisi_zip *ret = NULL;
108+
#ifdef CONFIG_NUMA
109+
struct hisi_zip_resource *res, *tmp;
94110
struct hisi_zip *hisi_zip;
95-
int min_distance = HZIP_NUMA_DISTANCE;
111+
struct list_head *n;
96112
struct device *dev;
113+
LIST_HEAD(head);
114+
115+
mutex_lock(&hisi_zip_list_lock);
97116

98117
list_for_each_entry(hisi_zip, &hisi_zip_list, list) {
118+
res = kzalloc(sizeof(*res), GFP_KERNEL);
119+
if (!res)
120+
goto err;
121+
99122
dev = &hisi_zip->qm.pdev->dev;
100-
if (node_distance(dev->numa_node, node) < min_distance) {
101-
zip = hisi_zip;
102-
min_distance = node_distance(dev->numa_node, node);
123+
res->hzip = hisi_zip;
124+
res->distance = node_distance(dev->numa_node, node);
125+
126+
n = &head;
127+
list_for_each_entry(tmp, &head, list) {
128+
if (res->distance < tmp->distance) {
129+
n = &tmp->list;
130+
break;
131+
}
103132
}
133+
list_add_tail(&res->list, n);
104134
}
105135

106-
return zip;
107-
}
108-
#endif
109-
110-
struct hisi_zip *find_zip_device(int node)
111-
{
112-
struct hisi_zip *zip = NULL;
136+
list_for_each_entry(tmp, &head, list) {
137+
if (hisi_qm_get_free_qp_num(&tmp->hzip->qm)) {
138+
ret = tmp->hzip;
139+
break;
140+
}
141+
}
113142

114-
mutex_lock(&hisi_zip_list_lock);
115-
#ifdef CONFIG_NUMA
116-
zip = find_zip_device_numa(node);
143+
free_list(&head);
117144
#else
118-
zip = list_first_entry(&hisi_zip_list, struct hisi_zip, list);
145+
mutex_lock(&hisi_zip_list_lock);
146+
147+
ret = list_first_entry(&hisi_zip_list, struct hisi_zip, list);
119148
#endif
120149
mutex_unlock(&hisi_zip_list_lock);
121150

122-
return zip;
151+
return ret;
152+
153+
err:
154+
free_list(&head);
155+
mutex_unlock(&hisi_zip_list_lock);
156+
return NULL;
123157
}
124158

125159
struct hisi_zip_hw_error {

0 commit comments

Comments
 (0)