Ejemplo n.º 1
0
static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
{
	unsigned int cpu;
	int online, rc;
	int configured = -1;

	for (cpu = 0; cpu < setsize; cpu++) {
		if (!CPU_ISSET(cpu, cpu_set))
			continue;
		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
			printf(_("CPU %d does not exist\n"), cpu);
			continue;
		}
		if (!path_exist(_PATH_SYS_CPU "/cpu%d/online", cpu)) {
			printf(_("CPU %d is not hot pluggable\n"), cpu);
			continue;
		}
		online = path_read_s32(_PATH_SYS_CPU "/cpu%d/online", cpu);
		if ((online == 1) && (enable == 1)) {
			printf(_("CPU %d is already enabled\n"), cpu);
			continue;
		}
		if ((online == 0) && (enable == 0)) {
			printf(_("CPU %d is already disabled\n"), cpu);
			continue;
		}
		if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu))
			configured = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
		if (enable) {
			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
			if ((rc == -1) && (configured == 0))
				printf(_("CPU %d enable failed "
					 "(CPU is deconfigured)\n"), cpu);
			else if (rc == -1)
				printf(_("CPU %d enable failed (%m)\n"), cpu);
			else
				printf(_("CPU %d enabled\n"), cpu);
		} else {
			if (onlinecpus && num_online_cpus() == 1) {
				printf(_("CPU %d disable failed "
					 "(last enabled CPU)\n"), cpu);
				continue;
			}
			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
			if (rc == -1)
				printf(_("CPU %d disable failed (%m)\n"), cpu);
			else {
				printf(_("CPU %d disabled\n"), cpu);
				if (onlinecpus)
					CPU_CLR(cpu, onlinecpus);
			}
		}
	}
	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int ipc_msg_get_limits(struct ipc_limits *lim)
{
	if (path_exist(_PATH_PROC_IPC_MSGMNI) &&
	    path_exist(_PATH_PROC_IPC_MSGMNB) &&
	    path_exist(_PATH_PROC_IPC_MSGMAX)) {

		lim->msgmni = path_read_s32(_PATH_PROC_IPC_MSGMNI);
		lim->msgmnb = path_read_s32(_PATH_PROC_IPC_MSGMNB);
		lim->msgmax = path_read_s32(_PATH_PROC_IPC_MSGMAX);
	} else {
		struct msginfo msginfo;

		if (msgctl(0, IPC_INFO, (struct msqid_ds *) &msginfo) < 0)
			return 1;
		lim->msgmni = msginfo.msgmni;
		lim->msgmnb = msginfo.msgmnb;
		lim->msgmax = msginfo.msgmax;
	}

	return 0;
}
Ejemplo n.º 3
0
/* returns:   0 = success
 *          < 0 = failure
 *          > 0 = partial success
 */
