accel-config/dsa_test: Add device and wq selection for test
Tony Zhu
PATCH v3 1/1 accel-config/dsa_test: Add device and wq selection for test
Add -d to input device like dsa0/wq0.0 which allows the device and wq selection.
Changelog:
v2:
- Modify the patch subject
- Remove -i, keep only -d dsa0/wq0.0
v3:
- Define ACCFG_DEVICE_INVALID_ID -1
- Drop the vaiable which is only checking one time
- Remove errors checked by checkpatch.pl
--- test/dsa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++----- test/dsa.h | 2 +- test/dsa_test.c | 14 ++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-)
test/dsa.c +52 -5
@@ -17,6 +17,7 @@#include "dsa.h" #define DSA_COMPL_RING_SIZE 64 +#define ACCFG_DEVICE_INVALID_ID -1unsigned int ms_timeout =5000 ;int debug_logging;
@@ -146,6 +147,49 @@ static struct accfg_wq *dsa_get_wq(struct dsa_context *ctx,return NULL ; } +static struct accfg_wq *dsa_get_wq_byid (struct dsa_context *ctx, +int dev_id,int wq_id) +{ +struct accfg_device *device; +struct accfg_wq *wq; +int rc; + + accfg_device_foreach(ctx->ctx, device) { + +/* Make sure that the device is enabled */ +if (accfg_device_get_state (device) !=ACCFG_DEVICE_ENABLED ) +continue ; + +/* Match the device to the id requested */ +if (accfg_device_get_id (device) != dev_id && + dev_id !=ACCFG_DEVICE_INVALID_ID ) +continue ; + + accfg_wq_foreach(device, wq) { + +/* Get a workqueue that's enabled */ +if (accfg_wq_get_state (wq) !=ACCFG_WQ_ENABLED ) +continue ; + +/* The wq type should be user */ +if (accfg_wq_get_type (wq) !=ACCFG_WQT_USER ) +continue ; + +/* Make sure the wq id is correct */ +if (wq_id !=accfg_wq_get_id (wq)) +continue ; + + rc =dsa_setup_wq (ctx, wq); +if (rc <0 ) +return NULL ; + +return wq; + } + } + +return NULL ; +} +static uint32_t bsr (uint32_t val) {uint32_t msb;
@@ -154,7 +198,7 @@ static uint32_t bsr(uint32_t val)return msb -1 ; } -int dsa_alloc (struct dsa_context *ctx,int shared) +int dsa_alloc (struct dsa_context *ctx,int shared,int dev_id,int wq_id) {struct accfg_device *dev;
@@ -162,14 +206,17 @@ int dsa_alloc(struct dsa_context *ctx, int shared)if (ctx->wq_reg)return 0 ; - ctx->wq =dsa_get_wq (ctx,-1 , shared); +if (wq_id !=-1 ) + ctx->wq =dsa_get_wq_byid (ctx, dev_id, wq_id); +else + ctx->wq =dsa_get_wq (ctx, dev_id, shared); +if (!ctx->wq) {err ("No usable wq found\n" );return -ENODEV ; } dev =accfg_wq_get_device (ctx->wq); - - ctx->dedicated = !shared; + ctx->dedicated =accfg_wq_get_mode (ctx->wq); ctx->wq_size =accfg_wq_get_size (ctx->wq); ctx->wq_idx =accfg_wq_get_id (ctx->wq); ctx->bof =accfg_wq_get_block_on_fault (ctx->wq);
@@ -182,7 +229,7 @@ int dsa_alloc(struct dsa_context *ctx, int shared) ctx->max_xfer_bits =bsr (ctx->max_xfer_size);info ("alloc wq %d shared %d size %d addr %p batch sz %#x xfer sz %#x\n" , - ctx->wq_idx, shared, ctx->wq_size, ctx->wq_reg, + ctx->wq_idx, ctx->dedicated, ctx->wq_size, ctx->wq_reg, ctx->max_batch_size, ctx->max_xfer_size);return 0 ;
test/dsa.h +1 -1
@@ -211,7 +211,7 @@ int memcmp_pattern(const void *src, const uint64_t pattern, size_t len);int dsa_enqcmd (struct dsa_context *ctx,struct dsa_hw_desc *hw);struct dsa_context *dsa_init (void ); -int dsa_alloc (struct dsa_context *ctx,int shared); +int dsa_alloc (struct dsa_context *ctx,int shared,int dev_id,int wq_id);int alloc_task (struct dsa_context *ctx);struct task *__alloc_task (void ); int init_task(struct task *tsk, int tflags, int opcode,
test/dsa_test.c +12 -2
@@ -23,6 +23,7 @@ static void usage(void)"-o <opcode> ; opcode, same value as in DSA spec\n" "-b <opcode> ; if batch opcode, opcode in the batch\n" "-c <batch_size> ; if batch opcode, number of descriptors for batch\n" +"-d ; wq device such as dsa0/wq0.0\n" "-t <ms timeout> ; ms to wait for descs to complete\n" "-v ; verbose\n" "-h ; print this message\n");
@@ -110,8 +111,10 @@ int main(int argc, char *argv[])int tflags =TEST_FLAGS_BOF ;int opt;unsigned int bsize =0 ; +char dev_type[MAX_DEV_LEN ]; +int wq_id =-1 , dev_id =-1 , dev_wq_id =-1 ; -while ((opt =getopt (argc, argv,"w:l:f:o:b:c:t:p:vh" )) !=-1 ) { +while ((opt =getopt (argc, argv,"w:l:f:o:b:c:d:t:p:vh" )) !=-1 ) {switch (opt) {case 'w' : wq_type =atoi (optarg);
@@ -131,6 +134,13 @@ int main(int argc, char *argv[])case 'c' : bsize =strtoul (optarg,NULL ,0 );break ; +case 'd' : +if (sscanf (optarg,"%[a-z]%u/%*[a-z]%u.%u" , dev_type, + &dev_id, &dev_wq_id, &wq_id) !=4 ) { +err ("invalid input device:dev_wq_id:%d ,wq_id:%d\n" , dev_wq_id, wq_id); +return -EINVAL ; + } +break ;case 't' : ms_timeout =strtoul (optarg,NULL ,0 );break ;
@@ -150,7 +160,7 @@ int main(int argc, char *argv[])if (dsa ==NULL )return -ENOMEM ; - rc =dsa_alloc (dsa, wq_type); + rc =dsa_alloc (dsa, wq_type, dev_id, wq_id);if (rc <0 )return -ENOMEM ;
Signature · 1 line
2.17.1
Dave Jiang
Quoted 91 lines · Tony Zhu
Add -d to input device like dsa0/wq0.0 which allows the device and wq selection.
Changelog:
v2:
- Modify the patch subject
- Remove -i, keep only -d dsa0/wq0.0
v3:
- DefineACCFG_DEVICE_INVALID_ID-1
- Drop the vaiable which is only checking one time
- Remove errors checked by checkpatch.plSigned-off-by Tony Zhu <tony.zhu(a)intel.com>Reviewed-by Dave Jiang <dave.jiang(a)intel.com>--- test/dsa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++----- test/dsa.h | 2 +- test/dsa_test.c | 14 ++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-)test/dsa.c +45
-1@@ -17,6 +17,7 @@#include "dsa.h" #define DSA_COMPL_RING_SIZE 64 +#define ACCFG_DEVICE_INVALID_ID -1unsigned int ms_timeout =5000 ;int debug_logging;@@ -146,6 +147,49 @@ static struct accfg_wq *dsa_get_wq(struct dsa_context *ctx,return NULL ; } +static struct accfg_wq *dsa_get_wq_byid (struct dsa_context *ctx, +int dev_id,int wq_id) +{ +struct accfg_device *device; +struct accfg_wq *wq; +int rc; + + accfg_device_foreach(ctx->ctx, device) { + +/* Make sure that the device is enabled */ +if (accfg_device_get_state (device) !=ACCFG_DEVICE_ENABLED ) +continue ; + +/* Match the device to the id requested */ +if (accfg_device_get_id (device) != dev_id && + dev_id !=ACCFG_DEVICE_INVALID_ID ) +continue ; + + accfg_wq_foreach(device, wq) { + +/* Get a workqueue that's enabled */ +if (accfg_wq_get_state (wq) !=ACCFG_WQ_ENABLED ) +continue ; + +/* The wq type should be user */ +if (accfg_wq_get_type (wq) !=ACCFG_WQT_USER ) +continue ; + +/* Make sure the wq id is correct */ +if (wq_id !=accfg_wq_get_id (wq)) +continue ; + + rc =dsa_setup_wq (ctx, wq); +if (rc <0 ) +return NULL ; + +return wq; + } + } + +return NULL ; +} +static uint32_t bsr (uint32_t val) {uint32_t msb;@@ -154,7 +198,7 @@ static uint32_t bsr(uint32_t val)return msb -1 ; } -int dsa_alloc (struct dsa_context *ctx,int shared) +int dsa_alloc (struct dsa_context *ctx,int shared,int dev_id,int wq_id) {struct accfg_device *dev;
test/dsa.c int dsa_alloc(struct dsa_context *ctx, int shared) · line 209
Quoted 5 lines
test/dsa.c +1
-1@@ -162,14 +206,17 @@ int dsa_alloc(struct dsa_context *ctx, int shared)if (ctx->wq_reg)return 0 ; - ctx->wq =dsa_get_wq (ctx,-1 , shared); +if (wq_id !=-1 )
Define the -1 instead of use magic number
Quoted 84 lines
test/dsa.c +6
-3+ ctx->wq =dsa_get_wq_byid (ctx, dev_id, wq_id); + else + ctx->wq = dsa_get_wq(ctx, dev_id, shared); +if (!ctx->wq) {err ("No usable wq found\n" );return -ENODEV ; } dev =accfg_wq_get_device (ctx->wq); - - ctx->dedicated = !shared; + ctx->dedicated =accfg_wq_get_mode (ctx->wq); ctx->wq_size =accfg_wq_get_size (ctx->wq); ctx->wq_idx =accfg_wq_get_id (ctx->wq); ctx->bof =accfg_wq_get_block_on_fault (ctx->wq);@@ -182,7 +229,7 @@ int dsa_alloc(struct dsa_context *ctx, int shared) ctx->max_xfer_bits =bsr (ctx->max_xfer_size);info ("alloc wq %d shared %d size %d addr %p batch sz %#x xfer sz %#x\n" , - ctx->wq_idx, shared, ctx->wq_size, ctx->wq_reg, + ctx->wq_idx, ctx->dedicated, ctx->wq_size, ctx->wq_reg, ctx->max_batch_size, ctx->max_xfer_size);return 0 ;test/dsa.h +1
-1@@ -211,7 +211,7 @@ int memcmp_pattern(const void *src, const uint64_t pattern, size_t len);int dsa_enqcmd (struct dsa_context *ctx,struct dsa_hw_desc *hw);struct dsa_context *dsa_init (void ); -int dsa_alloc (struct dsa_context *ctx,int shared); +int dsa_alloc (struct dsa_context *ctx,int shared,int dev_id,int wq_id);int alloc_task (struct dsa_context *ctx);struct task *__alloc_task (void ); int init_task(struct task *tsk, int tflags, int opcode,test/dsa_test.c +12
-2@@ -23,6 +23,7 @@ static void usage(void)"-o <opcode> ; opcode, same value as in DSA spec\n" "-b <opcode> ; if batch opcode, opcode in the batch\n" "-c <batch_size> ; if batch opcode, number of descriptors for batch\n" +"-d ; wq device such as dsa0/wq0.0\n" "-t <ms timeout> ; ms to wait for descs to complete\n" "-v ; verbose\n" "-h ; print this message\n");@@ -110,8 +111,10 @@ int main(int argc, char *argv[])int tflags =TEST_FLAGS_BOF ;int opt;unsigned int bsize =0 ; +char dev_type[MAX_DEV_LEN ]; +int wq_id =-1 , dev_id =-1 , dev_wq_id =-1 ; -while ((opt =getopt (argc, argv,"w:l:f:o:b:c:t:p:vh" )) !=-1 ) { +while ((opt =getopt (argc, argv,"w:l:f:o:b:c:d:t:p:vh" )) !=-1 ) {switch (opt) {case 'w' : wq_type =atoi (optarg);@@ -131,6 +134,13 @@ int main(int argc, char *argv[])case 'c' : bsize =strtoul (optarg,NULL ,0 );break ; +case 'd' : +if (sscanf (optarg,"%[a-z]%u/%*[a-z]%u.%u" , dev_type, + &dev_id, &dev_wq_id, &wq_id) !=4 ) { +err ("invalid input device:dev_wq_id:%d ,wq_id:%d\n" , dev_wq_id, wq_id); +return -EINVAL ; + } +break ;case 't' : ms_timeout =strtoul (optarg,NULL ,0 );break ;@@ -150,7 +160,7 @@ int main(int argc, char *argv[])if (dsa ==NULL )return -ENOMEM ; - rc =dsa_alloc (dsa, wq_type); + rc =dsa_alloc (dsa, wq_type, dev_id, wq_id);if (rc <0 )return -ENOMEM ;