Content-Type: multipart/mixed; boundary="===============4822678610563190089==" MIME-Version: 1.0 From: Dave Jiang Subject: [Accel-config] Re: [PATCH v2 1/1] accel-config/dsa_test: Add device and wq selection for test Date: Fri, 24 Sep 2021 09:26:42 -0700 Message-ID: <02e7b8f6-e9d1-984b-4140-03c10604eb64@intel.com> In-Reply-To: 20210924113442.27958-2-tony.zhu@intel.com To: accel-config@lists.01.org List-ID: --===============4822678610563190089== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On 9/24/2021 4:34 AM, Tony Zhu wrote: > Add -d to input device like dsa0/wq0.0 which allows the device and wq sel= ection. > > Signed-off-by: Tony Zhu > Reviewed-by: Dave Jiang > --- > test/dsa.c | 63 +++++++++++++++++++++++++++++++++++++++++++++---- > test/dsa.h | 2 +- > test/dsa_test.c | 14 +++++++++-- > 3 files changed, 71 insertions(+), 8 deletions(-) > > diff --git a/test/dsa.c b/test/dsa.c > index ce6f6a1..83e4b4e 100644 > --- a/test/dsa.c > +++ b/test/dsa.c > @@ -146,6 +146,55 @@ static struct accfg_wq *dsa_get_wq(struct dsa_contex= t *ctx, > return NULL; > } > = > +static struct accfg_wq *dsa_get_wq_byid(struct dsa_context *ctx, > + int dev_id, int wq_id) Can you align the function indentation such as: +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) { > + enum accfg_device_state dstate; > + > + /* Make sure that the device is enabled */ > + dstate =3D accfg_device_get_state(device); > + if (dstate !=3D ACCFG_DEVICE_ENABLED) > + continue; Since you are only checking it here once, you can drop the variable if (accfg_device_get_state(device) !=3D ACCFG_DEVICE_ENABLED) continue; > + > + /* Match the device to the id requested */ > + if (accfg_device_get_id(device) !=3D dev_id && > + dev_id !=3D -1) Preferably if you can line up the arguments: if (accfg_device_get_id(device) !=3D dev_id && dev_id !=3D -1) Also, can we define -1? #define ACCFG_DEVICE_INVALID_ID -1 > + continue; > + > + accfg_wq_foreach(device, wq) { > + enum accfg_wq_state wstate; > + enum accfg_wq_type type; > + > + /* Get a workqueue that's enabled */ > + wstate =3D accfg_wq_get_state(wq); > + if (wstate !=3D ACCFG_WQ_ENABLED) > + continue; Probably no need to have wstate variable. Just check directly. > + > + /* The wq type should be user */ > + type =3D accfg_wq_get_type(wq); > + if (type !=3D ACCFG_WQT_USER) > + continue; Same here for type. > + > + /* Make sure the wq id is correct */ > + if(wq_id !=3D accfg_wq_get_id(wq)) > + continue; > + > + rc =3D 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 +203,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 +211,18 @@ int dsa_alloc(struct dsa_context *ctx, int shared) > if (ctx->wq_reg) > return 0; > = > - ctx->wq =3D dsa_get_wq(ctx, -1, shared); > + if(wq_id !=3D -1){ > + ctx->wq =3D dsa_get_wq_byid(ctx, dev_id, wq_id); > + }else{ > + ctx->wq =3D dsa_get_wq(ctx, dev_id, shared); > + } Fix spacing here. Also single line does not need {}: if (wq_id !=3D -1) ctx->wq =3D dsa_get_wq_byid(ctx, dev_id, wq_id); else ctx->wq =3D dsa_get_wq(...); > + > if (!ctx->wq) { > err("No usable wq found\n"); > return -ENODEV; > } > dev =3D accfg_wq_get_device(ctx->wq); > - > - ctx->dedicated =3D !shared; > + ctx->dedicated =3D accfg_wq_get_mode(ctx->wq); > ctx->wq_size =3D accfg_wq_get_size(ctx->wq); > ctx->wq_idx =3D accfg_wq_get_id(ctx->wq); > ctx->bof =3D accfg_wq_get_block_on_fault(ctx->wq); > @@ -182,7 +235,7 @@ int dsa_alloc(struct dsa_context *ctx, int shared) > ctx->max_xfer_bits =3D 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; > diff --git a/test/dsa.h b/test/dsa.h > index 5db0c02..393221b 100644 > --- a/test/dsa.h > +++ b/test/dsa.h > @@ -211,7 +211,7 @@ int memcmp_pattern(const void *src, const uint64_t pa= ttern, 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, > diff --git a/test/dsa_test.c b/test/dsa_test.c > index 5f7a7f1..a2bffe8 100644 > --- a/test/dsa_test.c > +++ b/test/dsa_test.c > @@ -23,6 +23,7 @@ static void usage(void) > "-o ; opcode, same value as in DSA spec\n" > "-b ; if batch opcode, opcode in the batch\n" > "-c ; if batch opcode, number of descriptors for batch\n" > + "-d ; wq device such as dsa0/wq0.0\n" > "-t ; 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 =3D TEST_FLAGS_BOF; > int opt; > unsigned int bsize =3D 0; > + char dev_type[MAX_DEV_LEN]; > + int wq_id =3D -1, dev_id=3D-1, dev_wq_id=3D-1; > = > - while ((opt =3D getopt(argc, argv, "w:l:f:o:b:c:t:p:vh")) !=3D -1) { > + while ((opt =3D getopt(argc, argv, "w:l:f:o:b:c:d:t:p:vh")) !=3D -1) { > switch (opt) { > case 'w': > wq_type =3D atoi(optarg); > @@ -131,6 +134,13 @@ int main(int argc, char *argv[]) > case 'c': > bsize =3D 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) !=3D 4) { > + err("invalid input device:dev_wq_id:%d ,wq_id:%d\n", dev_wq_id, wq_i= d); > + return -EINVAL; > + } > + break; > case 't': > ms_timeout =3D strtoul(optarg, NULL, 0); > break; > @@ -150,7 +160,7 @@ int main(int argc, char *argv[]) > if (dsa =3D=3D NULL) > return -ENOMEM; > = > - rc =3D dsa_alloc(dsa, wq_type); > + rc =3D dsa_alloc(dsa, wq_type, dev_id, wq_id); > if (rc < 0) > return -ENOMEM; > =20 --===============4822678610563190089==--