int main(int argc, char **argv){ char c; char *cores = NULL; char *nodes = NULL; int shuffle = 0; struct shared_state s = {}; while ((c = getopt(argc, argv, "+vVsc:n:SN")) != -1) { switch (c) { case 'c': if(cores) { fprintf(stderr, "-c or -n already used !\n"); exit(EXIT_FAILURE); } cores = strdup(optarg); break; case 'n': if(nodes || cores) { fprintf(stderr, "-c or -n already used !\n"); exit(EXIT_FAILURE); } nodes = strdup(optarg); break; case 'N': s.per_node = 1; break; case 's': shuffle = 1; break; case 'S': s.server = 1; break; case 'v': s.verbose = 1; break; case 'V': s.verbose = 1; s.verbose_err = 1; break; default: usage(argv[0]); } } if(!cores && !nodes) cores = build_default_affinity_string(shuffle); if(optind == argc) usage(argv[0]); argv += optind; char *lib = get_lib_path(); setenv("LD_PRELOAD", lib, 1); free(lib); int *cores_array; if(cores) { parse_cores(cores, &cores_array, &s.nr_entries_in_cores, 0); } else { parse_cores(nodes, &cores_array, &s.nr_entries_in_cores, 1); } char *uniq_shm_name = NULL; assert(asprintf(&uniq_shm_name, "%s_%d", "/tmp/shm", gettid())); assert(create_shm(uniq_shm_name, &s, cores_array)); setenv("PINTHREADS_SHMID", uniq_shm_name, 1); setenv("PINTHREADS_SHMSIZE", get_shm_size(), 1); free(uniq_shm_name); execvp(argv[0], argv); perror("execvp"); fprintf(stderr,"failed to execute %s\n", argv[0]); cleanup_shm(uniq_shm_name); return EXIT_SUCCESS; }
int parse_config(char *config_file) { config_t config; int ret = -1; config_setting_t *rtdal,*dac; const char *tmp; int single_timer; int time_slot_us; config_init(&config); if (!config_read_file(&config, config_file)) { aerror_msg("line %d - %s: \n", config_error_line(&config), config_error_text(&config)); goto destroy; } rtdal = config_lookup(&config, "rtdal"); if (!rtdal) { aerror("Error parsing config file: rtdal section not found.\n"); goto destroy; } if (!config_setting_lookup_int(rtdal, "time_slot_us", &time_slot_us)) { aerror("time_slot_us field not defined\n"); goto destroy; } if (!config_setting_lookup_string(rtdal, "cores", &tmp)) { aerror("cores field not defined\n"); goto destroy; } nof_cores = parse_cores((char*) tmp); if (nof_cores < 0) { printf("Error invalid cores %s\n",tmp); exit(0); } if (!config_setting_lookup_bool(rtdal, "enable_usrp", &using_uhd)) { aerror("enable_usrp field not defined\n"); goto destroy; } if (!config_setting_lookup_bool(rtdal, "timer_mode_single", &single_timer)) { aerror("timer_mode_single field not defined\n"); goto destroy; } if (using_uhd) { if (single_timer) { clock_source = SINGLE_TIMER; } else { clock_source = DAC; } } else { if (single_timer) { clock_source = SINGLE_TIMER; } else { clock_source = MULTI_TIMER; } } if (!config_setting_lookup_string(rtdal, "path_to_libs", &tmp)) { aerror("path_to_libs field not defined\n"); goto destroy; } strcpy(libs_path,tmp); if (using_uhd) { dac = config_lookup(&config, "dac"); if (!dac) { aerror("Error parsing config file: dac section not found.\n"); goto destroy; } #ifdef HAVE_UHD double tmp; if (!config_setting_lookup_float(dac, "samp_freq", &dac_cfg.inputFreq)) { aerror("samp_freq field not defined\n"); goto destroy; } dac_cfg.outputFreq = dac_cfg.inputFreq; if (!config_setting_lookup_float(dac, "rf_freq", &dac_cfg.inputRFFreq)) { aerror("rf_freq field not defined\n"); goto destroy; } dac_cfg.outputRFFreq = dac_cfg.inputRFFreq; if (!config_setting_lookup_float(dac, "rf_gain", &tmp)) { aerror("rf_gain field not defined\n"); goto destroy; } dac_cfg.tx_gain = tmp; dac_cfg.rx_gain = tmp; if (!config_setting_lookup_float(dac, "if_bw", &tmp)) { aerror("rf_gain field not defined\n"); goto destroy; } dac_cfg.tx_bw = tmp; dac_cfg.rx_bw = tmp; if (!config_setting_lookup_bool(dac, "sample_is_short", &dac_cfg.sampleType)) { aerror("rf_gain field not defined\n"); goto destroy; } if (!config_setting_lookup_int(dac, "block_size", &dac_cfg.NsamplesIn)) { aerror("block_size field not defined\n"); goto destroy; } dac_cfg.NsamplesOut = dac_cfg.NsamplesIn; if (!config_setting_lookup_bool(dac, "chain_is_tx", &dac_cfg.chain_is_tx)) { aerror("chain_is_tx field not defined\n"); goto destroy; } dac_cfg.sampleType = 0; dac_cfg.nof_channels = 1; uhd_readcfg(&dac_cfg); #endif } if (using_uhd) { #ifdef HAVE_UHD timeslot_us = (long int) 1000000*((float) dac_cfg.NsamplesOut/dac_cfg.outputFreq); #endif } else { timeslot_us = time_slot_us; } ret=0; destroy: config_destroy(&config); return ret; }