nvme: plot eye chart data and hex dumping VS eye data#2828
nvme: plot eye chart data and hex dumping VS eye data#2828sivaprasad6541 wants to merge 7 commits intolinux-nvme:masterfrom
Conversation
sivaprasad6541
commented
May 27, 2025
- Fixed segmentation fault issue in JSON output format for VS Eye data.
- Added support to hex dump VS Eye data in both normal and JSON formats.
- This enables customers to decode the raw eye chart data if needed.
- Ensured compatibility with existing d() and obj_d() hex dump utilities.
- Fixed segmentation fault issue in JSON output format for VS Eye data. - Added support to hex dump VS Eye data in both normal and JSON formats. - This enables customers to decode the raw eye chart data if needed. - Ensured compatibility with existing d() and obj_d() hex dump utilities. Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
- Added contributors list to the AUTHORS section of the Micron plugin. Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
|
Tested both formats and here is the results. |
igaw
left a comment
There was a problem hiding this comment.
A few nitpicks.
The only real issue I see is JSON member name change, because this breaks any existing parser.
nvme-print-json.c
Outdated
| /* Printable Eye string is allocated and returned, caller must free */ | ||
| static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane, | ||
| struct json_object *r) | ||
| struct json_object *r) |
There was a problem hiding this comment.
unrelated whitespace change, please drop this one
There was a problem hiding this comment.
I've undone the unrelated whitespace change as suggested.
nvme-print-json.c
Outdated
| goto exit; | ||
| return NULL; | ||
|
|
||
| struct json_object *eye_array = json_create_array(); |
There was a problem hiding this comment.
If we are checking for null pointers, then this one should also be checked I suppose.
And don't we need to free it eventually? In this case use the cleanup helpers so that you can exit the funtion at anytime. Can't remember what json-c does, if it takes the owner ship.
There was a problem hiding this comment.
Thanks for the suggestion! I initially tried using cleanup helpers, but encountered a segfault in the caller while printing the root JSON object. Since the caller is responsible for freeing the memory, I've kept the manual cleanup logic in place to avoid ownership issues.
Added a null check for eye_array now.
There was a problem hiding this comment.
again declaration go to the beginning of the block
There was a problem hiding this comment.
Moved this to beginning of the block.
nvme-print-json.c
Outdated
| char *row = malloc(ncols + 1); | ||
|
|
||
| if (!row) | ||
| continue; |
There was a problem hiding this comment.
Does it make to continue if we run out of memory? Maybe break or return NULL?
There was a problem hiding this comment.
Thanks for the catch. I've modified it to return NULL.
nvme-print-json.c
Outdated
| obj_add_str(r, "printable_eye", printable_start); | ||
| *printable = '\0'; | ||
|
|
||
| obj_add_array(r, "printable_eye_rows", eye_array); |
There was a problem hiding this comment.
This breaks the 'API', the name changes and existing parsers will be unhappy.
There was a problem hiding this comment.
Ah wait, there is a way for this change. We introduced the possibility to select the output format with --output-format-version, e.g. see f8f086c ("nvme: add output-format-version option")
There was a problem hiding this comment.
I have renamed it as earlier.
As per #2828 (comment)
If we hear feedback from users later, we can revisit with the --output-format-version approach as you suggested.
nvme-print-json.c
Outdated
| continue; | ||
| else { | ||
| /* Hex dump Vendor Specific Eye Data*/ | ||
| vsdata = (unsigned char *)malloc(desc->edlen); |
There was a problem hiding this comment.
Removed the casting as suggested.
nvme-print-json.c
Outdated
| char *hexstr = malloc(desc->edlen * 3 + 1); // 2 hex chars + space per byte | ||
|
|
||
| if (!hexstr) | ||
| return; |
There was a problem hiding this comment.
Thanks for the catch.
I've removed memory allocation for vsdata as it is not required.
nvme-print-json.c
Outdated
| /* Hex dump Vendor Specific Eye Data*/ | ||
| vsdata = (unsigned char *)malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + | ||
| sizeof(struct nvme_eom_lane_desc); |
There was a problem hiding this comment.
indention seems to be off here.
There was a problem hiding this comment.
Thanks for pointing that out! had to break the line due to the 100-column limit, which affected the indentation slightly.
Now, I've modified it to look better indentation.
nvme-print-stdout.c
Outdated
| /* Hex dump Vendor Specific Eye Data */ | ||
| vsdata = (unsigned char *)malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + | ||
| sizeof(struct nvme_eom_lane_desc); |
There was a problem hiding this comment.
Thanks for pointing that out! had to break the line due to the 100-column limit, which affected the indentation slightly.
Now, I've modified it to look better indentation.
nvme-print-stdout.c
Outdated
| /* Eye Data field is vendor specific */ | ||
| if (desc->edlen == 0) | ||
| continue; | ||
| else { |
There was a problem hiding this comment.
no need for the else branch, reduces the indention.
There was a problem hiding this comment.
Removed the else branch is suggested.
nvme-print-stdout.c
Outdated
| continue; | ||
| else { | ||
| /* Hex dump Vendor Specific Eye Data */ | ||
| vsdata = (unsigned char *)malloc(desc->edlen); |
There was a problem hiding this comment.
Removed the cast as suggested.
|
@brandon-paupore-sndk maybe also have a look at it, as you provided the initial code. |
brandon-paupore-sndk
left a comment
There was a problem hiding this comment.
Looks good to me, other than @igaw's comments and some minor little-endian conversion cleanup. I don't have any preference against the main update to the JSON eye object as an array of strings per newline rather than one large string with embedded newlines.
nvme-print-json.c
Outdated
| uint16_t nrows = lane->nrows; | ||
| uint16_t ncols = lane->ncols; |
There was a problem hiding this comment.
These should be swapped to the host endianness (i.e. le16_to_cpu(lane->nrows)), not that it's a new issue.
There was a problem hiding this comment.
I’ve updated the code to convert the values to host endianness using le16_to_cpu() as suggested.
nvme-print-json.c
Outdated
| vsdata = (unsigned char *)malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + |
There was a problem hiding this comment.
The various __le16 fields in desc should be converted to host-endianness before being used. The uses of these fields below should also be swapped.
There was a problem hiding this comment.
I’ve updated the code to convert the values to host endianness using le16_to_cpu() as suggested.
nvme-print-stdout.c
Outdated
| vsdata = (unsigned char *)malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + |
There was a problem hiding this comment.
As on the JSON side, the various __le16 fields in desc should be converted to host-endianness before being used. The use below should also be swapped.
There was a problem hiding this comment.
I’ve updated the code to convert the values to host endianness using le16_to_cpu() as suggested.
I am a bit wary with json output format changes. If you think it's okay to change to format now (I don't expect many users for this interface anyway) we can do it. If someone complains we could use the Basically it's your call :) |
Well thanks! And yeah, I agree that ideally the JSON output would be stable, but I think it'd be early enough to change this without needing different output versions. Particularly given that the other JSON output fixes here address a likely segfault. If this array output format would be preferred in the long-term then I'm good with making the switch now, or if not then leaving the format as-is and just keeping the fixes. |
-Addressing review comments Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
nvme-print-stdout.c
Outdated
| if (desc->edlen == 0) | ||
| continue; | ||
|
|
||
| /* Hex dump Vendor Specific Eye Data */ | ||
| vsdata = malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + | ||
| sizeof(struct nvme_eom_lane_desc); | ||
| vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset); | ||
| printf("Eye Data:\n"); | ||
| d(vsdata, desc->edlen, 16, 1); |
There was a problem hiding this comment.
Most of the le16 conversions are done, but there's still a few in this section for desc->(edlen, nrows, ncols).
There was a problem hiding this comment.
Sorry for that. I've converted all the remaining ones now.
-Addressing review comments -Converting all the unsigned shorts into host-endianness Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
igaw
left a comment
There was a problem hiding this comment.
Please merge the updates/fixes into the first patch.
nvme-print-json.c
Outdated
| if (nrows == 0 || ncols == 0) | ||
| return NULL; | ||
|
|
||
| // Allocate buffer for full printable string (with newlines) |
There was a problem hiding this comment.
Please use /* */ commet style, e.g.
/*
* Allocate buffer for full printable string (with newlines)
* +1 for null terminator
*/
printable = malloc(nrows * ncols + nrows + 1);
printable_start = printable;There was a problem hiding this comment.
Modified as suggested.
nvme-print-json.c
Outdated
| return NULL; | ||
|
|
||
| // Allocate buffer for full printable string (with newlines) | ||
| char *printable = malloc(nrows * ncols + nrows + 1); // +1 for null terminator |
There was a problem hiding this comment.
Variable declaration are at the beginning of the block. There only a few exceptions allowed.
There was a problem hiding this comment.
Modified as suggested.
nvme-print-json.c
Outdated
| goto exit; | ||
| return NULL; | ||
|
|
||
| struct json_object *eye_array = json_create_array(); |
There was a problem hiding this comment.
again declaration go to the beginning of the block
nvme-print-json.c
Outdated
| sizeof(struct nvme_eom_lane_desc); | ||
| vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset); | ||
| // 2 hex chars + space per byte | ||
| _cleanup_free_ char *hexstr = malloc(le16_to_cpu(desc->edlen) * 3 + 1); |
There was a problem hiding this comment.
Please introduce local variable for nrows ncols and edlen so you only need to to the cpu conversion once.
Also while at it please use consistent comment style.
There was a problem hiding this comment.
Modified as suggested.
nvme-print-json.c
Outdated
| /* Hex dump Vendor Specific Eye Data*/ | ||
| vsdataoffset = (le16_to_cpu(desc->nrows) * le16_to_cpu(desc->ncols)) + | ||
| sizeof(struct nvme_eom_lane_desc); | ||
| vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset); |
There was a problem hiding this comment.
I would first do the allocation (hexstr) before the computation.
There was a problem hiding this comment.
Modified as suggested.
nvme-print-stdout.c
Outdated
| vsdata = malloc(desc->edlen); | ||
| vsdataoffset = (desc->nrows * desc->ncols) + | ||
| vsdata = malloc(le16_to_cpu(desc->edlen)); | ||
| vsdataoffset = (le16_to_cpu(desc->nrows) * le16_to_cpu(desc->ncols)) + |
There was a problem hiding this comment.
please introduce local varables instead redoing the cpu conversion everytime.
There was a problem hiding this comment.
Modified as suggested.
- Addressing review comments Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
@igaw you mean, do I need to raise separate PR with all the changes I did in 5 commits as a single commit. |
Support for the 0xC0 log page needs to be added for the SNTMP device. Removed support for parsing the 0xCA log page for the SNTMP device. Update the wdc plugin version to 2.14.0 Remove vs-drive-info support for SNTMP Signed-off-by: jeff-lien-wdc <jeff.lien@sandisk.com>
0a5f016 to
1b88468
Compare
-resolving merge conflicts from master Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
|
I'd expect no merges from master into to your PR, see https://github.com/linux-nvme/nvme-cli?tab=readme-ov-file#how-to-cleanup-your-series-before-creating-pr |
Hi @igaw, |
-Fixed segmentation fault issue in JSON output format for VS Eye data -Added support to hex dump VS Eye data in both normal and JSON formats -This enables customers to decode the raw eye chart data if needed -Ensured compatibility with existing d() and obj_d() hex dump utilities -Addressed all the review comments that are given as part of pull request linux-nvme#2828 Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
-Fixed segmentation fault issue in JSON output format for VS Eye data -Added support to hex dump VS Eye data in both normal and JSON formats -This enables customers to decode the raw eye chart data if needed -Ensured compatibility with existing d() and obj_d() hex dump utilities -Addressed all the review comments that are given as part of PR linux-nvme#2828 Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
-Fixed segmentation fault issue in JSON output format for VS Eye data -Added support to hex dump VS Eye data in both normal and JSON formats -This enables customers to decode the raw eye chart data if needed -Ensured compatibility with existing d() and obj_d() hex dump utilities -Addressed all the review comments that are given as part of PR linux-nvme#2828 Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>
-Fixed segmentation fault issue in JSON output format for VS Eye data -Added support to hex dump VS Eye data in both normal and JSON formats -This enables customers to decode the raw eye chart data if needed -Ensured compatibility with existing d() and obj_d() hex dump utilities -Addressed all the review comments that are given as part of PR #2828 Signed-off-by: Sivaprasad Gutha <sivaprasad6541@gmail.com>