void perfmon_init(void)
{
	size_t i;
	long nr;

	if (cpu_type == CPU_TIMER_INT)
		return;

	if (!no_xen) {
		xen_ctx = xmalloc(sizeof(struct child));
		xen_ctx->pid = getpid();
		xen_ctx->up_pipe[0] = -1;
		xen_ctx->up_pipe[1] = -1;
		xen_ctx->sigusr1 = 0;
		xen_ctx->sigusr2 = 0;
		xen_ctx->sigterm = 0;

		create_context(xen_ctx);

		write_pmu(xen_ctx);
		
		load_context(xen_ctx);
		return;
	}
	

	nr = sysconf(_SC_NPROCESSORS_ONLN);
	if (nr == -1) {
		fprintf(stderr, "Couldn't determine number of CPUs.\n");
		exit(EXIT_FAILURE);
	}

	nr_cpus = nr;

	children = xmalloc(sizeof(struct child) * nr_cpus);
	bzero(children, sizeof(struct child) * nr_cpus);

	for (i = 0; i < nr_cpus; ++i) {
		int ret;

		if (pipe(children[i].up_pipe)) {
			perror("Couldn't create child pipe");
			exit(EXIT_FAILURE);
		}

		ret = fork();
		if (ret == -1) {
			perror("Couldn't fork perfmon child");
			exit(EXIT_FAILURE);
		} else if (ret == 0) {
			close(children[i].up_pipe[0]);
			run_child(i);
		} else {
			children[i].pid = ret;
			close(children[i].up_pipe[1]);
			printf("Waiting on CPU%d\n", (int)i);
			wait_for_child(&children[i]);
		}
	}
}
static void run_child(size_t cpu)
{
	struct child * self = &children[cpu];

	self->pid = getpid();
	self->sigusr1 = 0;
	self->sigusr2 = 0;
	self->sigterm = 0;

	inner_child = self;
	if (atexit(close_pipe)){
		close_pipe();
		exit(EXIT_FAILURE);
	}

	umask(0);
	/* Change directory to allow directory to be removed */
	if (chdir("/") < 0) {
		perror("Unable to chdir to \"/\"");
		exit(EXIT_FAILURE);
	}

	setup_signals();

	set_affinity(cpu);

	create_context(self);

	write_pmu(self);

	load_context(self);

	notify_parent(self, cpu);

	/* Redirect standard files to /dev/null */
	freopen( "/dev/null", "r", stdin);
	freopen( "/dev/null", "w", stdout);
	freopen( "/dev/null", "w", stderr);

	for (;;) {
		sigset_t sigmask;
		sigfillset(&sigmask);
		sigdelset(&sigmask, SIGUSR1);
		sigdelset(&sigmask, SIGUSR2);
		sigdelset(&sigmask, SIGTERM);

		if (self->sigusr1) {
			perfmon_start_child(self->ctx_fd);
			self->sigusr1 = 0;
		}

		if (self->sigusr2) {
			perfmon_stop_child(self->ctx_fd);
			self->sigusr2 = 0;
		}

		sigsuspend(&sigmask);
	}
}
Exemplo n.º 3
0
  void PendSV_Handler( void )
  {
    static unsigned stackPointer = 0;

    stackPointer = save_context();
    stackPointer = cHwRTOS_MCU::schedule( stackPointer, false );
    load_context( stackPointer );
  }
Exemplo n.º 4
0
  void SysTick_Handler( void )
  {
    static unsigned stackPointer = 0;

    stackPointer = save_context();
    cHwRTOS_MCU::sysTic++;
    stackPointer = cHwRTOS_MCU::schedule( stackPointer, true );
    load_context( stackPointer );
  }
Exemplo n.º 5
0
void thread_terminate()
{
    thread_t *me = scheduler_running_thread();

    (void) scheduler_remove_thread(me->tid);
    schedule_thread();
    me = scheduler_running_thread();
    load_context(me->context);
}
Exemplo n.º 6
0
/*
 *	Start up the first thread on a CPU.
 *	First thread is specified for the master CPU.
 */
