Skip to content

Commit 29cb129

Browse files
committed
feat: add arbitration command
Also fixed temp-thresh command string and added get-feature print. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 19edb52 commit 29cb129

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

plugins/feat/feat-nvme.c

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ struct temp_thresh_config {
3131
__u8 sel;
3232
};
3333

34+
struct arbitration_config {
35+
__u8 ab;
36+
__u8 lpw;
37+
__u8 mpw;
38+
__u8 hpw;
39+
__u8 sel;
40+
};
41+
3442
static const char *power_mgmt_feat = "power management feature";
3543
static const char *sel = "[0-3]: current/default/saved/supported";
3644
static const char *save = "Specifies that the controller shall save the attribute";
3745
static const char *perfc_feat = "performance characteristics feature";
3846
static const char *hctm_feat = "host controlled thermal management feature";
3947
static const char *timestamp_feat = "timestamp feature";
48+
static const char *temp_thresh_feat = "temperature threshold feature";
49+
static const char *arbitration_feat = "arbitration feature";
4050

4151
static int feat_get(struct nvme_dev *dev, const __u8 fid, __u32 cdw11, __u8 sel, const char *feat)
4252
{
@@ -68,7 +78,11 @@ static int feat_get(struct nvme_dev *dev, const __u8 fid, __u32 cdw11, __u8 sel,
6878
};
6979

7080
err = nvme_get_features(&args);
81+
82+
nvme_show_init();
83+
7184
if (!err) {
85+
nvme_feature_show(fid, sel, result);
7286
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
7387
nvme_show_select_result(fid, result);
7488
else
@@ -79,6 +93,8 @@ static int feat_get(struct nvme_dev *dev, const __u8 fid, __u32 cdw11, __u8 sel,
7993
nvme_show_error("Get %s: %s", feat, nvme_strerror(errno));
8094
}
8195

96+
nvme_show_finish();
97+
8298
return err;
8399
}
84100

@@ -423,9 +439,9 @@ static int temp_thresh_set(int fd, const __u8 fid, struct argconfig_commandline_
423439
if (err > 0) {
424440
nvme_show_status(err);
425441
} else if (err < 0) {
426-
nvme_show_perror("Set %s", timestamp_feat);
442+
nvme_show_perror("Set %s", temp_thresh_feat);
427443
} else {
428-
nvme_show_result("Set %s: (%s)", timestamp_feat, save ? "Save" : "Not save");
444+
nvme_show_result("Set %s: (%s)", temp_thresh_feat, save ? "Save" : "Not save");
429445
nvme_feature_show_fields(fid, NVME_SET(cfg->tmpth, FEAT_TT_TMPTH) |
430446
NVME_SET(cfg->tmpsel, FEAT_TT_TMPSEL) |
431447
NVME_SET(cfg->thsel, FEAT_TT_THSEL) |
@@ -464,7 +480,86 @@ static int feat_temp_thresh(int argc, char **argv, struct command *cmd, struct p
464480
err = temp_thresh_set(dev_fd(dev), fid, opts, &cfg);
465481
else
466482
err = feat_get(dev, fid, NVME_SET(cfg.tmpsel, FEAT_TT_TMPSEL) |
467-
NVME_SET(cfg.thsel, FEAT_TT_THSEL), cfg.sel, timestamp_feat);
483+
NVME_SET(cfg.thsel, FEAT_TT_THSEL), cfg.sel, temp_thresh_feat);
484+
485+
return err;
486+
}
487+
488+
static int arbitration_set(int fd, const __u8 fid, struct argconfig_commandline_options *opts,
489+
struct arbitration_config *cfg)
490+
{
491+
__u32 result;
492+
int err;
493+
enum nvme_get_features_sel sel = NVME_GET_FEATURES_SEL_CURRENT;
494+
__u8 ab;
495+
__u8 lpw;
496+
__u8 mpw;
497+
__u8 hpw;
498+
bool save = argconfig_parse_seen(opts, "save");
499+
500+
if (save)
501+
sel = NVME_GET_FEATURES_SEL_SAVED;
502+
503+
err = nvme_get_features_arbitration(fd, sel, &result);
504+
if (!err) {
505+
nvme_feature_decode_arbitration(result, &ab, &lpw, &mpw, &hpw);
506+
if (!argconfig_parse_seen(opts, "ab"))
507+
cfg->ab = ab;
508+
if (!argconfig_parse_seen(opts, "lpw"))
509+
cfg->lpw = lpw;
510+
if (!argconfig_parse_seen(opts, "mpw"))
511+
cfg->mpw = mpw;
512+
if (!argconfig_parse_seen(opts, "hpw"))
513+
cfg->hpw = hpw;
514+
}
515+
516+
err = nvme_set_features_arbitration(fd, cfg->ab, cfg->lpw, cfg->mpw, cfg->hpw,
517+
save, &result);
518+
519+
nvme_show_init();
520+
521+
if (err > 0) {
522+
nvme_show_status(err);
523+
} else if (err < 0) {
524+
nvme_show_perror("Set %s", temp_thresh_feat);
525+
} else {
526+
nvme_show_result("Set %s: (%s)", arbitration_feat, save ? "Save" : "Not save");
527+
nvme_feature_show_fields(fid, NVME_SET(cfg->ab, FEAT_ARBITRATION_BURST) |
528+
NVME_SET(cfg->lpw, FEAT_ARBITRATION_LPW) |
529+
NVME_SET(cfg->mpw, FEAT_ARBITRATION_MPW) |
530+
NVME_SET(cfg->hpw, FEAT_ARBITRATION_HPW), NULL);
531+
}
532+
533+
nvme_show_finish();
468534

469535
return err;
470536
}
537+
538+
static int feat_arbitration(int argc, char **argv, struct command *cmd, struct plugin *plugin)
539+
{
540+
const __u8 fid = NVME_FEAT_FID_ARBITRATION;
541+
const char *ab = "arbitration burst";
542+
const char *lpw = "low priority weight";
543+
const char *mpw = "medium priority weight";
544+
const char *hpw = "high priority weight";
545+
int err;
546+
547+
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
548+
549+
struct arbitration_config cfg = { 0 };
550+
551+
FEAT_ARGS(opts,
552+
OPT_BYTE("ab", 'a', &cfg.ab, ab),
553+
OPT_BYTE("lpw", 'l', &cfg.lpw, lpw),
554+
OPT_BYTE("mpw", 'm', &cfg.mpw, mpw),
555+
OPT_BYTE("hpw", 'h', &cfg.hpw, hpw));
556+
557+
err = parse_and_open(&dev, argc, argv, TEMP_THRESH_DESC, opts);
558+
if (err)
559+
return err;
560+
561+
if (argc == 2 || argconfig_parse_seen(opts, "sel"))
562+
return feat_get(dev, fid, 0, cfg.sel, "arbitration feature");
563+
564+
return arbitration_set(dev_fd(dev), fid, opts, &cfg);
565+
}

plugins/feat/feat-nvme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define HCTM_DESC "Get and set host controlled thermal management feature"
1616
#define TIMESTAMP_DESC "Get and set timestamp feature"
1717
#define TEMP_THRESH_DESC "Get and set temperature threshold feature"
18+
#define ARBITRATION_DESC "Get and set arbitration feature"
1819

1920
#define FEAT_ARGS(n, ...) \
2021
NVME_ARGS(n, ##__VA_ARGS__, OPT_FLAG("save", 's', NULL, save), \
@@ -27,6 +28,7 @@ PLUGIN(NAME("feat", "NVMe feature extensions", FEAT_PLUGIN_VERSION),
2728
ENTRY("hctm", HCTM_DESC, feat_hctm)
2829
ENTRY("timestamp", TIMESTAMP_DESC, feat_timestamp)
2930
ENTRY("temp-thresh", TEMP_THRESH_DESC, feat_temp_thresh)
31+
ENTRY("arbitration", ARBITRATION_DESC, feat_arbitration)
3032
)
3133
);
3234
#endif /* !FEAT_NVME || CMD_HEADER_MULTI_READ */

0 commit comments

Comments
 (0)