Beispiel #1
0
/*
 * get the number of the nodes including offline nodes
 */
int get_nmems(void)
{
	struct bitmask *bmp = NULL;
	int n = 0;

	/* get the bitmask's len */
	if (mems_nbits <= 0) {
		mems_nbits = cpuset_mems_nbits();
		if (mems_nbits <= 0)
			return -1;
	}

	/* allocate the space for bitmask */
	bmp = bitmask_alloc(mems_nbits);
	if (bmp == NULL)
		return -1;

	if (present_memmask(bmp)) {
		bitmask_free(bmp);
		return -1;
	}

	/* Numbwe of highest set bit +1 is the number of the nodes */
	if (bitmask_weight(bmp) <= 0) {
		bitmask_free(bmp);
		return -1;
	}

	n = bitmask_last(bmp) + 1;
	bitmask_free(bmp);

	return n;
}
Beispiel #2
0
int main(int argc, const char *argv[])
{
	const char *cmd;
	unsigned int i, ret;
	struct stat statbuf;
	struct utsname uts;

	cpus_chosen = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF));

	argc--;
	argv += 1;

	handle_options(&argc, &argv);

	cmd = argv[0];

	if (argc < 1) {
		print_help();
		return EXIT_FAILURE;
	}

	setlocale(LC_ALL, "");
	textdomain(PACKAGE);

	/* Turn "perf cmd --help" into "perf help cmd" */
	if (argc > 1 && !strcmp(argv[1], "--help")) {
		argv[1] = argv[0];
		argv[0] = cmd = "help";
	}

	get_cpu_info(0, &cpupower_cpu_info);
	run_as_root = !getuid();
	if (run_as_root) {
		ret = uname(&uts);
		if (!ret && !strcmp(uts.machine, "x86_64") &&
		    stat("/dev/cpu/0/msr", &statbuf) != 0) {
			if (system("modprobe msr") == -1)
	fprintf(stderr, _("MSR access not available.\n"));
		}
	}
		

	for (i = 0; i < ARRAY_SIZE(commands); i++) {
		struct cmd_struct *p = commands + i;
		if (strcmp(p->cmd, cmd))
			continue;
		if (!run_as_root && p->needs_root) {
			fprintf(stderr, _("Subcommand %s needs root "
					  "privileges\n"), cmd);
			return EXIT_FAILURE;
		}
		ret = p->main(argc, argv);
		if (cpus_chosen)
			bitmask_free(cpus_chosen);
		return ret;
	}
	print_help();
	return EXIT_FAILURE;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	struct bitmask *mask1 = NULL, *mask2 = NULL, *mask3 = NULL;
	char buff[MAX_STRING_SIZE];

	checkopt(argc, argv);

	mask1 = bitmask_alloc(MAX_NBITS);
	if (mask1 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask1 failed.");

	mask2 = bitmask_alloc(MAX_NBITS);
	if (mask2 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask2 failed.");

	mask3 = bitmask_alloc(MAX_NBITS);
	if (mask3 == NULL)
		err(EXIT_FAILURE, "alloc memory space for bitmask3 failed.");

	if (bitmask_parselist(argv[argc - 2 + convert], mask1) != 0)
		err(EXIT_FAILURE, "parse list1 string failed.");

	if (convert) {
		bitmask_displaylist(buff, MAX_STRING_SIZE, mask1);
		printf("%s\n", buff);
		return 0;
	}

	if (bitmask_parselist(argv[argc - 1], mask2) != 0)
		err(EXIT_FAILURE, "parse list2 string failed.");

	if (add_or_subtract)
		bitmask_andnot(mask3, mask1, mask2);
	else
		bitmask_or(mask3, mask1, mask2);

	bitmask_displaylist(buff, MAX_STRING_SIZE, mask3);
	printf("%s\n", buff);

	return 0;
}
int main(int argc, const char *argv[])
{
	const char *cmd;
	unsigned int i, ret;

	cpus_chosen = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF));

	argc--;
	argv += 1;

	handle_options(&argc, &argv);

	cmd = argv[0];

	if (argc < 1) {
		print_help();
		return EXIT_FAILURE;
	}

	setlocale(LC_ALL, "");
	textdomain(PACKAGE);

	
	if (argc > 1 && !strcmp(argv[1], "--help")) {
		argv[1] = argv[0];
		argv[0] = cmd = "help";
	}

	get_cpu_info(0, &cpupower_cpu_info);
	run_as_root = !getuid();

	for (i = 0; i < ARRAY_SIZE(commands); i++) {
		struct cmd_struct *p = commands + i;
		if (strcmp(p->cmd, cmd))
			continue;
		if (!run_as_root && p->needs_root) {
			fprintf(stderr, _("Subcommand %s needs root "
					  "privileges\n"), cmd);
			return EXIT_FAILURE;
		}
		ret = p->main(argc, argv);
		if (cpus_chosen)
			bitmask_free(cpus_chosen);
		return ret;
	}
	print_help();
	return EXIT_FAILURE;
}
Beispiel #5
0
/**
 * @brief
 *	Add a memory node to the memory mask that is constructed while reading
 *	vnode definitions files.
 *
 * @param[in] memnum - memory board node id
 *
 * @return    int
 * @retval    0     Success
 * @retval   -1     Failure
 *
 */
