Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2133,15 +2133,17 @@ static void stdout_id_ctrl_apsta(__u8 apsta)

static void stdout_id_ctrl_wctemp(__le16 wctemp)
{
printf(" [15:0] : %s (%u K)\tWarning Composite Temperature Threshold (WCTEMP)\n",
nvme_degrees_string(le16_to_cpu(wctemp)), le16_to_cpu(wctemp));
printf(" [15:0] : %s (%u K, %s)\tWarning Composite Temperature Threshold (WCTEMP)\n",
nvme_degrees_string(le16_to_cpu(wctemp)), le16_to_cpu(wctemp),
nvme_degrees_fahrenheit_string(le16_to_cpu(wctemp)));
printf("\n");
}

static void stdout_id_ctrl_cctemp(__le16 cctemp)
{
printf(" [15:0] : %s (%u K)\tCritical Composite Temperature Threshold (CCTEMP)\n",
nvme_degrees_string(le16_to_cpu(cctemp)), le16_to_cpu(cctemp));
printf(" [15:0] : %s (%u K, %s)\tCritical Composite Temperature Threshold (CCTEMP)\n",
nvme_degrees_string(le16_to_cpu(cctemp)), le16_to_cpu(cctemp),
nvme_degrees_fahrenheit_string(le16_to_cpu(cctemp)));
printf("\n");
}

Expand Down Expand Up @@ -2206,15 +2208,17 @@ static void stdout_id_ctrl_hctma(__le16 ctrl_hctma)

static void stdout_id_ctrl_mntmt(__le16 mntmt)
{
printf(" [15:0] : %s (%u K)\tMinimum Thermal Management Temperature (MNTMT)\n",
nvme_degrees_string(le16_to_cpu(mntmt)), le16_to_cpu(mntmt));
printf(" [15:0] : %s (%u K, %s)\tMinimum Thermal Management Temperature (MNTMT)\n",
nvme_degrees_string(le16_to_cpu(mntmt)), le16_to_cpu(mntmt),
nvme_degrees_fahrenheit_string(le16_to_cpu(mntmt)));
printf("\n");
}

static void stdout_id_ctrl_mxtmt(__le16 mxtmt)
{
printf(" [15:0] : %s (%u K)\tMaximum Thermal Management Temperature (MXTMT)\n",
nvme_degrees_string(le16_to_cpu(mxtmt)), le16_to_cpu(mxtmt));
printf(" [15:0] : %s (%u K, %s)\tMaximum Thermal Management Temperature (MXTMT)\n",
nvme_degrees_string(le16_to_cpu(mxtmt)), le16_to_cpu(mxtmt),
nvme_degrees_fahrenheit_string(le16_to_cpu(mxtmt)));
printf("\n");
}

Expand Down Expand Up @@ -4394,8 +4398,9 @@ static void stdout_smart_log(struct nvme_smart_log *smart, unsigned int nsid, co
(smart->critical_warning & 0x20) >> 5);
}

printf("temperature : %s (%u K)\n",
nvme_degrees_string(temperature), temperature);
printf("temperature : %s (%u K, %s)\n",
nvme_degrees_string(temperature), temperature,
nvme_degrees_fahrenheit_string(temperature));
printf("available_spare : %u%%\n", smart->avail_spare);
printf("available_spare_threshold : %u%%\n", smart->spare_thresh);
printf("percentage_used : %u%%\n", smart->percent_used);
Expand Down Expand Up @@ -4431,8 +4436,9 @@ static void stdout_smart_log(struct nvme_smart_log *smart, unsigned int nsid, co
temperature = le16_to_cpu(smart->temp_sensor[i]);
if (!temperature)
continue;
printf("Temperature Sensor %d : %s (%u K)\n", i + 1,
nvme_degrees_string(temperature), temperature);
printf("Temperature Sensor %d : %s (%u K, %s)\n", i + 1,
nvme_degrees_string(temperature), temperature,
nvme_degrees_fahrenheit_string(temperature));
}

