Skip to contentSkip to conversation

lib/crypto: add callback handlers for crypto

PATCH Superseded Vipin Varghese 3 participants 8 messages Jun 10, 2019 – Jul 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/crypto: add callback handlers for crypto

Add callback handlers for enqueue-dequeue operation on crypto device. The pre-enqueue and post-dequeue are selected on invoke user registered callback functions.

Use cases:
- allow user to investigate the contents pre-enqueue.
- allow user to investigate the contents post-dequeue.
- modify pre-enqueue and post-dequeue stage content.
- investigate PMD meta data.

---
 config/common_base                            |   1 +
 lib/librte_cryptodev/rte_cryptodev.c          | 181 ++++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.h          | 125 ++++++++++++
 .../rte_cryptodev_version.map                 |   4 +
 4 files changed, 311 insertions(+)
config/common_base +1 -0
index 022734f19..dbd5cd8e2 100644
@@ -540,6 +540,7 @@ CONFIG_RTE_LIBRTE_PMD_BBDEV_TURBO_SW=n
 #
 CONFIG_RTE_LIBRTE_CRYPTODEV=y
 CONFIG_RTE_CRYPTO_MAX_DEVS=64
+CONFIG_RTE_CRYPTODEV_ENQDEQ_CALLBACKS=n
 
 #
 # Compile PMD for ARMv8 Crypto device
lib/librte_cryptodev/rte_cryptodev.c +181 -0

196 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev.h +125 -0

164 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev_version.map +4 -0
index 3deb265ac..e0c1900f3 100644
@@ -101,6 +101,10 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
+	rte_cryptodev_preenq_callback_register;
+	rte_cryptodev_preenq_callback_unregister;
+	rte_cryptodev_pstdeq_callback_register;
+	rte_cryptodev_pstdeq_callback_unregister;
 	rte_cryptodev_sym_get_existing_header_session_size;
 	rte_cryptodev_sym_session_get_user_data;
 	rte_cryptodev_sym_session_pool_create;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 examples/l2fwd-crypto: add callback handlers

Register user callback handlers for pre-enqueue and pst-dequeue for crypto device instance 0 with port 0.

---
 examples/l2fwd-crypto/main.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
examples/l2fwd-crypto/main.c +36 -0
index e282cb7bf..db2ac2624 100644
@@ -255,6 +255,20 @@ struct l2fwd_crypto_statistics crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+static uint16_t dump_crypto(__rte_unused uint8_t dev_id,
+		__rte_unused uint8_t qp_id,
+		__rte_unused struct rte_crypto_op **ops,
+		__rte_unused uint16_t nb_ops,
+		__rte_unused void *cb_arg)
+{
+	if (nb_ops)
+		RTE_LOG(DEBUG, L2FWD, " dev_id (%u) qp_id (%u)"
+				" ops (%p) nb_ops (%u)\n",
+				dev_id, qp_id, ops, nb_ops);
+
+	return nb_ops;
+}
+
 /* Print out statistics on packets dropped */
 static void
 print_stats(void)