static int
memmask_add(unsigned int memnum)
{
	if (mem_mask == NULL) {
		if (mems_nbits == 0)
			mems_nbits = cpuset_mems_nbits();
		mem_mask = bitmask_alloc(mems_nbits);
		if (mem_mask == NULL) {
			log_err(PBSE_SYSTEM, __func__, "bitmask_alloc failed");
			return (-1);
		} else
			bitmask_clearall(mem_mask);
	}
	assert(memnum < bitmask_nbits(mem_mask));
	(void) bitmask_setbit(mem_mask, memnum);

	return (0);
}
Beispiel #6
0
/**
 * @brief
 *	Add a CPU to the mask of CPUs that is constructed while reading
 *	vnode definitions files.
 *
 * @param[in] cpunum - number of cpus
 *
 * @return   int
 * @retval   0    Success
 * @retval  -1    Failure
 *
 */
static int
cpumask_add(unsigned int cpunum)
{
	if (cpu_mask == NULL) {
		if (cpus_nbits == 0)
			cpus_nbits = cpuset_cpus_nbits();
		cpu_mask = bitmask_alloc(cpus_nbits);
		if (cpu_mask == NULL) {
			log_err(PBSE_SYSTEM, __func__, "bitmask_alloc failed");
			return (-1);
		} else
			bitmask_clearall(cpu_mask);
	}
	assert(cpunum < bitmask_nbits(cpu_mask));
	(void) bitmask_setbit(cpu_mask, cpunum);

	return (0);
}
Beispiel #7
0
int main(int argc, char* argv[]) {
#define LEN (65543)
#define NT (1024)
	buffer = calloc(sizeof(int), LEN);
	mask = bitmask_alloc(LEN);
	bitmask_clear_all(mask);
	int i;
	int js[NT];
	#pragma omp parallel for private(i)
	for(i = 0; i < NT; i++) {
		int j;
		for(j = 0; j < LEN; j++) {
			js[i] = j;
			while(bitmask_test_and_set(mask, j)) {
				continue;
			}
			buffer[j]++;
			buffer[j]++;
			buffer[j]--;
			bitmask_clear(mask, j);
		}
	}
	for(i = 0; i < LEN; i++) {
		if(buffer[i] != NT) {
			printf("failed on %d\n", i);
			abort();
		}
	}
	intptr_t tests[] = {
28250585,
28250789,
	};
	for(i = 0; i < sizeof(tests) / sizeof(intptr_t); i++) {
		intptr_t idx = bitmask_shuffle(tests[i]);
		printf("%lX %lX %lX ", tests[i], idx, bitmask_shuffle(idx));
		printf("ele= %ld", idx >> 5);
		printf("offset = %d\n", idx & 31);
	}
}
/*
 * check sched domains in system
 *
 * return 0  - sched domains is true
 *        1  - sched domains is wrong, and print error info
 *        -1 - other error
 */