void
cpu_launch_first_thread(
	register thread_t	th)
{
	register int	mycpu;

	mycpu = cpu_number();

#if	MACH_ASSERT
	if (watchacts & WA_BOOT)
		printf("cpu_launch_first_thread(%x) cpu=%d\n", th, mycpu);
#endif	/* MACH_ASSERT */

	cpu_up(mycpu);

	start_timer(&kernel_timer[mycpu]);

	/*
	 * Block all interrupts for choose_thread.
	 */
	(void) splhigh();

	if (th == THREAD_NULL) {
	    th = cpu_to_processor(mycpu)->idle_thread;
		if (th == THREAD_NULL || !rem_runq(th))
		    panic("cpu_launch_first_thread");
	}

	rtclock_reset();		/* start realtime clock ticking */
	PMAP_ACTIVATE_KERNEL(mycpu);

	thread_machine_set_current(th);
	thread_lock(th);
	th->state &= ~TH_UNINT;
	thread_unlock(th);
	timer_switch(&th->system_timer);

	PMAP_ACTIVATE_USER(th->top_act, mycpu);

	assert(mycpu == cpu_number());

        /* The following is necessary to keep things balanced */
        disable_preemption();

	load_context(th);
	/*NOTREACHED*/
}
Exemplo n.º 7
0
void kernel_run()
{
    thread_t *init;
    unsigned i;

    for (i = 0; i < NELEMENTS(start_array); i++) {
        start_array[i]();
    }

    kprintf("system is running.\n");

    schedule_thread();

    init = scheduler_running_thread();

    load_context(init->context);
}
Exemplo n.º 8
0
static void run_child(size_t cpu)
{
	struct child * self = &children[cpu];

	self->pid = getpid();
	self->sigusr1 = 0;
	self->sigusr2 = 0;
	self->sigterm = 0;

	setup_signals();

	set_affinity(cpu);

	create_context(self);

	write_pmu(self);

	load_context(self);

	notify_parent(self, cpu);

	for (;;) {
		sigset_t sigmask;
		sigfillset(&sigmask);
		sigdelset(&sigmask, SIGUSR1);
		sigdelset(&sigmask, SIGUSR2);
		sigdelset(&sigmask, SIGTERM);

		if (self->sigusr1) {
			printf("PFM_START on CPU%d\n", (int)cpu);
			fflush(stdout);
			perfmon_start_child(self->ctx_fd);
			self->sigusr1 = 0;
		}

		if (self->sigusr2) {
			printf("PFM_STOP on CPU%d\n", (int)cpu);
			fflush(stdout);
			perfmon_stop_child(self->ctx_fd);
			self->sigusr2 = 0;
		}

		sigsuspend(&sigmask);
	}
}
Exemplo n.º 9
0
/*
 *	slave_main:
 *
 *	Load the first thread to start a processor.
 */
void
slave_main(void *machine_param)
{
    processor_t		processor = current_processor();
    thread_t		thread;

    /*
     *	Use the idle processor thread if there
     *	is no dedicated start up thread.
     */
    if (processor->next_thread == THREAD_NULL) {
        thread = processor->idle_thread;
        thread->continuation = (thread_continue_t)processor_start_thread;
        thread->parameter = machine_param;
    }
    else {
        thread = processor->next_thread;
        processor->next_thread = THREAD_NULL;
    }

    load_context(thread);
    /*NOTREACHED*/
}
Exemplo n.º 10
0
void
kernel_bootstrap(void)
{
    kern_return_t	result;
    thread_t	thread;
    char		namep[16];

    printf("%s\n", version); /* log kernel version */

#define kernel_bootstrap_kprintf(x...) /* kprintf("kernel_bootstrap: " x) */

    if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
        turn_on_log_leaks = 1;

    PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));

    /* i386_vm_init already checks for this ; do it aagin anyway */
    if (PE_parse_boot_argn("serverperfmode", &serverperfmode, sizeof (serverperfmode))) {
        serverperfmode = 1;
    }
    scale_setup();

    kernel_bootstrap_kprintf("calling vm_mem_bootstrap\n");
    vm_mem_bootstrap();

    kernel_bootstrap_kprintf("calling vm_mem_init\n");
    vm_mem_init();

    machine_info.memory_size = (uint32_t)mem_size;
    machine_info.max_mem = max_mem;
    machine_info.major_version = version_major;
    machine_info.minor_version = version_minor;

    kernel_bootstrap_kprintf("calling sched_init\n");
    sched_init();

    kernel_bootstrap_kprintf("calling wait_queue_bootstrap\n");
    wait_queue_bootstrap();

    kernel_bootstrap_kprintf("calling ipc_bootstrap\n");
    ipc_bootstrap();

