Exemple #1
0
struct config_server_t *
config_parse_server(FILE *in)
{
	char *tmp;
	struct config_server_t *s;
	s = (struct config_server_t *)malloc(sizeof(*s));

	config_read_key(in);
	while(strlen(key)!=0 && !feof(in)) {
		if(!strcmp(key,"server_port"))
			s->port = config_read_value(in);
		else if(!strcmp(key,"server_ipv6"))
			s->ipv6 = config_read_string(in);
		else if(!strcmp(key,"server_tls"))
			s->tls = config_read_string(in);
		else if(!strcmp(key,"server_deamon")) {
			tmp = config_read_value(in);
			s->deamon = atoi(tmp);
			free(tmp);
		}
		config_read_key(in);
	}

	return s;
}
Exemple #2
0
bool agent_load_key(unsigned char key[KDF_HASH_LEN])
{
	_cleanup_free_ char *iterationbuf = NULL;
	_cleanup_free_ char *verify = NULL;
	_cleanup_free_ char *username = NULL;
	_cleanup_free_ char *password = NULL;
	int iterations;

	iterationbuf = config_read_string("iterations");
	username = config_read_string("username");
	if (!iterationbuf || !username || !config_exists("verify"))
		return false;
	iterations = strtoul(iterationbuf, NULL, 10);
	if (iterations <= 0)
		return false;

	for (;;) {
		free(password);
		password = password_prompt("Master Password", password ? "Incorrect master password; please try again." : NULL, "Please enter the LastPass master password for <%s>.", username);
		if (!password)
			return false;
		kdf_decryption_key(username, password, iterations, key);

		/* no longer need password contents, zero it */
		secure_clear_str(password);

		verify = config_read_encrypted_string("verify", key);
		if (verify && !strcmp(verify, AGENT_VERIFICATION_STRING))
			break;
	}

	return true;
}
void frm_spatial_report_config_read(struct config_t *config)
{
	char *section;
	char *file_name;

	/*Nothing if section or config is not present */
	section = frm_spatial_report_section_name;
	if (!config_section_exists(config, section))
	{
		/*no spatial profiling */
		return;
	}

	/* Spatial reports are active */
	frm_spatial_report_active = 1;

	/* Interval */
	config_var_enforce(config, section, "Interval");
	spatial_profiling_interval = config_read_int(config, section,
		"Interval", spatial_profiling_interval);

	/* File name */
	config_var_enforce(config, section, "File");
	file_name = config_read_string(config, section, "File", NULL);
	if (!file_name || !*file_name)
		fatal("%s: %s: invalid or missing value for 'File'",
			frm_spatial_report_section_name, section);
	spatial_report_filename = str_set(NULL, file_name);

	spatial_report_file = file_open_for_write(spatial_report_filename);
	if (!spatial_report_file)
		fatal("%s: could not open spatial report file",
				spatial_report_filename);

}
Exemple #4
0
bool upload_queue_is_running(void)
{
	_cleanup_free_ char *pidstr = NULL;
	pid_t pid;

	pidstr = config_read_string("uploader.pid");
	if (!pidstr)
		return false;
	pid = strtoul(pidstr, NULL, 10);
	if (!pid)
		return false;
	return process_is_same_executable(pid);
}
Exemple #5
0
void upload_queue_kill(void)
{
	_cleanup_free_ char *pidstr = NULL;
	pid_t pid;

	pidstr = config_read_string("uploader.pid");
	if (!pidstr)
		return;
	pid = strtoul(pidstr, NULL, 10);
	if (!pid)
		return;
	kill(pid, SIGTERM);
}
Exemple #6
0
static void net_config_command_create(struct net_t *net, struct config_t *config, char *section)
{
	char *command_line;
	char command_var[MAX_STRING_SIZE];

	int command_var_id;

	/* Checks */
	if (net_injection_rate > 0.001)
		fatal("Network %s:%s: Using Command section; \n"
				"\t option --net-injection-rate should not be used \n",
				net->name,section);
	/* Read commands */
	net_injection_rate = 0;
	if (strcmp(net_traffic_pattern, "") &&
			(strcmp(net_traffic_pattern, "command")))
		fatal("Network %s: Command option doesn't comply with other "
				"traffic pattern\n (%s)", net->name,
				net_traffic_pattern);
	net_traffic_pattern = "command";
	command_var_id = 0;

	/* Register events for command handler*/
	EV_NET_COMMAND = esim_register_event_with_name(net_command_handler,
			net_domain_index, "net_command");
	EV_NET_COMMAND_RCV = esim_register_event_with_name(net_command_handler,
			net_domain_index, "net_command_receive");


	while (1)
	{
		/* Get command */
		snprintf(command_var, sizeof command_var, "Command[%d]", command_var_id);
		command_line = config_read_string(config, section, command_var, NULL);
		if (!command_line)
			break;

		/* Schedule event to process command */
		struct net_stack_t *stack;
		stack = net_stack_create(net,ESIM_EV_NONE, NULL);
		stack->net = net;
		stack->command = xstrdup(command_line);
		esim_schedule_event(EV_NET_COMMAND, stack, 0);

		/* Next command */
		command_var_id++;
	}
}
Exemple #7
0
static void load_config(void)
{
	char config_key[6];
	int i;
	const char *val;

	strcpy(config_key, "ir_");
	for(i=0;i<64;i++) {
		sprintf(&config_key[3], "%02x", i);
		val = config_read_string(config_key);
		if(val != NULL)
			strcpy(key_bindings[i], val);
		else
			key_bindings[i][0] = 0;
	}
}
struct session *sesssion_load(unsigned const char key[KDF_HASH_LEN])
{
	struct session *session = session_new();
	session->uid = config_read_encrypted_string("session_uid", key);
	session->sessionid = config_read_encrypted_string("session_sessionid", key);
	session->token = config_read_encrypted_string("session_token", key);
	session->server = config_read_string("session_server");
	session->private_key.len = config_read_encrypted_buffer("session_privatekey", &session->private_key.key, key);
	mlock(session->private_key.key, session->private_key.len);

