Пример #1
0
Файл: sigyn.c Проект: alyx/sigyn
int main(int argc, char *argv[])
{
    me.ev = mowgli_eventloop_create();

    signals_init();

    parse_commandline_options(argc, argv);

    me.config = mowgli_config_file_load(config_file);

    if(me.config == NULL)
        sigyn_fatal("Cannot load configuration file.");
    logger_init(me.config->entries);
    config_check(me.config);

    me.uplink.line = new_conn(me.uplink.hostname, me.uplink.port, me.uplink.ssl, read_irc, NULL);
    if (me.uplink.line == NULL)
        sigyn_fatal("Connection to uplink failed.");
    me.uplink.connected = true;

    loadmodules(me.config->entries);

    sigyn_introduce_client(me.client->nick, me.client->user, NULL);
    if (should_fork)
        daemonise(SYSCONFDIR "/sigyn.pid");
    mowgli_eventloop_run(me.ev);

    sigyn_cleanup();
    return EXIT_SUCCESS;
}
Пример #2
0
/**
 * Load the configuration of Sally
 * @param argc number of arguments
 * @param argv arguments
 */
static void sally_load_config(int argc, char **argv)
{
    char* cfg_file = NULL;
    int ch;

    /* Check for config file in command line */
    while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) {
        switch (ch) {
        case 'c':
            cfg_file = optarg;
            break;
        case '?':
            print_usage();
            exit(EXIT_SUCCESS);
            break;
        default:                                                                    
            /* empty */
            break;
        }
    }

    /* Init and load configuration */
    config_init(&cfg);

    if (cfg_file != NULL) {
        if (config_read_file(&cfg, cfg_file) != CONFIG_TRUE)
            fatal("Could not read configuration (%s in line %d)",
                  config_error_text(&cfg), config_error_line(&cfg));
    }

    /* Check configuration */
    if (!config_check(&cfg)) {
        exit(EXIT_FAILURE);
    }
}
Пример #3
0
/*
 * __wt_config_check --
 *	Check the keys in an application-supplied config string match what is
 *	specified in an array of check strings.
 */
int
__wt_config_check(WT_SESSION_IMPL *session,
    const WT_CONFIG_ENTRY *entry, const char *config, size_t config_len)
{
	/*
	 * Callers don't check, it's a fast call without a configuration or
	 * check array.
	 */
	return (config == NULL || entry->checks == NULL ?
	    0 : config_check(session, entry->checks, config, config_len));
}
Пример #4
0
/**
 * Main test function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    config_init(&cfg);
    config_check(&cfg);

    err |= test_compare();

    config_destroy(&cfg);
    return err;
}
Пример #5
0
/**
 * Load configuration
 * @param argc Number of arguments
 * @param argv Argument values
 */
static void load_config(int argc, char **argv)
{
    char cfg_path[MAX_PATH_LEN];
    int ch;

    /* Prepare dir */
    snprintf(malheur_dir, MAX_PATH_LEN, "%s", MALHEUR_DIR);

    /* Check for config file in command line */
    while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) {
        switch (ch) {
            case 'm':
                strncpy(malheur_dir, optarg, MAX_PATH_LEN);
                malheur_dir[MAX_PATH_LEN - 1] = 0;
                break;
            case 'v':
                verbose++;
                break;
            case '?':
            default:
                /* empty */
                break;
        }
    }

    /* Prepare malheur files */
    snprintf(cfg_path, MAX_PATH_LEN, "%s/%s", malheur_dir, CONFIG_FILE);

    /* Check for directories and files */
    if (access(malheur_dir, F_OK))
        fatal("Malheur directory '%s'", malheur_dir);

    /* Copy configuration file */
    if (access(cfg_path, R_OK)) {
        if (verbose > 0)
            printf("Copying configuration to '%s'.\n", cfg_path);
        copy_file(GLOBAL_CONFIG_FILE, cfg_path);
    }

    /* Init and load configuration */
    config_init(&cfg);
    if (config_read_file(&cfg, cfg_path) != CONFIG_TRUE)
        fatal("Could not read configuration (%s in line %d)",
              config_error_text(&cfg), config_error_line(&cfg));

    /* Check configuration */
    config_check(&cfg);
    if (verbose > 1)
        config_print(&cfg);
}
Пример #6
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    err |= test_static();
    err |= test_stress();
    err |= test_stress_omp();
    err |= test_load_save();

    config_destroy(&cfg);
    return err;
}
Пример #7
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    ftable_init();
    err |= test_classify();
    err |= test_stress();
    ftable_destroy();

    config_destroy(&cfg);
    return err;
}
Пример #8
0
FILE *
configure ()
{
    FILE    *rc;
    char    *home, *temp;

    /*
     *  Open *conf_file, ./.spcrc, ~/.spcrc, /etc/spcrc
     */
    if (opt_config) {
        if (!strncmp (opt_config, "~/", 2)) {
            if (!(home = getenv ("HOME")))
                err_quit ("can't find home directory");
            temp = malloc (strlen (home)+strlen (opt_config)+1);
            strcpy (temp, home);
            strcat (temp, opt_config+1);
        } else
            temp = opt_config;

        if (!(rc = config_check (temp)))
            err_quit ("can't open config file %s", temp);
        free (temp);
        return (rc);
    }

    /*
     *  look for spcrc-type in the standard locations
     */
    if (opt_type) {
        opt_config = malloc (strlen (opt_type)+7);
        sprintf (opt_config, "spcrc-%s", opt_type);
        return  (config_search (opt_config));
    }

    obtain_suffix ();

    /*
     *  look for spcrc-suffix in the standard locations
     */
    if (typ_suffix) {
        opt_config = malloc (strlen (typ_suffix)+7);
        sprintf (opt_config, "spcrc-%s", typ_suffix);
        return  (config_search (opt_config));
    }

    err_quit ("can't find a config file");
}
Пример #9
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    fhash_init();

    err |= test_sorted_ngrams();
    err |= test_blended_ngrams();
    err |= test_pos_ngrams();

    fhash_destroy();

    config_destroy(&cfg);
    return err;
}
Пример #10
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    config_set_string(&cfg, "features.granularity", "tokens");
    config_set_string(&cfg, "features.token_delim", " .,%0a%0d");
    config_set_int(&cfg, "features.ngram_len", 1);
    config_set_string(&cfg, "input.input_format", "lines");

    err |= test_norm_l1();
    err |= test_norm_l2();
    err |= test_embed_tfidf();
    err |= test_embed_bin();

    return err;
}
Пример #11
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    ftable_init();

    err |= test_cluster_complete();
    err |= test_cluster_average();
    err |= test_cluster_single();
    err |= test_stress();

    ftable_destroy();

    config_destroy(&cfg);
    return err;
}
Пример #12
0
/**
 * Main function
 */
int main(int argc, char **argv)
{
    int err = FALSE;

    /* Create config */
    config_init(&cfg);
    config_check(&cfg);

    config_set_string(&cfg, "features.vect_embed", "cnt");
    config_set_string(&cfg, "generic.event_delim", "0");
    config_set_int(&cfg, "features.ngram_len", 1);

    err |= test_static_add();
    err |= test_stress_add();
    err |= test_static_dot();
    err |= test_stress_dot();

    config_destroy(&cfg);
    return err;
}
Пример #13
0
FILE *
config_search (char *file)
{
    char    string [1024];
    char   *home = getenv ("HOME");
    FILE   *rc;

    if (!opt_nocwdrc) {
        sprintf (string, "./.%s", file);
        if ((rc = config_check (string)))     return (rc);
        if ((rc = config_check ("./.spcrc"))) return (rc);
    }

    if (home && !opt_nohomerc) {
        sprintf (string, "%s/.spcrc/%s", home, file);
        if ((rc = config_check (string))) return (rc);
        sprintf (string, "%s/.spcrc/spcrc", home);
        if ((rc = config_check (string))) return (rc);
    }

    if (opt_directory) {
        sprintf (string, "%s/%s", opt_directory, file);
        if ((rc = config_check (string))) return (rc);
        sprintf (string, "%s/spcrc", opt_directory);
        if ((rc = config_check (string))) return (rc);
    }

    sprintf (string, "%s/%s", SYSTEM_DIRECTORY, file);
    if ((rc = config_check (string))) return (rc);
    sprintf (string, "%s/spcrc", SYSTEM_DIRECTORY);
    if ((rc = config_check (string))) return (rc);

    if (opt_debug)
        err_quit ("can't find a config file");
    else
        err_quit ("can't find a config file, try using -d to show where I'm checking");
}
Пример #14
0
int main(int argc, char* argv[]) {

    parse_options(argc, argv);

    if(nologo == false) {
        printf("opensn0w 2.0, free your devices.\n"
               "version: " __SN0W_VERSION_FULL__ "\n\n"
               "Compiled on: " __DATE__ " " __TIME__ "\n\n");
    }

    config = config_file_load(config_file);
    if(!config) {
        printf("\ncannot load configuration file\n");
        return -1;
    }
    config_check(config);

    loadmodules(config->entries);

    jailbreak();

    return 0;
}
Пример #15
0
static void run()
{
    str_t post_data = empty_str, cookie_str;
    curl_data_t data_poll = empty_curl_data;
    curl_header_t header_poll = empty_curl_header;
    size_t i;

    for (i = 0; modules[i]; ++i)
    {
        if (modules[i]->module_begin && !modules[i]->module_begin()) return;
    }

    if (!config_check()) return;
    if (!init()) return;
    if (!login()) return;

    make_poll_post_data(&post_data);

    cookie_str = cookie_to_str(&robot.cookie);

    while (robot.run)
    {
        if (!post_request_with_cookie("https://d.web2.qq.com/channel/poll2", 1, "./pems/d.web2.qq.com.pem", post_data.ptr, cookie_str.ptr, &data_poll, &header_poll)) continue;

        route(&cookie_str, &data_poll, &header_poll);

        curl_data_free(&data_poll);
        pair_array_free(&header_poll);
    }

    for (i = 0; modules[i]; ++i)
    {
        if (modules[i] == &conf_module) continue;
        if (modules[i]->module_exit) modules[i]->module_exit();
    }
    conf_module.module_exit();
}
Пример #16
0
/* Check config values and correct invalid ones
 */
