From: Alison Schofield <alison.schofield@intel.com>
To: Dave Jiang <dave.jiang@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>,
nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [ndctl PATCH v7 5/7] cxl/list: collect and parse media_error records
Date: Wed, 28 Feb 2024 18:45:09 -0800 [thread overview]
Message-ID: <Zd/vtfjCoLvjTT1q@aschofie-mobl2> (raw)
In-Reply-To: <b3f23b92-99f6-404e-aed2-19a8f5ceb43f@intel.com>
On Thu, Feb 08, 2024 at 09:50:27AM -0700, Dave Jiang wrote:
>
Hi Dave,
Sorry I missed this in v8. Picking up for v9.
See a question below -
snip
>
> > +static const char *
> > +find_decoder_name(struct poison_ctx *ctx, const char *name, u64 addr)
> > +{
> > + struct cxl_memdev *memdev = ctx->memdev;
> > + struct cxl_memdev_mapping *mapping;
> > + struct cxl_endpoint *endpoint;
> > + struct cxl_decoder *decoder;
> > + struct cxl_port *port;
> > + u64 start, end;
> > +
> > + if (memdev)
> > + goto find_decoder;
> > +
> > + cxl_mapping_foreach(ctx->region, mapping) {
> > + decoder = cxl_mapping_get_decoder(mapping);
> > + if (!decoder)
> > + continue;
> > +
> > + memdev = cxl_decoder_get_memdev(decoder);
> > + if (strcmp(name, cxl_memdev_get_devname(memdev)) == 0)
> > + break;
> > +
> > + memdev = NULL;
> > + }
> > +
> > +find_decoder:
>
> Would it be cleaner to move this block into a helper function? Don't really care for goto blocks that are not error handling paths.
Done. Added a __find_memdev.
>
> > + if (!memdev)
> > + return NULL;
> > +
> > + endpoint = cxl_memdev_get_endpoint(memdev);
> > + port = cxl_endpoint_get_port(endpoint);
> > +
> > + cxl_decoder_foreach(port, decoder) {
> > + start = cxl_decoder_get_resource(decoder);
> > + end = start + cxl_decoder_get_size(decoder) - 1;
> > + if (start <= addr && addr <= end)
> > + return cxl_decoder_get_devname(decoder);
> > + }
> > +
> > + return NULL;
And, with another look - cleaned up the above indented/hidden
successful return ;)
> > +}
> > +
> > +int poison_event_to_json(struct tep_event *event, struct tep_record *record,
> > + void *ctx)
> > +{
> > + struct poison_ctx *p_ctx = (struct poison_ctx *)ctx;
> > + struct json_object *jobj, *jp, *jpoison = p_ctx->jpoison;
> > + unsigned long flags = p_ctx->flags;
> > + bool overflow = false;
> > + unsigned char *data;
> > + const char *name;
> > + int pflags;
> > + char *str;
> > +
> > + jp = json_object_new_object();
> > + if (!jp)
> > + return -ENOMEM;
> > +
> > + /* Skip records not in this region when listing by region */
> > + name = p_ctx->region ? cxl_region_get_devname(p_ctx->region) : NULL;
> > + if (name)
> > + str = cxl_get_field_string(event, record, "region");
> > +
> > + if ((name) && (strcmp(name, str) != 0)) {
> > + json_object_put(jp);
> > + return 0;
> > + }
> > +
> > + /* Include endpoint decoder name with hpa, when present */
> > + name = cxl_get_field_string(event, record, "memdev");
> > + data = cxl_get_field_data(event, record, "hpa");
> > + if (*(uint64_t *)data != ULLONG_MAX)
> > + name = find_decoder_name(p_ctx, name, *(uint64_t *)data);
> > + else
> > + name = NULL;
> > +
> > + if (name) {
> > + jobj = json_object_new_string(name);
> > + if (jobj)
> > + json_object_object_add(jp, "decoder", jobj);
> > +
> > + jobj = util_json_object_hex(*(uint64_t *)data, flags);
> > + if (jobj)
> > + json_object_object_add(jp, "hpa", jobj);
> > + }
> > +
> > + data = cxl_get_field_data(event, record, "dpa");
> > + jobj = util_json_object_hex(*(uint64_t *)data, flags);
> > + if (jobj)
> > + json_object_object_add(jp, "dpa", jobj);
> > +
> > + data = cxl_get_field_data(event, record, "dpa_length");
> > + jobj = util_json_object_size(*(uint32_t *)data, flags);
> > + if (jobj)
> > + json_object_object_add(jp, "length", jobj);
> > +
> > + str = cxl_get_field_string(event, record, "source");
> > + switch (*(uint8_t *)str) {
>
> This causes reading confusion when it looks like the code is retrieving a string and then compare as an integer. Should this be done through cxl_get_field_data()?
>
Did a couple of things here -
reworked the helpers to give exactly what is needed here,
ie int, u64 or string. That gets rid of all the casting.
It also led to a bit more error checking on return value,
so bonus goodness.
> > + case CXL_POISON_SOURCE_UNKNOWN:
> > + jobj = json_object_new_string("Unknown");
> > + break;
> > + case CXL_POISON_SOURCE_EXTERNAL:
> > + jobj = json_object_new_string("External");
> > + break;
> > + case CXL_POISON_SOURCE_INTERNAL:
> > + jobj = json_object_new_string("Internal");
> > + break;
> > + case CXL_POISON_SOURCE_INJECTED:
> > + jobj = json_object_new_string("Injected");
> > + break;
> > + case CXL_POISON_SOURCE_VENDOR:
> > + jobj = json_object_new_string("Vendor");
> > + break;
> > + default:
> > + jobj = json_object_new_string("Reserved");
> > + }
> > + if (jobj)
> > + json_object_object_add(jp, "source", jobj);
> > +
> > + str = cxl_get_field_string(event, record, "flags");
> > + pflags = *(uint8_t *)str;
>
> Same as above comment here
Gone. All the values that can be held in "int" are fetched
using a cxl_get_field_int().
snip
> > +static struct json_object *
> > +util_cxl_poison_events_to_json(struct tracefs_instance *inst,
> > + struct poison_ctx *p_ctx)
> > +{
> > + struct event_ctx ectx = {
> > + .event_name = "cxl_poison",
> > + .event_pid = getpid(),
> > + .system = "cxl",
> > + .private_ctx = p_ctx,
> > + .parse_event = poison_event_to_json,
> > + };
> > + int rc = 0;
> > +
> > + p_ctx->jpoison = json_object_new_array();
> > + if (!p_ctx->jpoison)
> > + return NULL;
> > +
> > + rc = cxl_parse_events(inst, &ectx);
> > + if (rc < 0) {
> > + fprintf(stderr, "Failed to parse events: %d\n", rc);
> > + json_object_put(p_ctx->jpoison);
> > + return NULL;
>
> Maybe a goto err here and the next error path may now be warranted?
> > + }
> > +
> > + if (json_object_array_length(p_ctx->jpoison) == 0) {
> > + json_object_put(p_ctx->jpoison);
> > + return NULL;
> > + }
> > +
> > + return p_ctx->jpoison;
> > +}
Not sure what you suggest here. I can combine the err cases like
this:
if ((rc < 0) || json_object_array_length(p_ctx->jpoison) == 0) {
fprintf(stderr, "Failed to parse events: %d\n", rc);
json_object_put(p_ctx->jpoison);
return NULL;
}
Or (and) something else?
next prev parent reply other threads:[~2024-02-29 2:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 1:01 [ndctl PATCH v7 0/7] Support poison list retrieval alison.schofield
2024-02-08 1:01 ` [ndctl PATCH v7 1/7] libcxl: add interfaces for GET_POISON_LIST mailbox commands alison.schofield
2024-02-08 1:01 ` [ndctl PATCH v7 2/7] cxl: add an optional pid check to event parsing alison.schofield
2024-02-08 1:01 ` [ndctl PATCH v7 3/7] cxl/event_trace: add a private context for private parsers alison.schofield
2024-02-08 1:01 ` [ndctl PATCH v7 4/7] cxl/event_trace: add helpers get_field_[string|data]() alison.schofield
2024-02-08 1:01 ` [ndctl PATCH v7 5/7] cxl/list: collect and parse media_error records alison.schofield
2024-02-08 16:50 ` Dave Jiang
2024-02-29 2:45 ` Alison Schofield [this message]
2024-02-08 1:01 ` [ndctl PATCH v7 6/7] cxl/list: add --media-errors option to cxl list alison.schofield
2024-02-08 16:51 ` Dave Jiang
2024-02-08 1:01 ` [ndctl PATCH v7 7/7] cxl/test: add cxl-poison.sh unit test alison.schofield
2024-02-08 18:18 ` Dave Jiang
2024-02-22 8:04 ` Verma, Vishal L
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=Zd/vtfjCoLvjTT1q@aschofie-mobl2 \
--to=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=vishal.l.verma@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).