printf("Thermal Management T1 Trans Count : %u\n",
Expand Down Expand Up @@ -5033,16 +5039,17 @@ static void stdout_feature_show_fields(enum nvme_features_id fid,
break;
case NVME_FEAT_FID_TEMP_THRESH:
field = (result & 0x1c00000) >> 22;
printf("\tTemperature Threshold Hysteresis(TMPTHH): %s (%u K)\n",
nvme_degrees_string(field), field);
printf("\tTemperature Threshold Hysteresis(TMPTHH): %s (%u K, %s)\n",
nvme_degrees_string(field), field, nvme_degrees_fahrenheit_string(field));
field = NVME_FEAT_TT_THSEL(result);
printf("\tThreshold Type Select (THSEL): %u - %s\n", field,
nvme_feature_temp_type_to_string(field));
field = NVME_FEAT_TT_TMPSEL(result);
printf("\tThreshold Temperature Select (TMPSEL): %u - %s\n",
field, nvme_feature_temp_sel_to_string(field));
printf("\tTemperature Threshold (TMPTH): %s (%u K)\n",
nvme_degrees_string(NVME_FEAT_TT_TMPTH(result)), NVME_FEAT_TT_TMPTH(result));
printf("\tTemperature Threshold (TMPTH): %s (%u K, %s)\n",
nvme_degrees_string(NVME_FEAT_TT_TMPTH(result)), NVME_FEAT_TT_TMPTH(result),
nvme_degrees_fahrenheit_string(NVME_FEAT_TT_TMPTH(result)));
break;
case NVME_FEAT_FID_ERR_RECOVERY:
printf("\tDeallocated or Unwritten Logical Block Error Enable (DULBE): %s\n",
Expand Down Expand Up @@ -5135,12 +5142,14 @@ static void stdout_feature_show_fields(enum nvme_features_id fid,
printf("\tKeep Alive Timeout (KATO) in milliseconds: %u\n", result);
break;
case NVME_FEAT_FID_HCTM:
printf("\tThermal Management Temperature 1 (TMT1) : %u K (%s)\n",
printf("\tThermal Management Temperature 1 (TMT1) : %u K (%s, %s)\n",
NVME_FEAT_HCTM_TMT1(result),
nvme_degrees_string(NVME_FEAT_HCTM_TMT1(result)));
printf("\tThermal Management Temperature 2 (TMT2) : %u K (%s)\n",
nvme_degrees_string(NVME_FEAT_HCTM_TMT1(result)),
nvme_degrees_fahrenheit_string(NVME_FEAT_HCTM_TMT1(result)));
printf("\tThermal Management Temperature 2 (TMT2) : %u K (%s, %s)\n",
NVME_FEAT_HCTM_TMT2(result),
nvme_degrees_string(NVME_FEAT_HCTM_TMT2(result)));
nvme_degrees_string(NVME_FEAT_HCTM_TMT2(result)),
nvme_degrees_fahrenheit_string(NVME_FEAT_HCTM_TMT2(result)));
break;
case NVME_FEAT_FID_NOPSC:
printf("\tNon-Operational Power State Permissive Mode Enable (NOPPME): %s\n",
Expand Down
55 changes: 12 additions & 43 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,59 +815,28 @@ void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
nvme_print(endurance_log, flags, endurance_log, group_id, devname);
}

static bool is_fahrenheit_country(const char *country)
{
static const char * const countries[] = {
"AQ", "AS", "BS", "BZ", "CY", "FM", "GU", "KN", "KY", "LR",
"MH", "MP", "MS", "PR", "PW", "TC", "US", "VG", "VI"
};
int i;

for (i = 0; i < ARRAY_SIZE(countries); i++) {
if (!strcmp(country, countries[i]))
return true;
}

return false;
}

#ifndef LC_MEASUREMENT
#define LC_MEASUREMENT LC_ALL
#endif

static bool is_temperature_fahrenheit(void)
const char *nvme_degrees_string(long t)
{
const char *locale, *underscore;
char country[3] = { 0 };

setlocale(LC_MEASUREMENT, "");
locale = setlocale(LC_MEASUREMENT, NULL);

if (!locale || strlen(locale) < 2)
return false;

underscore = strchr(locale, '_');
if (underscore && strlen(underscore) >= 3)
locale = underscore + 1;
static char str[STR_LEN];
long val = kelvin_to_celsius(t);

memcpy(country, locale, 2);
if (nvme_is_output_format_json())
sprintf(str, "%ld %s", val, "Celsius");
else
sprintf(str, "%ld °%s", val, "C");

return is_fahrenheit_country(country);
return str;
}

const char *nvme_degrees_string(long t)
const char *nvme_degrees_fahrenheit_string(long t)
{
static char str[STR_LEN];
long val = kelvin_to_celsius(t);
bool fahrenheit = is_temperature_fahrenheit();

if (fahrenheit)
val = kelvin_to_fahrenheit(t);
long val = kelvin_to_fahrenheit(t);

if (nvme_is_output_format_json())
sprintf(str, "%ld %s", val, fahrenheit ? "Fahrenheit" : "Celsius");
sprintf(str, "%ld %s", val, "Fahrenheit");
else
sprintf(str, "%ld °%s", val, fahrenheit ? "F" : "C");
sprintf(str, "%ld °%s", val, "F");

return str;
}
Expand Down
1 change: 1 addition & 0 deletions nvme-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ bool nvme_is_fabrics_optional_reg(int offset);
bool nvme_registers_cmbloc_support(__u32 cmbsz);
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
const char *nvme_degrees_string(long t);
const char *nvme_degrees_fahrenheit_string(long t);
void print_array(char *name, __u8 *data, int size);
void json_print(struct json_object *r);
struct json_object *obj_create_array_obj(struct json_object *o, const char *k);
Expand Down