Skip to content
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

nvme: Add support for get-reg command to output single register #2188

Merged
merged 7 commits into from
Apr 9, 2024

Conversation

ikegami-t
Copy link
Contributor

Note: Currently only stdout print supported.

@ikegami-t ikegami-t force-pushed the nvme-reg branch 6 times, most recently from 80db8ea to d176ec3 Compare January 21, 2024 18:00
Copy link
Collaborator

@igaw igaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please avoid mixing white space cleanup patches with feature patches
  • Documentation is missing

How does the kernel figure out that some of the register values have changes?

nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme-print.c Outdated Show resolved Hide resolved
nvme.c Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
common.h Outdated Show resolved Hide resolved
common.h Show resolved Hide resolved
nvme-print.h Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
@ikegami-t
Copy link
Contributor Author

Fixed for some comments but still remaining comments to fix so will update later.

common.h Outdated Show resolved Hide resolved
Comment on lines 1435 to 1438
if (human)
printf("%s: ", nvme_register_to_string(offset));
else
printf("register: 0x%02x (%s), value: ", offset, nvme_register_to_string(offset));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verbose output is less verbose?

Also why use %02x? There are already some offsets that take 3 hex digits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output example is below also the human-readable option is for readable format output but not for verbose output.

tokunori@tokunori-desktop:~/nvme-cli$ sudo .build/nvme get-reg /dev/nvme0 -c
register: 0x00 (Controller Capabilities), value: 3028033fff
tokunori@tokunori-desktop:~/nvme-cli$ sudo .build/nvme get-reg /dev/nvme0 -c -H
Controller Capabilities: 3028033fff
        Controller Ready With Media Support (CRWMS): Not Supported
        Controller Ready Independent of Media Support (CRIMS): Not Supported
        NVM Subsystem Shutdown Supported   (NSSS): Not Supported
        Controller Memory Buffer Supported (CMBS): The Controller Memory Buffer is Not Supported
        Persistent Memory Region Supported (PMRS): The Persistent Memory Region is Not Supported
        Memory Page Size Maximum         (MPSMAX): 4096 bytes
        Memory Page Size Minimum         (MPSMIN): 4096 bytes
        Controller Power Scope              (CPS): Not Reported
        Boot Partition Support              (BPS): No
        Command Sets Supported              (CSS): NVM command set is Supported
                                                   One or more I/O Command Sets are Not Supported
                                                   I/O Command Set is Supported
        NVM Subsystem Reset Supported     (NSSRS): Yes
        Doorbell Stride                   (DSTRD): 4 bytes
        Timeout                              (TO): 20000 ms
        Arbitration Mechanism Supported     (AMS): Weighted Round Robin with Urgent Priority Class is Not supported
        Contiguous Queues Required          (CQR): Yes
        Maximum Queue Entries Supported    (MQES): 16384

tokunori@tokunori-desktop:~/nvme-cli$ sudo .build/nvme get-reg /dev/nvme0 -c -h
Usage: nvme get-reg <device> [OPTIONS]

Reads and shows the defined NVMe controller register.
Register offset must be one of:
CAP=0x0, VS=0x8, INTMS=0xc, INTMC=0x10, CC=0x14, CSTS=0x1c,
NSSR=0x20, AQA=0x24, ASQ=0x28, ACQ=0x30, CMBLOC=0x38,
CMBSZ=0x3c, BPINFO=0x40, BPRSEL=0x44, BPMBL=0x48, CMBMSC=0x50,
CMBSTS=0x58, CRTO=0x68, PMRCAP=0xe00, PMRCTL=0xe04,
PMRSTS=0xe08, PMREBS=0xe0c, PMRSWTP=0xe10, PMRMSCL=0xe14, PMRMSCU=0xe18

Options:
  [  --verbose, -v ]                    --- Increase output verbosity
  [  --output-format=<FMT>, -o <FMT> ]  --- Output format: normal|json|binary
  [  --offset=<NUM>, -O <NUM> ]         --- offset of the requested register
  [  --human-readable, -H ]             --- show register in readable format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why use %02x? There are already some offsets that take 3 hex digits.

Fixed by the commit 24f79e3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in this specific line (register: 0x00 (Controller Capabilities), value: 3028033fff vs. Controller Capabilities: 3028033fff), the verbose output doesn't have the register number. It seems like "verbose" should at least contain all the information that "not verbose" does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure let me reconfirm as the "verbose" mentioned is not actually set by the command verbose option but set by the human-readable so not necessary to contain the register number for the option output.

