Ejemplo n.º 1
0
void
proc_main(processor_t proc)
{
    printf("mutex main %p\n", proc);
    processor_t shared = proc_new_from_other(proc);
    for (int i = 0; i < num_each; i++)
    {
        printf("creating worker %d\n", i);
        processor_t worker_proc = proc_new_from_other(proc);
        priv_queue_t q = proc_get_queue(proc, worker_proc);

        void ***args;
        clos_type_t *arg_types;

        closure_t clos =
            closure_new(worker,
                        closure_void_type(),
                        2,
                        &args,
                        &arg_types);

        arg_types[0] = closure_pointer_type();
        arg_types[1] = closure_pointer_type();

        *args[0] = worker_proc;
        *args[1] = shared;

        priv_queue_lock(q, proc);
        priv_queue_routine(q, clos, proc);
        proc_shutdown(worker_proc, proc);
        priv_queue_unlock(q, proc);
    }
}
Ejemplo n.º 2
0
void
worker(processor_t proc, processor_t shared)
{
  void ***args;
  clos_type_t *arg_types;
  priv_queue_t q = NULL;

  printf("worker running\n");

  assert(proc->stask.executor != NULL);
  for (int i = 0; i < num_iters; i++)
    { 
      q = proc_get_queue(proc, shared);
      closure_t clos =
        closure_new((void*)action,
                    closure_void_type(),
                    1,
                    &args,
                    &arg_types);

      arg_types[0] = closure_pointer_type();
      
      *args[0] = shared;

      priv_queue_lock(q, proc);
      priv_queue_routine(q, clos, proc);
      priv_queue_unlock(q, proc);
    }

  printf("worker done\n");
  if( __sync_add_and_fetch(&num_finished, 1) == num_each)
    {
      proc_shutdown(shared, proc);
    }
}
Ejemplo n.º 3
0
void
worker(processor_t proc, processor_t shared)
{
    void ***args;
    clos_type_t *arg_types;
    priv_queue_t q = NULL;
    for (int i = 0; i < num_iters; i++)
    {
        q = proc_get_queue(proc, shared);

        closure_t clos =
            closure_new(action,
                        closure_void_type(),
                        1,
                        &args,
                        &arg_types);

        arg_types[0] = closure_pointer_type();

        *args[0] = shared;

        priv_queue_lock(q, proc);
        priv_queue_routine(q, clos, proc);
        priv_queue_unlock(q, proc);
    }

    if( __sync_add_and_fetch(&num_finished, 1) == num_each)
    {
        proc_shutdown(shared, proc);
    }
}
Ejemplo n.º 4
0
void
wait_worker(processor_t proc, processor_t shared, uint64_t flag)
{

  void ***args;
  clos_type_t *arg_types;
  priv_queue_t q = NULL;
  assert(proc->stask.executor != NULL);
  for (int i = 0; i < num_iters; i++)
    {
      int val;
      closure_t clos;
      q = proc_get_queue (proc, shared);

      priv_queue_lock(q, proc);
      priv_queue_sync(q, proc);
      priv_queue_set_in_wait(q);

      val = x;

      while (val % 2 != flag)
        {
          priv_queue_unlock(q, proc);

          proc_wait_for_available(shared, proc);

          q = proc_get_queue (proc, shared);

          priv_queue_lock(q, proc);
          priv_queue_sync(q, proc);
          priv_queue_set_in_wait(q);

          val = x;
        }

      priv_queue_set_in_body(q);

      clos =
        closure_new((void*)action,
                    closure_void_type(),
                    1,
                    &args,
                    &arg_types);

      arg_types[0] = closure_pointer_type();
      *args[0] = shared;

      priv_queue_routine(q, clos, proc);
      priv_queue_unlock(q, proc);
    }

  if( __sync_add_and_fetch(&num_finished, 1) == num_each)
    {
      proc_shutdown(shared, proc);
    }  
}
Ejemplo n.º 5
0
void
proc_sig_handler(int sig, short event, void *arg)
{
	struct privsep_proc	*p = arg;

	switch (sig) {
	case SIGINT:
	case SIGTERM:
		proc_shutdown(p);
		break;
	case SIGCHLD:
	case SIGHUP:
	case SIGPIPE:
		/* ignore */
		break;
	default:
		fatalx("proc_sig_handler: unexpected signal");
		/* NOTREACHED */
	}
}
Ejemplo n.º 6
0
void
root_wait(processor_t proc)
{
  processors = (processor_t*) malloc((num_each + 1) * sizeof(processor_t));
  processor_t shared = proc_new_from_other(proc);
  processors[num_each] = shared;
  for (int i = 0; i < num_each; i++)
    {
      processor_t worker_proc = proc_new_from_other(proc);
      processors[i] = worker_proc;
      priv_queue_t q = proc_get_queue(proc, worker_proc);
      int64_t flag = i % 2 == 0;
      
      void ***args;
      clos_type_t *arg_types;
 
      closure_t clos =
        closure_new((void*)wait_worker,
                    closure_void_type(),
                    3,
                    &args,
                    &arg_types);
      
      arg_types[0] = closure_pointer_type();
      arg_types[1] = closure_pointer_type();
      arg_types[2] = closure_sint_type();

      *args[0] = worker_proc;
      *args[1] = shared;
      *args[2] = (void*)flag;

      priv_queue_lock(q, proc);
      priv_queue_routine(q, clos, proc);
      priv_queue_unlock(q, proc);

      proc_shutdown(worker_proc, proc);
    }
}
Ejemplo n.º 7
0
void
root_create(processor_t proc)
{
  processors = (processor_t*) malloc((num_each + 1) * sizeof(processor_t));
  processor_t shared = proc_new_from_other(proc);
  processors[num_each] = shared;
  for (int i = 0; i < num_each; i++)
    {
      processor_t worker_proc = proc_new_from_other(proc);
      processors[i] = worker_proc;
      priv_queue_t q = proc_get_queue(proc, worker_proc);
      assert(worker_proc->stask.executor != NULL);
      void ***args;
      clos_type_t *arg_types;
 
      printf("creating worker\n");

      closure_t clos =
        closure_new((void*)worker,
                    closure_void_type(),
                    2,
                    &args,
                    &arg_types);
      
      arg_types[0] = closure_pointer_type();
      arg_types[1] = closure_pointer_type();
      
      *args[0] = worker_proc;
      *args[1] = shared;

      priv_queue_lock(q, proc);
      priv_queue_routine(q, clos, proc);
      priv_queue_unlock(q, proc);
      proc_shutdown(worker_proc, proc);
    }
}
Ejemplo n.º 8
0
int
boot(int paniced, int howto, char *command)
{
	struct proc *p = current_proc();	/* XXX */
	int hostboot_option=0;

	if (!OSCompareAndSwap(0, 1, &system_inshutdown)) {
		if ( (howto&RB_QUICK) == RB_QUICK)
			goto force_reboot;
		return (EBUSY);
	}
	/*
	 * Temporary hack to notify the power management root domain
	 * that the system will shut down.
	 */
	IOSystemShutdownNotification();

	md_prepare_for_shutdown(paniced, howto, command);

	if ((howto&RB_QUICK)==RB_QUICK) {
		printf("Quick reboot...\n");
		if ((howto&RB_NOSYNC)==0) {
			sync(p, (void *)NULL, (int *)NULL);
		}
	}
	else if ((howto&RB_NOSYNC)==0) {
		int iter, nbusy;

		printf("syncing disks... ");

		/*
		 * Release vnodes held by texts before sync.
		 */

		/* handle live procs (deallocate their root and current directories). */		
		proc_shutdown();

#if CONFIG_AUDIT
		audit_shutdown();
#endif

		if (unmountroot_pre_hook != NULL)
			unmountroot_pre_hook();

		sync(p, (void *)NULL, (int *)NULL);

		/*
		 * Now that all processes have been terminated and system is
		 * sync'ed up, suspend init
		 */
			
		if (initproc && p != initproc)
			task_suspend(initproc->task);

		if (kdebug_enable)
			kdbg_dump_trace_to_file("/var/log/shutdown/shutdown.trace");

		/*
		 * Unmount filesystems
		 */
		vfs_unmountall();

		/* Wait for the buffer cache to clean remaining dirty buffers */
		for (iter = 0; iter < 100; iter++) {
			nbusy = count_busy_buffers();
			if (nbusy == 0)
				break;
			printf("%d ", nbusy);
			delay_for_interval( 1 * nbusy, 1000 * 1000);
		}
		if (nbusy)
			printf("giving up\n");
		else
			printf("done\n");
	}
#if NETWORKING
	/*
	 * Can't just use an splnet() here to disable the network
	 * because that will lock out softints which the disk
	 * drivers depend on to finish DMAs.
	 */
	if_down_all();
#endif /* NETWORKING */

force_reboot:
	if (howto & RB_POWERDOWN)
		hostboot_option = HOST_REBOOT_HALT;
	if (howto & RB_HALT)
		hostboot_option = HOST_REBOOT_HALT;
	if (paniced == RB_PANIC)
		hostboot_option = HOST_REBOOT_HALT;

	if (howto & RB_UPSDELAY) {
		hostboot_option = HOST_REBOOT_UPSDELAY;
	}

	host_reboot(host_priv_self(), hostboot_option);
	/*
	 * should not be reached
	 */
	return (0);
}
Ejemplo n.º 9
0
int
reboot_kernel(int howto, char *message)
{
	int hostboot_option=0;

	if (!OSCompareAndSwap(0, 1, &system_inshutdown)) {
		if ( (howto&RB_QUICK) == RB_QUICK)
			goto force_reboot;
		return (EBUSY);
	}
	/*
	 * Temporary hack to notify the power management root domain
	 * that the system will shut down.
	 */
	IOSystemShutdownNotification();

	if ((howto&RB_QUICK)==RB_QUICK) {
		printf("Quick reboot...\n");
		if ((howto&RB_NOSYNC)==0) {
			sync((proc_t)NULL, (void *)NULL, (int *)NULL);
		}
	}
	else if ((howto&RB_NOSYNC)==0) {
		int iter, nbusy;

		printf("syncing disks... ");

		/*
		 * Release vnodes held by texts before sync.
		 */

		/* handle live procs (deallocate their root and current directories), suspend initproc */
		proc_shutdown();

#if CONFIG_AUDIT
		audit_shutdown();
#endif

		if (unmountroot_pre_hook != NULL)
			unmountroot_pre_hook();

		sync((proc_t)NULL, (void *)NULL, (int *)NULL);

		if (kdebug_enable)
			kdbg_dump_trace_to_file("/var/log/shutdown/shutdown.trace");

		/*
		 * Unmount filesystems
		 */

#if DEVELOPMENT || DEBUG
		if (!(howto & RB_PANIC) || !kdp_has_polled_corefile())
#endif /* DEVELOPMENT || DEBUG */
		{
			vfs_unmountall();
		}

		/* Wait for the buffer cache to clean remaining dirty buffers */
		for (iter = 0; iter < 100; iter++) {
			nbusy = count_busy_buffers();
			if (nbusy == 0)
				break;
			printf("%d ", nbusy);
			delay_for_interval( 1 * nbusy, 1000 * 1000);
		}
		if (nbusy)
			printf("giving up\n");
		else
			printf("done\n");
	}
#if NETWORKING
	/*
	 * Can't just use an splnet() here to disable the network
	 * because that will lock out softints which the disk
	 * drivers depend on to finish DMAs.
	 */
	if_down_all();
#endif /* NETWORKING */

force_reboot:

	if (howto & RB_PANIC) {
		if (strncmp(message, "Kernel memory has exceeded limits", 33) == 0) {
			kernel_hwm_panic_info();
		}
		panic ("userspace panic: %s", message);
	}

	if (howto & RB_POWERDOWN)
		hostboot_option = HOST_REBOOT_HALT;
	if (howto & RB_HALT)
		hostboot_option = HOST_REBOOT_HALT;

	if (howto & RB_UPSDELAY) {
		hostboot_option = HOST_REBOOT_UPSDELAY;
	}

	host_reboot(host_priv_self(), hostboot_option);
	/*
	 * should not be reached
	 */
	return (0);
}
Ejemplo n.º 10
0
pid_t
proc_run(struct privsep *ps, struct privsep_proc *p,
    struct privsep_proc *procs, u_int nproc,
    void (*init)(struct privsep *, void *), void *arg)
{
	pid_t		 pid;
	struct passwd	*pw;
	const char	*root;
	u_int32_t	 seed[256];

	switch (pid = fork()) {
	case -1:
		fatal("proc_run: cannot fork");
	case 0:
		break;
	default:
		return (pid);
	}

	pw = ps->ps_pw;

	if (p->p_id == PROC_CONTROL) {
		if (control_init(ps, &ps->ps_csock) == -1)
			fatalx(p->p_title);
	}

	/* Change root directory */
	if (p->p_chroot != NULL)
		root = p->p_chroot;
	else
		root = pw->pw_dir;

#ifndef DEBUG
	if (chroot(root) == -1)
		fatal("proc_run: chroot");
	if (chdir("/") == -1)
		fatal("proc_run: chdir(\"/\")");
#else
#warning disabling privilege revocation and chroot in DEBUG MODE
	if (p->p_chroot != NULL) {
		if (chroot(root) == -1)
			fatal("proc_run: chroot");
		if (chdir("/") == -1)
			fatal("proc_run: chdir(\"/\")");
	}
#endif

	privsep_process = p->p_id;

	setproctitle("%s", p->p_title);

#ifndef DEBUG
	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("proc_run: cannot drop privileges");
#endif

	event_init();

	signal_set(&ps->ps_evsigint, SIGINT, proc_sig_handler, p);
	signal_set(&ps->ps_evsigterm, SIGTERM, proc_sig_handler, p);
	signal_set(&ps->ps_evsigchld, SIGCHLD, proc_sig_handler, p);
	signal_set(&ps->ps_evsighup, SIGHUP, proc_sig_handler, p);
	signal_set(&ps->ps_evsigpipe, SIGPIPE, proc_sig_handler, p);

	signal_add(&ps->ps_evsigint, NULL);
	signal_add(&ps->ps_evsigterm, NULL);
	signal_add(&ps->ps_evsigchld, NULL);
	signal_add(&ps->ps_evsighup, NULL);
	signal_add(&ps->ps_evsigpipe, NULL);

	proc_config(ps, procs, nproc);

	arc4random_buf(seed, sizeof(seed));
	RAND_seed(seed, sizeof(seed));

	if (p->p_id == PROC_CONTROL) {
		TAILQ_INIT(&ctl_conns);
		if (control_listen(&ps->ps_csock) == -1)
			fatalx(p->p_title);
	}

	if (init != NULL)
		init(ps, arg);

	event_dispatch();

	proc_shutdown(p);

	return (0);
}