[Accel-config] Re: [PATCH v1 02/11] accel-config: Create mdev structures and load mdevs into device context

Jiang, Dave <dave.jiang at intel.com>
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>

> -----Original Message-----
> From: Thomas, Ramesh <ramesh.thomas(a)intel.com>
> Sent: Friday, December 4, 2020 4:53 PM
> To: Jiang, Dave <dave.jiang(a)intel.com>; accel-config(a)lists.01.org
> Cc: Luck, Tony <tony.luck(a)intel.com>
> Subject: RE: [PATCH v1 02/11] accel-config: Create mdev structures and load
> mdevs into device context
> 
> On Fri, Dec 04, 2020 at 03:41:21PM, Dave Jiang <dave.jiang(a)intel.com>
> wrote:
> >
> >
> > > -----Original Message-----
> > > From: ramesh.thomas(a)intel.com <ramesh.thomas(a)intel.com>
> > > Sent: Wednesday, December 2, 2020 12:31 PM
> > > To: accel-config(a)lists.01.org
> > > Cc: Thomas, Ramesh <ramesh.thomas(a)intel.com>; Luck, Tony
> > > <tony.luck(a)intel.com>; Jiang, Dave <dave.jiang(a)intel.com>
> > > Subject: [PATCH v1 02/11] accel-config: Create mdev structures and
> > > load mdevs into device context
> > >
> > > From: Ramesh Thomas <ramesh.thomas(a)intel.com>
> > >
> > > Lays the foundation for the mdev implementation
> > >
> > > - Create private and exported structures for mdev types and mdev
> > > list
> > > - Create routines to scan and classify mdevs in sysfs
> > > - Store mdev details in device contexts during init
> > >
> > > Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
> > > ---
> > >  accfg/lib/libaccfg.c    | 81
> > > +++++++++++++++++++++++++++++++++++++++++
> > >  accfg/lib/private.h     |  8 ++++
> > >  accfg/libaccel_config.h |  7 ++++
> > >  3 files changed, 96 insertions(+)
> > >
> > > diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index
> > > 9b5615a..0dd1f0c
> > > 100644
> > > --- a/accfg/lib/libaccfg.c
> > > +++ b/accfg/lib/libaccfg.c
> > > @@ -43,6 +43,12 @@ ACCFG_EXPORT char *accfg_basenames[] = {  NULL
> > > };
> > >
> > > +ACCFG_EXPORT char *accfg_mdev_basenames[] = {
> > > +[ACCFG_MDEV_TYPE_1_DWQ]      = "1dwq",
> > > +[ACCFG_MDEV_TYPE_1_SWQ]      = "1swq",
> > > +NULL
> > > +};
> > > +
> > >  enum {
> > >  ACCFG_CMD_STATUS_MAX = 0x45,
> > >  };
> > > @@ -407,6 +413,77 @@ static int device_parse_type(struct
> > > accfg_device
> > > *device)
> > >  return 0;
> > >  }
> > >
> > > +static int mdev_str_to_type(char *mdev_type_str) {
> >
> > Please start the { on a new line for all functions
> 
> I think it is your Outlook removing newlines. The code is ok

Grrrr ok. I'll do the review in Mutt. I had Thunderbird working but it stopped with an update :( 

> 
> >
> > > +char **b;
> > > +char *s;
> > > +int l, i;
> > > +
> > > +s = strchr(mdev_type_str, '-');
> > > +if (!s)
> > > +s = mdev_type_str;
> > > +else
> > > +s++;
> > > +l = (int) (strchrnul(s, '-') - s);
> > > +
> > > +for (b = accfg_mdev_basenames, i = 0; *b != NULL; b++, i++) if
> > > +(!strncmp(*b, s, l)) return i;
> > > +
> > > +return ACCFG_MDEV_TYPE_UNKNOWN;
> > > +}
> > > +
> > > +static int add_device_mdevs(struct accfg_ctx *ctx, struct
> > > +accfg_device
> > > +*dev) {
> > > +struct accfg_device_mdev *dev_mdev; uuid_t uu; struct dirent **d;
> > > +char *f, *mdev_type_str; char p[PATH_MAX]; char
> > > +mdev_path[PATH_MAX]; int n, n1, rc = 0;
> > > +
> > > +n1 = n = scandir(dev->mdev_path, &d, NULL, alphasort); if (n < 0) {
> > > +err(ctx, "scandir failed\n"); return -ENOENT; }
> > > +
> > > +while (n--) {
> > > +f = &d[n]->d_name[0];
> > > +if (*f == '.' || uuid_parse(f, uu)) continue; sprintf(p,
> > > +"%s/%s/mdev_type", dev->mdev_path, f); if (!realpath(p, mdev_path))
> > > +continue; dev_mdev = calloc(1, sizeof(struct accfg_device_mdev));
> > > +if (!dev_mdev) { err(ctx, "allocation failed\n"); rc = -ENOMEM;
> > > +goto exit_add_mdev; } uuid_copy(dev_mdev->uuid, uu);
> mdev_type_str
> > > += strrchr(mdev_path, '/') + 1; dev_mdev->device = dev;
> > > +dev_mdev->type = mdev_str_to_type(mdev_type_str); if
> > > +(dev_mdev->type == ACCFG_MDEV_TYPE_UNKNOWN) { err(ctx,
> "mdev type
> > > +error\n"); free(dev_mdev); rc = -EINVAL; goto exit_add_mdev; }
> > > +list_add_tail(&dev->mdev_list, &dev_mdev->list); }
> > > +
> > > +exit_add_mdev:
> > > +while (n1--)
> > > +free(d[n1]);
> > > +free(d);
> > > +
> > > +return rc;
> > > +}
> > > +
> > >  static void *add_device(void *parent, int id, const char *ctl_base,
> > > char
> > > *dev_prefix)  {
> > >  struct accfg_ctx *ctx = parent;
> > > @@ -439,6 +516,7 @@ static void *add_device(void *parent, int id,
> > > const char *ctl_base, char *dev_pr  list_head_init(&device->groups);
> > > list_head_init(&device->wqs);  list_head_init(&device->engines);
> > > +list_head_init(&device->mdev_list);
> > >
> > >  device->ctx = ctx;
> > >  device->id = id;
> > > @@ -501,6 +579,9 @@ static void *add_device(void *parent, int id,
> > > const char *ctl_base, char *dev_pr  list_add_tail(&ctx->devices,
> > > &device->list);  free(path);
> > >
> > > +if (add_device_mdevs(ctx, device))
> > > +goto err_dev_path;
> > > +
> > >  return device;
> > >
> > >  err_dev_path:
> > > diff --git a/accfg/lib/private.h b/accfg/lib/private.h index
> > > 365d484..305d73e
> > > 100644
> > > --- a/accfg/lib/private.h
> > > +++ b/accfg/lib/private.h
> > > @@ -35,6 +35,7 @@ struct accfg_device {  char *device_type_str;
> > > enum accfg_device_type type;
> > >          size_t buf_len;
> > > +struct list_head mdev_list;
> > >
> > >  /* Device Attributes */
> > >  struct accfg_error errors;
> > > @@ -56,6 +57,13 @@ struct accfg_device {  char *pasid_enabled;  };
> > >
> > > +struct accfg_device_mdev {
> > > +struct accfg_device *device;
> > > +uuid_t uuid;
> > > +enum accfg_mdev_type type;
> > > +struct list_node list;
> > > +};
> > > +
> > >  struct accfg_group {
> > >          struct accfg_device *device;
> > >          int id;
> > > diff --git a/accfg/libaccel_config.h b/accfg/libaccel_config.h index
> > > f85670c..e89bd40 100644
> > > --- a/accfg/libaccel_config.h
> > > +++ b/accfg/libaccel_config.h
> > > @@ -67,6 +67,12 @@ enum accfg_control_flag {  ACCFG_WQ_DISABLE,
> };
> > >
> > > +enum accfg_mdev_type {
> > > +ACCFG_MDEV_TYPE_1_DWQ,
> > > +ACCFG_MDEV_TYPE_1_SWQ,
> > > +ACCFG_MDEV_TYPE_UNKNOWN,
> >
> > Should we assign the UNKNOWN to a -1 value?
> >
> > > +};
> > > +
> > >  /* no need to save device error */
> > >  struct accfg_error {
> > >          uint64_t val[4];
> > > @@ -78,6 +84,7 @@ struct dev_parameters {  };
> > >
> > >  extern char *accfg_basenames[];
> > > +extern char *accfg_mdev_basenames[];
> > >
> > >  struct group_parameters {
> > >  unsigned int tokens_reserved;
> > > --
> > > 2.26.2
> > _______________________________________________
> > Accel-config mailing list -- accel-config(a)lists.01.org To unsubscribe
> > send an email to accel-config-leave(a)lists.01.org
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.