#if CONFIG_MACF
    mac_policy_init();
#endif
    kernel_bootstrap_kprintf("calling ipc_init\n");
    ipc_init();

    /*
     * As soon as the virtual memory system is up, we record
     * that this CPU is using the kernel pmap.
     */
    kernel_bootstrap_kprintf("calling PMAP_ACTIVATE_KERNEL\n");
    PMAP_ACTIVATE_KERNEL(master_cpu);

    kernel_bootstrap_kprintf("calling mapping_free_prime\n");
    mapping_free_prime();						/* Load up with temporary mapping blocks */

    kernel_bootstrap_kprintf("calling machine_init\n");
    machine_init();

    kernel_bootstrap_kprintf("calling clock_init\n");
    clock_init();

    ledger_init();

    /*
     *	Initialize the IPC, task, and thread subsystems.
     */
    kernel_bootstrap_kprintf("calling task_init\n");
    task_init();

    kernel_bootstrap_kprintf("calling thread_init\n");
    thread_init();

    /*
     *	Create a kernel thread to execute the kernel bootstrap.
     */
    kernel_bootstrap_kprintf("calling kernel_thread_create\n");
    result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

    if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

    thread->state = TH_RUN;
    thread_deallocate(thread);

    kernel_bootstrap_kprintf("calling load_context - done\n");
    load_context(thread);
    /*NOTREACHED*/
}
Exemplo n.º 11
0
void
kernel_bootstrap(void)
{
	kern_return_t	result;
	thread_t	thread;
	char		namep[16];

	printf("%s\n", version); /* log kernel version */

	if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
		turn_on_log_leaks = 1;

	PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));
	PE_parse_boot_argn("trace_wake", &wake_nkdbufs, sizeof (wake_nkdbufs));
	PE_parse_boot_argn("trace_panic", &write_trace_on_panic, sizeof(write_trace_on_panic));
	PE_parse_boot_argn("trace_typefilter", &trace_typefilter, sizeof(trace_typefilter));

	scale_setup();

	kernel_bootstrap_log("vm_mem_bootstrap");
	vm_mem_bootstrap();

	kernel_bootstrap_log("cs_init");
	cs_init();

	kernel_bootstrap_log("vm_mem_init");
	vm_mem_init();

	machine_info.memory_size = (uint32_t)mem_size;
	machine_info.max_mem = max_mem;
	machine_info.major_version = version_major;
	machine_info.minor_version = version_minor;


#if CONFIG_TELEMETRY
	kernel_bootstrap_log("telemetry_init");
	telemetry_init();
#endif

#if CONFIG_CSR
	kernel_bootstrap_log("csr_init");
	csr_init();
#endif

	kernel_bootstrap_log("stackshot_lock_init");	
	stackshot_lock_init();

	kernel_bootstrap_log("sched_init");
	sched_init();

	kernel_bootstrap_log("waitq_bootstrap");
	waitq_bootstrap();

	kernel_bootstrap_log("ipc_bootstrap");
	ipc_bootstrap();

#if CONFIG_MACF
	kernel_bootstrap_log("mac_policy_init");
	mac_policy_init();
#endif

	kernel_bootstrap_log("ipc_init");
	ipc_init();

	/*
	 * As soon as the virtual memory system is up, we record
	 * that this CPU is using the kernel pmap.
	 */
	kernel_bootstrap_log("PMAP_ACTIVATE_KERNEL");
	PMAP_ACTIVATE_KERNEL(master_cpu);

	kernel_bootstrap_log("mapping_free_prime");
	mapping_free_prime();						/* Load up with temporary mapping blocks */

	kernel_bootstrap_log("machine_init");
	machine_init();

	kernel_bootstrap_log("clock_init");
	clock_init();

	ledger_init();

	/*
	 *	Initialize the IPC, task, and thread subsystems.
	 */
#if CONFIG_COALITIONS
	kernel_bootstrap_log("coalitions_init");
	coalitions_init();
#endif

	kernel_bootstrap_log("task_init");
	task_init();

	kernel_bootstrap_log("thread_init");
	thread_init();

#if CONFIG_ATM
	/* Initialize the Activity Trace Resource Manager. */
	kernel_bootstrap_log("atm_init");
	atm_init();
#endif

#if CONFIG_BANK
	/* Initialize the BANK Manager. */
	kernel_bootstrap_log("bank_init");
	bank_init();
