コード例 #1
0
ファイル: odp_cpumask_task.c プロジェクト: nmorey/odp
int odp_cpumask_default_worker(odp_cpumask_t *mask, int num)
{
	odp_cpumask_t overlap;
	int cpu, i;

	/*
	 * If no user supplied number or it's too large, then attempt
	 * to use all CPUs
	 */
	cpu = odp_cpumask_count(&odp_global_data.worker_cpus);
	if (0 == num || cpu < num)
		num = cpu;

	/* build the mask, allocating down from highest numbered CPU */
	odp_cpumask_zero(mask);
	for (cpu = 0, i = CPU_SETSIZE - 1; i >= 0 && cpu < num; --i) {
		if (odp_cpumask_isset(&odp_global_data.worker_cpus, i)) {
			odp_cpumask_set(mask, i);
			cpu++;
		}
	}

	odp_cpumask_and(&overlap, mask, &odp_global_data.control_cpus);
	if (odp_cpumask_count(&overlap))
		ODP_DBG("\n\tWorker CPUs overlap with control CPUs...\n"
			"\tthis will likely have a performance impact on the worker threads.\n");

	return cpu;
}
コード例 #2
0
ファイル: odp_cpumask_task.c プロジェクト: nmorey/odp
int odp_cpumask_default_control(odp_cpumask_t *mask, int num)
{
	odp_cpumask_t overlap;
	int cpu, i;

	/*
	 * If no user supplied number then default to one control CPU.
	 */
	if (0 == num) {
		num = 1;
	} else {
		/*
		 * If user supplied number is too large, then attempt
		 * to use all installed control CPUs
		 */
		cpu = odp_cpumask_count(&odp_global_data.control_cpus);
		if (cpu < num)
			num = cpu;
	}

	/* build the mask, allocating upwards from lowest numbered CPU */
	odp_cpumask_zero(mask);
	for (cpu = 0, i = 0; i < CPU_SETSIZE && cpu < num; i++) {
		if (odp_cpumask_isset(&odp_global_data.control_cpus, i)) {
			odp_cpumask_set(mask, i);
			cpu++;
		}
	}

	odp_cpumask_and(&overlap, mask, &odp_global_data.worker_cpus);
	if (odp_cpumask_count(&overlap))
		ODP_DBG("\n\tControl CPUs overlap with worker CPUs...\n"
			"\tthis will likely have a performance impact on the worker threads.\n");

	return cpu;
}
コード例 #3
0
ファイル: odp_generator.c プロジェクト: kalray/odp-mppa
/**
 * Parse and store the command line arguments
 *
 * @param argc       argument count
 * @param argv[]     argument vector
 * @param appl_args  Store application arguments here
 */