static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
{
	unsigned int cpu;
	int rc, current;
	size_t fails = 0;

	for (cpu = 0; cpu < setsize; cpu++) {
		if (!CPU_ISSET(cpu, cpu_set))
			continue;
		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
			warnx(_("CPU %u does not exist"), cpu);
			fails++;
			continue;
		}
		if (!path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu)) {
			warnx(_("CPU %u is not configurable"), cpu);
			fails++;
			continue;
		}
		current = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
		if ((current == 1) && (configure == 1)) {
			printf(_("CPU %u is already configured\n"), cpu);
			continue;
		}
		if ((current == 0) && (configure == 0)) {
			printf(_("CPU %u is already deconfigured\n"), cpu);
			continue;
		}
		if ((current == 1) && (configure == 0) && onlinecpus &&
		    is_cpu_online(cpu)) {
			warnx(_("CPU %u deconfigure failed (CPU is enabled)"), cpu);
			fails++;
			continue;
		}
		if (configure) {
			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
			if (rc == -1) {
				warn(_("CPU %u configure failed"), cpu);
				fails++;
			} else
				printf(_("CPU %u configured\n"), cpu);
		} else {
			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
			if (rc == -1) {
				warn(_("CPU %u deconfigure failed"), cpu);
				fails++;
			} else
				printf(_("CPU %u deconfigured\n"), cpu);
		}
	}

	return fails == 0 ? 0 : fails == setsize ? -1 : 1;
}
Ejemplo n.º 4
0
static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
{
	unsigned int cpu;
	int rc, current;

	for (cpu = 0; cpu < setsize; cpu++) {
		if (!CPU_ISSET(cpu, cpu_set))
			continue;
		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
			printf(_("CPU %d does not exist\n"), cpu);
			continue;
		}
		if (!path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu)) {
			printf(_("CPU %d is not configurable\n"), cpu);
			continue;
		}
		current = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
		if ((current == 1) && (configure == 1)) {
			printf(_("CPU %d is already configured\n"), cpu);
			continue;
		}
		if ((current == 0) && (configure == 0)) {
			printf(_("CPU %d is already deconfigured\n"), cpu);
			continue;
		}
		if ((current == 1) && (configure == 0) && onlinecpus &&
		    is_cpu_online(cpu)) {
			printf(_("CPU %d deconfigure failed "
				 "(CPU is enabled)\n"), cpu);
			continue;
		}
		if (configure) {
			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/configure", cpu);
			if (rc == -1)
				printf(_("CPU %d configure failed (%m)\n"), cpu);
			else
				printf(_("CPU %d configured\n"), cpu);
		} else {
			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/configure", cpu);
			if (rc == -1)
				printf(_("CPU %d deconfigure failed (%m)\n"), cpu);
			else
				printf(_("CPU %d deconfigured\n"), cpu);
		}
	}
	return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
static int get_score_adj(const pid_t pid)
{
	return path_read_s32("/proc/%d/oom_score_adj", (int) pid);
}
Ejemplo n.º 6
0
/* returns:   0 = success
 *          < 0 = failure
 *          > 0 = partial success
 */
static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
{
	unsigned int cpu;
	int online, rc;
	int configured = -1;
	size_t fails = 0;

	for (cpu = 0; cpu < setsize; cpu++) {
		if (!CPU_ISSET(cpu, cpu_set))
			continue;
		if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
			warnx(_("CPU %u does not exist"), cpu);
			fails++;
			continue;
		}
		if (!path_exist(_PATH_SYS_CPU "/cpu%d/online", cpu)) {
			warnx(_("CPU %u is not hot pluggable"), cpu);
			fails++;
			continue;
		}
		online = path_read_s32(_PATH_SYS_CPU "/cpu%d/online", cpu);
		if ((online == 1) && (enable == 1)) {
			printf(_("CPU %u is already enabled\n"), cpu);
			continue;
		}
		if ((online == 0) && (enable == 0)) {
			printf(_("CPU %u is already disabled\n"), cpu);
			continue;
		}
		if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu))
			configured = path_read_s32(_PATH_SYS_CPU "/cpu%d/configure", cpu);
		if (enable) {
			rc = path_write_str("1", _PATH_SYS_CPU "/cpu%d/online", cpu);
			if ((rc == -1) && (configured == 0)) {
				warn(_("CPU %u enable failed (CPU is deconfigured)"), cpu);
				fails++;
			} else if (rc == -1) {
				warn(_("CPU %u enable failed"), cpu);
				fails++;
			} else
				printf(_("CPU %u enabled\n"), cpu);
		} else {
			if (onlinecpus && num_online_cpus() == 1) {
				warnx(_("CPU %u disable failed (last enabled CPU)"), cpu);
				fails++;
				continue;
			}
			rc = path_write_str("0", _PATH_SYS_CPU "/cpu%d/online", cpu);
			if (rc == -1) {
				warn(_("CPU %u disable failed"), cpu);
				fails++;
			} else {
				printf(_("CPU %u disabled\n"), cpu);
				if (onlinecpus)
					CPU_CLR(cpu, onlinecpus);
			}
		}
	}

	return fails == 0 ? 0 : fails == setsize ? -1 : 1;
}