Print numbers instead of hex values for smart data. The full 128-bit
number is printed, even though you'd need like a billion IOPs for a 10 billion seconds to overflow the 64-bit counters (~300 years). Sponsored by: Netflix, Inc
This commit is contained in:
parent
cc63e8e6ab
commit
33a099d2e5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=308850
@ -42,6 +42,11 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/endian.h>
|
||||||
|
|
||||||
|
#if _BYTE_ORDER != _LITTLE_ENDIAN
|
||||||
|
#error "Code only works on little endian machines"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "nvmecontrol.h"
|
#include "nvmecontrol.h"
|
||||||
|
|
||||||
@ -50,6 +55,38 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
typedef void (*print_fn_t)(void *buf, uint32_t size);
|
typedef void (*print_fn_t)(void *buf, uint32_t size);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 128-bit integer augments to standard values
|
||||||
|
*/
|
||||||
|
#define UINT128_DIG 39
|
||||||
|
typedef __uint128_t uint128_t;
|
||||||
|
|
||||||
|
static inline uint128_t
|
||||||
|
to128(void *p)
|
||||||
|
{
|
||||||
|
return *(uint128_t *)p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
uint128_to_str(uint128_t u, char *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
char *end = buf + buflen - 1;
|
||||||
|
|
||||||
|
*end-- = '\0';
|
||||||
|
if (u == 0)
|
||||||
|
*end-- = '0';
|
||||||
|
while (u && end >= buf) {
|
||||||
|
*end-- = u % 10 + '0';
|
||||||
|
u /= 10;
|
||||||
|
}
|
||||||
|
end++;
|
||||||
|
if (u != 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
get_log_buffer(uint32_t size)
|
get_log_buffer(uint32_t size)
|
||||||
{
|
{
|
||||||
@ -128,6 +165,7 @@ static void
|
|||||||
print_log_health(void *buf, uint32_t size __unused)
|
print_log_health(void *buf, uint32_t size __unused)
|
||||||
{
|
{
|
||||||
struct nvme_health_information_page *health = buf;
|
struct nvme_health_information_page *health = buf;
|
||||||
|
char cbuf[UINT128_DIG + 1];
|
||||||
|
|
||||||
printf("SMART/Health Information Log\n");
|
printf("SMART/Health Information Log\n");
|
||||||
printf("============================\n");
|
printf("============================\n");
|
||||||
@ -155,40 +193,26 @@ print_log_health(void *buf, uint32_t size __unused)
|
|||||||
printf("Percentage used: %u\n",
|
printf("Percentage used: %u\n",
|
||||||
health->percentage_used);
|
health->percentage_used);
|
||||||
|
|
||||||
/*
|
printf("Data units (512,000 byte) read: %s\n",
|
||||||
* TODO: These are pretty ugly in hex. Is there a library that
|
uint128_to_str(to128(health->data_units_read), cbuf, sizeof(cbuf)));
|
||||||
* will convert 128-bit unsigned values to decimal?
|
printf("Data units (512,000 byte) written: %s\n",
|
||||||
*/
|
uint128_to_str(to128(health->data_units_written), cbuf, sizeof(cbuf)));
|
||||||
printf("Data units (512 byte) read: 0x%016jx%016jx\n",
|
printf("Host read commands: %s\n",
|
||||||
health->data_units_read[1],
|
uint128_to_str(to128(health->host_read_commands), cbuf, sizeof(cbuf)));
|
||||||
health->data_units_read[0]);
|
printf("Host write commands: %s\n",
|
||||||
printf("Data units (512 byte) written: 0x%016jx%016jx\n",
|
uint128_to_str(to128(health->host_write_commands), cbuf, sizeof(cbuf)));
|
||||||
health->data_units_written[1],
|
printf("Controller busy time (minutes): %s\n",
|
||||||
health->data_units_written[0]);
|
uint128_to_str(to128(health->controller_busy_time), cbuf, sizeof(cbuf)));
|
||||||
printf("Host read commands: 0x%016jx%016jx\n",
|
printf("Power cycles: %s\n",
|
||||||
health->host_read_commands[1],
|
uint128_to_str(to128(health->power_cycles), cbuf, sizeof(cbuf)));
|
||||||
health->host_read_commands[0]);
|
printf("Power on hours: %s\n",
|
||||||
printf("Host write commands: 0x%016jx%016jx\n",
|
uint128_to_str(to128(health->power_on_hours), cbuf, sizeof(cbuf)));
|
||||||
health->host_write_commands[1],
|
printf("Unsafe shutdowns: %s\n",
|
||||||
health->host_write_commands[0]);
|
uint128_to_str(to128(health->unsafe_shutdowns), cbuf, sizeof(cbuf)));
|
||||||
printf("Controller busy time (minutes): 0x%016jx%016jx\n",
|
printf("Media errors: %s\n",
|
||||||
health->controller_busy_time[1],
|
uint128_to_str(to128(health->media_errors), cbuf, sizeof(cbuf)));
|
||||||
health->controller_busy_time[0]);
|
printf("No. error info log entries: %s\n",
|
||||||
printf("Power cycles: 0x%016jx%016jx\n",
|
uint128_to_str(to128(health->num_error_info_log_entries), cbuf, sizeof(cbuf)));
|
||||||
health->power_cycles[1],
|
|
||||||
health->power_cycles[0]);
|
|
||||||
printf("Power on hours: 0x%016jx%016jx\n",
|
|
||||||
health->power_on_hours[1],
|
|
||||||
health->power_on_hours[0]);
|
|
||||||
printf("Unsafe shutdowns: 0x%016jx%016jx\n",
|
|
||||||
health->unsafe_shutdowns[1],
|
|
||||||
health->unsafe_shutdowns[0]);
|
|
||||||
printf("Media errors: 0x%016jx%016jx\n",
|
|
||||||
health->media_errors[1],
|
|
||||||
health->media_errors[0]);
|
|
||||||
printf("No. error info log entries: 0x%016jx%016jx\n",
|
|
||||||
health->num_error_info_log_entries[1],
|
|
||||||
health->num_error_info_log_entries[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user