-
Notifications
You must be signed in to change notification settings - Fork 695
nvme: plot eye chart data and hex dumping VS eye data #2845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2124,23 +2124,60 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane, | |
| struct json_object *r) | ||
| { | ||
| char *eye = (char *)lane->eye_desc; | ||
| char *printable = malloc(lane->nrows * lane->ncols + lane->ncols); | ||
| char *printable_start = printable; | ||
| int i, j; | ||
| uint16_t nrows = le16_to_cpu(lane->nrows); | ||
| uint16_t ncols = le16_to_cpu(lane->ncols); | ||
| struct json_object *eye_array = NULL; | ||
| char *printable_start = NULL; | ||
| char *printable = NULL; | ||
|
|
||
| if (nrows == 0 || ncols == 0) | ||
| return NULL; | ||
|
|
||
| eye_array = json_create_array(); | ||
| if (!eye_array) | ||
| return NULL; | ||
|
|
||
| /* | ||
| * Allocate buffer for full printable string (with newlines) | ||
| * +1 for null terminator | ||
| */ | ||
| printable = malloc(nrows * ncols + nrows + 1); | ||
| printable_start = printable; | ||
|
|
||
| if (!printable) | ||
| goto exit; | ||
| goto fail_free_eye_array; | ||
|
|
||
| for (i = 0; i < lane->nrows; i++) { | ||
| for (j = 0; j < lane->ncols; j++, printable++) | ||
| sprintf(printable, "%c", eye[i * lane->ncols + j]); | ||
| sprintf(printable++, "\n"); | ||
| for (int i = 0; i < nrows; i++) { | ||
| char *row = malloc(ncols + 1); | ||
|
|
||
| if (!row) | ||
| goto fail_free_eye_printable; | ||
|
|
||
| for (int j = 0; j < ncols; j++) { | ||
| char ch = eye[i * ncols + j]; | ||
| *printable++ = ch; | ||
| row[j] = ch; | ||
| } | ||
|
|
||
| *printable++ = '\n'; | ||
| row[ncols] = '\0'; | ||
|
|
||
| array_add_str(eye_array, row); | ||
| free(row); | ||
| } | ||
|
|
||
| obj_add_str(r, "printable_eye", printable_start); | ||
| *printable = '\0'; | ||
|
|
||
| obj_add_array(r, "printable_eye", eye_array); | ||
|
|
||
| exit: | ||
| return printable_start; | ||
|
|
||
| fail_free_eye_printable: | ||
| free(printable); | ||
| fail_free_eye_array: | ||
| json_free_object(eye_array); | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, | ||
|
|
@@ -2155,7 +2192,20 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, | |
|
|
||
| for (i = 0; i < num_descs; i++) { | ||
| struct nvme_eom_lane_desc *desc = p; | ||
| struct json_object *jdesc = json_create_object(); | ||
| _cleanup_free_ char *hexstr = NULL; | ||
| unsigned char *vsdata = NULL; | ||
| unsigned int vsdataoffset = 0; | ||
| uint16_t nrows, ncols, edlen; | ||
| struct json_object *jdesc; | ||
| char *hexdata; | ||
|
|
||
| jdesc = json_create_object(); | ||
| if (!desc) | ||
| return; | ||
|
|
||
| nrows = le16_to_cpu(desc->nrows); | ||
| ncols = le16_to_cpu(desc->ncols); | ||
| edlen = le16_to_cpu(desc->edlen); | ||
|
|
||
| obj_add_uint(jdesc, "lid", desc->mstatus); | ||
| obj_add_uint(jdesc, "lane", desc->lane); | ||
|
|
@@ -2164,14 +2214,36 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log, | |
| obj_add_uint(jdesc, "bottom", le16_to_cpu(desc->bottom)); | ||
| obj_add_uint(jdesc, "left", le16_to_cpu(desc->left)); | ||
| obj_add_uint(jdesc, "right", le16_to_cpu(desc->right)); | ||
| obj_add_uint(jdesc, "nrows", le16_to_cpu(desc->nrows)); | ||
| obj_add_uint(jdesc, "ncols", le16_to_cpu(desc->ncols)); | ||
| obj_add_uint(jdesc, "edlen", le16_to_cpu(desc->edlen)); | ||
| obj_add_uint(jdesc, "nrows", nrows); | ||
| obj_add_uint(jdesc, "ncols", ncols); | ||
| obj_add_uint(jdesc, "edlen", edlen); | ||
|
|
||
| if (NVME_EOM_ODP_PEFP(log->odp)) | ||
| allocated_eyes[i] = json_eom_printable_eye(desc, r); | ||
| allocated_eyes[i] = json_eom_printable_eye(desc, jdesc); | ||
|
|
||
| if (edlen == 0) | ||
| continue; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this leaking jdesc?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modified as suggested. |
||
|
|
||
| /* 2 hex chars + space per byte */ | ||
| hexstr = malloc(edlen * 3 + 1); | ||
|
|
||
| if (!hexstr) { | ||
| json_free_object(jdesc); | ||
| return; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this leaks jdec for sure.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added code to free the jdesc. |
||
| } | ||
|
|
||
| /* Hex dump Vendor Specific Eye Data */ | ||
| vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc); | ||
| vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset); | ||
|
|
||
| hexdata = hexstr; | ||
|
|
||
| for (int offset = 0; offset < edlen; offset++) | ||
| hexdata += sprintf(hexdata, "%02X ", vsdata[offset]); | ||
| /* remove trailing space */ | ||
| *(hexdata - 1) = '\0'; | ||
|
|
||
| /* Eye Data field is vendor specific, doesn't map to JSON */ | ||
| obj_add_str(jdesc, "vsdata_hex", hexstr); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so maybe something like for (i = 0; i < num_descs; i++) {
struct nvme_eom_lane_desc *desc = p;
+ _cleanup_free_ char *hexstr = NULL;
unsigned char *vsdata = NULL;
unsigned int vsdataoffset = 0;
- struct json_object *jdesc = json_create_object();
- uint16_t nrows = le16_to_cpu(desc->nrows);
- uint16_t ncols = le16_to_cpu(desc->ncols);
- uint16_t edlen = le16_to_cpu(desc->edlen);
+ uint16_t nrows, ncols, edlen;
+ struct json_object *jdesc;
+ char *hexdata;
+
+ jdesc = json_create_object();
+ if (!jdesc)
+ return;
+
+ nrows = le16_to_cpu(desc->nrows);
+ ncols = le16_to_cpu(desc->ncols);
+ edlen = le16_to_cpu(desc->edlen);
obj_add_uint(jdesc, "lid", desc->mstatus);
obj_add_uint(jdesc, "lane", desc->lane);
@@ -2214,16 +2225,17 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
continue;
/* 2 hex chars + space per byte */
- _cleanup_free_ char *hexstr = malloc(edlen * 3 + 1);
-
- if (!hexstr)
+ hexstr = malloc(edlen * 3 + 1);
+ if (!hexstr) {
+ json_free_object(jdesc);
return;
+ }
/* Hex dump Vendor Specific Eye Data */
vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
- char *hexdata = hexstr;
+ hexdata = hexstr;
for (int offset = 0; offset < edlen; offset++)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestions. I've modified the code as per your suggestion. Please review the code. |
||
|
|
||
| array_add_obj(descs, jdesc); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -776,9 +776,9 @@ static void stdout_eom_printable_eye(struct nvme_eom_lane_desc *lane) | |
| char *eye = (char *)lane->eye_desc; | ||
| int i, j; | ||
|
|
||
| for (i = 0; i < lane->nrows; i++) { | ||
| for (j = 0; j < lane->ncols; j++) | ||
| printf("%c", eye[i * lane->ncols + j]); | ||
| for (i = 0; i < le16_to_cpu(lane->nrows); i++) { | ||
| for (j = 0; j < le16_to_cpu(lane->ncols); j++) | ||
| printf("%c", eye[i * le16_to_cpu(lane->ncols) + j]); | ||
| printf("\n"); | ||
| } | ||
| } | ||
|
|
@@ -790,6 +790,13 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log) | |
|
|
||
| for (i = 0; i < log->nd; i++) { | ||
| struct nvme_eom_lane_desc *desc = p; | ||
| unsigned char *vsdata = NULL; | ||
| unsigned int vsdataoffset = 0; | ||
| uint16_t nrows, ncols, edlen; | ||
|
|
||
| nrows = le16_to_cpu(desc->nrows); | ||
| ncols = le16_to_cpu(desc->ncols); | ||
| edlen = le16_to_cpu(desc->edlen); | ||
|
|
||
| printf("Measurement Status: %s\n", | ||
| desc->mstatus ? "Successful" : "Not Successful"); | ||
|
|
@@ -799,14 +806,28 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log) | |
| printf("Bottom: %u\n", le16_to_cpu(desc->bottom)); | ||
| printf("Left: %u\n", le16_to_cpu(desc->left)); | ||
| printf("Right: %u\n", le16_to_cpu(desc->right)); | ||
| printf("Number of Rows: %u\n", le16_to_cpu(desc->nrows)); | ||
| printf("Number of Columns: %u\n", le16_to_cpu(desc->ncols)); | ||
| printf("Eye Data Length: %u\n", le16_to_cpu(desc->edlen)); | ||
| printf("Number of Rows: %u\n", nrows); | ||
| printf("Number of Columns: %u\n", ncols); | ||
| printf("Eye Data Length: %u\n", desc->edlen); | ||
|
|
||
| if (NVME_EOM_ODP_PEFP(log->odp)) | ||
| stdout_eom_printable_eye(desc); | ||
|
|
||
| /* Eye Data field is vendor specific */ | ||
| if (edlen == 0) | ||
| continue; | ||
|
|
||
| /* Hex dump Vendor Specific Eye Data */ | ||
| vsdata = malloc(edlen); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return value is not checked, could be NULL.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added NULL check as suggested. |
||
| if (!vsdata) | ||
| return; | ||
|
|
||
| vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc); | ||
| vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here we leak vsdata. BTW,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks you for the feedback @igaw. |
||
| printf("Eye Data:\n"); | ||
| d(vsdata, edlen, 16, 1); | ||
| printf("\n"); | ||
| free(vsdata); | ||
|
|
||
| p += log->dsize; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |
| * | ||
| * @file: micron-nvme.c | ||
| * @brief: This module contains all the constructs needed for micron nvme-cli plugin. | ||
| * @authors:Chaithanya Shoba <[email protected]>, | ||
| * @authors:Hanumanthu H <[email protected]> | ||
| * Chaithanya Shoba <[email protected]> | ||
| * Sivaprasad Gutha <[email protected]> | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| * | ||
| * @file: micron-nvme.h | ||
| * @brief: This module contains all the constructs needed for micron nvme-cli plugin. | ||
| * @authors:Chaithanya Shoba <[email protected]>, | ||
| * @authors:Hanumanthu H <[email protected]> | ||
| * Chaithanya Shoba <[email protected]> | ||
| * Sivaprasad Gutha <[email protected]> | ||
| */ | ||
|
|
||
| #undef CMD_INC_FILE | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use goto error handlilng pattern:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay, and thank you so much for your feedback and suggestions. I've incorporated the suggested changes. Please take a moment to review and let me know if everything looks good or if any further adjustments are needed.