	if (session_is_valid(session))
		return session;
	else {
		session_free(session);
		return NULL;
	}
}
Exemple #9
0
static void load_saved_environment(void)
{
	_cleanup_free_ char *env = NULL;

	env = config_read_string("env");
	if (!env)
		return;

	for (char *tok = strtok(env, "\n"); tok; tok = strtok(NULL, "\n")) {
		char *equals = strchr(tok, '=');
		if (!equals || !*equals) {
			warn("The environment line '%s' is invalid.", tok);
			continue;
		}
		*equals = '\0';
		if (setenv(tok, equals + 1, true))
			warn_errno("The environment line '%s' is invalid.", tok);
	}
}
int cmd_status(int argc, char **argv)
{
	unsigned char key[KDF_HASH_LEN];
	static struct option long_options[] = {
		{"quiet", no_argument, NULL, 'q'},
		{"color", required_argument, NULL, 'C'},
		{0, 0, 0, 0}
	};
	int option;
	int option_index;
	bool quiet = false;
	_cleanup_free_ char *username = NULL;

	while ((option = getopt_long(argc, argv, "q", long_options, &option_index)) != -1) {
		switch (option) {
			case 'q':
				quiet = true;
				break;
			case 'C':
				terminal_set_color_mode(
					parse_color_mode_string(optarg));
				break;
			case '?':
			default:
				die_usage(cmd_status_usage);
		}
	}

	if (!agent_ask(key)) {
		if(!quiet) {
			terminal_printf(TERMINAL_FG_RED TERMINAL_BOLD "Not logged in" TERMINAL_RESET ".\n");
		}
		return 1;
	} else {
		if(!quiet) {
			username = config_read_string("username");
			terminal_printf(TERMINAL_FG_GREEN TERMINAL_BOLD "Logged in" TERMINAL_RESET " as " TERMINAL_UNDERLINE "%s" TERMINAL_RESET ".\n", username);
		}
		return 0;
	}
}
Exemple #11
0
struct config_group_t *
config_parse_group(FILE *in)
{
	struct config_group_t *p;
	p = (struct config_group_t *)malloc(sizeof(*p));

	config_read_key(in);
	while(strlen(key) && !feof(in)) {
		if(!strcmp(key,"group_name")) {
			p->name = config_read_string(in);
		}
		else if(!strcmp(key,"group_servers")) {
			p->servers = config_read_list(in);
		}
		else if(!strcmp(key,"group_users")) {
			p->users = config_read_list(in);
		}
		config_read_key(in);
	}

	return p;
}
static void dram_config_request_create(struct dram_system_t *system, struct config_t *config,
		char *section)
{
	char *request_line;
	char request_var[MAX_STRING_SIZE];

	int request_var_id;

	/* Read Requests */
	request_var_id = 0;

	/* Register events for request handler*/
	EV_DRAM_REQUEST = esim_register_event_with_name(dram_request_handler,
			dram_domain_index, "dram_request");

	while (1)
	{
		/* Get request */
		snprintf(request_var, sizeof request_var, "Request[%d]", request_var_id);
		request_line = config_read_string(config, section, request_var, NULL);
		if (!request_line)
			break;

		/* Schedule event to process request */
		struct request_stack_t *stack;
		stack = dram_request_stack_create();

		request_line = xstrdup(request_line);
		stack->request_line = request_line;
		stack->system = system;

		esim_schedule_event(EV_DRAM_REQUEST, stack, 0);

		/* Next command */
		request_var_id++;
	}
}
Exemple #13
0
void FrmGpuMemConfigParseEntry(Timing *self, struct config_t *config, char *section)
{
	char *file_name;
	char *module_name;

	int sm_id;

	FrmSM *sm;

	/* Get configuration file name */
	file_name = config_get_file_name(config);

	/* Allow these sections in case we quit before reading them. */
	config_var_allow(config, section, "Module");

	/* Read SM */
	sm_id = config_read_int(config, section, "SM", -1);
	if (sm_id < 0)
		fatal("%s: section [%s]: invalid or missing value for 'SM'",
				file_name, section);

	/* Check SM boundaries */
	if (sm_id >= frm_gpu_num_sms)
	{
		warning("%s: section [%s] ignored, referring to Fermi SM[%d].\n"
				"\tThis section refers to a SM that does not currently exist.\n"
				"\tPlease review your Fermi configuration file if this is not the\n"
				"\tdesired behavior.\n",
				file_name, section, sm_id);
		return;
	}

	/* Check that entry has not been assigned before */
	sm = frm_gpu->sms[sm_id];
	if (sm->global_memory)
		fatal("%s: section [%s]: entry from SM[%d] already assigned.\n"
				"\tA different [Entry <name>] section in the memory configuration file has already\n"
				"\tassigned an entry for this particular SM. Please review your\n"
				"\tconfiguration file to avoid duplicates.\n",
				file_name, section, sm_id);

	/* Read module */
	module_name = config_read_string(config, section, "Module", NULL);
	if (!module_name)
		fatal("%s: section [%s]: variable 'Module' missing.\n"
				"\tPlease run use '--mem-help' for more information on the\n"
				"\tconfiguration file format, or consult the Multi2Sim Guide.\n",
				file_name, section);

	/* Assign module */
	sm->global_memory = mem_system_get_mod(module_name);
	if (!sm->global_memory)
		fatal("%s: section [%s]: '%s' is not a valid module name.\n"
				"\tThe given module name must match a module declared in a section\n"
				"\t[Module <name>] in the memory configuration file.\n",
				file_name, section, module_name);

	/* Add modules to list of memory entries */
	linked_list_add(arch_fermi->mem_entry_mod_list,
			sm->global_memory);

	/* Debug */
	mem_debug("\tFermi SM[%d]\n", sm_id);
	mem_debug("\t\tEntry -> %s\n", sm->global_memory->name);
	mem_debug("\n");
}
Exemple #14
0
struct net_t *net_create_from_config(struct config_t *config, char *name)
{
	int routing_type = 0;
	struct net_t *net;
	char *section;
	char section_str[MAX_STRING_SIZE];
	int def_input_buffer_size;
	int def_output_buffer_size;
	int def_bandwidth;

