From: Arthur Shau Date: Wed, 5 Apr 2023 22:56:14 +0000 (-0700) Subject: plugins/ocp: Fix endianness in Latency Monitor Log output X-Git-Tag: v2.5~141 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d267abff62698e1f92503b19dd0434088e85f297;p=users%2Fsagi%2Fnvme-cli.git plugins/ocp: Fix endianness in Latency Monitor Log output OCP 2.0 spec changed the endianness for some of the fields in the C3 LM Log. Fixed this when outputting the values. --- diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 213ba3f7..b86b7362 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -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])); }