int SC68config_valid(SC68config_t * conf)
{
  int i;

  if (config_check(conf)) {
    return -1;
  }

  for (i=0; i < nconfig; i++) {
    if (tab[i].min==0 && tab[i].max==0) {
      continue;
    } else if (tab[i].min==0 && tab[i].max==1) {
      /* Boolean */
      (*conf)[i] = !! (*conf)[i];
    } else if ((*conf)[i] < tab[i].min) {
      /* Clamp min */
      (*conf)[i] = tab[i].min;
    } else if ((*conf)[i]>tab[i].max) {
      /* Clamp max */
      (*conf)[i] = tab[i].max;
    }
  }
  return 0;
}
Пример #17
0
int main(int argc, char **argv) {
	int exit_code = EXIT_FAILURE;
	int i;
	bool help = false;
	bool version = false;
	bool check_config = false;
	bool daemon = false;
	const char *debug_filter = NULL;
	int pid_fd = -1;
#ifdef BRICKD_WITH_LIBUDEV
	bool initialized_udev = false;
#endif

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = true;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = true;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = true;
		} else if (strcmp(argv[i], "--daemon") == 0) {
			daemon = true;
		} else if (strcmp(argv[i], "--debug") == 0) {
			if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) {
				debug_filter = argv[++i];
			} else {
				debug_filter = "";
			}
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		printf("%s\n", VERSION_STRING);

		return EXIT_SUCCESS;
	}

	if (prepare_paths() < 0) {
		return EXIT_FAILURE;
	}

	if (check_config) {
		return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	config_init(_config_filename);

	if (config_has_error()) {
		fprintf(stderr, "Error(s) occurred while reading config file '%s'\n",
		        _config_filename);

		goto error_config;
	}

	log_init();

	if (daemon) {
		pid_fd = daemon_start(_log_filename, &_log_file, _pid_filename, true);
	} else {
		pid_fd = pid_file_acquire(_pid_filename, getpid());

		if (pid_fd == PID_FILE_ALREADY_ACQUIRED) {
			fprintf(stderr, "Already running according to '%s'\n", _pid_filename);
		}
	}

	if (pid_fd < 0) {
		goto error_pid_file;
	}

	log_info("Brick Daemon %s started (pid: %u, daemonized: %d)",
	         VERSION_STRING, getpid(), daemon ? 1 : 0);

	if (debug_filter != NULL) {
		log_enable_debug_override(debug_filter);
	}

	if (config_has_warning()) {
		log_warn("Warning(s) in config file '%s', run with --check-config option for details",
		         _config_filename);
	}

	if (event_init() < 0) {
		goto error_event;
	}

	if (signal_init(handle_sighup, handle_sigusr1) < 0) {
		goto error_signal;
	}

	if (hardware_init() < 0) {
		goto error_hardware;
	}

	if (usb_init() < 0) {
		goto error_usb;
	}

#ifdef BRICKD_WITH_LIBUDEV
	if (!usb_has_hotplug()) {
		if (udev_init() < 0) {
			goto error_udev;
		}

		initialized_udev = true;
	}
#endif

	if (network_init() < 0) {
		goto error_network;
	}

	if (mesh_init() < 0) {
		goto error_mesh;
	}

#ifdef BRICKD_WITH_RED_BRICK
	if (gpio_init() < 0) {
		goto error_gpio;
	}

	if (redapid_init() < 0) {
		goto error_redapid;
	}

	if (red_stack_init() < 0) {
		goto error_red_stack;
	}

	if (red_extension_init() < 0) {
		goto error_red_extension;
	}

	if (red_usb_gadget_init() < 0) {
		goto error_red_usb_gadget;
	}

	red_led_set_trigger(RED_LED_GREEN, config_get_option_value("led_trigger.green")->symbol);
	red_led_set_trigger(RED_LED_RED, config_get_option_value("led_trigger.red")->symbol);
#endif

	if (event_run(network_cleanup_clients_and_zombies) < 0) {
		goto error_run;
	}

#ifdef BRICKD_WITH_RED_BRICK
	hardware_announce_disconnect();
	network_announce_red_brick_disconnect();
	red_usb_gadget_announce_red_brick_disconnect();
#endif

	exit_code = EXIT_SUCCESS;

error_run:
#ifdef BRICKD_WITH_RED_BRICK
	red_usb_gadget_exit();

error_red_usb_gadget:
	red_extension_exit();

error_red_extension:
	red_stack_exit();

error_red_stack:
	redapid_exit();

error_redapid:
	//gpio_exit();

error_gpio:
#endif
	network_exit();

error_mesh:
	mesh_exit();

error_network:
#ifdef BRICKD_WITH_LIBUDEV
	if (initialized_udev) {
		udev_exit();
	}

error_udev:
#endif
	usb_exit();

error_usb:
	hardware_exit();

error_hardware:
	signal_exit();

error_signal:
	event_exit();

error_event:
	log_info("Brick Daemon %s stopped", VERSION_STRING);

error_pid_file:
	if (pid_fd >= 0) {
		pid_file_release(_pid_filename, pid_fd);
	}

	log_exit();

error_config:
	config_exit();

	return exit_code;
}
Пример #18
0
static void si_config_read(void)
{
    struct config_t *gpu_config;
    char *section;
    char *err_note =
        "\tPlease run 'm2s --help-gpu-config' or consult the Multi2Sim Guide for a\n"
        "\tdescription of the GPU configuration file format.";

    char *gpu_register_alloc_granularity_str;
    char *gpu_sched_policy_str;

    /* Load GPU configuration file */
    gpu_config = config_create(si_gpu_config_file_name);
    if (*si_gpu_config_file_name && !config_load(gpu_config))
        fatal("%s: cannot load GPU configuration file", si_gpu_config_file_name);

    /* Device */
    section = "Device";
    si_gpu_num_compute_units = config_read_int(gpu_config, section, "NumComputeUnits",
                               si_gpu_num_compute_units);
    si_gpu_num_wavefront_pools = config_read_int(gpu_config, section, "NumWavefrontPools",
                                 si_gpu_num_wavefront_pools);
    si_gpu_num_stream_cores = config_read_int(gpu_config, section, "NumStreamCores",
                              si_gpu_num_stream_cores);
    si_gpu_num_registers = config_read_int(gpu_config, section, "NumRegisters",
                                           si_gpu_num_registers);
    si_gpu_register_alloc_size = config_read_int(gpu_config, section, "RegisterAllocSize",
                                 si_gpu_register_alloc_size);
    gpu_register_alloc_granularity_str = config_read_string(gpu_config, section,
                                         "RegisterAllocGranularity", "WorkGroup");
    si_emu_wavefront_size = config_read_int(gpu_config, section, "WavefrontSize",
                                            si_emu_wavefront_size);
    si_gpu_max_work_groups_per_wavefront_pool = config_read_int(gpu_config, section,
            "MaxWorkGroupsPerComputeUnit", si_gpu_max_work_groups_per_wavefront_pool);
    si_gpu_max_wavefronts_per_wavefront_pool = config_read_int(gpu_config, section,
            "MaxWavefrontsPerComputeUnit", si_gpu_max_wavefronts_per_wavefront_pool);
    si_gpu_fetch_latency = config_read_int(gpu_config, section, "FetchLatency",
                                           si_gpu_fetch_latency);
    si_gpu_decode_latency = config_read_int(gpu_config, section, "DecodeLatency",
                                            si_gpu_decode_latency);
    si_gpu_simd_issue_width = config_read_int(gpu_config, section, "SIMDIssueWidth",
                              si_gpu_simd_issue_width);
    si_gpu_simd_alu_latency = config_read_int(gpu_config, section, "SIMDALULatency",
                              si_gpu_simd_alu_latency);
    si_gpu_scalar_unit_issue_width= config_read_int(gpu_config, section,
                                    "ScalarUnitIssueWidth", si_gpu_scalar_unit_issue_width);
    si_gpu_scalar_unit_alu_latency = config_read_int(gpu_config, section,
                                     "ScalarUnitALULatency", si_gpu_scalar_unit_alu_latency);
    si_gpu_branch_unit_issue_width = config_read_int(gpu_config, section,
                                     "BranchUnitIssueWidth", si_gpu_branch_unit_issue_width);
    si_gpu_branch_unit_latency = config_read_int(gpu_config, section, "BranchUnitLatency",
                                 si_gpu_branch_unit_latency);
    gpu_sched_policy_str = config_read_string(gpu_config, section, "SchedulingPolicy",
                           "RoundRobin");

    if (si_gpu_num_compute_units < 1)
        fatal("%s: invalid value for 'NumComputeUnits'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_num_wavefront_pools < 1)
        fatal("%s: invalid value for 'NumWavefrontPools'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_num_stream_cores < 1)
        fatal("%s: invalid value for 'NumStreamCores'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_register_alloc_size < 1)
        fatal("%s: invalid value for 'RegisterAllocSize'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_num_registers < 1)
        fatal("%s: invalid value for 'NumRegisters'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_num_registers % si_gpu_register_alloc_size)
        fatal("%s: 'NumRegisters' must be a multiple of 'RegisterAllocSize'.\n%s",
              si_gpu_config_file_name, err_note);
    si_gpu_register_alloc_granularity = map_string_case(&si_gpu_register_alloc_granularity_map,
                                        gpu_register_alloc_granularity_str);
    if (si_gpu_register_alloc_granularity == si_gpu_register_alloc_invalid)
        fatal("%s: invalid value for 'RegisterAllocGranularity'.\n%s",
              si_gpu_config_file_name, err_note);
    si_gpu_sched_policy = map_string_case(&si_gpu_sched_policy_map,
                                          gpu_sched_policy_str);
    if (si_gpu_sched_policy == si_gpu_sched_invalid)
        fatal("%s: invalid value for 'SchedulingPolicy'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_emu_wavefront_size < 1)
        fatal("%s: invalid value for 'WavefrontSize'.\n%s", si_gpu_config_file_name,
              err_note);
    if (si_gpu_max_work_groups_per_wavefront_pool < 1)
        fatal("%s: invalid value for 'MaxWorkGroupsPerComputeUnit'.\n%s",
              si_gpu_config_file_name, err_note);
    if (si_gpu_max_wavefronts_per_wavefront_pool < 1)
        fatal("%s: invalid value for 'MaxWavefrontsPerComputeUnit'.\n%s",
              si_gpu_config_file_name, err_note);

    /* Local memory */
    section = "LocalMemory";
    si_gpu_local_mem_size = config_read_int(gpu_config, section, "Size", si_gpu_local_mem_size);
    si_gpu_local_mem_alloc_size = config_read_int(gpu_config, section, "AllocSize",
                                  si_gpu_local_mem_alloc_size);
    si_gpu_local_mem_block_size = config_read_int(gpu_config, section, "BlockSize",
                                  si_gpu_local_mem_block_size);
    si_gpu_local_mem_latency = config_read_int(gpu_config, section, "Latency",
                               si_gpu_local_mem_latency);
    si_gpu_local_mem_num_ports = config_read_int(gpu_config, section, "Ports",
                                 si_gpu_local_mem_num_ports);

    if ((si_gpu_local_mem_size & (si_gpu_local_mem_size - 1)) || si_gpu_local_mem_size < 4)
        fatal("%s: %s->Size must be a power of two and at least 4.\n%s",
              si_gpu_config_file_name, section, err_note);
    if (si_gpu_local_mem_alloc_size < 1)
        fatal("%s: invalid value for %s->Allocsize.\n%s", si_gpu_config_file_name, section,
              err_note);
    if (si_gpu_local_mem_size % si_gpu_local_mem_alloc_size)
        fatal("%s: %s->Size must be a multiple of %s->AllocSize.\n%s",
              si_gpu_config_file_name, section, section, err_note);
    if ((si_gpu_local_mem_block_size & (si_gpu_local_mem_block_size - 1)) ||
            si_gpu_local_mem_block_size < 4)
        fatal("%s: %s->BlockSize must be a power of two and at least 4.\n%s",
              si_gpu_config_file_name, section, err_note);
    if (si_gpu_local_mem_alloc_size % si_gpu_local_mem_block_size)
        fatal("%s: %s->AllocSize must be a multiple of %s->BlockSize.\n%s",
              si_gpu_config_file_name, section, section, err_note);
    if (si_gpu_local_mem_latency < 1)
        fatal("%s: invalid value for %s->Latency.\n%s", si_gpu_config_file_name, section,
              err_note);
    if (si_gpu_local_mem_size < si_gpu_local_mem_block_size)
        fatal("%s: %s->Size cannot be smaller than %s->BlockSize * %s->Banks.\n%s",
              si_gpu_config_file_name, section, section, section, err_note);


    /* Close GPU configuration file */
    config_check(gpu_config);
    config_free(gpu_config);
}
Пример #19
0
/**
 * Parse command line options
 * @param argc Number of arguments
 * @param argv Argument values
 */
static void sally_parse_options(int argc, char **argv)
{
    int ch, user_conf = FALSE;

    optind = 0;

    while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) {
        switch (ch) {
        case 'c':
            /* Skip. See sally_load_config(). */
            user_conf = TRUE;
            break;
        case 'i':
            config_set_string(&cfg, "input.input_format", optarg);
            break;
        case 1000:
            config_set_int(&cfg, "input.chunk_size", atoi(optarg));
            break;
        case 1001:
            config_set_string(&cfg, "input.fasta_regex", optarg);
            break;
        case 1002:
            config_set_string(&cfg, "input.lines_regex", optarg);
            break;
        case 1005:
            config_set_int(&cfg, "input.decode_str", atoi(optarg));
            break;
        case 1006:
            config_set_int(&cfg, "features.vect_sign", atoi(optarg));
            break;
        case 1007:
            config_set_int(&cfg, "input.reverse_str", atoi(optarg));
            break;
        case 1008:
            config_set_string(&cfg, "input.stopword_file", optarg);
            break;
        case 1009:
            config_set_float(&cfg, "features.thres_low", atof(optarg));
            break;
        case 1010:
            config_set_float(&cfg, "features.thres_high", atof(optarg));
            break;
        case 1011:
            config_set_string(&cfg, "features.hash_file", optarg);
            break;
        case 'n':
            config_set_int(&cfg, "features.ngram_len", atoi(optarg));
            break;
        case 'd':
            config_set_string(&cfg, "features.ngram_delim", optarg);
            break;
        case 'p':
            config_set_int(&cfg, "features.ngram_pos", atoi(optarg));
            break;
        case 's':
            config_set_int(&cfg, "features.ngram_sort", atoi(optarg));
            break;
        case 'E':
            config_set_string(&cfg, "features.vect_embed", optarg);
            break;
        case 'N':
            config_set_string(&cfg, "features.vect_norm", optarg);
            break;
        case 'b':
            config_set_int(&cfg, "features.hash_bits", atoi(optarg));
            break;
        case 1003:
            config_set_int(&cfg, "features.explicit_hash", atoi(optarg));
            break;
        case 1004:
            config_set_string(&cfg, "features.tfidf_file", optarg);
            break;
        case 'o':
            config_set_string(&cfg, "output.output_format", optarg);
            break;
        case 'q':
            verbose = 0;
            break;
        case 'v':
            verbose++;
            break;
        case 'D':
            print_config("Default configuration");
            exit(EXIT_SUCCESS);
            break;
        case 'C':
            print_conf = 1;
            break;
        case 'V':
            print_version();
            exit(EXIT_SUCCESS);
            break;
        case 'h':
        case '?':
            print_usage();
            exit(EXIT_SUCCESS);
            break;
        }
    }

#ifdef ENABLE_EVALTIME
    config_set_int(&cfg, "input.chunk_size", 1);
    verbose = 0;
#endif

    /* Check configuration */
    if(!config_check(&cfg)) {
        exit(EXIT_FAILURE);
    }

    /* We are through with parsing. Print the config if requested */
    if (print_conf) {
        print_config("Current configuration");
        exit(EXIT_SUCCESS);
    }

    argc -= optind;
    argv += optind;
    
    /* Check for input and output arguments */
    if (argc != 2) {
        print_usage();
        exit(EXIT_FAILURE);
    } else {
        input = argv[0];
        output = argv[1];
    }
    
    /* Last but not least. Warn about default config */
    if (!user_conf) {
        warning("No config file given. Using defaults (see -D)");
    }
}
Пример #20
0
/*
 * config_check --
 *	Check the keys in an application-supplied config string match what is
 * specified in an array of check strings.
 */
static int
config_check(WT_SESSION_IMPL *session,
    const WT_CONFIG_CHECK *checks, const char *config, size_t config_len)
{
	WT_CONFIG parser, cparser, sparser;
	WT_CONFIG_ITEM k, v, ck, cv, dummy;
	WT_DECL_RET;
	int i;
	bool badtype, found;

	/*
	 * The config_len parameter is optional, and allows passing in strings
	 * that are not nul-terminated.
	 */
	if (config_len == 0)
		WT_RET(__wt_config_init(session, &parser, config));
	else
		WT_RET(__wt_config_initn(session, &parser, config, config_len));
	while ((ret = __wt_config_next(&parser, &k, &v)) == 0) {
		if (k.type != WT_CONFIG_ITEM_STRING &&
		    k.type != WT_CONFIG_ITEM_ID)
			WT_RET_MSG(session, EINVAL,
			    "Invalid configuration key found: '%.*s'",
			    (int)k.len, k.str);

		/* Search for a matching entry. */
		for (i = 0; checks[i].name != NULL; i++)
			if (WT_STRING_MATCH(checks[i].name, k.str, k.len))
				break;
		if (checks[i].name == NULL)
			WT_RET_MSG(session, EINVAL,
			    "unknown configuration key: '%.*s'",
			    (int)k.len, k.str);

		if (strcmp(checks[i].type, "boolean") == 0) {
			badtype = v.type != WT_CONFIG_ITEM_BOOL &&
			    (v.type != WT_CONFIG_ITEM_NUM ||
			    (v.val != 0 && v.val != 1));
		} else if (strcmp(checks[i].type, "category") == 0) {
			/* Deal with categories of the form: XXX=(XXX=blah). */
			ret = config_check(session,
			    checks[i].subconfigs,
			    k.str + strlen(checks[i].name) + 1, v.len);
			if (ret != EINVAL)
				badtype = false;
			else
				badtype = true;
		} else if (strcmp(checks[i].type, "format") == 0) {
			badtype = false;
		} else if (strcmp(checks[i].type, "int") == 0) {
			badtype = v.type != WT_CONFIG_ITEM_NUM;
		} else if (strcmp(checks[i].type, "list") == 0) {
			badtype = v.len > 0 && v.type != WT_CONFIG_ITEM_STRUCT;
		} else if (strcmp(checks[i].type, "string") == 0) {
			badtype = false;
		} else
			WT_RET_MSG(session, EINVAL,
			    "unknown configuration type: '%s'",
			    checks[i].type);

		if (badtype)
			WT_RET_MSG(session, EINVAL,
			    "Invalid value for key '%.*s': expected a %s",
			    (int)k.len, k.str, checks[i].type);

		if (checks[i].checkf != NULL)
			WT_RET(checks[i].checkf(session, &v));

		if (checks[i].checks == NULL)
			continue;

		/* Setup an iterator for the check string. */
		WT_RET(__wt_config_init(session, &cparser, checks[i].checks));
		while ((ret = __wt_config_next(&cparser, &ck, &cv)) == 0) {
			if (WT_STRING_MATCH("min", ck.str, ck.len)) {
				if (v.val < cv.val)
					WT_RET_MSG(session, EINVAL,
					    "Value too small for key '%.*s' "
					    "the minimum is %.*s",
					    (int)k.len, k.str,
					    (int)cv.len, cv.str);
			} else if (WT_STRING_MATCH("max", ck.str, ck.len)) {
				if (v.val > cv.val)
					WT_RET_MSG(session, EINVAL,
					    "Value too large for key '%.*s' "
					    "the maximum is %.*s",
					    (int)k.len, k.str,
					    (int)cv.len, cv.str);
			} else if (WT_STRING_MATCH("choices", ck.str, ck.len)) {
				if (v.len == 0)
					WT_RET_MSG(session, EINVAL,
					    "Key '%.*s' requires a value",
					    (int)k.len, k.str);
				if (v.type == WT_CONFIG_ITEM_STRUCT) {
					/*
					 * Handle the 'verbose' case of a list
					 * containing restricted choices.
					 */
					WT_RET(__wt_config_subinit(session,
					    &sparser, &v));
					found = true;
					while (found &&
					    (ret = __wt_config_next(&sparser,
					    &v, &dummy)) == 0) {
						ret = __wt_config_subgetraw(
						    session, &cv, &v, &dummy);
						found = ret == 0;
					}
				} else  {
					ret = __wt_config_subgetraw(session,
					    &cv, &v, &dummy);
					found = ret == 0;
				}

				if (ret != 0 && ret != WT_NOTFOUND)
					return (ret);
				if (!found)
					WT_RET_MSG(session, EINVAL,
					    "Value '%.*s' not a "
					    "permitted choice for key '%.*s'",
					    (int)v.len, v.str,
					    (int)k.len, k.str);
			} else
				WT_RET_MSG(session, EINVAL,
				    "unexpected configuration description "
				    "keyword %.*s", (int)ck.len, ck.str);
		}
	}

	if (ret == WT_NOTFOUND)
		ret = 0;

	return (ret);
}
Пример #21
0
/*
 * __wt_configure_method --
 *	WT_CONNECTION.configure_method.
 */
int
__wt_configure_method(WT_SESSION_IMPL *session,
    const char *method, const char *uri,
    const char *config, const char *type, const char *check)
{
	const WT_CONFIG_CHECK *cp;
	WT_CONFIG_CHECK *checks, *newcheck;
	const WT_CONFIG_ENTRY **epp;
	WT_CONFIG_ENTRY *entry;
	WT_CONNECTION_IMPL *conn;
	WT_DECL_RET;
	size_t cnt;
	char *newcheck_name, *p;

	/*
	 * !!!
	 * We ignore the specified uri, that is, all new configuration options
	 * will be valid for all data sources.   That shouldn't be too bad
	 * as the worst that can happen is an application might specify some
	 * configuration option and not get an error -- the option should be
	 * ignored by the underlying implementation since it's unexpected, so
	 * there shouldn't be any real problems.  Eventually I expect we will
	 * get the whole data-source thing sorted, at which time there may be
	 * configuration arrays for each data source, and that's when the uri
	 * will matter.
	 */
	WT_UNUSED(uri);

	conn = S2C(session);
	checks = newcheck = NULL;
	entry = NULL;
	newcheck_name = NULL;

	/* Argument checking; we only support a limited number of types. */
	if (config == NULL)
		WT_RET_MSG(session, EINVAL, "no configuration specified");
	if (type == NULL)
		WT_RET_MSG(session, EINVAL, "no configuration type specified");
	if (strcmp(type, "boolean") != 0 && strcmp(type, "int") != 0 &&
	    strcmp(type, "list") != 0 && strcmp(type, "string") != 0)
		WT_RET_MSG(session, EINVAL,
		    "type must be one of \"boolean\", \"int\", \"list\" or "
		    "\"string\"");

	/* Find a match for the method name. */
	for (epp = conn->config_entries; (*epp)->method != NULL; ++epp)
		if (strcmp((*epp)->method, method) == 0)
			break;
	if ((*epp)->method == NULL)
		WT_RET_MSG(session,
		    WT_NOTFOUND, "no method matching %s found", method);

	/*
	 * Technically possible for threads to race, lock the connection while
	 * adding the new configuration information.  We're holding the lock
	 * for an extended period of time, but configuration changes should be
	 * rare and only happen during startup.
	 */
	__wt_spin_lock(session, &conn->api_lock);

	/*
	 * Allocate new configuration entry and fill it in.
	 *
	 * The new base value is the previous base value, a separator and the
	 * new configuration string.
	 */
	WT_ERR(__wt_calloc_one(session, &entry));
	entry->method = (*epp)->method;
	WT_ERR(__wt_calloc_def(session,
	    strlen((*epp)->base) + strlen(",") + strlen(config) + 1, &p));
	(void)strcpy(p, (*epp)->base);
	(void)strcat(p, ",");
	(void)strcat(p, config);
	entry->base = p;

	/*
	 * There may be a default value in the config argument passed in (for
	 * example, (kvs_parallelism=64").  The default value isn't part of the
	 * name, build a new one.
	 */
	WT_ERR(__wt_strdup(session, config, &newcheck_name));
	if ((p = strchr(newcheck_name, '=')) != NULL)
		*p = '\0';

	/*
	 * The new configuration name may replace an existing check with new
	 * information, in that case skip the old version.
	 */
	cnt = 0;
	if ((*epp)->checks != NULL)
		for (cp = (*epp)->checks; cp->name != NULL; ++cp)
			++cnt;
	WT_ERR(__wt_calloc_def(session, cnt + 2, &checks));
	cnt = 0;
	if ((*epp)->checks != NULL)
		for (cp = (*epp)->checks; cp->name != NULL; ++cp)
			if (strcmp(newcheck_name, cp->name) != 0)
				checks[cnt++] = *cp;
	newcheck = &checks[cnt];
	newcheck->name = newcheck_name;
	WT_ERR(__wt_strdup(session, type, &newcheck->type));
	if (check != NULL)
		WT_ERR(__wt_strdup(session, check, &newcheck->checks));
	entry->checks = checks;

	/*
	 * Confirm the configuration string passes the new set of
	 * checks.
	 */
	WT_ERR(config_check(session, entry->checks, config, 0));

	/*
	 * The next time this configuration is updated, we don't want to figure
	 * out which of these pieces of memory were allocated and will need to
	 * be free'd on close (this isn't a heavily used API and it's too much
	 * work); add them all to the free-on-close list now.  We don't check
	 * for errors deliberately, we'd have to figure out which elements have
	 * already been added to the free-on-close array and which have not in
	 * order to avoid freeing chunks of memory twice.  Again, this isn't a
	 * commonly used API and it shouldn't ever happen, just leak it.
	 */
	(void)__conn_foc_add(session, entry->base);
	(void)__conn_foc_add(session, entry);
	(void)__conn_foc_add(session, checks);
	(void)__conn_foc_add(session, newcheck->type);
	(void)__conn_foc_add(session, newcheck->checks);
	(void)__conn_foc_add(session, newcheck_name);

	/*
	 * Instead of using locks to protect configuration information, assume
	 * we can atomically update a pointer to a chunk of memory, and because
	 * a pointer is never partially written, readers will correctly see the
	 * original or new versions of the memory.  Readers might be using the
	 * old version as it's being updated, though, which means we cannot free
	 * the old chunk of memory until all possible readers have finished.
	 * Currently, that's on connection close: in other words, we can use
	 * this because it's small amounts of memory, and we really, really do
	 * not want to acquire locks every time we access configuration strings,
	 * since that's done on every API call.
	 */
	WT_PUBLISH(*epp, entry);

	if (0) {
err:		if (entry != NULL) {
			__wt_free(session, entry->base);
			__wt_free(session, entry);
		}
		__wt_free(session, checks);
		if (newcheck != NULL) {
			__wt_free(session, newcheck->type);
			__wt_free(session, newcheck->checks);
		}
		__wt_free(session, newcheck_name);
	}

	__wt_spin_unlock(session, &conn->api_lock);
	return (ret);
}
Пример #22
0
int main(int argc, char *argv[])
{
    int		    loop = 1;
    struct passwd   *pw;

    /*
     * Find out who is on the keyboard or automated the keyboard.
     */
    pw = getpwuid(geteuid());
    if (strcmp(pw->pw_name, (char *)"ftnd")) {
	printf("ERROR: only user \"ftnd\" may use this program\n");
        exit(FTNERR_INIT_ERROR);
    }

    /*
     * Read the global configuration data, registrate connection
     */
    config_check(getenv("FTND_ROOT"));
    config_read();
    if (strlen(CFG.debuglog) == 0)
	snprintf(CFG.debuglog, 15, "debug.log");
    InitClient(pw->pw_name, (char *)"ftnsetup", CFG.location, CFG.logfile, 0x1f, CFG.error_log, CFG.mgrlog, CFG.debuglog);

    /*
     * Setup several signals so when the program terminate's it
     * will properly close the curses screens.
     */
    signal(SIGINT, (void (*))die);
    signal(SIGBUS, (void (*))die);
    signal(SIGSEGV,(void (*))die);
    signal(SIGTERM,(void (*))die);
    signal(SIGKILL,(void (*))die);
    signal(SIGIOT, (void (*))die);

    oldmask = umask(002);

    do_quiet = TRUE;
    Syslog(' ', " ");
    Syslog(' ', "FTNSETUP v%s started by %s", VERSION, pw->pw_name);
    if (init)
	Syslog('+', "Cmd: ftnsetup init");

    if ((argc == 2) && (strncmp(tl(argv[1]), "i", 1) == 0))
	init = TRUE;
    else
	screen_start((char *)"ftnsetup");
    
    if (lockprogram((char *)"ftnsetup")) {
	printf("\n\7Another ftnsetup is already running, abort.\n\n");
	die(FTNERR_NO_PROGLOCK);
    }

    bbs_free = FALSE;
    initdatabases();
	
    if (!init) {
	do {
	    IsDoing("Browsing Menu");
	    clr_index();
	    set_color(WHITE, BLACK);
	    ftnd_mvprintw( 5, 6, "0.    MAIN SETUP");
	    set_color(CYAN, BLACK);
	    ftnd_mvprintw( 7, 6, "1.    Edit Global configuration");
	    ftnd_mvprintw( 8, 6, "2.    Edit Fido Networks");
	    ftnd_mvprintw( 9, 6, "3.    Edit Archiver Programs");
	    ftnd_mvprintw(10, 6, "4.    Edit Virus Scanners");
	    ftnd_mvprintw(11, 6, "5.    Edit Modem types");
	    ftnd_mvprintw(12, 6, "6.    Edit TTY lines info");
	    ftnd_mvprintw(13, 6, "7.    Edit Fidonet Nodes");
	    ftnd_mvprintw(14, 6, "8.    Edit BBS Setup");
	    ftnd_mvprintw(15, 6, "9.    Edit Mail Setup");
	    ftnd_mvprintw(16, 6, "10.   Edit File Echo's setup");
	    ftnd_mvprintw(17, 6, "11.   Edit Newfiles Groups");
	    ftnd_mvprintw( 7,46, "12.   Edit Newfiles Reports");
	    ftnd_mvprintw( 8,46, "13.   Edit FileFind Setup");
	    ftnd_mvprintw( 9,46, "14.   Edit Files Database");
	    ftnd_mvprintw(10,46, "15.   Edit BBS Users");
	    ftnd_mvprintw(11,46, "16.   Edit Services");
	    ftnd_mvprintw(12,46, "17.   Edit Domains");
	    ftnd_mvprintw(13,46, "18.   Edit Task Manager");
	    ftnd_mvprintw(14,46, "19.   Edit Routing Table");
	    ftnd_mvprintw(15,46, "20.   Edit Internet BBS Chat");
	    ftnd_mvprintw(16,46, "21.   Show software information");
	    ftnd_mvprintw(17,46, "22.   Create site documents");
 
	    switch(select_menu(22)) {
		case 0:
			loop = 0;
			break;
		case 1:
			global_menu();
			break;
		case 2:
			EditFidonet();
			break;
		case 3:
			EditArchive();
			break;
		case 4:
			EditVirus();
			break;
		case 5:
			EditModem();
			break;
		case 6:
			EditTtyinfo();
			break;
		case 7:
			EditNodes();
			break;
		case 8:
			bbs_menu();
			break;
		case 9:
			mail_menu();
			break;
		case 10:
			tic_menu();
			break;
		case 11:
			EditNGroup();
			break;
		case 12:	
			EditNewfiles();
			break;
		case 13:
			EditFilefind();
			break;
		case 14:
			EditFDB();
			break;
		case 15:
			EditUsers();
			break;
		case 16:
			EditService();
			break;
		case 17:
			EditDomain();
			break;
		case 18:
			task_menu();
			break;
		case 19:
			EditRoute();
			break;
		case 20:
			EditIBC();
			break;
		case 21:
			soft_info();
			break;
		case 22:
			site_docs();
			break;
	    }
	} while (loop == 1);
    }

    die(FTNERR_OK);
    return 0;
}
Пример #23
0
void evg_gpu_read_config(void)
{
	struct config_t *gpu_config;
	char *section;
	char *err_note =
		"\tPlease run 'm2s --evg-help' or consult the Multi2Sim Guide for a\n"
		"\tdescription of the GPU configuration file format.";

	char *gpu_register_alloc_granularity_str;
	char *gpu_sched_policy_str;

	/* Load GPU configuration file */
	gpu_config = config_create(evg_gpu_config_file_name);
	if (*evg_gpu_config_file_name)
		config_load(gpu_config);
	
	/* Device */
	section = "Device";

	/* Frequency */
	evg_gpu_frequency = config_read_int(gpu_config, section, "Frequency", evg_gpu_frequency);
	if (!IN_RANGE(evg_gpu_frequency, 1, ESIM_MAX_FREQUENCY))
		fatal("%s: invalid value for 'Frequency'.\n%s",
				evg_gpu_config_file_name, err_note);

	evg_gpu_num_compute_units = config_read_int(gpu_config, section, "NumComputeUnits", evg_gpu_num_compute_units);
	evg_gpu_num_stream_cores = config_read_int(gpu_config, section, "NumStreamCores", evg_gpu_num_stream_cores);
	evg_gpu_num_registers = config_read_int(gpu_config, section, "NumRegisters", evg_gpu_num_registers);
	evg_gpu_register_alloc_size = config_read_int(gpu_config, section, "RegisterAllocSize", evg_gpu_register_alloc_size);
	gpu_register_alloc_granularity_str = config_read_string(gpu_config, section, "RegisterAllocGranularity", "WorkGroup");
	evg_emu_wavefront_size = config_read_int(gpu_config, section, "WavefrontSize", evg_emu_wavefront_size);
	evg_gpu_max_work_groups_per_compute_unit = config_read_int(gpu_config, section, "MaxWorkGroupsPerComputeUnit",
		evg_gpu_max_work_groups_per_compute_unit);
	evg_gpu_max_wavefronts_per_compute_unit = config_read_int(gpu_config, section, "MaxWavefrontsPerComputeUnit",
		evg_gpu_max_wavefronts_per_compute_unit);
	gpu_sched_policy_str = config_read_string(gpu_config, section, "SchedulingPolicy", "RoundRobin");
	if (evg_gpu_num_compute_units < 1)
		fatal("%s: invalid value for 'NumComputeUnits'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_num_stream_cores < 1)
		fatal("%s: invalid value for 'NumStreamCores'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_register_alloc_size < 1)
		fatal("%s: invalid value for 'RegisterAllocSize'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_num_registers < 1)
		fatal("%s: invalid value for 'NumRegisters'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_num_registers % evg_gpu_register_alloc_size)
		fatal("%s: 'NumRegisters' must be a multiple of 'RegisterAllocSize'.\n%s", evg_gpu_config_file_name, err_note);

	evg_gpu_register_alloc_granularity = str_map_string_case(&evg_gpu_register_alloc_granularity_map, gpu_register_alloc_granularity_str);
	if (evg_gpu_register_alloc_granularity == evg_gpu_register_alloc_invalid)
		fatal("%s: invalid value for 'RegisterAllocGranularity'.\n%s", evg_gpu_config_file_name, err_note);

	evg_gpu_sched_policy = str_map_string_case(&evg_gpu_sched_policy_map, gpu_sched_policy_str);
	if (evg_gpu_sched_policy == evg_gpu_sched_invalid)
		fatal("%s: invalid value for 'SchedulingPolicy'.\n%s", evg_gpu_config_file_name, err_note);

	if (evg_emu_wavefront_size < 1)
		fatal("%s: invalid value for 'WavefrontSize'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_max_work_groups_per_compute_unit < 1)
		fatal("%s: invalid value for 'MaxWorkGroupsPerComputeUnit'.\n%s", evg_gpu_config_file_name, err_note);
	if (evg_gpu_max_wavefronts_per_compute_unit < 1)
		fatal("%s: invalid value for 'MaxWavefrontsPerComputeUnit'.\n%s", evg_gpu_config_file_name, err_note);
	
	/* Local memory */
	section = "LocalMemory";
	evg_gpu_local_mem_size = config_read_int(gpu_config, section, "Size", evg_gpu_local_mem_size);
	evg_gpu_local_mem_alloc_size = config_read_int(gpu_config, section, "AllocSize", evg_gpu_local_mem_alloc_size);
	evg_gpu_local_mem_block_size = config_read_int(gpu_config, section, "BlockSize", evg_gpu_local_mem_block_size);
	evg_gpu_local_mem_latency = config_read_int(gpu_config, section, "Latency", evg_gpu_local_mem_latency);
	evg_gpu_local_mem_num_ports = config_read_int(gpu_config, section, "Ports", evg_gpu_local_mem_num_ports);
	if ((evg_gpu_local_mem_size & (evg_gpu_local_mem_size - 1)) || evg_gpu_local_mem_size < 4)
		fatal("%s: %s->Size must be a power of two and at least 4.\n%s",
			evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_local_mem_alloc_size < 1)
		fatal("%s: invalid value for %s->Allocsize.\n%s", evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_local_mem_size % evg_gpu_local_mem_alloc_size)
		fatal("%s: %s->Size must be a multiple of %s->AllocSize.\n%s", evg_gpu_config_file_name,
			section, section, err_note);
	if ((evg_gpu_local_mem_block_size & (evg_gpu_local_mem_block_size - 1)) || evg_gpu_local_mem_block_size < 4)
		fatal("%s: %s->BlockSize must be a power of two and at least 4.\n%s",
			evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_local_mem_alloc_size % evg_gpu_local_mem_block_size)
		fatal("%s: %s->AllocSize must be a multiple of %s->BlockSize.\n%s", evg_gpu_config_file_name,
			section, section, err_note);
	if (evg_gpu_local_mem_latency < 1)
		fatal("%s: invalid value for %s->Latency.\n%s", evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_local_mem_size < evg_gpu_local_mem_block_size)
		fatal("%s: %s->Size cannot be smaller than %s->BlockSize * %s->Banks.\n%s", evg_gpu_config_file_name,
			section, section, section, err_note);
	
	/* CF Engine */
	section = "CFEngine";
	evg_gpu_cf_engine_inst_mem_latency = config_read_int(gpu_config, section, "InstructionMemoryLatency",
		evg_gpu_cf_engine_inst_mem_latency);
	if (evg_gpu_cf_engine_inst_mem_latency < 1)
		fatal("%s: invalid value for %s->InstructionMemoryLatency.\n%s", evg_gpu_config_file_name, section, err_note);
	
	/* ALU Engine */
	section = "ALUEngine";
	evg_gpu_alu_engine_inst_mem_latency = config_read_int(gpu_config, section, "InstructionMemoryLatency",
		evg_gpu_alu_engine_inst_mem_latency);
	evg_gpu_alu_engine_fetch_queue_size = config_read_int(gpu_config, section, "FetchQueueSize",
		evg_gpu_alu_engine_fetch_queue_size);
	evg_gpu_alu_engine_pe_latency = config_read_int(gpu_config, section, "ProcessingElementLatency",
		evg_gpu_alu_engine_pe_latency);
	if (evg_gpu_alu_engine_inst_mem_latency < 1)
		fatal("%s: invalid value for %s->InstructionMemoryLatency.\n%s", evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_alu_engine_fetch_queue_size < 56)
		fatal("%s: the minimum value for %s->FetchQueueSize is 56.\n"
			"This is the maximum size of one VLIW bundle, including 5 ALU instructions\n"
			"(2 words each), and 4 literal constants (1 word each).\n%s",
			evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_alu_engine_pe_latency < 1)
		fatal("%s: invalid value for %s->ProcessingElementLatency.\n%s", evg_gpu_config_file_name, section, err_note);

	/* TEX Engine */
	section = "TEXEngine";
	evg_gpu_tex_engine_inst_mem_latency = config_read_int(gpu_config, section, "InstructionMemoryLatency",
		evg_gpu_tex_engine_inst_mem_latency);
	evg_gpu_tex_engine_fetch_queue_size = config_read_int(gpu_config, section, "FetchQueueSize",
		evg_gpu_tex_engine_fetch_queue_size);
	evg_gpu_tex_engine_load_queue_size = config_read_int(gpu_config, section, "LoadQueueSize",
		evg_gpu_tex_engine_load_queue_size);
	if (evg_gpu_tex_engine_inst_mem_latency < 1)
		fatal("%s: invalid value for %s.InstructionMemoryLatency.\n%s", evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_tex_engine_fetch_queue_size < 16)
		fatal("%s: the minimum value for %s.FetchQueueSize is 16.\n"
			"This size corresponds to the 4 words comprising a TEX Evergreen instruction.\n%s",
			evg_gpu_config_file_name, section, err_note);
	if (evg_gpu_tex_engine_load_queue_size < 1)
		fatal("%s: the minimum value for %s.LoadQueueSize is 1.\n%s",
			evg_gpu_config_file_name, section, err_note);
	
	/* Periodic report */
	evg_periodic_report_config_read(gpu_config);
	evg_spatial_report_config_read(gpu_config);

	/* Close GPU configuration file */
	config_check(gpu_config);
	config_free(gpu_config);
}
Пример #24
0
/**
 * Parse command line options
 * @param argc Number of arguments
 * @param argv Argument values
 */
static void parse_options(int argc, char **argv)
{
    int ch;
    
    /* reset getopt */
    optind = 0;
    
    while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) {
        switch (ch) {
        case 'n': 
            save = FALSE;
            break;
        case 'r':
            reset = TRUE;
            break;
        case 'v':
        case 'm':
            /* Empty. See load_config() */
            break;
        case 'o':
            output_file = optarg;
            break;
        case 'V':
            malheur_version(stdout);
            exit(EXIT_SUCCESS);
            break;
        case 'h':
        case '?':
            print_usage();
            exit(EXIT_SUCCESS);
            break;

        /* long options */
        case 1001:
            config_set_string(&cfg, "input.format", optarg);    
            break;
        case 1002:
            config_set_int(&cfg, "input.mist_level", atoi(optarg));    
            break;
        case 1003:
            config_set_int(&cfg, "input.mist_rlen", atoi(optarg));    
            break;
        case 1004:
            config_set_int(&cfg, "input.mist_tlen", atoi(optarg));    
            break;
        case 1005:
            config_set_string(&cfg, "features.ngram_delim", optarg);    
            break;
        case 1006:
            config_set_int(&cfg, "features.ngram_len", atoi(optarg));    
            break;
        case 1007:
            config_set_string(&cfg, "features.vect_embed", optarg);    
            break;
        case 1008:
            config_set_int(&cfg, "features.lookup_table", atoi(optarg));    
            break;
        case 1009:
            config_set_float(&cfg, "prototypes.max_dist", atof(optarg));    
            break;
        case 1010:
            config_set_int(&cfg, "prototypes.max_num", atoi(optarg));    
            break;
        case 1011:
            config_set_float(&cfg, "classify.max_dist", atof(optarg));    
            break;
        case 1012:
            config_set_string(&cfg, "cluster.link_mode", optarg);    
            break;
        case 1013:
            config_set_float(&cfg, "cluster.min_dist", atof(optarg));    
            break;
        case 1014:
            config_set_int(&cfg, "cluster.reject_num", atoi(optarg));    
            break;
        case 1015:
            config_set_int(&cfg, "cluster.shared_ngrams", atoi(optarg));    
            break;
        }
    }

    /* Check configuration */
    config_check(&cfg);

    argc -= optind;
    argv += optind;

    if (argc < 1)
        fatal("the <action> argument is required");

    /* Argument: action */
    if (!strcasecmp(argv[0], "prototype")) {
        action = PROTOTYPE;
    } else if (!strcasecmp(argv[0], "distance")) {
        action = DISTANCE;
    } else if (!strcasecmp(argv[0], "cluster")) {
        action = CLUSTER;
    } else if (!strcasecmp(argv[0], "classify")) {
        action = CLASSIFY;
    } else if (!strcasecmp(argv[0], "increment")) {
        action = INCREMENT;
    } else if (!strcasecmp(argv[0], "protodist")) {
        action = PROTODIST;
    } else if (!strcasecmp(argv[0], "info")) {
        action = INFO;
    } else {
        fatal("Unknown analysis action '%s'", argv[0]);
    }
    
    if (argc < 2 && action != PROTODIST && action != INFO) 
        fatal("the <dataset> argument is required");

    /* Assign input files */
    input_files = argv + 1;
    input_len = argc - 1;
}
Пример #25
0
int main(int argc, char **argv) {
	int exit_code = EXIT_FAILURE;
	int i;
	bool help = false;
	bool version = false;
	bool check_config = false;
	bool daemon = false;
	bool debug = false;
	bool libusb_debug = false;
	int pid_fd = -1;
#ifdef BRICKD_WITH_LIBUDEV
	bool initialized_udev = false;
#endif

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = true;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = true;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = true;
		} else if (strcmp(argv[i], "--daemon") == 0) {
			daemon = true;
		} else if (strcmp(argv[i], "--debug") == 0) {
			debug = true;
		} else if (strcmp(argv[i], "--libusb-debug") == 0) {
			libusb_debug = true;
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		printf("%s\n", VERSION_STRING);

		return EXIT_SUCCESS;
	}

	if (prepare_paths() < 0) {
		return EXIT_FAILURE;
	}

	if (check_config) {
		return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	config_init(_config_filename);

	log_init();

	if (daemon) {
		pid_fd = daemon_start(_log_filename, _pid_filename, true);
	} else {
		pid_fd = pid_file_acquire(_pid_filename, getpid());

		if (pid_fd == PID_FILE_ALREADY_ACQUIRED) {
			fprintf(stderr, "Already running according to '%s'\n", _pid_filename);
		}
	}

	if (pid_fd < 0) {
		goto error_log;
	}

	log_set_debug_override(debug);

	log_set_level(LOG_CATEGORY_EVENT, config_get_option("log_level.event")->value.log_level);
	log_set_level(LOG_CATEGORY_USB, config_get_option("log_level.usb")->value.log_level);
	log_set_level(LOG_CATEGORY_NETWORK, config_get_option("log_level.network")->value.log_level);
	log_set_level(LOG_CATEGORY_HOTPLUG, config_get_option("log_level.hotplug")->value.log_level);
	log_set_level(LOG_CATEGORY_HARDWARE, config_get_option("log_level.hardware")->value.log_level);
	log_set_level(LOG_CATEGORY_WEBSOCKET, config_get_option("log_level.websocket")->value.log_level);
#ifdef BRICKD_WITH_RED_BRICK
	log_set_level(LOG_CATEGORY_RED_BRICK, config_get_option("log_level.red_brick")->value.log_level);
	log_set_level(LOG_CATEGORY_SPI, config_get_option("log_level.spi")->value.log_level);
	log_set_level(LOG_CATEGORY_RS485, config_get_option("log_level.rs485")->value.log_level);
#endif
	log_set_level(LOG_CATEGORY_OTHER, config_get_option("log_level.other")->value.log_level);

	if (config_has_error()) {
		log_error("Error(s) in config file '%s', run with --check-config option for details",
		          _config_filename);

		goto error_config;
	}

	if (daemon) {
		log_info("Brick Daemon %s started (daemonized)", VERSION_STRING);
	} else {
		log_info("Brick Daemon %s started", VERSION_STRING);
	}

	if (config_has_warning()) {
		log_error("Warning(s) in config file '%s', run with --check-config option for details",
		          _config_filename);
	}

	if (event_init() < 0) {
		goto error_event;
	}

	if (signal_init(handle_sigusr1) < 0) {
		goto error_signal;
	}

	if (hardware_init() < 0) {
		goto error_hardware;
	}

	if (usb_init(libusb_debug) < 0) {
		goto error_usb;
	}

#ifdef BRICKD_WITH_LIBUDEV
	if (!usb_has_hotplug()) {
		if (udev_init() < 0) {
			goto error_udev;
		}

		initialized_udev = true;
	}
#endif

	if (network_init() < 0) {
		goto error_network;
	}

#ifdef BRICKD_WITH_RED_BRICK
	if (gpio_init() < 0) {
		goto error_gpio;
	}

	if (red_usb_gadget_init() < 0) {
		goto error_red_usb_gadget;
	}

	if (redapid_init() < 0) {
		goto error_redapid;
	}

	if (red_stack_init() < 0) {
		goto error_red_stack;
	}

	if (rs485_extension_init() < 0) {
		goto error_rs485_extension;
	}
#endif

	if (event_run(network_cleanup_clients_and_zombies) < 0) {
		goto error_run;
	}

	exit_code = EXIT_SUCCESS;

error_run:
#ifdef BRICKD_WITH_RED_BRICK
	rs485_extension_exit();

error_rs485_extension:
	red_stack_exit();
    
error_red_stack:
	redapid_exit();

error_redapid:
	red_usb_gadget_exit();

error_red_usb_gadget:
	//gpio_exit();

error_gpio:
#endif
	network_exit();

error_network:
#ifdef BRICKD_WITH_LIBUDEV
	if (initialized_udev) {
		udev_exit();
	}

error_udev:
#endif
	usb_exit();

error_usb:
	hardware_exit();

error_hardware:
	signal_exit();

error_signal:
	event_exit();

error_event:
	log_info("Brick Daemon %s stopped", VERSION_STRING);

error_config:
error_log:
	log_exit();

	if (pid_fd >= 0) {
		pid_file_release(_pid_filename, pid_fd);
	}

	config_exit();

	return exit_code;
}
Пример #26
0
int main(int argc, char **argv) {
	int exit_code = EXIT_FAILURE;
	int i;
	bool help = false;
	bool version = false;
	bool check_config = false;
	bool daemon = false;
	const char *debug_filter = NULL;
	int pid_fd = -1;

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = true;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = true;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = true;
		} else if (strcmp(argv[i], "--daemon") == 0) {
			daemon = true;
		} else if (strcmp(argv[i], "--debug") == 0) {
			if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) {
				debug_filter = argv[++i];
			} else {
				debug_filter = "";
			}
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		printf("%s\n", VERSION_STRING);

		return EXIT_SUCCESS;
	}

	read_image_version();

	_x11_enabled = access("/etc/tf_x11_enabled", F_OK) == 0;

	if (prepare_paths() < 0) {
		return EXIT_FAILURE;
	}

	if (check_config) {
		return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	config_init(_config_filename);

	if (config_has_error()) {
		fprintf(stderr, "Error(s) occurred while reading config file '%s'",
		        _config_filename);

		goto error_config;
	}

	log_init();

	if (daemon) {
		pid_fd = daemon_start(_log_filename, _pid_filename, 1);
	} else {
		pid_fd = pid_file_acquire(_pid_filename, getpid());

		if (pid_fd == PID_FILE_ALREADY_ACQUIRED) {
			fprintf(stderr, "Already running according to '%s'\n", _pid_filename);
		}
	}

	if (pid_fd < 0) {
		goto error_pid_file;
	}

	if (daemon && _x11_enabled) {
		log_info("RED Brick API Daemon %s started (daemonized, X11 enabled) on %s image",
		         VERSION_STRING, _image_version);
	} else if (daemon) {
		log_info("RED Brick API Daemon %s started (daemonized) on %s image",
		         VERSION_STRING, _image_version);
	} else if (_x11_enabled) {
		log_info("RED Brick API Daemon %s started (X11 enabled) on %s image",
		         VERSION_STRING, _image_version);
	} else {
		log_info("RED Brick API Daemon %s started on %s image",
		         VERSION_STRING, _image_version);
	}

	if (debug_filter != NULL) {
		log_enable_debug_override(debug_filter);
	}

	if (config_has_warning()) {
		log_warn("Warning(s) in config file '%s', run with --check-config option for details",
		         _config_filename);
	}

	if (event_init() < 0) {
		goto error_event;
	}

	if (signal_init(handle_sighup, NULL) < 0) {
		goto error_signal;
	}

	if (process_monitor_init() < 0) {
		goto error_process_monitor;
	}

	if (cron_init() < 0) {
		goto error_cron;
	}

	if (inventory_init() < 0) {
		goto error_inventory;
	}

	if (api_init() < 0) {
		goto error_api;
	}

	if (network_init(_brickd_socket_filename, _cron_socket_filename) < 0) {
		goto error_network;
	}

	if (inventory_load_programs() < 0) {
		goto error_load_programs;
	}

	if (event_run(network_cleanup_brickd_and_socats) < 0) {
		goto error_run;
	}

	exit_code = EXIT_SUCCESS;

error_run:
	inventory_unload_programs();

error_load_programs:
	network_exit();

error_network:
	api_exit();

error_api:
	inventory_exit();

error_inventory:
	cron_exit();

error_cron:
	process_monitor_exit();

error_process_monitor:
	signal_exit();

error_signal:
	event_exit();

error_event:
	log_info("RED Brick API Daemon %s stopped", VERSION_STRING);

error_pid_file:
	if (pid_fd >= 0) {
		pid_file_release(_pid_filename, pid_fd);
	}

	log_exit();

error_config:
	config_exit();

	return exit_code;
}
Пример #27
0
int main(int argc, char **argv) {
	int i;
	int help = 0;
	int version = 0;
	int check_config = 0;
	int install = 0;
	int uninstall = 0;
	int console = 0;
	int log_to_file = 0;
	int debug = 0;
	int rc;

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = 1;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = 1;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = 1;
		} else if (strcmp(argv[i], "--install") == 0) {
			install = 1;
		} else if (strcmp(argv[i], "--uninstall") == 0) {
			uninstall = 1;
		} else if (strcmp(argv[i], "--console") == 0) {
			console = 1;
		} else if (strcmp(argv[i], "--log-to-file") == 0) {
			log_to_file = 1;
		} else if (strcmp(argv[i], "--debug") == 0) {
			debug = 1;
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		printf("%s\n", VERSION_STRING);

		return EXIT_SUCCESS;
	}

	if (GetModuleFileName(NULL, _config_filename, sizeof(_config_filename)) == 0) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		fprintf(stderr, "Could not get module file name: %s (%d)\n",
		        get_errno_name(rc), rc);

		return EXIT_FAILURE;
	}

	i = strlen(_config_filename);

	if (i < 4) {
		fprintf(stderr, "Module file name '%s' is too short", _config_filename);

		return EXIT_FAILURE;
	}

	strcpy(_config_filename + i - 3, "ini");

	if (check_config) {
		return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	if (install && uninstall) {
		fprintf(stderr, "Invalid option combination\n");
		print_usage();

		return EXIT_FAILURE;
	}

	if (install) {
		if (service_install(log_to_file, debug) < 0) {
			return EXIT_FAILURE;
		}
	} else if (uninstall) {
		if (service_uninstall() < 0) {
			return EXIT_FAILURE;
		}
	} else {
		printf("Starting...\n");

		config_init(_config_filename);

		log_init();

		if (console) {
			_run_as_service = 0;
			_pause_before_exit = started_by_explorer();

			return generic_main(log_to_file, debug);
		} else {
			return service_run(log_to_file, debug);
		}
	}

	return EXIT_SUCCESS;
}
Пример #28
0
struct dram_system_t *dram_system_config_with_file(struct config_t *config, char *system_name)
{
	int j;
	int controller_sections = 0;
	unsigned int highest_addr = 0;
	char *section;
	char section_str[MAX_STRING_SIZE];
	char *row_buffer_policy_map[] = {"OpenPage", "ClosePage", "hybird"};
	char *scheduling_policy_map[] = {"RankBank", "BankRank"};
	struct dram_system_t *system;

	/* Controller parameters
	 * FIXME: we should create a default variation for times this values
	 * are not assigned. For now we set it as DRAM DDR3 Micron
	 * */
	unsigned int num_physical_channels = 1;
	unsigned int request_queue_depth = 32;
	enum dram_controller_row_buffer_policy_t rb_policy = open_page_row_buffer_policy;
	enum dram_controller_scheduling_policy_t scheduling_policy = rank_bank_round_robin;

	unsigned int dram_num_ranks = 8;
	unsigned int dram_num_devices_per_rank = 1;
	unsigned int dram_num_banks_per_device = 1;
	unsigned int dram_num_rows_per_bank = 8192;
	unsigned int dram_num_columns_per_row = 1024;
	unsigned int dram_num_bits_per_column = 16;

	unsigned int dram_timing_tCAS = 24;
	unsigned int dram_timing_tRCD = 10;
	unsigned int dram_timing_tRP = 10;
	unsigned int dram_timing_tRAS = 24;
	unsigned int dram_timing_tCWL = 9;
	unsigned int dram_timing_tCCD = 4;

	system = dram_system_create(system_name);
	/* DRAM system configuration */
	snprintf(section_str, sizeof section_str, "DRAMsystem.%s", system_name);
	for (section = config_section_first(config); section;
			section = config_section_next(config))
	{
		if (strcasecmp(section, section_str))
			continue;
		system->num_logical_channels = config_read_int(config, section,
				"NumLogicalChannels", system->num_logical_channels);
	}



	/* Create controllers */

	for (section = config_section_first(config); section;
			section = config_section_next(config))
	{
		char *delim = ".";
		char *token;
		char *controller_name;

		/* First token must be 'Network' */
		snprintf(section_str, sizeof section_str, "%s", section);
		token = strtok(section_str, delim);
		if (!token || strcasecmp(token, "DRAMsystem"))
			continue;

		/* Second token must be the name of the network */
		token = strtok(NULL, delim);
		if (!token || strcasecmp(token, system_name))
			continue;

		/* Third token must be 'Node' */
		token = strtok(NULL, delim);
		if (!token || strcasecmp(token, "Controller"))
			continue;

		/* Get name */
		controller_name = strtok(NULL, delim);
		token = strtok(NULL, delim);
		if (!controller_name || token)
			fatal("%s:%s: wrong format for controller name .\n%s",
					system->name, section, dram_err_config);

		/* Read Properties */

		num_physical_channels = config_read_int(config, section, "NumPhysicalChannels", num_physical_channels);
		dram_num_ranks = config_read_int(config, section, "NumRanks", dram_num_ranks);
		dram_num_devices_per_rank = config_read_int(config, section, "NumDevicesPerRank", dram_num_devices_per_rank);
		dram_num_banks_per_device = config_read_int(config, section, "NumBanksPerDevice", dram_num_banks_per_device);
		dram_num_rows_per_bank = config_read_int(config, section, "NumRowsPerBank", dram_num_rows_per_bank);
		dram_num_columns_per_row = config_read_int(config, section, "NumColumnPerRow", dram_num_columns_per_row);
		dram_num_bits_per_column = config_read_int(config, section, "NumBitsPerColumn", dram_num_bits_per_column);
		request_queue_depth = config_read_int(config, section, "RequestQueueDepth", request_queue_depth);
		rb_policy = config_read_enum(config, section, "RowBufferPolicy", rb_policy, row_buffer_policy_map, 3);
		scheduling_policy = config_read_enum(config, section, "SchedulingPolicy", scheduling_policy, scheduling_policy_map, 2);
		dram_timing_tCAS = config_read_int(config, section, "tCAS", dram_timing_tCAS);
		dram_timing_tRCD = config_read_int(config, section, "tRCD", dram_timing_tRCD);
		dram_timing_tRP = config_read_int(config, section, "tRP", dram_timing_tRP);
		dram_timing_tRAS = config_read_int(config, section, "tRAS", dram_timing_tRAS);
		dram_timing_tCWL = config_read_int(config, section, "tCWL", dram_timing_tCWL);
		dram_timing_tCCD = config_read_int(config, section, "tCCD", dram_timing_tCCD);

		/* Create controller */
		struct dram_controller_t *controller;
		controller = dram_controller_create(request_queue_depth, rb_policy, scheduling_policy);

		/* Assign controller parameters */
		controller->id = controller_sections;
		if (!controller_sections)
			controller->lowest_addr = 0;
		else
			controller->lowest_addr = highest_addr + 1;

		controller->highest_addr = controller->lowest_addr + ((dram_num_bits_per_column * dram_num_devices_per_rank) / 8 * dram_num_columns_per_row * dram_num_rows_per_bank * dram_num_banks_per_device * dram_num_ranks * num_physical_channels) - 1;

		controller->dram_addr_bits_rank = log_base2(dram_num_ranks);
		controller->dram_addr_bits_row = log_base2(dram_num_rows_per_bank);
		controller->dram_addr_bits_bank = log_base2(dram_num_banks_per_device);
		controller->dram_addr_bits_column = log_base2(dram_num_columns_per_row);
		controller->dram_addr_bits_physical_channel = log_base2(num_physical_channels);
		controller->dram_addr_bits_byte = log_base2(dram_num_bits_per_column * dram_num_devices_per_rank / 8);
		controller->dram_timing_tCAS = dram_timing_tCAS;
		controller->dram_timing_tRCD = dram_timing_tRCD;
		controller->dram_timing_tRP = dram_timing_tRP;
		controller->dram_timing_tRAS = dram_timing_tRAS;
		controller->dram_timing_tCWL = dram_timing_tCWL;
		controller->dram_timing_tCCD = dram_timing_tCCD;

		/* Update the highest address in memory system */
		highest_addr = controller->highest_addr;

		/* Add controller to system */
		list_add(system->dram_controller_list, controller);

		/* Create and add DRAM*/
		for (j = 0; j < num_physical_channels; j++)
		{
			struct dram_t *dram;
			dram = dram_create(dram_num_ranks,
					dram_num_devices_per_rank,
					dram_num_banks_per_device,
					dram_num_rows_per_bank,
					dram_num_columns_per_row,
					dram_num_bits_per_column);

			dram->timing_tCAS = dram_timing_tCAS;
			dram->timing_tRCD = dram_timing_tRCD;
			dram->timing_tRP = dram_timing_tRP;
			dram->timing_tRAS = dram_timing_tRAS;
			dram->timing_tCWL = dram_timing_tCWL;

			dram_controller_add_dram(list_get(system->dram_controller_list, controller_sections), dram);
		}
		controller_sections++;
	}

	if (controller_sections != system->num_logical_channels)
		fatal("%s: number of controllers should match the number of logical"
				"channels \n%s", system->name, dram_err_config);

	/* Request Section */
	for (section = config_section_first(config); section;
			section = config_section_next(config))
	{
		char *delim = ".";

		char *token;
		char *token_endl;

		/* First token must be 'Network' */
		snprintf(section_str, sizeof section_str, "%s", section);
		token = strtok(section_str, delim);
		if (!token || strcasecmp(token, "DRAMsystem"))
			continue;

		/* Second token must be the name of the network */
		token = strtok(NULL, delim);
		if (!token || strcasecmp(token, system_name))
			continue;

		/* Third token must be 'Commands' */
		token = strtok(NULL, delim);
		if (!token || strcasecmp(token, "Requests"))
			continue;

		token_endl = strtok(NULL, delim);
		if (token_endl)
			fatal("%s: %s: bad format for Commands section.\n%s",
					system_name, section, dram_err_config);

		/* Requests */
		dram_config_request_create(system, config, section);
		config_check(config);
	}

	/* Return dram_system on success */
	return system;
}
Пример #29
0
void X86CpuReadConfig(void) {
  struct config_t *config;
  char *section;

  /* Open file */
  config = config_create(x86_config_file_name);
  if (*x86_config_file_name) config_load(config);

  /* General configuration */

  section = "General";

  x86_cpu_frequency =
      config_read_int(config, section, "Frequency", x86_cpu_frequency);
  if (!IN_RANGE(x86_cpu_frequency, 1, ESIM_MAX_FREQUENCY))
    fatal("%s: invalid value for 'Frequency'.", x86_config_file_name);

  x86_cpu_num_cores =
      config_read_int(config, section, "Cores", x86_cpu_num_cores);
  x86_cpu_num_threads =
      config_read_int(config, section, "Threads", x86_cpu_num_threads);

  x86_cpu_fast_forward_count =
      config_read_llint(config, section, "FastForward", 0);

  x86_cpu_context_quantum =
      config_read_int(config, section, "ContextQuantum", 100000);
  x86_cpu_thread_quantum =
      config_read_int(config, section, "ThreadQuantum", 1000);
  x86_cpu_thread_switch_penalty =
      config_read_int(config, section, "ThreadSwitchPenalty", 0);

  x86_cpu_recover_kind = config_read_enum(config, section, "RecoverKind",
                                          x86_cpu_recover_kind_writeback,
                                          x86_cpu_recover_kind_map, 2);
  x86_cpu_recover_penalty =
      config_read_int(config, section, "RecoverPenalty", 0);

  x86_emu_process_prefetch_hints =
      config_read_bool(config, section, "ProcessPrefetchHints", 1);
  prefetch_history_size =
      config_read_int(config, section, "PrefetchHistorySize", 10);

  /* Section '[ Pipeline ]' */

  section = "Pipeline";

  x86_cpu_fetch_kind =
      config_read_enum(config, section, "FetchKind",
                       x86_cpu_fetch_kind_timeslice, x86_cpu_fetch_kind_map, 3);

  x86_cpu_decode_width = config_read_int(config, section, "DecodeWidth", 4);

  x86_cpu_dispatch_kind = config_read_enum(config, section, "DispatchKind",
                                           x86_cpu_dispatch_kind_timeslice,
                                           x86_cpu_dispatch_kind_map, 2);
  x86_cpu_dispatch_width = config_read_int(config, section, "DispatchWidth", 4);

  x86_cpu_issue_kind =
      config_read_enum(config, section, "IssueKind",
                       x86_cpu_issue_kind_timeslice, x86_cpu_issue_kind_map, 2);
  x86_cpu_issue_width = config_read_int(config, section, "IssueWidth", 4);

  x86_cpu_commit_kind =
      config_read_enum(config, section, "CommitKind",
                       x86_cpu_commit_kind_shared, x86_cpu_commit_kind_map, 2);
  x86_cpu_commit_width = config_read_int(config, section, "CommitWidth", 4);

  x86_cpu_occupancy_stats =
      config_read_bool(config, section, "OccupancyStats", 0);

  /* Section '[ Queues ]' */

  section = "Queues";

  x86_fetch_queue_size = config_read_int(config, section, "FetchQueueSize", 64);

  x86_uop_queue_size = config_read_int(config, section, "UopQueueSize", 32);

  x86_rob_kind = config_read_enum(config, section, "RobKind",
                                  x86_rob_kind_private, x86_rob_kind_map, 2);
  x86_rob_size = config_read_int(config, section, "RobSize", 64);

  x86_iq_kind = config_read_enum(config, section, "IqKind", x86_iq_kind_private,
                                 x86_iq_kind_map, 2);
  x86_iq_size = config_read_int(config, section, "IqSize", 40);

  x86_lsq_kind = config_read_enum(config, section, "LsqKind",
                                  x86_lsq_kind_private, x86_lsq_kind_map, 2);
  x86_lsq_size = config_read_int(config, section, "LsqSize", 20);

  /* Register file */
  X86ReadRegFileConfig(config);

  /* Functional Units */
  X86ReadFunctionalUnitsConfig(config);

  /* Branch predictor */
  X86ReadBranchPredConfig(config);

  /* Trace Cache */
  X86ReadTraceCacheConfig(config);

  /* Close file */
  config_check(config);
  config_free(config);
}
Пример #30
0
int main(int argc, char **argv) {
	int i;
	bool help = false;
	bool version = false;
	bool check_config = false;
	bool install = false;
	bool uninstall = false;
	bool console = false;
	bool log_to_file = false;
	bool debug = false;
	bool libusb_debug = false;
	int rc;

	fixes_init();

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "--help") == 0) {
			help = true;
		} else if (strcmp(argv[i], "--version") == 0) {
			version = true;
		} else if (strcmp(argv[i], "--check-config") == 0) {
			check_config = true;
		} else if (strcmp(argv[i], "--install") == 0) {
			install = true;
		} else if (strcmp(argv[i], "--uninstall") == 0) {
			uninstall = true;
		} else if (strcmp(argv[i], "--console") == 0) {
			console = true;
		} else if (strcmp(argv[i], "--log-to-file") == 0) {
			log_to_file = true;
		} else if (strcmp(argv[i], "--debug") == 0) {
			debug = true;
		} else if (strcmp(argv[i], "--libusb-debug") == 0) {
			libusb_debug = true;
		} else {
			fprintf(stderr, "Unknown option '%s'\n\n", argv[i]);
			print_usage();

			return EXIT_FAILURE;
		}
	}

	if (help) {
		print_usage();

		return EXIT_SUCCESS;
	}

	if (version) {
		print_version();

		return EXIT_SUCCESS;
	}

	if (GetModuleFileName(NULL, _config_filename, sizeof(_config_filename)) == 0) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		fprintf(stderr, "Could not get module file name: %s (%d)\n",
		        get_errno_name(rc), rc);

		return EXIT_FAILURE;
	}

	i = strlen(_config_filename);

	if (i < 4) {
		fprintf(stderr, "Module file name '%s' is too short", _config_filename);

		return EXIT_FAILURE;
	}

	_config_filename[i - 3] = '\0';
	string_append(_config_filename, "ini", sizeof(_config_filename));

	if (check_config) {
		rc = config_check(_config_filename);

		if (started_by_explorer(false)) {
			printf("\nPress any key to exit...\n");
			getch();
		}

		return rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
	}

	if (install && uninstall) {
		fprintf(stderr, "Invalid option combination\n");
		print_usage();

		return EXIT_FAILURE;
	}

	if (install) {
		if (service_install(log_to_file, debug) < 0) {
			return EXIT_FAILURE;
		}
	} else if (uninstall) {
		if (service_uninstall() < 0) {
			return EXIT_FAILURE;
		}
	} else {
		printf("Starting...\n");

		config_init(_config_filename);

		log_init();

		if (console) {
			_run_as_service = false;
			_pause_before_exit = started_by_explorer(true);

			return generic_main(log_to_file, debug, libusb_debug);
		} else {
			return service_run(log_to_file, debug, libusb_debug);
		}
	}

	return EXIT_SUCCESS;
}