	/* Create network */
	net = net_create(name);

	/* Main section */
	snprintf(section_str, sizeof section_str, "Network.%s", name);
	for (section = config_section_first(config); section;
			section = config_section_next(config))
	{
		if (strcasecmp(section, section_str))
			continue;

		net->def_input_buffer_size = config_read_int(config, section,
				"DefaultInputBufferSize", 0);
		net->def_output_buffer_size = config_read_int(config, section,
				"DefaultOutputBufferSize", 0);
		def_bandwidth = config_read_int(config, section, 
				"DefaultBandwidth", 0);
		if (!net->def_input_buffer_size)
			fatal("%s:%s: DefaultInputBufferSize: invalid/missing value.\n%s",
					net->name, section, net_err_config);
		if (!net->def_output_buffer_size)
			fatal("%s:%s: DefaultOutputBufferSize: invalid/missing value.\n%s",
					net->name, section, net_err_config);
		if (!def_bandwidth)
			fatal("%s:%s: DefaultBandwidth: invalid/missing value.\n%s",
					net->name, section, net_err_config);
		def_output_buffer_size = net->def_output_buffer_size;
		def_input_buffer_size = net->def_input_buffer_size;
	}

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

		char *token;
		char *node_name;
		char *node_type;

		int input_buffer_size;
		int output_buffer_size;
		int bandwidth;
		int lanes;	/* BUS lanes */

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

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

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

		/* Get name */
		node_name = strtok(NULL, delim);
		token = strtok(NULL, delim);
		if (!node_name || token)
			fatal("%s:%s: wrong format for node.\n%s",
					net->name, section, net_err_config);

		/* Get properties */
		node_type = config_read_string(config, section, "Type", "");
		input_buffer_size = config_read_int(config, section,
				"InputBufferSize", def_input_buffer_size);
		output_buffer_size = config_read_int(config, section,
				"OutputBufferSize", def_output_buffer_size);
		bandwidth = config_read_int(config, section,
				"BandWidth", def_bandwidth);
		lanes = config_read_int(config, section, "Lanes", 1);

