]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/ocp: Fix endianness in Latency Monitor Log output
authorArthur Shau <arthurshau@fb.com>
Wed, 5 Apr 2023 22:56:14 +0000 (15:56 -0700)
committerDaniel Wagner <wagi@monom.org>
Thu, 27 Apr 2023 13:14:28 +0000 (15:14 +0200)
OCP 2.0 spec changed the endianness for some of the fields in the C3 LM Log. Fixed this when outputting the values.

plugins/ocp/ocp-nvme.c

index 213ba3f775a105caa334eb1cff5c3d54aa37c98d..b86b7362f8542a1b1e8a8d4dfa55ec053f8d7c68 100644 (file)
@@ -55,10 +55,10 @@ static __u8 lat_mon_guid[C3_GUID_LENGTH] = {
        0x58, 0x5e, 0xd4, 0x85
 };
 
-#define READ           0
-#define WRITE          1
-#define TRIM           2
-#define RESERVED       3
+#define READ           3
+#define WRITE          2
+#define TRIM           1
+#define RESERVED       0
 
 struct __attribute__((__packed__)) ssd_latency_monitor_log {
        __u8    feature_status;                 /* 0x00 */
@@ -196,7 +196,7 @@ static int ocp_print_C3_log_normal(struct nvme_dev *dev,
 
        for (i = 0; i < C3_BUCKET_NUM; i++) {
                printf("  Active Latency Time Stamp: Bucket %d    ", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        if (le64_to_cpu(log_data->active_latency_timestamp[i][j]) == -1)
                                printf("                    N/A         ");
                        else {
@@ -210,11 +210,12 @@ static int ocp_print_C3_log_normal(struct nvme_dev *dev,
        for (i = 0; i < C3_BUCKET_NUM; i++) {
                printf("  Active Measured Latency: Bucket %d  %27d ms  %27d ms  %27d ms\n",
                       i,
-                      le16_to_cpu(log_data->active_measured_latency[i][READ]),
-                      le16_to_cpu(log_data->active_measured_latency[i][WRITE]),
-                      le16_to_cpu(log_data->active_measured_latency[i][TRIM]));
+                      le16_to_cpu(log_data->active_measured_latency[i][READ-1]),
+                      le16_to_cpu(log_data->active_measured_latency[i][WRITE-1]),
+                      le16_to_cpu(log_data->active_measured_latency[i][TRIM-1]));
        }
 
+       printf("\n");
        for (i = 0; i < C3_BUCKET_NUM; i++) {
                printf("  Static Bucket Counter: Bucket %d    %27d     %27d     %27d\n",
                       i,
@@ -225,7 +226,7 @@ static int ocp_print_C3_log_normal(struct nvme_dev *dev,
 
        for (i = 0; i < C3_BUCKET_NUM; i++) {
                printf("  Static Latency Time Stamp: Bucket %d    ", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        if (le64_to_cpu(log_data->static_latency_timestamp[i][j]) == -1)
                                printf("                    N/A         ");
                        else {
@@ -239,9 +240,9 @@ static int ocp_print_C3_log_normal(struct nvme_dev *dev,
        for (i = 0; i < C3_BUCKET_NUM; i++) {
                printf("  Static Measured Latency: Bucket %d  %27d ms  %27d ms  %27d ms \n",
                       i,
-                      le16_to_cpu(log_data->static_measured_latency[i][READ]),
-                      le16_to_cpu(log_data->static_measured_latency[i][WRITE]),
-                      le16_to_cpu(log_data->static_measured_latency[i][TRIM]));
+                      le16_to_cpu(log_data->static_measured_latency[i][READ-1]),
+                      le16_to_cpu(log_data->static_measured_latency[i][WRITE-1]),
+                      le16_to_cpu(log_data->static_measured_latency[i][TRIM-1]));
        }
 
        return 0;
@@ -254,7 +255,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
        char buf[128];
        int i, j;
        int pos = 0;
-       char *operation[3] = {"Read", "Write", "Trim"};
+       char *operation[3] = {"Trim", "Write", "Read"};
 
        root = json_create_object();
 
@@ -284,7 +285,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Active Latency Mode: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        json_object_add_value_uint(bucket, operation[j],
                                                   log_data->active_latency_config & (1 << pos));
                }
@@ -300,9 +301,9 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Active Bucket Counter: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        json_object_add_value_uint(bucket, operation[j],
-                               le32_to_cpu(log_data->active_bucket_counter[i][j]));
+                               le32_to_cpu(log_data->active_bucket_counter[i][j+1]));
                }
                json_object_add_value_object(root, buf, bucket);
        }
@@ -312,7 +313,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Active Latency Time Stamp: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        if (le64_to_cpu(log_data->active_latency_timestamp[i][j]) == -1)
                                json_object_add_value_string(bucket, operation[j], "NA");
                        else {
@@ -328,7 +329,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Active Measured Latency: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        json_object_add_value_uint(bucket, operation[j],
                                le16_to_cpu(log_data->active_measured_latency[i][j]));
                }
@@ -343,9 +344,9 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Static Bucket Counter: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        json_object_add_value_uint(bucket, operation[j],
-                               le32_to_cpu(log_data->static_bucket_counter[i][j]));
+                               le32_to_cpu(log_data->static_bucket_counter[i][j+1]));
                }
                json_object_add_value_object(root, buf, bucket);
        }
@@ -355,7 +356,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Static Latency Time Stamp: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        if (le64_to_cpu(log_data->static_latency_timestamp[i][j]) == -1)
                                json_object_add_value_string(bucket, operation[j], "NA");
                        else {
@@ -371,7 +372,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
 
                bucket = json_create_object();
                sprintf(buf, "Static Measured Latency: Bucket %d", i);
-               for (j = 0; j <= 2; j++) {
+               for (j = 2; j >= 0; j--) {
                        json_object_add_value_uint(bucket, operation[j],
                                le16_to_cpu(log_data->static_measured_latency[i][j]));
                }