Skip to content

Commit 1d0c765

Browse files
kevin-chaumeinkeithbusch
authored andcommitted
intel: Add enable-lat-stats function.
This adds the cli function for lat-stats-tracking. Enabling it allows the drive to start tracking latency statistics during i/o.
1 parent bb958d5 commit 1d0c765

2 files changed

Lines changed: 91 additions & 3 deletions

File tree

plugins/intel/intel-nvme.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,3 +1215,90 @@ static int get_internal_log(int argc, char **argv, struct command *command,
12151215
free(intel);
12161216
return err;
12171217
}
1218+
1219+
static int enable_lat_stats_tracking(int argc, char **argv,
1220+
struct command *command, struct plugin *plugin)
1221+
{
1222+
int err, fd;
1223+
const char *desc = (
1224+
"Enable/Disable Intel Latency Statistics Tracking.\n"
1225+
"No argument prints current status.");
1226+
const char *enable_desc = "Enable LST";
1227+
const char *disable_desc = "Disable LST";
1228+
const __u32 nsid = 0;
1229+
const __u8 fid = 0xe2;
1230+
const __u8 sel = 0;
1231+
const __u32 cdw11 = 0x0;
1232+
const __u32 cdw12 = 0x0;
1233+
const __u32 data_len = 32;
1234+
const __u32 save = 0;
1235+
__u32 result;
1236+
void *buf = NULL;
1237+
1238+
struct config {
1239+
bool enable, disable;
1240+
};
1241+
1242+
struct config cfg = {
1243+
.enable = false,
1244+
.disable = false,
1245+
};
1246+
1247+
const struct argconfig_commandline_options command_line_options[] = {
1248+
{"enable", 'e', "", CFG_NONE, &cfg.enable, no_argument, enable_desc},
1249+
{"disable", 'd', "", CFG_NONE, &cfg.disable, no_argument, disable_desc},
1250+
{NULL}
1251+
};
1252+
1253+
fd = parse_and_open(argc, argv, desc, command_line_options, &cfg,
1254+
sizeof(cfg));
1255+
1256+
enum Option {
1257+
None = -1,
1258+
True = 1,
1259+
False = 0,
1260+
};
1261+
1262+
enum Option option = None;
1263+
1264+
if (cfg.enable && cfg.disable)
1265+
printf("Cannot enable and disable simultaneously.");
1266+
else if (cfg.enable || cfg.disable)
1267+
option = cfg.enable;
1268+
1269+
if (fd < 0)
1270+
return fd;
1271+
switch (option) {
1272+
case None:
1273+
err = nvme_get_feature(fd, nsid, fid, sel, cdw11, data_len, buf,
1274+
&result);
1275+
if (!err) {
1276+
printf(
1277+
"Latency Statistics Tracking (FID 0x%X) is currently (%i).\n",
1278+
fid, result);
1279+
} else {
1280+
printf("Could not read feature id 0xE2.");
1281+
return err;
1282+
}
1283+
break;
1284+
case True:
1285+
case False:
1286+
err = nvme_set_feature(fd, nsid, fid, option, cdw12, save,
1287+
data_len, buf, &result);
1288+
if (err > 0) {
1289+
fprintf(stderr, "NVMe Status:%s(%x)\n",
1290+
nvme_status_to_string(err), err);
1291+
} else if (err < 0) {
1292+
perror("Enable latency tracking");
1293+
fprintf(stderr, "Command failed while parsing.");
1294+
} else {
1295+
printf("Successfully set enable bit for FID (0x%X) to %i.\n",
1296+
fid, option);
1297+
}
1298+
break;
1299+
default:
1300+
printf("%d not supported.", option);
1301+
return EINVAL;
1302+
}
1303+
return fd;
1304+
}

plugins/intel/intel-nvme.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
PLUGIN(NAME("intel", "Intel vendor specific extensions"),
1010
COMMAND_LIST(
1111
ENTRY("id-ctrl", "Send NVMe Identify Controller", id_ctrl)
12-
ENTRY("smart-log-add", "Retrieve Intel SMART Log, show it", get_additional_smart_log)
12+
ENTRY("internal-log", "Retrieve Intel internal firmware log, save it", get_internal_log)
13+
ENTRY("lat-stats", "Retrieve Intel IO Latency Statistics log, show it", get_lat_stats_log)
14+
ENTRY("lat-stats-tracking", "Enable and disable Latency Statistics logging.", enable_lat_stats_tracking)
1315
ENTRY("market-name", "Retrieve Intel Marketing Name log, show it", get_market_log)
16+
ENTRY("smart-log-add", "Retrieve Intel SMART Log, show it", get_additional_smart_log)
1417
ENTRY("temp-stats", "Retrieve Intel Temperature Statistics log, show it", get_temp_stats_log)
15-
ENTRY("lat-stats", "Retrieve Intel IO Latency Statistics log, show it", get_lat_stats_log)
16-
ENTRY("internal-log", "Retrieve Intel internal firmware log, save it", get_internal_log)
1718
)
1819
);
1920

0 commit comments

Comments
 (0)