void check_sched_domains(void)
{
	int i;
	char buf1[128], buf2[128];
	struct bitmask *alldomains = NULL;

	/* get the bitmask's len */
	if (!cpus_nbits) {
		cpus_nbits = cpuset_cpus_nbits();
		if (cpus_nbits <= 0) {
			tst_resm(TFAIL, "get cpus nbits failed");
			return;
		}
	}

	if (getcpuinfo()) {
		tst_resm(TFAIL, "getcpuinfo failed");
		return;
	}

	if (partition_domains()) {
		tst_resm(TFAIL, "partition domains failed.");
		return;
	}

	alldomains = bitmask_alloc(cpus_nbits);
	if (alldomains == NULL) {
		tst_resm(TFAIL, "alloc alldomains space failed.");
		return;
	}

	for (i = 0; i < ndomains; i++) {
		unsigned int cpu;
		bitmask_or(alldomains, alldomains, domains[i]);

		for (cpu = bitmask_first(domains[i]);
		     cpu < bitmask_nbits(domains[i]);
		     cpu = bitmask_next(domains[i], cpu + 1)) {
			if (bitmask_weight(domains[i]) == 1) {
				if (cpus[cpu].sched_domain != NULL) {
				    	bitmask_displaylist(buf1, sizeof(buf1),
							domains[i]);
					bitmask_displaylist(buf2, sizeof(buf2),
							cpus[cpu].sched_domain);
					tst_resm(TFAIL, "cpu%d's sched domain is not "
							"NULL(Domain: %s, "
							"CPU's Sched Domain: %s).",
						cpu, buf1, buf2);
					goto err;
				}
				break;
			}
			if (!bitmask_equal(domains[i],
			    cpus[cpu].sched_domain)) {
			    	bitmask_displaylist(buf1, sizeof(buf1),
						domains[i]);
				bitmask_displaylist(buf2, sizeof(buf2),
				    cpus[cpu].sched_domain);
				tst_resm(TFAIL, "cpu%d's sched domain is wrong"
					"(Domain: %s, CPU's Sched Domain: %s).",
					cpu, buf1, buf2);
				goto err;
			}
		}
	}

	for (i = 0; i < ncpus; i++) {
		if (bitmask_isbitset(alldomains, i))
			continue;
		if (cpus[i].sched_domain) {
			tst_resm(TFAIL, "cpu%d has redundant sched domain", i);
			goto err;
		}
	}

	tst_resm(TPASS, "check_sched_domains passed");

err:
	bitmask_free(alldomains);
}
Beispiel #9
0
/*
 * hog the cpu time and check the cpu which the task is running on is in the
 * cpus of the cpuset or not.
 *
 * return value: 0  - success.
 *               1  - the cpu which the task is running on isn't in the cpus
 *                    of the cpuset.
 *               -1 - failure for other reason.
 */
int cpu_hog(void)
{
	double f = 2744545.34456455;
	sigset_t sigset;
	struct cpuset *cp = NULL;
	struct bitmask *cpumask = NULL;
	int cpu;
	int nbits;
	int ret = 0;

	nbits = cpuset_cpus_nbits();

	cp = cpuset_alloc();
	if (cp == NULL)
		return -1;

	cpumask = bitmask_alloc(nbits);
	if (cpumask == NULL) {
		ret = -1;
		goto err1;
	}

	if (sigemptyset(&sigset) < 0) {
		ret = -1;
		goto err2;
	}

	sigsuspend(&sigset);

	if (cpuset_cpusetofpid(cp, 0) < 0) {
		ret = -1;
		goto err2;
	}
	if (cpuset_getcpus(cp, cpumask) != 0) {
		ret = -1;
		goto err2;
	}

	while (!end) {
		f = sqrt(f * f);
		cpu = cpuset_latestcpu(0);
		if (cpu < 0) {
			warn("get latest cpu failed.\n");
			ret = -1;
			goto err2;
		}
		if (!bitmask_isbitset(cpumask, cpu)) {
			char str[50];
			bitmask_displaylist(str, 50, cpumask);
			warn("the task(%d) is running on the cpu(%d) excluded"
			     " by cpuset(cpus: %s)\n", getpid(), cpu, str);
			ret = 1;
			goto err2;
		}
	}

err2:
	bitmask_free(cpumask);
err1:
	cpuset_free(cp);
	return ret;
}