#endif
	
	/* initialize the corpse config based on boot-args */
	corpses_init();

	/*
	 *	Create a kernel thread to execute the kernel bootstrap.
	 */
	kernel_bootstrap_log("kernel_thread_create");
	result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

	if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

	thread->state = TH_RUN;
	thread->last_made_runnable_time = mach_absolute_time();
	thread_deallocate(thread);

	kernel_bootstrap_log("load_context - done");
	load_context(thread);
	/*NOTREACHED*/
}
Exemplo n.º 12
0
void mod_setup(unsigned int setupfr)
{
        //default key bindings
        exec_commands("defaults");

        //make the mother object
        fr[setupfr].objs[0] = (object){ mother_type, 0, 0, sizeof(mother), malloc(sizeof(mother)) };
        memset( fr[setupfr].objs[0].data, 0, sizeof(mother) );

        //make default context object (map)
        fr[setupfr].objs[1] = (object){ context_type, OBJF_REFC, 0, sizeof(context), malloc(sizeof(context)) };
        context *co = fr[setupfr].objs[1].data;
        co->bsx = co->bsy = co->bsz = 16;
        co->x   = co->y   = co->z   = 15;
        co->tileuw = 48;
        co->tileuh = 24;
        co->projection = DIMETRIC;
        int volume = co->x * co->y * co->z;
        co->map  = hack_map  = malloc( (sizeof *co->map ) * volume ); //FIXME remove hack
        co->dmap = hack_dmap = malloc( (sizeof *co->dmap) * volume );
        memset( co->map,  0, (sizeof *co->map ) * volume );
        memset( co->dmap, 0, (sizeof *co->dmap) * volume );
        int i;
        for( i=0; i<volume; i++ )
        {
                co->map[ i].spr   = 0;
                co->dmap[i].flags = CBF_NULL;
        }
        load_context("noise", 1, setupfr); //load a default map

        //make some dummys
        #define MAYBE_A_DUMMY(i,x,y,w,h) {                                                               \
                dummy *du;                                                                               \
                fr[setupfr].objs[i+20].type = dummy_type;                                                \
                fr[setupfr].objs[i+20].flags = OBJF_POS|OBJF_VEL|OBJF_HULL|OBJF_VIS|OBJF_PLAT|OBJF_CLIP| \
                                               OBJF_BNDX|OBJF_BNDZ|OBJF_BNDB;                            \
                fr[setupfr].objs[i+20].context = 1;                                                      \
                fr[setupfr].objs[i+20].size = sizeof *du;                                                \
                du = fr[setupfr].objs[i+20].data = malloc(sizeof *du);                                   \
                du->pos = (V){x*8,y*8,0};                                                                \
                du->vel = (V){0,0,0};                                                                    \
                du->hull[0] = (V){-w*8,-h*8,-8};                                                         \
                du->hull[1] = (V){ w*8, h*8, 8};                                                         \
                du->model = 0;                                                                           }
        MAYBE_A_DUMMY(20,  3,-25,1,1);
        MAYBE_A_DUMMY(21,  3,-20,1,1);
        MAYBE_A_DUMMY(22,  3,-15,1,1);
        MAYBE_A_DUMMY(23,  3,-10,1,1);
        MAYBE_A_DUMMY(24,  5,-15,1,1);
        MAYBE_A_DUMMY(25,  9,-15,1,1);
        MAYBE_A_DUMMY(26, 43,-20,1,1);
        MAYBE_A_DUMMY(27, 43,-15,1,1);
        MAYBE_A_DUMMY(28, 45,-25,1,1);
        MAYBE_A_DUMMY(29, 45,-20,1,1);
        MAYBE_A_DUMMY(30, 45,-15,1,1);
        #undef MAYBE_A_DUMMY

        fr[setupfr+1].cmds[0].flags |= CMDF_NEW; //server is a client

        echo("Default controls: \\#F80A, S, Numpad Arrows, F11");
}
Exemplo n.º 13
0
mm_html_template::mm_html_template(const wxString& arg_template): html_template(arg_template.ToStdWstring())
{
    load_context();
}
Exemplo n.º 14
0
void SLoader::load_context(
		const int num_attrs,
		std::vector<const char*> &positive_context,
		std::vector<const char*> &negative_context) const {
	load_context(_path, num_attrs, positive_context, negative_context);
}