static int get_register(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
...
	bool human = stdout_print_ops.flags & VERBOSE;
...
static void stdout_ctrl_register(int offset, uint64_t value64)
{
	if (cfg.human_readable)
		flags |= VERBOSE;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think stdout_ctrl_register_common still has this issue.

+static void stdout_ctrl_register_common(int offset, uint64_t value, bool fabrics)
+{
+       bool human = !!(stdout_print_ops.flags & VERBOSE);
+       const char *name = nvme_register_to_string(offset);
+       const char *type = fabrics ? "property" : "register";
+
+       if (human) {
+               printf("%s: %#"PRIx64"\n", name, value);
+               stdout_ctrl_register_human(offset, value, true);
+               return;
+       }
+
+       printf("%s: %#04x (%s), value: %#"PRIx64"\n", type, offset,
+              name, value);
+}

While stdout_ctrl_register_support handle the verbose flag differently, that is it prints the normal output and then the verbose. This is what I would expect from the previous output as well

+static void stdout_ctrl_register_support(void *bar, bool fabrics, int offset, bool human,
+                                        bool support)
+{
+       uint64_t value = nvme_is_64bit_reg(offset) ? mmio_read64(bar + offset) :
+           mmio_read32(bar + offset);
+
+       if (fabrics && value == -1)
+               return;
+
+       printf("%-8s: ", nvme_register_symbol_to_string(offset));
+
+       printf("%#"PRIx64"\n", value);
+
+       if (human)
+               stdout_ctrl_register_human(offset, value, support);
+}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No stdout_ctrl_register_common() returns after the verbose output and before it outputs also the normal output. So the order itself same with the stdout_ctrl_register_support().
Note: The normal outputs below are different since depended on the current show-regs command outputs.

stdout_ctrl_register_support
static void stdout_ctrl_register_common(int offset, uint64_t value, bool fabrics)
{
...
	if (human) {
		printf("%s: %#"PRIx64"\n", name, value);
...
	printf("%s: %#04x (%s), value: %#"PRIx64"\n", type, offset,
	       name, value);
}

nvme-print-stdout.c Outdated Show resolved Hide resolved
nvme-print-stdout.c Outdated Show resolved Hide resolved
Comment on lines 1525 to 1546
printf("unknown register: 0x%02x (%s), value: %"PRIx64"\n",
offset, nvme_register_to_string(offset), value64);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset and nvme_register_to_string(offset) have already been printed. Is it necessary to do it again here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those only printed if the human-readable option not set but this output is only for the option so not duplicated to output actually. By the way fixed the offset output to take 4 hex digits by the commit 227ce4e.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The human flag should only annotate information. If the flag is actually influence the control flow, than this doesn't sound right.

Copy link
Contributor Author

@ikegami-t ikegami-t Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the human flag flow not changed as same with the current show-regs command and the new get-reg command follows the output I think.

nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Show resolved Hide resolved
nvme.h Outdated Show resolved Hide resolved
nvme-print.c Outdated Show resolved Hide resolved
nvme-print-stdout.c Outdated Show resolved Hide resolved
nvme-print-stdout.c Outdated Show resolved Hide resolved
nvme-print-stdout.c Outdated Show resolved Hide resolved
nvme-print.c Outdated Show resolved Hide resolved
nvme-print.c Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Show resolved Hide resolved
@ikegami-t
Copy link
Contributor Author

Just rebased with the linux-nvme:master.

@ikegami-t
Copy link
Contributor Author

ikegami-t commented Feb 4, 2024

Still to do belows.

  1. Add documentation
  2. Have a flag to fallback to 32 bit writes
  3. Consider how to figure out the register values changes by the kernel
  4. Enforce arguments mutual exclusivity
  5. Resolve PR run failures
  6. Add support for json and binary print outputs
  7. Rebase changes to combine review comment fix patches
  8. Add SQ/CQ 0..y tail/head doorbell registers

@igaw
Copy link
Collaborator

igaw commented Feb 5, 2024

Please squash your fixes for new code into the new code. There is no need to see the development history in the final version.

@ikegami-t
Copy link
Contributor Author

Just squashed the changes.

@ikegami-t ikegami-t force-pushed the nvme-reg branch 6 times, most recently from fec85e7 to a830385 Compare February 10, 2024 07:34
@ikegami-t
Copy link
Contributor Author

ikegami-t commented Feb 10, 2024

The review comments almost fixed so could you please review again? Still the following items to do but will do separately if you okay.

3. Consider how to figure out the register values changes by the kernel
6. Add support for json and binary print outputs
8. Add SQ/CQ 0..y tail/head doorbell registers
9. Add completions
10. Support for fabrics by set-reg

@ikegami-t ikegami-t force-pushed the nvme-reg branch 3 times, most recently from b306922 to 1e95aad Compare February 11, 2024 11:14
nvme-print-stdout.c Outdated Show resolved Hide resolved
nvme-print.h Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
nvme.c Outdated Show resolved Hide resolved
@ikegami-t ikegami-t force-pushed the nvme-reg branch 3 times, most recently from bcd89a7 to 3561329 Compare March 11, 2024 13:36
@ikegami-t
Copy link
Contributor Author

Just confirmed as the access issue by CC.EN zero caused by the nvme identify namespace to scan NVMe topology sysfs ns nuse attribute and this can be avoided by stopping nvme identify namespace since the attirute not necesary for the PCI register access.

Just considered this but seems no way to do it.. By the way confirmed if CC.EN set to zero then the device not able to be accessed and reset by the timeout error. Also to avoid the error tried to reset the device after the CC.EN zero setting before the access but the CC.EN setting is reset to one by the reset. So seems difficult to let the kernel figure out the command settings.

nvme.c Show resolved Hide resolved
nvme.h Outdated Show resolved Hide resolved
Move the mmio_read up the call chain.

Signed-off-by: Tokunori Ikegami <[email protected]>
To use the function by other registers print functions.

Signed-off-by: Tokunori Ikegami <[email protected]>
To prepare the stage for the set register feature.

Signed-off-by: Tokunori Ikegami <[email protected]>
To prepare the state for the get register feature.

Signed-off-by: Tokunori Ikegami <[email protected]>
To prepare the state for the get register feature.

Signed-off-by: Tokunori Ikegami <[email protected]>
To prepare the state for the get register feature.

Signed-off-by: Tokunori Ikegami <[email protected]>
The get-reg command is to output register(s), it's possible to show
several registers when register name are used as command line option.

The set-reg command is to write nvme register(s). Again, the command is
able to set several registers when the register name are used.

Signed-off-by: Tokunori Ikegami <[email protected]>
@igaw igaw merged commit 293e622 into linux-nvme:master Apr 9, 2024
15 of 16 checks passed
@igaw
Copy link
Collaborator

igaw commented Apr 9, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants