Skip to content

Commit 01836c0

Browse files
committed
nvme-print: print always celsius temperature value
The fahrenheit value also printed if used by the locale country. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent eb12965 commit 01836c0

4 files changed

Lines changed: 75 additions & 25 deletions

File tree

nvme-print-json.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,17 @@ static void json_feature_show_fields_lba_range(struct json_object *r, __u8 field
35043504
json_lba_range_entry((struct nvme_lba_range_type *)buf, field, r);
35053505
}
35063506

3507+
static void obj_add_degrees_fahrenheit_str(struct json_object *r, const char *k, long t)
3508+
{
3509+
const char *fahrenheit = nvme_degrees_fahrenheit_string(t);
3510+
char json_str[STR_LEN];
3511+
3512+
if (fahrenheit) {
3513+
sprintf(json_str, "%s", fahrenheit);
3514+
obj_add_str(r, k, json_str);
3515+
}
3516+
}
3517+
35073518
static void json_feature_show_fields_temp_thresh(struct json_object *r, unsigned int result)
35083519
{
35093520
char json_str[STR_LEN];
@@ -3516,6 +3527,8 @@ static void json_feature_show_fields_temp_thresh(struct json_object *r, unsigned
35163527
sprintf(json_str, "%u K", field);
35173528
obj_add_str(r, "TMPTHH kelvin", json_str);
35183529

3530+
obj_add_degrees_fahrenheit_str(r, "TMPTHH fahrenheit", field);
3531+
35193532
field = (result & 0x300000) >> 20;
35203533
obj_add_uint(r, "Threshold Type Select (THSEL)", field);
35213534
obj_add_str(r, "THSEL description", nvme_feature_temp_type_to_string(field));
@@ -3530,6 +3543,8 @@ static void json_feature_show_fields_temp_thresh(struct json_object *r, unsigned
35303543

35313544
sprintf(json_str, "%u K", result & 0xffff);
35323545
obj_add_str(r, "TMPTH kelvin", json_str);
3546+
3547+
obj_add_degrees_fahrenheit_str(r, "TMPTH fahrenheit", result & 0xffff);
35333548
}
35343549

35353550
static void json_feature_show_fields_err_recovery(struct json_object *r, unsigned int result)
@@ -3714,11 +3729,15 @@ static void json_feature_show_fields_hctm(struct json_object *r, unsigned int re
37143729
sprintf(json_str, "%s", nvme_degrees_string(result >> 16));
37153730
obj_add_str(r, "TMT1 celsius", json_str);
37163731

3732+
obj_add_degrees_fahrenheit_str(r, "TMT1 fahrenheit", result >> 16);
3733+
37173734
sprintf(json_str, "%u K", result & 0xffff);
37183735
obj_add_str(r, "Thermal Management Temperature 2", json_str);
37193736

37203737
sprintf(json_str, "%s", nvme_degrees_string(result & 0xffff));
37213738
obj_add_str(r, "TMT2 celsius", json_str);
3739+
3740+
obj_add_degrees_fahrenheit_str(r, "TMT2 fahrenheit", result & 0xffff);
37223741
}
37233742

37243743
static void json_feature_show_fields_nopsc(struct json_object *r, unsigned int result)

nvme-print-stdout.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,17 +2131,29 @@ static void stdout_id_ctrl_apsta(__u8 apsta)
21312131
printf("\n");
21322132
}
21332133

2134+
static const char *degrees_fahrenheit_str(long t)
2135+
{
2136+
const char *fahrenheit = nvme_degrees_fahrenheit_string(t);
2137+
static char str[STR_LEN];
2138+
2139+
sprintf(str, "%s%s", fahrenheit ? ", " : "", fahrenheit ? fahrenheit : "");
2140+
2141+
return str;
2142+
}
2143+
21342144
static void stdout_id_ctrl_wctemp(__le16 wctemp)
21352145
{
2136-
printf(" [15:0] : %s (%u K)\tWarning Composite Temperature Threshold (WCTEMP)\n",
2137-
nvme_degrees_string(le16_to_cpu(wctemp)), le16_to_cpu(wctemp));
2146+
printf(" [15:0] : %s (%u K%s)\tWarning Composite Temperature Threshold (WCTEMP)\n",
2147+
nvme_degrees_string(le16_to_cpu(wctemp)), le16_to_cpu(wctemp),
2148+
degrees_fahrenheit_str(le16_to_cpu(wctemp)));
21382149
printf("\n");
21392150
}
21402151

21412152
static void stdout_id_ctrl_cctemp(__le16 cctemp)
21422153
{
2143-
printf(" [15:0] : %s (%u K)\tCritical Composite Temperature Threshold (CCTEMP)\n",
2144-
nvme_degrees_string(le16_to_cpu(cctemp)), le16_to_cpu(cctemp));
2154+
printf(" [15:0] : %s (%u K%s)\tCritical Composite Temperature Threshold (CCTEMP)\n",
2155+
nvme_degrees_string(le16_to_cpu(cctemp)), le16_to_cpu(cctemp),
2156+
degrees_fahrenheit_str(le16_to_cpu(cctemp)));
21452157
printf("\n");
21462158
}
21472159

@@ -2206,15 +2218,17 @@ static void stdout_id_ctrl_hctma(__le16 ctrl_hctma)
22062218

22072219
static void stdout_id_ctrl_mntmt(__le16 mntmt)
22082220
{
2209-
printf(" [15:0] : %s (%u K)\tMinimum Thermal Management Temperature (MNTMT)\n",
2210-
nvme_degrees_string(le16_to_cpu(mntmt)), le16_to_cpu(mntmt));
2221+
printf(" [15:0] : %s (%u K%s)\tMinimum Thermal Management Temperature (MNTMT)\n",
2222+
nvme_degrees_string(le16_to_cpu(mntmt)), le16_to_cpu(mntmt),
2223+
degrees_fahrenheit_str(le16_to_cpu(mntmt)));
22112224
printf("\n");
22122225
}
22132226

22142227
static void stdout_id_ctrl_mxtmt(__le16 mxtmt)
22152228
{
2216-
printf(" [15:0] : %s (%u K)\tMaximum Thermal Management Temperature (MXTMT)\n",
2217-
nvme_degrees_string(le16_to_cpu(mxtmt)), le16_to_cpu(mxtmt));
2229+
printf(" [15:0] : %s (%u K%s)\tMaximum Thermal Management Temperature (MXTMT)\n",
2230+
nvme_degrees_string(le16_to_cpu(mxtmt)), le16_to_cpu(mxtmt),
2231+
degrees_fahrenheit_str(le16_to_cpu(mxtmt)));
22182232
printf("\n");
22192233
}
22202234

@@ -4394,8 +4408,8 @@ static void stdout_smart_log(struct nvme_smart_log *smart, unsigned int nsid, co
43944408
(smart->critical_warning & 0x20) >> 5);
43954409
}
43964410

