Skip to contentSkip to conversation

nvme-cli: Add get and set timestamp commands

PATCH New Dong Ho 2 participants 3 messages Oct 16, 2018 – Oct 17, 2018

Subsystems (3)
lore
Share & tools
lore

Dong Ho

author
#0 lore raw

PATCH 1/2 nvme-cli: Add get and set timestamp commands

---
 Makefile       |   2 +-
 nvme-builtin.h |   2 +
 nvme.c         | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 1 deletion(-)
Makefile +1 -1
index 433bc41..645ce5c 100644
@@ -37,7 +37,7 @@ OBJS := argconfig.o suffix.o parser.o nvme-print.o nvme-ioctl.o \
 	huawei-nvme.o netapp-nvme.o  toshiba-nvme.o micron-nvme.o seagate-nvme.o
 
 nvme: nvme.c nvme.h $(OBJS) NVME-VERSION-FILE
-	$(CC) $(CPPFLAGS) $(CFLAGS) nvme.c -o $(NVME) $(OBJS) $(LDFLAGS)
+	$(CC) $(CPPFLAGS) $(CFLAGS) nvme.c -o $(NVME) $(OBJS) $(LDFLAGS) -lm -lrt
 
 nvme.o: nvme.c nvme.h nvme-print.h nvme-ioctl.h argconfig.h suffix.h nvme-lightnvm.h fabrics.h
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
nvme-builtin.h +2 -0
index 7cf10ef..e66a2c2 100644
@@ -67,6 +67,8 @@ COMMAND_LIST(
 	ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd)
 	ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive)
 	ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)
+	ENTRY("set-timestamp", "Submit a Timestamp set feature command", set_timestamp)
+	ENTRY("get-timestamp", "Submit a Timestamp get feature command", get_timestamp)
 );
 
 #endif
nvme.c +136 -0

148 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 nvme-cli: add help text for get and set timestamp commands

---
 Documentation/nvme-get-timestamp.txt | 50 ++++++++++++++++++++++++++++++++++++
 Documentation/nvme-set-timestamp.txt | 46 +++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
 create mode 100644 Documentation/nvme-get-timestamp.txt
 create mode 100644 Documentation/nvme-set-timestamp.txt
Documentation/nvme-get-timestamp.txt new file +50 -0
new file mode 100644
index 0000000..a490fe9
@@ -0,0 +1,50 @@
+nvme-get-timestamp(1)
+=====================
+
+NAME
+----
+nvme-get-timestamp - Gets the timestamp feature ID data from the nvme controller.
+
+SYNOPSIS
+--------
+[verse]
+'nvme get-timestamp' <device>
+
+DESCRIPTION
+-----------
+Gets the timestamp feature id data from the NVMe controller.  The <device> parameter
+is mandatory and must be an NVMe character device (ex: /dev/nvme0).
+
+Returns the current timestamp value along the Timestamp Origin and Synch bits.  
+
+If the origin field is set to 000b, then the returned timestamp value is set to the 
+time in milliseconds since the last controller level reset.  If the origin field is 
+set to 0001b, then the returned timestamp value is set to the last timestamp value
+set by the host plus the time milliseconds since the timestamp was set.
+
+The Origin/Synch field is a byte in length with bits defined as follows:
+
+*  Bits 07:04  Reserved 
+*  Bits 03:01  Timestamp Origin
+**               000b - The timestamp field was initialized to '0' by a Controller Level Reset
+**               001b - The timestamp field was initialized with a value using the set features command.
+**               010b-111b - Reserved
+*  Bit  00     Synch
+**               0b - The controller counted time in milliseconds continuously since the timestamp value was initialized.
+**               1b - The controller may have stopped counting during vendor specific intervals after the timestamp value was initialized.
+                                           
+OPTIONS
+-------
+None
+
+EXAMPLES
+--------
+* Gets the timestamp feature id data from the NVMe controller.
++
+------------
+# nvme get-timestamp /dev/nvme0
+------------
+
+NVME
+----
+Part of the nvme-user suite
Documentation/nvme-set-timestamp.txt new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 1/2 nvme-cli: Add get and set timestamp commands

In reply to Dong Ho
Quoted 10 lines · Dong Ho
nvme.c +10 -0
+long get_current_time_in_ms(void)
+{
+    long            ms; // Milliseconds
+    time_t          s;  // Seconds
+    long            ts; // returned timestamp in ms
+    struct timespec spec;
+
+    clock_gettime(CLOCK_REALTIME, &spec);
+
+    s  = spec.tv_sec;

nvme.c static int admin_passthru(int argc, char **argv, struct command *cmd, struct plu · line 4647

Quoted 10 lines
nvme.c +10 -0
+    ms = round(spec.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
+    if (ms > 999) {
+        s++;
+        ms = 0;
+    }
+
+    ts = 1000*s + ms;
+
+    return ts;
+}

Regarding formatting, you have some indentations as tabs and others as spaces. This program prefers the linux kernel coding style, so tabs should be used consistently. Also, C89 comment /* style */ is preferred to //.

As to the feature itself, I don't think we should provide such a convenience function as I don't see why this should be something a user would want to set. The feature has in-kernel support to set if supported. If anything for nvme-cli, this feature should be a subset of the existing "set-feature" and "get-feature" commands rather than it's own top-level command (which it already is).