1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* main.c - rmtool entry point: command dispatch and global help/version.
*
* rmtool is a read-only host RM oracle for the Open-IOV accuracy loop. It
* never allocates engine/channel/memory objects and never touches VFIO,
* mdevs or kernel modules; write commands are refused by policy.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rmtool.h"
static void usage(void)
{
printf("rmtool %s - read-only NVIDIA RM host oracle\n\n",
RMTOOL_VERSION);
printf("usage: rmtool <command> [subcommand] [options]\n\n"
"commands:\n"
" gpu list|topology|info enumeration/identity\n"
" engine list|info engine inventory (read-only)\n"
" mem stats VRAM/heap/BAR1 totals\n"
" nv2080 class list device class list\n"
" nv2080 method call allowlisted read-only controls\n"
" sample timer GPU timer sampling\n"
" version print version\n\n"
"options:\n"
" -d N|BDF select GPU (minor or bus id)\n"
" -f FMT output format table|json|csv\n"
" --device PATH use an explicit GPU device node\n\n"
"safety: read-only queries only. alloc/map/pin, engine/channel\n"
"control and any write control are refused. Never touches\n"
"modules, VFIO, mdevs, sysfs bindings or /sys/fs/pstore.\n\n"
"Not implemented (documented commands): channel, context,\n"
"resserve, cudasw, resman, gsp. See docs/17-RM-HARNESS.md.\n");
}
int main(int argc, char **argv)
{
struct rm_ctx ctx;
const char *command;
int rc;
ctx.gpu_minor = -1;
ctx.dev_path = NULL;
ctx.format = RM_FMT_TABLE;
ctx.have_rm = 0;
ctx.rm.fd = -1;
if (argc < 2) {
usage();
return 2;
}
command = argv[1];
if (strcmp(command, "--help") == 0 || strcmp(command, "-h") == 0 ||
strcmp(command, "help") == 0) {
usage();
return 0;
}
if (strcmp(command, "--version") == 0 ||
strcmp(command, "version") == 0) {
printf("rmtool %s (read-only; Open-IOV RM oracle)\n",
RMTOOL_VERSION);
return 0;
}
if (strcmp(command, "gpu") == 0) {
rc = cmd_gpu(argc - 1, argv + 1, &ctx);
} else if (strcmp(command, "engine") == 0) {
rc = cmd_engine(argc - 1, argv + 1, &ctx);
} else if (strcmp(command, "mem") == 0) {
rc = cmd_mem(argc - 1, argv + 1, &ctx);
} else if (strcmp(command, "nv2080") == 0) {
rc = cmd_nv2080(argc - 1, argv + 1, &ctx);
} else if (strcmp(command, "sample") == 0) {
rc = cmd_sample(argc - 1, argv + 1, &ctx);
} else if (strcmp(command, "channel") == 0 ||
strcmp(command, "context") == 0 ||
strcmp(command, "resserve") == 0 ||
strcmp(command, "cudasw") == 0 ||
strcmp(command, "resman") == 0 ||
strcmp(command, "gsp") == 0) {
fprintf(stderr, "rmtool: '%s' is a documented but not-yet-"
"implemented surface in this minimal build; it is a "
"write/ownership path and is refused. See "
"docs/17-RM-HARNESS.md.\n", command);
rc = 3;
} else {
fprintf(stderr, "rmtool: unknown command '%s'\n", command);
usage();
rc = 2;
}
if (ctx.have_rm)
rm_client_close(&ctx.rm);
return rc;
}
|