示例#1
0
int __devinit
__cpu_up (unsigned int cpu)
{
	int ret;
	int sapicid;

	sapicid = ia64_cpu_to_sapicid[cpu];
	if (sapicid == -1)
		return -EINVAL;

	/*
	 * Already booted.. just enable and get outa idle lool
	 */
	if (cpu_isset(cpu, cpu_callin_map))
	{
		cpu_enable(cpu);
		local_irq_enable();
		while (!cpu_isset(cpu, cpu_online_map))
			mb();
		return 0;
	}
	/* Processor goes to start_secondary(), sets online flag */
	ret = do_boot_cpu(sapicid, cpu);
	if (ret < 0)
		return ret;

	return 0;
}
示例#2
0
static
void
set_cpue(uint32_t val)
{
	unsigned i, thisbit;
	struct lamebus_cpu *cpu;

	for (i=0; i<ncpus; i++) {
		thisbit = val & ((uint32_t)1 << i);
		cpu = &cpus[i];

		if (cpu->cpu_enabled && thisbit == 0) {
			/*
			 * Shutting off cpu.
			 *
			 * Just drop it in its tracks...
			 */
			cpu->cpu_enabled = 0;
			cpu_disable(i);
		}
		else if (!cpu->cpu_enabled && thisbit != 0) {
			/*
			 * Turning on cpu.
			 *
			 * According to spec, set stack to the top end
			 * of CRAM, and load the PC from the bottom
			 * end of CRAM.
			 */
			uint32_t cramoffset;
			uint32_t stackva, pcva, arg;
			uint32_t *cram;

			cramoffset = LAMEBUS_SLOT_MEM * LAMEBUS_CONTROLLER_SLOT
				+ 32768
				+ i * LAMEBUS_PERCPU_SIZE
				+ LBC_CRAM_END;

			stackva = cpu_get_secondary_start_stack(cramoffset);
			cram = (uint32_t *)cpu->cpu_cram;
			pcva = ntohl(cram[0]);
			arg = ntohl(cram[1]);

			cpu_set_entrypoint(i, pcva);
			cpu_set_stack(i, stackva, arg);

			cpu_enable(i);
		}
	}
}
示例#3
0
文件: smp.c 项目: ForayJones/iods
int __cpuinit __cpu_up(unsigned int cpu)
{
	int c;

	secondary_ti = current_set[cpu];
	if (!cpu_enable(cpu))
		return 0;

	if (smp_ops == NULL ||
	    (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
		return -EINVAL;

	/* Make sure callin-map entry is 0 (can be leftover a CPU
	 * hotplug
	 */
	cpu_callin_map[cpu] = 0;

	/* The information for processor bringup must
	 * be written out to main store before we release
	 * the processor.
	 */
	smp_mb();

	/* wake up cpus */
	DBG("smp: kicking cpu %d\n", cpu);
	smp_ops->kick_cpu(cpu);

	/*
	 * wait to see if the cpu made a callin (is actually up).
	 * use this value that I found through experimentation.
	 * -- Cort
	 */
	if (system_state < SYSTEM_RUNNING)
		for (c = 50000; c && !cpu_callin_map[cpu]; c--)
			udelay(100);
#ifdef CONFIG_HOTPLUG_CPU
	else
		/*
		 * CPUs can take much longer to come up in the
		 * hotplug case.  Wait five seconds.
		 */
		for (c = 25; c && !cpu_callin_map[cpu]; c--) {
			msleep(200);
		}
#endif

	if (!cpu_callin_map[cpu]) {
		printk("Processor %u is stuck.\n", cpu);
		return -ENOENT;
	}

	printk("Processor %u found.\n", cpu);

	if (smp_ops->give_timebase)
		smp_ops->give_timebase();

	/* Wait until cpu puts itself in the online map */
	while (!cpu_online(cpu))
		cpu_relax();

	return 0;
}
示例#4
0
int main(int argc, char *argv[])
{
	cpu_set_t *cpu_set;
	size_t setsize;
	int cmd = -1;
	int c;

	enum {
		EXCL_NONE,
		EXCL_CONFIGURE,
		EXCL_DECONFIGURE,
		EXCL_DISABLE,
		EXCL_DISPATCH,
		EXCL_ENABLE
	};
	int excl_any = EXCL_NONE;

	static const struct option longopts[] = {
		{ "configure",	required_argument, 0, 'c' },
		{ "deconfigure",required_argument, 0, 'g' },
		{ "disable",	required_argument, 0, 'd' },
		{ "dispatch",	required_argument, 0, 'p' },
		{ "enable",	required_argument, 0, 'e' },
		{ "help",	no_argument,       0, 'h' },
		{ "rescan",	no_argument,       0, 'r' },
		{ "version",	no_argument,       0, 'V' },
		{ NULL,		0, 0, 0 }
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	maxcpus = get_max_number_of_cpus();
	if (maxcpus < 1)
		errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting"));
	if (path_exist(_PATH_SYS_CPU_ONLINE))
		onlinecpus = path_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
	setsize = CPU_ALLOC_SIZE(maxcpus);
	cpu_set = CPU_ALLOC(maxcpus);
	if (!cpu_set)
		err(EXIT_FAILURE, _("cpuset_alloc failed"));

	while ((c = getopt_long(argc, argv, "c:d:e:g:hp:rV", longopts, NULL)) != -1) {
		switch (c) {
		case 'c':
			exclusive_option(&excl_any, EXCL_CONFIGURE, EXCL_ERROR);
			cmd = CMD_CPU_CONFIGURE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'd':
			exclusive_option(&excl_any, EXCL_DISABLE, EXCL_ERROR);
			cmd = CMD_CPU_DISABLE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'e':
			exclusive_option(&excl_any, EXCL_ENABLE, EXCL_ERROR);
			cmd = CMD_CPU_ENABLE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'g':
			exclusive_option(&excl_any, EXCL_DECONFIGURE, EXCL_ERROR);
			cmd = CMD_CPU_DECONFIGURE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'h':
			usage(stdout);
		case 'p':
			exclusive_option(&excl_any, EXCL_DISPATCH, EXCL_ERROR);
			if (strcmp("horizontal", argv[optind - 1]) == 0)
				cmd = CMD_CPU_DISPATCH_HORIZONTAL;
			else if (strcmp("vertical", argv[optind - 1]) == 0)
				cmd = CMD_CPU_DISPATCH_VERTICAL;
			else
				errx(EXIT_FAILURE, _("unsupported argument: %s"),
				     argv[optind -1 ]);
			break;
		case 'r':
			cmd = CMD_CPU_RESCAN;
			break;
		case 'V':
			printf(_("%s from %s\n"), program_invocation_short_name,
			       PACKAGE_STRING);
			return EXIT_SUCCESS;
		default:
			usage(stderr);
		}
	}

	if ((argc == 1) || (argc != optind))
		usage(stderr);

	switch (cmd) {
	case CMD_CPU_ENABLE:
		return cpu_enable(cpu_set, maxcpus, 1);
	case CMD_CPU_DISABLE:
		return cpu_enable(cpu_set, maxcpus, 0);
	case CMD_CPU_CONFIGURE:
		return cpu_configure(cpu_set, maxcpus, 1);
	case CMD_CPU_DECONFIGURE:
		return cpu_configure(cpu_set, maxcpus, 0);
	case CMD_CPU_RESCAN:
		return cpu_rescan();
	case CMD_CPU_DISPATCH_HORIZONTAL:
		return cpu_set_dispatch(0);
	case CMD_CPU_DISPATCH_VERTICAL:
		return cpu_set_dispatch(1);
	}
	return EXIT_SUCCESS;
}
示例#5
0
文件: chcpu.c 项目: sebras/util-linux
int main(int argc, char *argv[])
{
	cpu_set_t *cpu_set;
	size_t setsize;
	int cmd = -1;
	int c, rc;

	static const struct option longopts[] = {
		{ "configure",	required_argument, NULL, 'c' },
		{ "deconfigure",required_argument, NULL, 'g' },
		{ "disable",	required_argument, NULL, 'd' },
		{ "dispatch",	required_argument, NULL, 'p' },
		{ "enable",	required_argument, NULL, 'e' },
		{ "help",	no_argument,       NULL, 'h' },
		{ "rescan",	no_argument,       NULL, 'r' },
		{ "version",	no_argument,       NULL, 'V' },
		{ NULL,		0, NULL, 0 }
	};

	static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
		{ 'c','d','e','g','p' },
		{ 0 }
	};
	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	maxcpus = get_max_number_of_cpus();
	if (maxcpus < 1)
		errx(EXIT_FAILURE, _("cannot determine NR_CPUS; aborting"));
	if (path_exist(_PATH_SYS_CPU_ONLINE))
		onlinecpus = path_read_cpulist(maxcpus, _PATH_SYS_CPU_ONLINE);
	setsize = CPU_ALLOC_SIZE(maxcpus);
	cpu_set = CPU_ALLOC(maxcpus);
	if (!cpu_set)
		err(EXIT_FAILURE, _("cpuset_alloc failed"));

	while ((c = getopt_long(argc, argv, "c:d:e:g:hp:rV", longopts, NULL)) != -1) {

		err_exclusive_options(c, longopts, excl, excl_st);

		switch (c) {
		case 'c':
			cmd = CMD_CPU_CONFIGURE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'd':
			cmd = CMD_CPU_DISABLE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'e':
			cmd = CMD_CPU_ENABLE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'g':
			cmd = CMD_CPU_DECONFIGURE;
			cpu_parse(argv[optind - 1], cpu_set, setsize);
			break;
		case 'h':
			usage(stdout);
		case 'p':
			if (strcmp("horizontal", argv[optind - 1]) == 0)
				cmd = CMD_CPU_DISPATCH_HORIZONTAL;
			else if (strcmp("vertical", argv[optind - 1]) == 0)
				cmd = CMD_CPU_DISPATCH_VERTICAL;
			else
				errx(EXIT_FAILURE, _("unsupported argument: %s"),
				     argv[optind -1 ]);
			break;
		case 'r':
			cmd = CMD_CPU_RESCAN;
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		default:
			errtryhelp(EXIT_FAILURE);
		}
	}

	if ((argc == 1) || (argc != optind))
		usage(stderr);

	switch (cmd) {
	case CMD_CPU_ENABLE:
		rc = cpu_enable(cpu_set, maxcpus, 1);
		break;
	case CMD_CPU_DISABLE:
		rc = cpu_enable(cpu_set, maxcpus, 0);
		break;
	case CMD_CPU_CONFIGURE:
		rc = cpu_configure(cpu_set, maxcpus, 1);
		break;
	case CMD_CPU_DECONFIGURE:
		rc = cpu_configure(cpu_set, maxcpus, 0);
		break;
	case CMD_CPU_RESCAN:
		rc = cpu_rescan();
		break;
	case CMD_CPU_DISPATCH_HORIZONTAL:
		rc = cpu_set_dispatch(0);
		break;
	case CMD_CPU_DISPATCH_VERTICAL:
		rc = cpu_set_dispatch(1);
		break;
	default:
		rc = -EINVAL;
		break;
	}

	return rc == 0 ? EXIT_SUCCESS :
	        rc < 0 ? EXIT_FAILURE : CHCPU_EXIT_SOMEOK;
}