Skip to content

Commit 2bda067

Browse files
committed
Add support to "list" command to print /dev based capabilities
Signed-off-by: Kevin Klues <[email protected]>
1 parent aaabf50 commit 2bda067

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/cli/cli.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ struct devices {
6969
int new_devices(struct error *err, const struct nvc_device_info *dev, struct devices *d);
7070
void free_devices(struct devices *d);
7171

72+
int print_nvcaps_device_from_proc_file(struct nvc_context *, const char*, const char*);
73+
int print_all_mig_minor_devices(const struct nvc_device_node *);
74+
7275
int select_devices(
7376
struct error *err,
7477
char *devs,

src/cli/common.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
33
*/
44

5+
#include <sys/sysmacros.h>
6+
57
#include <inttypes.h>
68
#include <string.h>
79

@@ -464,3 +466,50 @@ free_devices(struct devices *d)
464466
free(d->migs);
465467
memset(d, 0, sizeof(*d));
466468
}
469+
470+
int
471+
print_nvcaps_device_from_proc_file(struct nvc_context *ctx, const char* cap_dir, const char* cap_file)
472+
{
473+
char cap_path[PATH_MAX];
474+
struct nvc_device_node node;
475+
476+
if (path_join(NULL, cap_path, cap_dir, cap_file) < 0)
477+
return (-1);
478+
if (nvc_nvcaps_device_from_proc_path(ctx, cap_path, &node) < 0)
479+
return (-1);
480+
481+
printf("%s\n", node.path);
482+
free(node.path);
483+
484+
return (0);
485+
}
486+
487+
int
488+
print_all_mig_minor_devices(const struct nvc_device_node *node)
489+
{
490+
unsigned int gpu_minor = 0;
491+
unsigned int mig_minor = 0;
492+
char line[PATH_MAX];
493+
char dummy[PATH_MAX];
494+
FILE *fp;
495+
int rv = -1;
496+
497+
if ((fp = fopen(NV_CAPS_MIG_MINORS_PATH, "r")) == NULL) {
498+
goto fail;
499+
}
500+
501+
line[PATH_MAX - 1] = '\0';
502+
while (fgets(line, PATH_MAX - 1, fp)) {
503+
if (sscanf(line, "gpu%u%s %u", &gpu_minor, dummy, &mig_minor) != 3)
504+
continue;
505+
if (gpu_minor != minor(node->id))
506+
continue;
507+
printf(NV_CAPS_DEVICE_PATH "\n", mig_minor);
508+
}
509+
510+
rv = 0;
511+
512+
fail:
513+
fclose(fp);
514+
return (rv);
515+
}

src/cli/list.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,38 @@ list_command(const struct context *ctx)
188188
for (size_t i = 0; i < devices.nmigs; ++i) {
189189
printf("%s/%s\n", devices.migs[i]->gi_caps_path, NV_MIG_ACCESS_FILE);
190190
printf("%s/%s\n", devices.migs[i]->ci_caps_path, NV_MIG_ACCESS_FILE);
191+
if (nvc_nvcaps_style() == NVC_NVCAPS_STYLE_DEV) {
192+
print_nvcaps_device_from_proc_file(nvc, devices.migs[i]->gi_caps_path, NV_MIG_ACCESS_FILE);
193+
print_nvcaps_device_from_proc_file(nvc, devices.migs[i]->ci_caps_path, NV_MIG_ACCESS_FILE);
194+
}
191195
}
192196
}
193197
}
194198

195199
/* List the files required for MIG configuration of the visible devices */
196200
if (mig_config_devices.all && mig_config_devices.ngpus) {
197201
printf("%s/%s\n", NV_MIG_CAPS_PATH, NV_MIG_CONFIG_FILE);
202+
if (nvc_nvcaps_style() == NVC_NVCAPS_STYLE_DEV)
203+
print_nvcaps_device_from_proc_file(nvc, NV_MIG_CAPS_PATH, NV_MIG_CONFIG_FILE);
198204
for (size_t i = 0; i < mig_config_devices.ngpus; ++i) {
199205
printf("%s\n", mig_config_devices.gpus[i]->mig_caps_path);
206+
if (nvc_nvcaps_style() == NVC_NVCAPS_STYLE_DEV) {
207+
printf("%s\n", NV_CAPS_DEVICE_DIR);
208+
print_all_mig_minor_devices(&mig_config_devices.gpus[i]->node);
209+
}
200210
}
201211
}
202212
/* List the files required for MIG monitoring of the visible devices */
203213
if (mig_monitor_devices.all && mig_monitor_devices.ngpus) {
204214
printf("%s/%s\n", NV_MIG_CAPS_PATH, NV_MIG_MONITOR_FILE);
215+
if (nvc_nvcaps_style() == NVC_NVCAPS_STYLE_DEV)
216+
print_nvcaps_device_from_proc_file(nvc, NV_MIG_CAPS_PATH, NV_MIG_MONITOR_FILE);
205217
for (size_t i = 0; i < mig_monitor_devices.ngpus; ++i) {
206218
printf("%s\n", mig_monitor_devices.gpus[i]->mig_caps_path);
219+
if (nvc_nvcaps_style() == NVC_NVCAPS_STYLE_DEV) {
220+
printf("%s\n", NV_CAPS_DEVICE_DIR);
221+
print_all_mig_minor_devices(&mig_monitor_devices.gpus[i]->node);
222+
}
207223
}
208224
}
209225

0 commit comments

Comments
 (0)