Skip to content

Commit 8540205

Browse files
committed
examples/nitro: Specify vCPUs and RAM for enclave
Add command line arguments to specify the number of vCPUs and amount of RAM (in MiB) allocated to an enclave. Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
1 parent 30a94a7 commit 8540205

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

examples/nitro.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
static void print_help(char *const name)
3434
{
3535
fprintf(stderr,
36-
"Usage: %s EIF_FILE [COMMAND_ARGS...]\n"
36+
"Usage: %s ENCLAVE_IMAGE NVCPUS RAM_MIB\n"
3737
"OPTIONS: \n"
3838
" -h --help Show help\n"
3939
"\n"
4040
"ENCLAVE_IMAGE: The enclave image to run\n",
41+
"NVCPUS: The amount of vCPUs for running the enclave\n",
42+
"RAM_MIB: The amount of RAM (MiB) allocated for enclave\n",
4143
name
4244
);
4345
}
@@ -50,6 +52,8 @@ static const struct option long_options[] = {
5052
struct cmdline {
5153
bool show_help;
5254
const char *eif_path;
55+
unsigned int nvcpus;
56+
unsigned int ram_mib;
5357
};
5458

5559
bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
@@ -78,11 +82,19 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
7882
}
7983
}
8084

81-
if (optind < argc) {
85+
if (optind < argc - 2) {
8286
cmdline->eif_path = argv[optind];
87+
cmdline->nvcpus = strtoul(argv[optind + 1], NULL, 10);
88+
cmdline->ram_mib = strtoul(argv[optind + 2], NULL, 10);
8389
return true;
84-
} else
85-
fprintf(stderr, "Missing EIF_FILE argument");
90+
}
91+
92+
if (optind >= argc - 2)
93+
fprintf(stderr, "Missing RAM_MIB argument\n");
94+
if (optind >= argc - 1)
95+
fprintf(stderr, "Missing VCPUS argument\n");
96+
if (optind == argc)
97+
fprintf(stderr, "Missing ENCLAVE_IMAGE argument\n");
8698

8799
return false;
88100
}
@@ -169,7 +181,7 @@ int main(int argc, char *const argv[])
169181
}
170182

171183
// Configure the number of vCPUs (1) and the amount of RAM (512 MiB).
172-
if (err = krun_set_vm_config(ctx_id, 1, 512)) {
184+
if (err = krun_set_vm_config(ctx_id, cmdline.nvcpus, cmdline.ram_mib)) {
173185
errno = -err;
174186
perror("Error configuring the number of vCPUs and/or the amount of RAM");
175187
return -1;

0 commit comments

Comments
 (0)