diff options
Diffstat (limited to 'tools/rmtool/src/main.c')
| -rw-r--r-- | tools/rmtool/src/main.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/rmtool/src/main.c b/tools/rmtool/src/main.c new file mode 100644 index 0000000..4e4b440 --- /dev/null +++ b/tools/rmtool/src/main.c @@ -0,0 +1,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; +} |