4397-
printf("temperature : %s (%u K)\n",
4398-
nvme_degrees_string(temperature), temperature);
4411+
printf("temperature : %s (%u K%s)\n",
4412+
nvme_degrees_string(temperature), temperature, degrees_fahrenheit_str(temperature));
43994413
printf("available_spare : %u%%\n", smart->avail_spare);
44004414
printf("available_spare_threshold : %u%%\n", smart->spare_thresh);
44014415
printf("percentage_used : %u%%\n", smart->percent_used);
@@ -4431,8 +4445,9 @@ static void stdout_smart_log(struct nvme_smart_log *smart, unsigned int nsid, co
44314445
temperature = le16_to_cpu(smart->temp_sensor[i]);
44324446
if (!temperature)
44334447
continue;
4434-
printf("Temperature Sensor %d : %s (%u K)\n", i + 1,
4435-
nvme_degrees_string(temperature), temperature);
4448+
printf("Temperature Sensor %d : %s (%u K%s)\n", i + 1,
4449+
nvme_degrees_string(temperature), temperature,
4450+
degrees_fahrenheit_str(temperature));
44364451
}
44374452

44384453
printf("Thermal Management T1 Trans Count : %u\n",
@@ -5033,16 +5048,17 @@ static void stdout_feature_show_fields(enum nvme_features_id fid,
50335048
break;
50345049
case NVME_FEAT_FID_TEMP_THRESH:
50355050
field = (result & 0x1c00000) >> 22;
5036-
printf("\tTemperature Threshold Hysteresis(TMPTHH): %s (%u K)\n",
5037-
nvme_degrees_string(field), field);
5051+
printf("\tTemperature Threshold Hysteresis(TMPTHH): %s (%u K%s)\n",
5052+
nvme_degrees_string(field), field, degrees_fahrenheit_str(field));
50385053
field = NVME_FEAT_TT_THSEL(result);
50395054
printf("\tThreshold Type Select (THSEL): %u - %s\n", field,
50405055
nvme_feature_temp_type_to_string(field));
50415056
field = NVME_FEAT_TT_TMPSEL(result);
50425057
printf("\tThreshold Temperature Select (TMPSEL): %u - %s\n",
50435058
field, nvme_feature_temp_sel_to_string(field));
5044-
printf("\tTemperature Threshold (TMPTH): %s (%u K)\n",
5045-
nvme_degrees_string(NVME_FEAT_TT_TMPTH(result)), NVME_FEAT_TT_TMPTH(result));
5059+
printf("\tTemperature Threshold (TMPTH): %s (%u K%s)\n",
5060+
nvme_degrees_string(NVME_FEAT_TT_TMPTH(result)), NVME_FEAT_TT_TMPTH(result),
5061+
degrees_fahrenheit_str(NVME_FEAT_TT_TMPTH(result)));
50465062
break;
50475063
case NVME_FEAT_FID_ERR_RECOVERY:
50485064
printf("\tDeallocated or Unwritten Logical Block Error Enable (DULBE): %s\n",
@@ -5135,12 +5151,14 @@ static void stdout_feature_show_fields(enum nvme_features_id fid,
51355151
printf("\tKeep Alive Timeout (KATO) in milliseconds: %u\n", result);
51365152
break;
51375153
case NVME_FEAT_FID_HCTM:
5138-
printf("\tThermal Management Temperature 1 (TMT1) : %u K (%s)\n",
5154+
printf("\tThermal Management Temperature 1 (TMT1) : %u K (%s%s)\n",
51395155
NVME_FEAT_HCTM_TMT1(result),
5140-
nvme_degrees_string(NVME_FEAT_HCTM_TMT1(result)));
5141-
printf("\tThermal Management Temperature 2 (TMT2) : %u K (%s)\n",
5156+
nvme_degrees_string(NVME_FEAT_HCTM_TMT1(result)),
5157+
degrees_fahrenheit_str(NVME_FEAT_HCTM_TMT1(result)));
5158+
printf("\tThermal Management Temperature 2 (TMT2) : %u K (%s%s)\n",
51425159
NVME_FEAT_HCTM_TMT2(result),
5143-
nvme_degrees_string(NVME_FEAT_HCTM_TMT2(result)));
5160+
nvme_degrees_string(NVME_FEAT_HCTM_TMT2(result)),
5161+
degrees_fahrenheit_str(NVME_FEAT_HCTM_TMT2(result)));
51445162
break;
51455163
case NVME_FEAT_FID_NOPSC:
51465164
printf("\tNon-Operational Power State Permissive Mode Enable (NOPPME): %s\n",

nvme-print.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,27 @@ const char *nvme_degrees_string(long t)
859859
{
860860
static char str[STR_LEN];
861861
long val = kelvin_to_celsius(t);
862-
bool fahrenheit = is_temperature_fahrenheit();
863862

864-
if (fahrenheit)
865-
val = kelvin_to_fahrenheit(t);
863+
if (nvme_is_output_format_json())
864+
sprintf(str, "%ld %s", val, "Celsius");
865+
else
866+
sprintf(str, "%ld °%s", val, "C");
867+
868+
return str;
869+
}
870+
871+
const char *nvme_degrees_fahrenheit_string(long t)
872+
{
873+
static char str[STR_LEN];
874+
long val = kelvin_to_fahrenheit(t);
875+
876+
if (!is_temperature_fahrenheit())
877+
return NULL;
866878

867879
if (nvme_is_output_format_json())
868-
sprintf(str, "%ld %s", val, fahrenheit ? "Fahrenheit" : "Celsius");
880+
sprintf(str, "%ld %s", val, "Fahrenheit");
869881
else
870-
sprintf(str, "%ld °%s", val, fahrenheit ? "F" : "C");
882+
sprintf(str, "%ld °%s", val, "F");
871883

872884
return str;
873885
}

nvme-print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ bool nvme_is_fabrics_optional_reg(int offset);
346346
bool nvme_registers_cmbloc_support(__u32 cmbsz);
347347
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
348348
const char *nvme_degrees_string(long t);
349+
const char *nvme_degrees_fahrenheit_string(long t);
349350
void print_array(char *name, __u8 *data, int size);
350351
void json_print(struct json_object *r);
351352
struct json_object *obj_create_array_obj(struct json_object *o, const char *k);

0 commit comments

Comments
 (0)