int process_mappings()

in src/parameter.c [188:234]


int process_mappings(struct ntttcp_test *test)
{
	int state = S_THREADS, threads = 0;
	char *token = NULL;
	int cpu = -1, total_cpus = 0;

	state = S_THREADS;
	char *element = strdup(test->mapping);

	while ((token = strsep(&element, ",")) != NULL) {
		if (S_THREADS == state) {
			threads = atoi(token);

			if (1 > threads) {
				return ERROR_ARGS;
			}
			test->server_ports = threads;
			test->threads_per_server_port = 1;
			++state;
		} else if (S_PROCESSOR == state) {
			if (0 == strcmp(token, "*")) {
				/* do nothing */
			} else {
				cpu = atoi(token);
				total_cpus = sysconf(_SC_NPROCESSORS_ONLN);
				if (total_cpus < 1) {
					PRINT_ERR("process_mappings: cannot set cpu affinity because we failed to determine number of CPUs online");
					continue;
				}

				if (cpu < -1 || cpu > total_cpus - 1) {
					PRINT_ERR("process_mappings: cpu specified is not in allowed scope");
					return ERROR_ARGS;
				}
				test->cpu_affinity = cpu;
			}
			++state;
		} else if (S_HOST == state) {
			test->bind_address = token;
			++state;
		} else {
			PRINT_ERR("process_mappings: unexpected parameters in mapping");
			return ERROR_ARGS;
		}
	}
	return NO_ERROR;
}