static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
{
	int opt;
	int long_index;
	char *token;
	size_t len;
	odp_cpumask_t cpumask, cpumask_args, cpumask_and;
	int i, num_workers;
	static struct option longopts[] = {
		{"interface", required_argument, NULL, 'I'},
		{"workers", required_argument, NULL, 'w'},
		{"cpumask", required_argument, NULL, 'c'},
		{"srcmac", required_argument, NULL, 'a'},
		{"dstmac", required_argument, NULL, 'b'},
		{"srcip", required_argument, NULL, 's'},
		{"dstip", required_argument, NULL, 'd'},
		{"packetsize", required_argument, NULL, 'p'},
		{"mode", required_argument, NULL, 'm'},
		{"count", required_argument, NULL, 'n'},
		{"timeout", required_argument, NULL, 't'},
		{"interval", required_argument, NULL, 'i'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};

	appl_args->mode = -1; /* Invalid, must be changed by parsing */
	appl_args->number = -1;
	appl_args->payload = 56;
	appl_args->timeout = -1;
	int remove_header_size = 0;

	while (1) {
		opt = getopt_long(argc, argv, "+I:a:b:s:d:p:P:i:m:n:t:w:c:h",
				  longopts, &long_index);
		if (opt == -1)
			break;	/* No more options */

		switch (opt) {
		case 'w':
			appl_args->cpu_count = atoi(optarg);
			break;
		case 'c':
			appl_args->mask = optarg;
			odp_cpumask_from_str(&cpumask_args, args->appl.mask);
			num_workers = odp_cpumask_default_worker(&cpumask, 0);
			odp_cpumask_and(&cpumask_and, &cpumask_args, &cpumask);
			if (odp_cpumask_count(&cpumask_and) <
			    odp_cpumask_count(&cpumask_args)) {
				EXAMPLE_ERR("Wrong cpu mask, max cpu's:%d\n",
					    num_workers);
				exit(EXIT_FAILURE);
			}
			break;
		/* parse packet-io interface names */
		case 'I':
			len = strlen(optarg);
			if (len == 0) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}
			len += 1;	/* add room for '\0' */

			appl_args->if_str = malloc(len);
			if (appl_args->if_str == NULL) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}

			/* count the number of tokens separated by ',' */
			strcpy(appl_args->if_str, optarg);
			for (token = strtok(appl_args->if_str, ","), i = 0;
			     token != NULL;
			     token = strtok(NULL, ","), i++)
				;

			appl_args->if_count = i;

			if (appl_args->if_count == 0) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}

			/* allocate storage for the if names */
			appl_args->if_names =
			    calloc(appl_args->if_count, sizeof(char *));

			/* store the if names (reset names string) */
			strcpy(appl_args->if_str, optarg);
			for (token = strtok(appl_args->if_str, ","), i = 0;
			     token != NULL; token = strtok(NULL, ","), i++) {
				appl_args->if_names[i] = token;
			}
			break;

		case 'm':
			if (optarg[0] == 'u') {
				appl_args->mode = APPL_MODE_UDP;
			} else if (optarg[0] == 'p') {
				appl_args->mode = APPL_MODE_PING;
			} else if (optarg[0] == 'r') {
				appl_args->mode = APPL_MODE_RCV;
			} else {
				EXAMPLE_ERR("wrong mode!\n");
				exit(EXIT_FAILURE);
			}
			break;

		case 'a':
			if (scan_mac(optarg, &appl_args->srcmac) != 1) {
				EXAMPLE_ERR("wrong src mac:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'b':
			if (scan_mac(optarg, &appl_args->dstmac) != 1) {
				EXAMPLE_ERR("wrong dst mac:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 's':
			if (scan_ip(optarg, &appl_args->srcip) != 1) {
				EXAMPLE_ERR("wrong src ip:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'd':
			if (scan_ip(optarg, &appl_args->dstip) != 1) {
				EXAMPLE_ERR("wrong dst ip:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'p':
			appl_args->payload = atoi(optarg);
			break;

		case 'P':
			appl_args->payload = atoi(optarg);
			remove_header_size = 1;
			break;

		case 'n':
			appl_args->number = atoi(optarg);
			break;

		case 't':
			appl_args->timeout = atoi(optarg);
			break;

		case 'i':
			appl_args->interval = atoi(optarg);
			break;

		case 'h':
			usage(argv[0]);
			exit(EXIT_SUCCESS);
			break;

		default:
			break;
		}
	}

	if ( remove_header_size ) {
		int header_size = 0;
		switch (appl_args->mode) {
			case APPL_MODE_UDP:
				header_size = ODPH_UDPHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN;
				break;
			case APPL_MODE_PING:
				header_size = ODPH_ICMPHDR_LEN + ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN;
				break;
			case APPL_MODE_RCV:
				break;
		}
		appl_args->payload -= header_size;
	}

	printf("PAYLOAD = %i\n", appl_args->payload);
	if (appl_args->if_count == 0 || appl_args->mode == -1) {
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	optind = 1;		/* reset 'extern optind' from the getopt lib */
}