mcexec: options for target CPU core ID where application is executed

This commit is contained in:
Balazs Gerofi bgerofi@riken.jp
2014-03-27 14:58:26 +09:00
parent 76089e2682
commit 51f75d9ba8

View File

@@ -37,6 +37,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include "../include/uprotocol.h" #include "../include/uprotocol.h"
@@ -564,6 +565,11 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
return 1; return 1;
} }
void print_usage(char **argv)
{
fprintf(stderr, "Usage: %s [-c target_core] [<mcos-id>] (program) [args...]\n", argv[0]);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// int fd; // int fd;
@@ -573,6 +579,7 @@ int main(int argc, char **argv)
#endif #endif
FILE *fp; FILE *fp;
struct program_load_desc *desc; struct program_load_desc *desc;
int envs_len;
char *envs; char *envs;
char *args; char *args;
char dev[64]; char dev[64];
@@ -587,6 +594,9 @@ int main(int argc, char **argv)
struct rlimit rlim_stack; struct rlimit rlim_stack;
unsigned long lcur; unsigned long lcur;
unsigned long lmax; unsigned long lmax;
int target_core = 0;
int mcosid = 0;
int opt;
#ifdef USE_SYSCALL_MOD_CALL #ifdef USE_SYSCALL_MOD_CALL
__glob_argc = argc; __glob_argc = argc;
@@ -597,6 +607,10 @@ int main(int argc, char **argv)
if (!altroot) { if (!altroot) {
altroot = "/usr/linux-k1om-4.7/linux-k1om"; altroot = "/usr/linux-k1om-4.7/linux-k1om";
} }
/* Collect environment variables */
envs_len = flatten_strings(-1, environ, &envs);
envs = envs;
error = getrlimit(RLIMIT_STACK, &rlim_stack); error = getrlimit(RLIMIT_STACK, &rlim_stack);
if (error) { if (error) {
@@ -610,24 +624,52 @@ int main(int argc, char **argv)
fprintf(stderr, "Error: Failed to reduce stack.\n"); fprintf(stderr, "Error: Failed to reduce stack.\n");
return 1; return 1;
} }
strcpy(dev, "/dev/mcos0"); /* Parse options ("+" denotes stop at the first non-option) */
if(argv[1]){ while ((opt = getopt(argc, argv, "+c:")) != -1) {
for(p = argv[1]; *p && *p >= '0' && *p <= '9'; p++); switch (opt) {
if(!*p){ case 'c':
sprintf(dev, "/dev/mcos%s", argv[1]); target_core = atoi(optarg);
for(a = argv + 2; *a; a++) break;
a[-1] = a[0];
a[-1] = NULL; default: /* '?' */
argc--; print_usage(argv);
exit(EXIT_FAILURE);
} }
} }
if (argc < 2) {
fprintf(stderr, "Usage: %s [<mcos-id>] (program) [args...]\n", if (optind >= argc) {
argv[0]); print_usage(argv);
return 1; exit(EXIT_FAILURE);
} }
/* Determine OS device */
if (isdigit(*argv[optind])) {
mcosid = atoi(argv[optind]);
++optind;
}
sprintf(dev, "/dev/mcos%d", mcosid);
/* No more arguments? */
if (optind >= argc) {
print_usage(argv);
exit(EXIT_FAILURE);
}
/* Shift arguments to the front */
for (a = argv + optind; *a; a++) {
a[- optind + 1] = a[0];
}
argv[optind + 2] = NULL;
argc -= (optind - 1);
printf("target_core: %d, device: %s, command: ", target_core, dev);
for (i = 1; i < argc; ++i) {
printf("%s ", argv[i]);
}
printf("\n");
fp = fopen(argv[1], "rb"); fp = fopen(argv[1], "rb");
if (!fp) { if (!fp) {
fprintf(stderr, "Error: Failed to open %s\n", argv[1]); fprintf(stderr, "Error: Failed to open %s\n", argv[1]);
@@ -663,7 +705,7 @@ int main(int argc, char **argv)
__dprintf("# of sections: %d\n", desc->num_sections); __dprintf("# of sections: %d\n", desc->num_sections);
desc->envs_len = flatten_strings(-1, environ, &envs); desc->envs_len = envs_len;
desc->envs = envs; desc->envs = envs;
//print_flat(envs); //print_flat(envs);
@@ -671,6 +713,7 @@ int main(int argc, char **argv)
desc->args = args; desc->args = args;
//print_flat(args); //print_flat(args);
desc->cpu = target_core;
p = getenv(rlimit_stack_envname); p = getenv(rlimit_stack_envname);
if (p) { if (p) {
errno = 0; errno = 0;