All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "Williams, Dan J" <dan.j.williams@intel.com>
Cc: "linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
	"nvdimm@lists.linux.dev" <nvdimm@lists.linux.dev>
Subject: Re: [ndctl PATCH 09/15] cxl/region: Make ways an integer argument
Date: Tue, 8 Nov 2022 19:36:32 +0000	[thread overview]
Message-ID: <2143317d50d570ca02d2975905612a196268d1f5.camel@intel.com> (raw)
In-Reply-To: <166777845733.1238089.4849744927692588680.stgit@dwillia2-xfh.jf.intel.com>

On Sun, 2022-11-06 at 15:47 -0800, Dan Williams wrote:
> Since --ways does not take a unit value like --size, just make it an
> integer argument directly and skip the hand coded conversion.

Ah I had gone back and forth between using an int vs. unsigned. I had
gone with unsigned because the kernel treats it as an unsigned too
behind the sysfs ABI. But I guess in practice it doesn't matter, since
the values are clamped to [256, 16K]. Certainly using an int here makes
things cleaner!

> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  cxl/region.c |   41 +++++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/cxl/region.c b/cxl/region.c
> index 334fcc291de7..494da5139c05 100644
> --- a/cxl/region.c
> +++ b/cxl/region.c
> @@ -21,21 +21,23 @@
>  static struct region_params {
>         const char *bus;
>         const char *size;
> -       const char *ways;
>         const char *granularity;
>         const char *type;
>         const char *root_decoder;
>         const char *region;
> +       int ways;
>         bool memdevs;
>         bool force;
>         bool human;
>         bool debug;
> -} param;
> +} param = {
> +       .ways = INT_MAX,
> +};
>  
>  struct parsed_params {
>         u64 size;
>         u64 ep_min_size;
> -       unsigned int ways;
> +       int ways;
>         unsigned int granularity;
>         const char **targets;
>         int num_targets;
> @@ -63,9 +65,8 @@ OPT_BOOLEAN(0, "debug", &param.debug, "turn on
> debug")
>  OPT_STRING('s', "size", &param.size, \
>            "size in bytes or with a K/M/G etc. suffix", \
>            "total size desired for the resulting region."), \
> -OPT_STRING('w', "ways", &param.ways, \
> -          "number of interleave ways", \
> -          "number of memdevs participating in the regions interleave
> set"), \
> +OPT_INTEGER('w', "ways", &param.ways, \
> +           "number of memdevs participating in the regions
> interleave set"), \
>  OPT_STRING('g', "granularity", \
>            &param.granularity, "interleave granularity", \
>            "granularity of the interleave set"), \
> @@ -126,15 +127,11 @@ static int parse_create_options(int argc, const
> char **argv,
>                 }
>         }
>  
> -       if (param.ways) {
> -               unsigned long ways = strtoul(param.ways, NULL, 0);
> -
> -               if (ways == ULONG_MAX || (int)ways <= 0) {
> -                       log_err(&rl, "Invalid interleave ways: %s\n",
> -                               param.ways);
> -                       return -EINVAL;
> -               }
> -               p->ways = ways;
> +       if (param.ways <= 0) {
> +               log_err(&rl, "Invalid interleave ways: %d\n",
> param.ways);
> +               return -EINVAL;
> +       } else if (param.ways < INT_MAX) {
> +               p->ways = param.ways;
>         } else if (argc) {
>                 p->ways = argc;
>         } else {
> @@ -155,13 +152,13 @@ static int parse_create_options(int argc, const
> char **argv,
>         }
>  
>  
> -       if (argc > (int)p->ways) {
> +       if (argc > p->ways) {
>                 for (i = p->ways; i < argc; i++)
>                         log_err(&rl, "extra argument: %s\n", p-
> >targets[i]);
>                 return -EINVAL;
>         }
>  
> -       if (argc < (int)p->ways) {
> +       if (argc < p->ways) {
>                 log_err(&rl,
>                         "too few target arguments (%d) for interleave
> ways (%u)\n",
>                         argc, p->ways);
> @@ -253,7 +250,7 @@ static bool validate_memdev(struct cxl_memdev
> *memdev, const char *target,
>  
>  static int validate_config_memdevs(struct cxl_ctx *ctx, struct
> parsed_params *p)
>  {
> -       unsigned int i, matched = 0;
> +       int i, matched = 0;
>  
>         for (i = 0; i < p->ways; i++) {
>                 struct cxl_memdev *memdev;
> @@ -393,7 +390,8 @@ static int
> cxl_region_determine_granularity(struct cxl_region *region,
>                                             struct parsed_params *p)
>  {
>         const char *devname = cxl_region_get_devname(region);
> -       unsigned int granularity, ways;
> +       unsigned int granularity;
> +       int ways;
>  
>         /* Default granularity will be the root decoder's granularity
> */
>         granularity = cxl_decoder_get_interleave_granularity(p-
> >root_decoder);
> @@ -408,7 +406,7 @@ static int
> cxl_region_determine_granularity(struct cxl_region *region,
>                 return granularity;
>  
>         ways = cxl_decoder_get_interleave_ways(p->root_decoder);
> -       if (ways == 0 || ways == UINT_MAX) {
> +       if (ways == 0 || ways == -1) {
>                 log_err(&rl, "%s: unable to determine root decoder
> ways\n",
>                         devname);
>                 return -ENXIO;
> @@ -436,12 +434,11 @@ static int create_region(struct cxl_ctx *ctx,
> int *count,
>  {
>         unsigned long flags = UTIL_JSON_TARGETS;
>         struct json_object *jregion;
> -       unsigned int i, granularity;
>         struct cxl_region *region;
> +       int i, rc, granularity;
>         u64 size, max_extent;
>         const char *devname;
>         uuid_t uuid;
> -       int rc;
>  
>         rc = create_region_validate_config(ctx, p);
>         if (rc)
> 


  parent reply	other threads:[~2022-11-08 19:36 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 23:46 [ndctl PATCH 00/15] cxl-cli test and usability updates Dan Williams
2022-11-06 23:46 ` [ndctl PATCH 01/15] ndctl/test: Move firmware-update.sh to the 'descructive' set Dan Williams
2022-11-06 23:46 ` [ndctl PATCH 02/15] ndctl/test: Add kernel backtrace detection to some dax tests Dan Williams
2022-11-07 22:55   ` Alison Schofield
2022-11-06 23:47 ` [ndctl PATCH 03/15] ndctl/clang-format: Move minimum version to 6 Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 04/15] ndctl/clang-format: Fix space after for_each macros Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 05/15] cxl/list: Always attempt to collect child objects Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 06/15] cxl/list: Skip emitting pmem_size when it is zero Dan Williams
2022-11-07 20:23   ` Alison Schofield
2022-11-07 23:42     ` Dan Williams
2022-12-08  3:36     ` Dan Williams
2022-11-07 22:47   ` Alison Schofield
2022-11-07 23:51     ` Dan Williams
2022-12-08  4:14     ` Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 07/15] cxl/filter: Return json-c topology Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 08/15] cxl/list: Record cxl objects in json objects Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 09/15] cxl/region: Make ways an integer argument Dan Williams
2022-11-07 22:43   ` Alison Schofield
2022-11-07 23:50     ` Dan Williams
2022-11-08 19:36   ` Verma, Vishal L [this message]
2022-11-06 23:47 ` [ndctl PATCH 10/15] cxl/region: Make granularity " Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 11/15] cxl/region: Use cxl_filter_walk() to gather create-region targets Dan Williams
2022-11-08  8:31   ` Verma, Vishal L
2022-12-08 20:23     ` Dan Williams
2022-11-06 23:47 ` [ndctl PATCH 12/15] cxl/region: Trim region size by max available extent Dan Williams
2022-11-06 23:48 ` [ndctl PATCH 13/15] cxl/region: Default to memdev mode for create with no arguments Dan Williams
2022-11-07 20:36   ` Alison Schofield
2022-11-07 23:48     ` Dan Williams
2022-11-08 16:03       ` Alison Schofield
2022-12-08  4:09     ` Dan Williams
2022-11-06 23:48 ` [ndctl PATCH 14/15] cxl/test: Extend cxl-topology.sh for a single root-port host-bridge Dan Williams
2022-11-07 22:38   ` Alison Schofield
2022-11-08 20:23   ` Verma, Vishal L
2022-12-08 20:25     ` Dan Williams
2022-11-06 23:48 ` [ndctl PATCH 15/15] cxl/test: Test single-port host-bridge region creation Dan Williams
2022-11-07 22:36   ` Alison Schofield

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2143317d50d570ca02d2975905612a196268d1f5.camel@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.