@@ -2783,6 +2797,18 @@ main(int argc, char **argv)
 				(unsigned)cdev_id);
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_register(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to preenq callback register\n");
+	RTE_LOG(INFO, L2FWD, " preenq callback register success\n");
+
+	ret = rte_cryptodev_pstdeq_callback_register(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to pstdeq callback register\n");
+	RTE_LOG(INFO, L2FWD, " pstdeq callback register success\n");
+#endif
+
 	/* launch per-lcore init on every lcore */
 	rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, (void *)&options,
 			CALL_MASTER);
@@ -2791,5 +2817,15 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_unregister(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		printf(" faield rte_cryptodev_preenq_callback_unregister\n");
+
+	ret = rte_cryptodev_pstdeq_callback_unregister(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		printf(" failed rte_cryptodev_pstdeq_callback_unregister\n");
+#endif
+
 	return 0;
 }
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/2 lib/crypto: add callback handlers for crypto

In reply to Vipin Varghese

Add callback handlers for enqueue-dequeue operation on crypto device. The pre-enqueue and post-dequeue are selected on invoke user registered callback functions.

Use cases:
- allow user to investigate the contents pre-enqueue.
- allow user to investigate the contents post-dequeue.
- modify pre-enqueue and post-dequeue stage content.
- investigate PMD meta data.

---
 config/common_base                            |   1 +
 lib/librte_cryptodev/rte_cryptodev.c          | 181 ++++++++++++++++++
 lib/librte_cryptodev/rte_cryptodev.h          | 125 ++++++++++++
 .../rte_cryptodev_version.map                 |   4 +
 4 files changed, 311 insertions(+)
config/common_base +1 -0
index 022734f19..dbd5cd8e2 100644
@@ -540,6 +540,7 @@ CONFIG_RTE_LIBRTE_PMD_BBDEV_TURBO_SW=n
 #
 CONFIG_RTE_LIBRTE_CRYPTODEV=y
 CONFIG_RTE_CRYPTO_MAX_DEVS=64
+CONFIG_RTE_CRYPTODEV_ENQDEQ_CALLBACKS=n
 
 #
 # Compile PMD for ARMv8 Crypto device
lib/librte_cryptodev/rte_cryptodev.c +181 -0

196 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev.h +125 -0

164 lines not on this page · raw message

lib/librte_cryptodev/rte_cryptodev_version.map +4 -0
index 3deb265ac..e0c1900f3 100644
@@ -101,6 +101,10 @@ EXPERIMENTAL {
 	rte_cryptodev_asym_session_init;
 	rte_cryptodev_asym_xform_capability_check_modlen;
 	rte_cryptodev_asym_xform_capability_check_optype;
+	rte_cryptodev_preenq_callback_register;
+	rte_cryptodev_preenq_callback_unregister;
+	rte_cryptodev_pstdeq_callback_register;
+	rte_cryptodev_pstdeq_callback_unregister;
 	rte_cryptodev_sym_get_existing_header_session_size;
 	rte_cryptodev_sym_session_get_user_data;
 	rte_cryptodev_sym_session_pool_create;
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 2/2 examples/l2fwd-crypto: add callback handlers

Register user callback handlers for pre-enqueue and pst-dequeue for crypto device instance 0 with port 0.

---
 examples/l2fwd-crypto/main.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
examples/l2fwd-crypto/main.c +38 -0
index e282cb7bf..c42b352f8 100644
@@ -255,6 +255,22 @@ struct l2fwd_crypto_statistics crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+static uint16_t dump_crypto(__rte_unused uint8_t dev_id,
+		__rte_unused uint8_t qp_id,
+		__rte_unused struct rte_crypto_op **ops,
+		__rte_unused uint16_t nb_ops,
+		__rte_unused void *cb_arg)
+{
+	if (nb_ops)
+		RTE_LOG(DEBUG, L2FWD, " dev_id (%u) qp_id (%u)"
+				" ops (%p) nb_ops (%u)\n",
+				dev_id, qp_id, ops, nb_ops);
+
+	return nb_ops;
+}
+#endif
+
 /* Print out statistics on packets dropped */
 static void
 print_stats(void)
@@ -2783,6 +2799,18 @@ main(int argc, char **argv)
 				(unsigned)cdev_id);
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_register(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to preenq callback register\n");
+	RTE_LOG(INFO, L2FWD, " preenq callback register success\n");
+
+	ret = rte_cryptodev_pstdeq_callback_register(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to pstdeq callback register\n");
+	RTE_LOG(INFO, L2FWD, " pstdeq callback register success\n");
+#endif
+
 	/* launch per-lcore init on every lcore */
 	rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, (void *)&options,
 			CALL_MASTER);
@@ -2791,5 +2819,15 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_unregister(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		printf(" faield rte_cryptodev_preenq_callback_unregister\n");
+
+	ret = rte_cryptodev_pstdeq_callback_unregister(0, 0, dump_crypto, NULL);
+	if (ret != 0)
+		printf(" failed rte_cryptodev_pstdeq_callback_unregister\n");
+#endif
+
 	return 0;
 }
Signature · 1 line
2.17.1
#4 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] examples/l2fwd-crypto: add callback handlers

Hi,

Quoted 67 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Vipin Varghese
Sent: Monday, June 10, 2019 14:30
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Vipin Varghese <[email protected]>
Subject: [dpdk-dev] [PATCH v2 2/2] examples/l2fwd-crypto: add callback handlers

Register user callback handlers for pre-enqueue and pst-dequeue for crypto device instance 0 with port 0.

---
 examples/l2fwd-crypto/main.c | 38
++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
examples/l2fwd-crypto/main.c +27 -0
index e282cb7bf..c42b352f8 100644
@@ -255,6 +255,22 @@ struct l2fwd_crypto_statistics
 crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+static uint16_t dump_crypto(__rte_unused uint8_t dev_id,
+		__rte_unused uint8_t qp_id,
+		__rte_unused struct rte_crypto_op **ops,
+		__rte_unused uint16_t nb_ops,
+		__rte_unused void *cb_arg)
+{
+	if (nb_ops)
+		RTE_LOG(DEBUG, L2FWD, " dev_id (%u) qp_id (%u)"
+				" ops (%p) nb_ops (%u)\n",
+				dev_id, qp_id, ops, nb_ops);
+
+	return nb_ops;
+}
+#endif
+
 /* Print out statistics on packets dropped */  static void
 print_stats(void)
@@ -2783,6 +2799,18 @@ main(int argc, char **argv)
 				(unsigned)cdev_id);
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_register(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to preenq callback register\n");
+	RTE_LOG(INFO, L2FWD, " preenq callback register success\n");
+
+	ret = rte_cryptodev_pstdeq_callback_register(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to pstdeq callback register\n");
+	RTE_LOG(INFO, L2FWD, " pstdeq callback register success\n"); #endif
+
 	/* launch per-lcore init on every lcore */
 	rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, (void

*)&options,

examples/l2fwd-crypto/main.c +0 -0
 			CALL_MASTER);

examples/l2fwd-crypto/main.c main(int argc, char **argv) · line 2826

Quoted 8 lines
examples/l2fwd-crypto/main.c +4 -0
@@ -2791,5 +2819,15 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_unregister(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		printf(" faield

Observed typo here 'faield' -> 'failed' ;)

Quoted 13 lines
examples/l2fwd-crypto/main.c +2 -0
 rte_cryptodev_preenq_callback_unregister\n");
+
+	ret = rte_cryptodev_pstdeq_callback_unregister(0, 0, dump_crypto,

NULL);

examples/l2fwd-crypto/main.c +2 -0
+	if (ret != 0)
+		printf(" failed

rte_cryptodev_pstdeq_callback_unregister\n");

examples/l2fwd-crypto/main.c +2 -1
+#endif
+
 	return 0;
 }
--

2.17.1

#5 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] examples/l2fwd-crypto: add callback handlers

Thanks Ruifeng, will work on the suggested changes.

Quoted 105 lines

-----Original Message-----
From: Ruifeng Wang (Arm Technology China) <[email protected]>
Sent: Friday, June 21, 2019 12:37 PM
To: Varghese, Vipin <[email protected]>; Wiles, Keith <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; [email protected]; Doherty, Declan <[email protected]>
Cc: Padubidri, Sanjay A <[email protected]>; nd <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 2/2] examples/l2fwd-crypto: add callback handlers

Hi,

Quoted 68 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Vipin Varghese
Sent: Monday, June 10, 2019 14:30
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Vipin Varghese <[email protected]>
Subject: [dpdk-dev] [PATCH v2 2/2] examples/l2fwd-crypto: add callback handlers

Register user callback handlers for pre-enqueue and pst-dequeue for crypto device instance 0 with port 0.

---
 examples/l2fwd-crypto/main.c | 38
++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
(quoted diff) +0 -0

b/examples/l2fwd-crypto/main.c index e282cb7bf..c42b352f8 100644

examples/l2fwd-crypto/main.c +27 -0
@@ -255,6 +255,22 @@ struct l2fwd_crypto_statistics
 crypto_statistics[RTE_CRYPTO_MAX_DEVS];
 /* default period is 10 seconds */
 static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000;
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS static uint16_t
+dump_crypto(__rte_unused uint8_t dev_id,
+		__rte_unused uint8_t qp_id,
+		__rte_unused struct rte_crypto_op **ops,
+		__rte_unused uint16_t nb_ops,
+		__rte_unused void *cb_arg)
+{
+	if (nb_ops)
+		RTE_LOG(DEBUG, L2FWD, " dev_id (%u) qp_id (%u)"
+				" ops (%p) nb_ops (%u)\n",
+				dev_id, qp_id, ops, nb_ops);
+
+	return nb_ops;
+}
+#endif
+
 /* Print out statistics on packets dropped */  static void
 print_stats(void)
@@ -2783,6 +2799,18 @@ main(int argc, char **argv)
 				(unsigned)cdev_id);
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_register(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to preenq callback register\n");
+	RTE_LOG(INFO, L2FWD, " preenq callback register success\n");
+
+	ret = rte_cryptodev_pstdeq_callback_register(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		RTE_LOG(ERR, L2FWD, " failed to pstdeq callback register\n");
+	RTE_LOG(INFO, L2FWD, " pstdeq callback register success\n"); #endif
+
 	/* launch per-lcore init on every lcore */
 	rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, (void *)&options,
 			CALL_MASTER);

examples/l2fwd-crypto/main.c main(int argc, char **argv) · line 2826

Quoted 8 lines
examples/l2fwd-crypto/main.c +4 -0
@@ -2791,5 +2819,15 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS
+	ret = rte_cryptodev_preenq_callback_unregister(0, 0, dump_crypto,
 NULL);
+	if (ret != 0)
+		printf(" faield

Observed typo here 'faield' -> 'failed' ;)

Quoted 13 lines
examples/l2fwd-crypto/main.c +2 -0
 rte_cryptodev_preenq_callback_unregister\n");
+
+	ret = rte_cryptodev_pstdeq_callback_unregister(0, 0, dump_crypto,

NULL);

examples/l2fwd-crypto/main.c +2 -0
+	if (ret != 0)
+		printf(" failed

rte_cryptodev_pstdeq_callback_unregister\n");

examples/l2fwd-crypto/main.c +2 -1
+#endif
+
 	return 0;
 }
--

2.17.1

#6 lore raw
In reply to Vipin Varghese

Hi Vipin,

Quoted 13 lines

Add callback handlers for enqueue-dequeue operation on crypto device. The pre-enqueue and post-dequeue are selected on invoke user registered callback functions.

Use cases:
- allow user to investigate the contents pre-enqueue.
- allow user to investigate the contents post-dequeue.
- modify pre-enqueue and post-dequeue stage content.
- investigate PMD meta data.

---

[..]

Quoted 6 lines
lib/librte_cryptodev/rte_cryptodev.h +1 -0
@@ -907,6 +926,19 @@ rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t
 qp_id,
 	nb_ops = (*dev->dequeue_burst)
 			(dev->data->queue_pairs[qp_id], ops, nb_ops);
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS

lib/librte_cryptodev/rte_cryptodev.h rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t · line 940

Quoted 10 lines
lib/librte_cryptodev/rte_cryptodev.h +10 -0
+	struct rte_cryptodev_enqdeq_callback *cb = NULL;
+
+	TAILQ_FOREACH(cb, &(dev->deq_cbs), next) {
+		if (cb->cb_fn == NULL)
+			continue;
+
+		cb->active = 1;
+		nb_ops = cb->cb_fn(dev_id, qp_id, ops, nb_ops, cb->cb_arg);
+		cb->active = 0;
+	}

Shouldn't this cb->active be set atomically.

Will it be thread safe? There may be multiple threads enqueuing on the same device. One may be executing while the other finished and set the active to 0, and may unregister While the some other thread is still executing.

One more thing, it would be better to have a debug prints about how many nb_ops have been Successfully passed through each of the callback.
And in the callback, it should be assumed that it will return back just after the first failed ops, so that The application can free the remaining one. This should be documented in the callback API.

Quoted 5 lines
lib/librte_cryptodev/rte_cryptodev.h +2 -0
+#endif
+
 	return nb_ops;
 }
#7 lore raw

Thanks Akhil, I will work on the suggested inputs.

Quoted 63 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Thursday, June 27, 2019 7:55 PM
To: Varghese, Vipin <[email protected]>; Wiles, Keith <[email protected]>; [email protected]; De Lara Guarch, Pablo <[email protected]>; Doherty, Declan <[email protected]>
Cc: Padubidri, Sanjay A <[email protected]>
Subject: RE: [PATCH v2 1/2] lib/crypto: add callback handlers for crypto

Hi Vipin,

Quoted 13 lines

Add callback handlers for enqueue-dequeue operation on crypto device. The pre-enqueue and post-dequeue are selected on invoke user registered callback functions.

Use cases:
- allow user to investigate the contents pre-enqueue.
- allow user to investigate the contents post-dequeue.
- modify pre-enqueue and post-dequeue stage content.
- investigate PMD meta data.

---

[..]

Quoted 6 lines
lib/librte_cryptodev/rte_cryptodev.h +1 -0
@@ -907,6 +926,19 @@ rte_cryptodev_dequeue_burst(uint8_t dev_id,
 uint16_t qp_id,
 	nb_ops = (*dev->dequeue_burst)
 			(dev->data->queue_pairs[qp_id], ops, nb_ops);
 
+#ifdef RTE_CRYPTODEV_ENQDEQ_CALLBACKS

lib/librte_cryptodev/rte_cryptodev.h rte_cryptodev_dequeue_burst(uint8_t dev_id, · line 940

Quoted 10 lines
lib/librte_cryptodev/rte_cryptodev.h +10 -0
+	struct rte_cryptodev_enqdeq_callback *cb = NULL;
+
+	TAILQ_FOREACH(cb, &(dev->deq_cbs), next) {
+		if (cb->cb_fn == NULL)
+			continue;
+
+		cb->active = 1;
+		nb_ops = cb->cb_fn(dev_id, qp_id, ops, nb_ops, cb->cb_arg);
+		cb->active = 0;
+	}

Shouldn't this cb->active be set atomically.

Will it be thread safe? There may be multiple threads enqueuing on the same device.
One may be executing while the other finished and set the active to 0, and may unregister While the some other thread is still executing.

One more thing, it would be better to have a debug prints about how many nb_ops have been Successfully passed through each of the callback.
And in the callback, it should be assumed that it will return back just after the first failed ops, so that The application can free the remaining one. This should be documented in the callback API.

Quoted 5 lines
lib/librte_cryptodev/rte_cryptodev.h +2 -0
+#endif
+
 	return nb_ops;
 }