		/* Create node */
		if (!strcasecmp(node_type, "EndNode"))
			net_add_end_node(net, input_buffer_size,
					output_buffer_size, node_name, NULL);
		else if (!strcasecmp(node_type, "Switch"))
			net_add_switch(net, input_buffer_size,
					output_buffer_size, bandwidth, node_name);
		else if (!strcasecmp(node_type, "Bus"))
		{
			/* Right now we ignore the size of buffers. But we
			 * can set it as the value for bus ports, making the
			 * connecting switches asymmetric. */
			if (input_buffer_size != def_input_buffer_size ||
					output_buffer_size != def_output_buffer_size)
				fatal("%s:%s: BUS does not contain input/output buffers. "
						"Size values will be ignored \n",
						net->name, section);

			/* If the number of lanes is smaller than 1 produce
			 * an error */
			if (lanes < 1)
				fatal("%s:%s: BUS cannot have less than 1 number of lanes \n%s",
						net->name, section, net_err_config);
			net_add_bus(net, bandwidth, node_name, lanes);
		}
		else
			fatal("%s:%s: Type: invalid/missing value.\n%s",
					net->name, section, net_err_config);
	}



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

		char *token;
		char *link_name;
		char *link_type;
		char *src_node_name;
		char *dst_node_name;

		int bandwidth;
		int v_channel_count;
		int src_buffer_size;
		int dst_buffer_size;

		struct net_node_t *src_node;
		struct net_node_t *dst_node;

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

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

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

		/* Fourth token must name of the link */
		link_name = strtok(NULL, delim);
		token = strtok(NULL, delim);
		if (!link_name || token)
			fatal("%s: %s: bad format for link.\n%s",
					name, section, net_err_config);

		/* Fields */
		link_type = config_read_string(config, section, "Type",
				"Unidirectional");
		bandwidth = config_read_int(config, section, "Bandwidth",
				def_bandwidth);
		src_node_name = config_read_string(config, section, "Source", "");
		dst_node_name = config_read_string(config, section, "Dest", "");
		v_channel_count = config_read_int(config, section, "VC", 1);
		src_buffer_size = config_read_int(config, section,
				"SourceBufferSize", 0);
		dst_buffer_size = config_read_int(config, section,
				"DestBufferSize", 0);

		/* Nodes */
		src_node = net_get_node_by_name(net, src_node_name);
		dst_node = net_get_node_by_name(net, dst_node_name);

		if (!src_node)
			fatal("%s: %s: %s: source node does not exist.\n%s",
					name, section, src_node_name, net_err_config);
		if (!dst_node)
			fatal("%s: %s: %s: destination node does not exist.\n%s",
					name, section, dst_node_name, net_err_config);


		/* If it is a link connection */
		if (src_node->kind != net_node_bus
				&& dst_node->kind != net_node_bus)
		{
			int link_src_bsize;
			int link_dst_bsize;

			if (v_channel_count >= 1)
			{

				if (!strcasecmp(link_type, "Unidirectional"))
				{
					link_src_bsize = (src_buffer_size)? src_buffer_size :
							src_node->output_buffer_size;
					link_dst_bsize = (dst_buffer_size) ?dst_buffer_size :
							dst_node->input_buffer_size;

					net_add_link(net, src_node, dst_node,
							bandwidth, link_src_bsize,
							link_dst_bsize,
							v_channel_count);
				}
				else if (!strcasecmp(link_type,
						"Bidirectional"))
				{
					net_add_bidirectional_link(net,
							src_node, dst_node, bandwidth,
							src_buffer_size,
							dst_buffer_size,
							v_channel_count);
				}
			}
			else
				fatal("%s: %s: Unacceptable number of virtual channels \n %s", 
						name, section, net_err_config);
		}
		/* If is is a Bus Connection */
		else
		{

			if (v_channel_count > 1)
				fatal("%s: %s: BUS can not have virtual channels. \n %s",
						name, section, net_err_config);

			if (!strcasecmp(link_type, "Unidirectional"))
			{
				if ((src_node->kind == net_node_bus &&
						src_buffer_size) ||
						(dst_node->kind == net_node_bus &&
								dst_buffer_size))
				{
					fatal ("%s: %s: Source/Destination BUS cannot have buffer. \n %s "
							,name, section, net_err_config);
				}

				net_add_bus_port(net, src_node, dst_node,
						src_buffer_size, dst_buffer_size);
			}
			else if (!strcasecmp(link_type, "Bidirectional"))
			{
				net_add_bidirectional_bus_port(net, src_node,
						dst_node, src_buffer_size,
						dst_buffer_size);
			}

		}
	}

	/* initializing the routing table */
	net_routing_table_initiate(net->routing_table);

	/* Routes */
	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, "Network"))
			continue;

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

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

		token_endl = strtok(NULL, delim);
		if (token_endl)
			fatal("%s: %s: bad format for route.\n%s",
					name, section, net_err_config);

		/* Routes */
		routing_type = 1;
		net_config_route_create(net, config, section);
		config_check(config);
	}
	/* Commands */
	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, "Network"))
			continue;

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

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

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

		/* Commands */
		net_config_command_create(net, config, section);
		config_check(config);
	}
	/* If there is no route section, Floyd-Warshall calculates the
	 * shortest path for all the nodes in the network */
	if (routing_type == 0)
		net_routing_table_floyd_warshall(net->routing_table);

	/* Return */
	return net;
}
Exemple #15
0
void evg_mem_config_parse_entry(struct config_t *config, char *section)
{
	char *file_name;
	char *module_name;

	int compute_unit_id;

	struct evg_compute_unit_t *compute_unit;

	/* Get configuration file name */
	file_name = config_get_file_name(config);

	/* Allow these sections in case we quit before reading them. */
	config_var_allow(config, section, "Module");

	/* Read compute unit */
	compute_unit_id = config_read_int(config, section, "ComputeUnit", -1);
	if (compute_unit_id < 0)
		fatal("%s: section [%s]: invalid or missing value for 'ComputeUnit'",
			file_name, section);

	/* Check compute unit boundaries */
	if (compute_unit_id >= evg_gpu_num_compute_units)
	{
		warning("%s: section [%s] ignored, referring to Evergreen compute unit %d.\n"
			"\tThis section refers to a compute unit that does not currently exist.\n"
			"\tPlease review your Evergreen configuration file if this is not the\n"
			"\tdesired behavior.\n",
			file_name, section, compute_unit_id);
		return;
	}

	/* Check that entry has not been assigned before */
	compute_unit = evg_gpu->compute_units[compute_unit_id];
	if (compute_unit->global_memory)
		fatal("%s: section [%s]: entry from compute unit %d already assigned.\n"
			"\tA different [Entry <name>] section in the memory configuration file has already\n"
			"\tassigned an entry for this particular compute unit. Please review your\n"
			"\tconfiguration file to avoid duplicates.\n",
			file_name, section, compute_unit_id);

	/* Read module */
	module_name = config_read_string(config, section, "Module", NULL);
	if (!module_name)
		fatal("%s: section [%s]: variable 'Module' missing.\n"
			"\tPlease run use '--mem-help' for more information on the\n"
			"\tconfiguration file format, or consult the Multi2Sim Guide.\n",
			file_name, section);
	
	/* Assign module */
	compute_unit->global_memory = mem_system_get_mod(module_name);
	if (!compute_unit->global_memory)
		fatal("%s: section [%s]: '%s' is not a valid module name.\n"
			"\tThe given module name must match a module declared in a section\n"
			"\t[Module <name>] in the memory configuration file.\n",
			file_name, section, module_name);
	
	/* Add modules to list of memory entries */
	linked_list_add(evg_emu_arch->mem_entry_mod_list, compute_unit->global_memory);
	
	/* Debug */
	mem_debug("\tEvergreen compute unit %d\n", compute_unit_id);
	mem_debug("\t\tEntry -> %s\n", compute_unit->global_memory->name);
	mem_debug("\n");
}
Exemple #16
0
static void net_config_route_create(struct net_t *net, struct config_t *config, char *section)
{
	char *token;
	char section_str[MAX_STRING_SIZE];
	char *delim_sep = ":";

	for (int i = 0; i < net->node_count; i++)
	{

		for (int j = 0; j < net->node_count; j++)
		{
			int vc_used = 0;

			char spr_result_size[MAX_STRING_SIZE];
			char *nxt_node_name;

			struct net_node_t *src_node_r;
			struct net_node_t *dst_node_r;
			struct net_node_t *nxt_node_r;

			src_node_r = list_get(net->node_list, i);
			dst_node_r = list_get(net->node_list, j);

			if (dst_node_r->kind == net_node_end)
			{
				snprintf(spr_result_size,
						sizeof spr_result_size,
						"%s.to.%s", src_node_r->name,
						dst_node_r->name);
				nxt_node_name =
						config_read_string(config,
								section, spr_result_size,
								"---");

				/* Token Separates the next node and
				 * VC */
				snprintf(section_str,
						sizeof section_str, "%s",
						nxt_node_name);
				token = strtok(section_str,
						delim_sep);
				nxt_node_name = token;
				token = strtok(NULL, delim_sep);

				if (token != NULL)
				{
					vc_used = atoi(token);
					if (vc_used < 0)
						fatal("Network %s:%s: Unacceptable virtual channel \n %s",
								net->name, section, net_err_config);
				}

				int name_check =
						strcmp(nxt_node_name, "---");
				nxt_node_r =
						net_get_node_by_name(net,
								nxt_node_name);

				if (name_check != 0)
				{
					if (nxt_node_r == NULL)
						fatal("Network %s:%s: Invalid node Name.\n %s",
								net->name, section,net_err_config);

					else
						net_routing_table_route_create
						(net->routing_table,
								src_node_r,
								dst_node_r,
								nxt_node_r,
								vc_used);
				}
			}
		}
	}
}
Exemple #17
0
void x86_mem_config_parse_entry(struct config_t *config, char *section)
{
	char *file_name;

	int core;
	int thread;

	int unified_present;
	int data_inst_present;

	char *data_module_name;
	char *inst_module_name;

	/* Get configuration file name */
	file_name = config_get_file_name(config);

	/* Allow these sections in case we quit before reading them. */
	config_var_allow(config, section, "DataModule");
	config_var_allow(config, section, "InstModule");
	config_var_allow(config, section, "Module");

	/* Check right presence of sections */
	unified_present = config_var_exists(config, section, "Module");
	data_inst_present = config_var_exists(config, section, "DataModule") &&
		config_var_exists(config, section, "InstModule");
	if (!(unified_present ^ data_inst_present))
		fatal("%s: section [%s]: invalid combination of modules.\n"
			"\tAn x86 entry to the memory hierarchy needs to specify either a unified\n"
			"\tentry for data and instructions (variable 'Module'), or two separate\n"
			"\tentries for data and instructions (variables 'DataModule' and 'InstModule'),\n"
			"\tbut not both.\n",
			file_name, section);

	/* Read core */
	core = config_read_int(config, section, "Core", -1);
	if (core < 0)
		fatal("%s: section [%s]: invalid or missing value for 'Core'",
			file_name, section);

	/* Read thread */
	thread = config_read_int(config, section, "Thread", -1);
	if (thread < 0)
		fatal("%s: section [%s]: invalid or missing value for 'Thread'",
			file_name, section);

	/* Check bounds */
	if (core >= x86_cpu_num_cores || thread >= x86_cpu_num_threads)
	{
		warning("%s: section [%s] ignored, referring to x86 Core %d, Thread %d.\n"
			"\tThis section refers to a core or thread that does not currently exists.\n"
			"\tPlease review your x86 configuration file if this behavior is not desired.\n",
			file_name, section, core, thread);
		return;
	}

	/* Check that entry has not been assigned before */
	if (X86_THREAD.data_mod || X86_THREAD.inst_mod)
	{
		assert(X86_THREAD.data_mod && X86_THREAD.inst_mod);
		fatal("%s: section [%s]: entry from Core %d, Thread %d already assigned.\n"
			"\tA different [Entry <name>] section in the memory configuration file has already\n"
			"\tassigned an entry for this particular core and thread. Please review your\n"
			"\tconfiguration file to avoid duplicates.\n",
			file_name, section, core, thread);
	}

	/* Read modules */
	if (data_inst_present)
	{
		data_module_name = config_read_string(config, section, "DataModule", NULL);
		inst_module_name = config_read_string(config, section, "InstModule", NULL);
		assert(data_module_name);
		assert(inst_module_name);
	}
	else
	{
		data_module_name = inst_module_name =
			config_read_string(config, section, "Module", NULL);
		assert(data_module_name);
	}

	/* Assign data module */
	X86_THREAD.data_mod = mem_system_get_mod(data_module_name);
	if (!X86_THREAD.data_mod)
		fatal("%s: section [%s]: '%s' is not a valid module name.\n"
			"\tThe given module name must match a module declared in a section\n"
			"\t[Module <name>] in the memory configuration file.\n",
			file_name, section, data_module_name);

	/* Assign instruction module */
	X86_THREAD.inst_mod = mem_system_get_mod(inst_module_name);
	if (!X86_THREAD.inst_mod)
		fatal("%s: section [%s]: '%s' is not a valid module name.\n"
			"\tThe given module name must match a module declared in a section\n"
			"\t[Module <name>] in the memory configuration file.\n",
			file_name, section, inst_module_name);
	
	/* Add modules to entry list */
	linked_list_add(x86_emu_arch->mem_entry_mod_list, X86_THREAD.data_mod);
	if (X86_THREAD.data_mod != X86_THREAD.inst_mod)
		linked_list_add(x86_emu_arch->mem_entry_mod_list, X86_THREAD.inst_mod);

	/* Debug */
	mem_debug("\tx86 Core %d, Thread %d\n", core, thread);
	mem_debug("\t\tEntry for instructions -> %s\n", X86_THREAD.inst_mod->name);
	mem_debug("\t\tEntry for data -> %s\n", X86_THREAD.data_mod->name);
	mem_debug("\n");
}
void SIGpuMemConfigParseEntry(Timing *self, struct config_t *config, char *section)
{
	char *file_name;
	char *vector_module_name;
	char *scalar_module_name;

	int unified_present;
	int separate_present;

	int compute_unit_id;

	struct si_compute_unit_t *compute_unit;

	/* Get configuration file name */
	file_name = config_get_file_name(config);

	/* Allow these sections in case we quit before reading them. */
	config_var_allow(config, section, "DataModule");
	config_var_allow(config, section, "ConstantDataModule");
	config_var_allow(config, section, "Module");

	unified_present = config_var_exists(config, section, "Module");
	separate_present = config_var_exists(config, section, 
		"DataModule") && config_var_exists(config, section, 
		"ConstantDataModule");

	if (!unified_present && !separate_present)
	{
		fatal(
	"%s: section [%s]: variable 'Module' missing.\n"
	"\tPlease run use '--mem-help' for more information on the\n"
	"\tconfiguration file format, or consult the Multi2Sim Guide.\n",
			file_name, section);
	}

	if (!(unified_present ^ separate_present))
	{
		fatal(
	"%s: section [%s]: invalid combination of modules.\n"
	"\tA Southern Islands entry to the memory hierarchy needs to specify\n"
	"\teither a unified entry for vector and scalar caches (variable \n"
	"\t'Module'), or two separate entries for data and scalar (constant)\n"
	"\tdata (variables 'DataModule' and 'ConstantDataModule'), but not\n"
	"\tboth.\n",
			file_name, section);
	}

	/* Read compute unit */
	compute_unit_id = config_read_int(config, section, "ComputeUnit", -1);
	if (compute_unit_id < 0)
	{
		fatal("%s: section [%s]: invalid or missing value for "
			"'ComputeUnit'", file_name, section);
	}

	/* Check compute unit boundaries */
	if (compute_unit_id >= si_gpu_num_compute_units)
	{
		warning(
	"%s: section [%s] ignored, referring to Southern Islands \n"
	"\tcompute unit %d. This section refers to a compute unit that\n" 
	"\tdoes not currently exist. Please review your Southern Islands\n" 
	"\tconfiguration file if this is not the desired behavior.\n",
			file_name, section, compute_unit_id);
		return;
	}

	/* Check that entry has not been assigned before */
	compute_unit = si_gpu->compute_units[compute_unit_id];
	if (compute_unit->vector_cache)
	{
		fatal(
	"%s: section [%s]: entry from compute unit %d already assigned.\n"
	"\tA different [Entry <name>] section in the memory configuration\n" 
	"\tfile has already assigned an entry for this particular compute \n"
	"\tunit. Please review your tconfiguration file to avoid duplicates.\n",
			file_name, section, compute_unit_id);
	}

	/* Read modules */
	if (separate_present)
	{
		vector_module_name = config_read_string(config, section, 
			"DataModule", NULL);
		scalar_module_name = config_read_string(config, section, 
			"ConstantDataModule", NULL);
	}
	else
	{
		vector_module_name = scalar_module_name =
			config_read_string(config, section, "Module", NULL);
	}
	assert(vector_module_name);
	assert(scalar_module_name);
	
	/* Assign modules */
	compute_unit->vector_cache = mem_system_get_mod(vector_module_name);
	if (!compute_unit->vector_cache)
	{
		fatal(
	"%s: section [%s]: '%s' is not a valid module name.\n"
	"\tThe given module name must match a module declared in a section\n"
	"\t[Module <name>] in the memory configuration file.\n",
			file_name, section, vector_module_name);
	}
	compute_unit->scalar_cache = mem_system_get_mod(scalar_module_name);
	if (!compute_unit->scalar_cache)
	{
		fatal(
	"%s: section [%s]: '%s' is not a valid module name.\n"
	"\tThe given module name must match a module declared in a section\n"
	"\t[Module <name>] in the memory configuration file.\n",
			file_name, section, scalar_module_name);
	}
	
	/* Add modules to list of memory entries */
	linked_list_add(arch_southern_islands->mem_entry_mod_list, 
		compute_unit->vector_cache);
	linked_list_add(arch_southern_islands->mem_entry_mod_list, 
		compute_unit->scalar_cache);
	
	/* Debug */
	mem_debug("\tSouthern Islands compute unit %d\n", compute_unit_id);
	mem_debug("\t\tEntry for vector mem -> %s\n", 
		compute_unit->vector_cache->name);
	mem_debug("\t\tEntry for scalar mem -> %s\n", 
		compute_unit->scalar_cache->name);
	mem_debug("\n");
}
Exemple #19
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);
}
Exemple #20
0
odesys_t *
odesys_parse_cfg_from_buffer_ctor (const char *buffer)
/* Parse the buffer and return an odesys_t object fully initialized
   and ready to use. */
{
  config_t cfg;
  odesys_t *odesys = NULL;
  molecule_t *molecule = NULL;
  laser_collection_t *lasers = NULL;

  /* Parse configurtion file into a libconfig config_t object. */
  config_init (&cfg);

  if (config_read_string (&cfg, buffer) == CONFIG_FALSE)
    {
      switch (config_error_type (&cfg))
	{
	case CONFIG_ERR_PARSE:
	  fprintf (stderr, "Error in configuration at line %d\n",
		   config_error_line (&cfg));
	  fprintf (stderr, "Error was: \"%s\"\n", config_error_text (&cfg));
	  return NULL;
	default:
	  fprintf (stderr, "Unknown error in parsing configuration.\n");
	  return NULL;
	}
    }

  /* Parse the config_t object. */
  molecule = molecule_cfg_parse_ctor (&cfg);
  if (molecule == NULL)
    {
      fprintf (stderr,
	       "Failed to parse molecule information from configuration file.\n");
      config_destroy (&cfg);
      return NULL;
    }

  lasers = laser_collection_cfg_parse_ctor (&cfg);
  if (lasers == NULL)
    {
      fprintf (stderr,
	       "Failed to parse laser information from configuration file.\n");
      molecule->dtor (molecule);
      config_destroy (&cfg);
      return NULL;
    }

  odesys = odesys_ctor (molecule, lasers);
  if (odesys == NULL)
    {
      fprintf (stderr, "Failed to initialize odesys.\n");
      molecule->dtor (molecule);
      laser_collection_dtor (lasers);
      config_destroy (&cfg);
      return NULL;
    }

  if (odesys_cfg_parse (odesys, &cfg) < 0)
    {
      fprintf (stderr, "%s %d: Failed to parse odesys information.\n",
	       __func__, __LINE__);
      odesys_dtor (odesys);
      config_destroy (&cfg);
      return NULL;
    }

  config_destroy (&cfg);

  return odesys;
}
Exemple #21
0
struct config_server_t *
config_parse_server(FILE *in)
{
	struct config_server_t *s;
	s = (struct config_server_t *)malloc(sizeof(*s));

	config_read_key(in);
	while(strlen(key)!=0 && !feof(in)) {
		if(!strcmp(key,"server_name"))
			s->name = config_read_string(in);
		else if(!strcmp(key,"server_autoconnect"))
			s->autoconnect = config_read_string(in);
		else if(!strcmp(key,"server_address"))
			s->address = config_read_string(in);
		else if(!strcmp(key,"server_port"))
			s->port = config_read_value(in);
		else if(!strcmp(key,"server_ipv6"))
			s->ipv6 = config_read_string(in);
		else if(!strcmp(key,"server_ssl"))
			s->ssl = config_read_string(in);
		else if(!strcmp(key,"server_password"))
			s->password = config_read_string(in);
		else if(!strcmp(key,"server_nick1"))
			s->nick1 = config_read_string(in);
		else if(!strcmp(key,"server_nick2"))
			s->nick2 = config_read_string(in);
		else if(!strcmp(key,"server_nick3"))
			s->nick3 = config_read_string(in);
		else if(!strcmp(key,"server_username"))
			s->username = config_read_string(in);
		else if(!strcmp(key,"server_realname"))
			s->realname = config_read_string(in);
		else if(!strcmp(key,"server_hostname"))
			s->hostname = config_read_string(in);
		else if(!strcmp(key,"server_command"))
			s->command = config_read_string(in);
		else if(!strcmp(key,"server_autojoin"))
			s->autojoin = config_read_string(in);
		config_read_key(in);
	}

	return s;
}
Exemple #22
0
/*-------------------------------------------------------------------------

	Load the game configuration and optionally emulator
	settings from the game config file.

	Input:  Filename    Name of the game config file.

	Return: 1 if read successfully or zero.

---------------------------------------------------------------------------*/
Uint32 config_load_cue_file ( char *Filename )
{
	char        File[256];
	CONFIG_FILE Config;
	Uint32      i;

	strcpy ( neogeo_toc_file_name, Filename );

	if ( config_fopen ( &Config, Filename ) )
	{
		if ( config_find_section ( &Config, "Game Info" ) )
			goto config_ok;

		config_fclose ( &Config );
	}

	platform_remove_trailing_slash ( Filename );
	platform_get_file_name ( Filename, File );

	strcpy ( neogeo_toc_file_name, Filename );
	strcat ( neogeo_toc_file_name, DIRECTORY_SEPARATOR_STRING );
	strcat ( neogeo_toc_file_name, File );
	strcat ( neogeo_toc_file_name, ".cfg" );

	if ( !config_fopen ( &Config, neogeo_toc_file_name ) )
	{
		fprintf ( stderr, "Can't open game configuration file. (%s)\n", neogeo_toc_file_name );
		return 0;
	}

	if ( !config_find_section ( &Config, "Game Info" ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, can't find section [Game Info]\n" );
		config_fclose ( &Config );
		return 0;
	}

config_ok:
	if ( !config_read_string ( &Config, "Name", neogeo_game_name, 256 ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, can't read variable 'Name'\n" );
		config_fclose ( &Config );
		return 0;
	}

	neogeo_cdrom_first_track = 1;

	if ( !config_read_integer ( &Config, "Tracks", &neogeo_cdrom_last_track ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, can't read variable 'Tracks'\n" );
		config_fclose ( &Config );
		return 0;
	}

	if ( ( !neogeo_cdrom_last_track ) || ( neogeo_cdrom_last_track > 99 ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, 'Tracks' must be between 1 & 99\n" );
		config_fclose ( &Config );
		return 0;
	}

	if ( !config_read_integer ( &Config, "Leadout", &neogeo_cdrom_toc[0].position ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, can't read variable 'Leadout'\n" );
		config_fclose ( &Config );
		return 0;
	}

	config_read_integer_default ( &Config, "Fix_DoubleDragon", &Fix_DoubleDragon, 0 );

	if ( !config_find_section ( &Config, "TOC" ) )
	{
		fprintf ( stderr, "Syntax error in game cfg file, can't find section [TOC]\n" );
		config_fclose ( &Config );
		return 0;
	}

	for ( i = 1; i <= neogeo_cdrom_last_track; i++ )
	{
		sprintf ( File, "%d", i );

		if ( !config_find_subsection ( &Config, File ) )
		{
			fprintf ( stderr, "Syntax error in game cfg file, can't find subsection %s\n", File );
			config_fclose ( &Config );
			return 0;
		}

		if ( !config_read_integer ( &Config, "Position", &neogeo_cdrom_toc[i].position ) )
		{
			fprintf ( stderr, "Syntax error in game cfg file, can't read Position for track %d\n", i );
			config_fclose ( &Config );
			return 0;
		}

		if ( !config_read_string ( &Config, "Filename", &neogeo_cdrom_toc[i].filename[0], 256 ) )
		{
			fprintf ( stderr, "Syntax error in game cfg file, can't read Filename for track %d\n", i );
			config_fclose ( &Config );
			return 0;
		}
	}

	config_load_settings ( &Config );

	config_fclose ( &Config );

	return 1;
}
Exemple #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);
}