示例#1
0
void
#else
int
#endif
sleeptab_init(sleeptab_t *st)
{
	sleepq_t *sq;
	int i;
#ifdef T2EX
	int error;
#endif

	for (i = 0; i < SLEEPTAB_HASH_SIZE; i++) {
		sq = &st->st_queues[i].st_queue;
#ifndef T2EX
		mutex_init(&st->st_queues[i].st_mutex, MUTEX_DEFAULT,
		    IPL_SCHED);
		sleepq_init(sq);
#else
		error = mutex_init(&st->st_queues[i].st_mutex, MUTEX_DEFAULT,
		    IPL_SCHED);
		if ( error != 0 ) {
			goto err_ret1_1;
		}
		error = sleepq_init(sq);
		if ( error != 0 ) {
			goto err_ret1_2;
		}
#endif
	}

#ifdef T2EX
	return 0;

err_ret1_2:
	for(int j = 0; j < i; j++) {
		mutex_destroy(&st->st_queues[j].st_mutex);
		sleepq_finish(&st->st_queues[i].st_queue);
	}
	goto err_ret0;
err_ret1_1:
	for(int j = 0; j < i; j++) {
		mutex_destroy(&st->st_queues[j].st_mutex);
		if ( j != i-1 ) {
			sleepq_finish(&st->st_queues[i].st_queue);
		}
	}
err_ret0:
	return error;
#endif
}
示例#2
0
/*
 * sleeptab_init:
 *
 *	Initialize a sleep table.
 */
void
sleeptab_init(sleeptab_t *st)
{
	sleepq_t *sq;
	int i;

	for (i = 0; i < SLEEPTAB_HASH_SIZE; i++) {
		sq = &st->st_queues[i].st_queue;
		st->st_queues[i].st_mutex =
		    mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
		sleepq_init(sq);
	}
}
示例#3
0
void
console_init(struct console *console)
{
	spinlock_init(&console->c_lock, "console", SPINLOCK_FLAG_DEFAULT);

	if (console->c_putc != NULL) {
		kernel_output = console;
		printf("Switched to output console: %s\n", console->c_name);
	}

	if (console->c_getc != NULL) {
		/* XXX Push sleepq into console?  */
		if (kernel_input == NULL)
			sleepq_init(&kernel_input_sleepq, &console->c_lock);
		else
			kernel_input_sleepq.sq_lock = &console->c_lock; /* XXX Filthy.  */

		kernel_input = console;
		printf("Switched to input console: %s\n", console->c_name);
	}
}
/*
 * callout_init_cpu:
 *
 *	Per-CPU initialization.
 */
void
callout_init_cpu(struct cpu_info *ci)
{
	struct callout_cpu *cc;
	int b;

	CTASSERT(sizeof(callout_impl_t) <= sizeof(callout_t));

	if ((cc = ci->ci_data.cpu_callout) == NULL) {
		cc = kmem_zalloc(sizeof(*cc), KM_SLEEP);
		if (cc == NULL)
			panic("callout_init_cpu (1)");
		cc->cc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
		CIRCQ_INIT(&cc->cc_todo);
		for (b = 0; b < BUCKETS; b++)
			CIRCQ_INIT(&cc->cc_wheel[b]);
	} else {
		/* Boot CPU, one time only. */
		callout_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
		    callout_softclock, NULL);
		if (callout_sih == NULL)
			panic("callout_init_cpu (2)");
	}

	sleepq_init(&cc->cc_sleepq);

	snprintf(cc->cc_name1, sizeof(cc->cc_name1), "late/%u",
	    cpu_index(ci));
	evcnt_attach_dynamic(&cc->cc_ev_late, EVCNT_TYPE_MISC,
	    NULL, "callout", cc->cc_name1);

	snprintf(cc->cc_name2, sizeof(cc->cc_name2), "wait/%u",
	    cpu_index(ci));
	evcnt_attach_dynamic(&cc->cc_ev_block, EVCNT_TYPE_MISC,
	    NULL, "callout", cc->cc_name2);

	ci->ci_data.cpu_callout = cc;
}
示例#5
0
文件: main.c 项目: cfrost/buenos
void init(void)
{
    TID_t startup_thread;
    int numcpus;

    /* Initialize polling TTY driver for kprintf() usage. */
    polltty_init();

    kwrite("BUENOS is a University Educational Nutshell Operating System\n");
    kwrite("==========================================================\n");
    kwrite("\n");

    kwrite("Copyright (C) 2003-2006  Juha Aatrokoski, Timo Lilja,\n");
    kwrite("  Leena Salmela, Teemu Takanen, Aleksi Virtanen\n");
    kwrite("See the file COPYING for licensing details.\n");
    kwrite("\n");

    kwrite("Initializing memory allocation system\n");
    kmalloc_init();

    kwrite("Reading boot arguments\n");
    bootargs_init();

    /* Seed the random number generator. */
    if (bootargs_get("randomseed") == NULL) {
	_set_rand_seed(0);
    } else {
	int seed = atoi(bootargs_get("randomseed"));
	kprintf("Seeding pseudorandom number generator with %i\n", seed);
	_set_rand_seed(seed);
    }

    numcpus = cpustatus_count();
    kprintf("Detected %i CPUs\n", numcpus);
    KERNEL_ASSERT(numcpus <= CONFIG_MAX_CPUS);

    kwrite("Initializing interrupt handling\n");
    interrupt_init(numcpus);

    kwrite("Initializing threading system\n");
    thread_table_init();

    kwrite("Initializing user process system\n");
    process_init();

    kwrite("Initializing sleep queue\n");
    sleepq_init();

    kwrite("Initializing semaphores\n");
    semaphore_init();

    kwrite("Initializing device drivers\n");
    device_init();

    kprintf("Initializing virtual filesystem\n");
    vfs_init();

    kwrite("Initializing scheduler\n");
    scheduler_init();

    kwrite("Initializing virtual memory\n");
    vm_init();

    kprintf("Creating initialization thread\n");
    startup_thread = thread_create(&init_startup_thread, 0);
    thread_run(startup_thread);

    kprintf("Starting threading system and SMP\n");

    /* Let other CPUs run */
    kernel_bootstrap_finished = 1;
    
    _interrupt_clear_bootstrap();
    _interrupt_enable();

    /* Enter context switch, scheduler will be run automatically,
       since thread_switch() behaviour is identical to timer tick
       (thread timeslice is over). */
    thread_switch();

    /* We should never get here */
    KERNEL_PANIC("Threading system startup failed.");
}
示例#6
0
文件: main.c 项目: JanmanX/KUDOS
void init(void)
{
    TID_t startup_thread;
    int numcpus;

    /* Initialise Static Allocation */
    stalloc_init();

    /* Initialize polling TTY driver for kprintf() usage. */
    polltty_init();

    kwrite("Kudos is an educational operating system by the University of Copenhagen\n");
    kwrite("========================================================================\n");
    kwrite("Based on the Buenos operating system skeleton\n");
    kwrite("\n");

    kprintf("Copyright (C) 2003-2016  Juha Aatrokoski, Timo Lilja,\n");
    kprintf("  Leena Salmela, Teemu Takanen, Aleksi Virtanen, Philip Meulengracht,\n");
    kprintf("  Troels Henriksen, Annie Jane Pinder, Niels Gustav Westphal Serup,\n");
    kprintf("  Nicklas Warming Jacobsen, Oleksandr Shturmov.\n");
    kwrite("See the file COPYING for licensing details.\n");
    kwrite("\n");

    kwrite("Reading boot arguments\n");
    bootargs_init((void*)BOOT_ARGUMENT_AREA);

    /* Seed the random number generator. */
    if (bootargs_get("randomseed") == NULL) {
        _set_rand_seed(0);
    } else {
        int seed = atoi(bootargs_get("randomseed"));
        kprintf("Seeding pseudorandom number generator with %i\n", seed);
        _set_rand_seed(seed);
    }

    numcpus = cpustatus_count();
    kprintf("Detected %i CPUs\n", numcpus);
    KERNEL_ASSERT(numcpus <= CONFIG_MAX_CPUS);

    kwrite("Initializing interrupt handling\n");
    interrupt_init(numcpus);

    kwrite("Initializing threading system\n");
    thread_table_init();

    kwrite("Initializing sleep queue\n");
    sleepq_init();

    kwrite("Initializing semaphores\n");
    semaphore_init();

    kwrite("Initializing device drivers\n");
    device_init();

    kprintf("Initializing virtual filesystem\n");
    vfs_init();

    kwrite("Initializing scheduler\n");
    scheduler_init();

    kwrite("Initializing virtual memory\n");
    vm_init();

    kprintf("Creating initialization thread\n");
    startup_thread = thread_create(&init_startup_thread, 0);
    thread_run(startup_thread);

    kprintf("Starting threading system and SMP\n");

    /* Let other CPUs run */
    kernel_bootstrap_finished = 1;

    _interrupt_clear_bootstrap();
    _interrupt_enable();

    /* Enter context switch, scheduler will be run automatically,
       since thread_switch() behaviour is identical to timer tick
       (thread timeslice is over). */
    thread_switch();

    /* We should never get here */
    KERNEL_PANIC("Threading system startup failed.");
}
示例#7
0
文件: main.c 项目: DIKU-EDU/kudos
int init(uint64_t magic, uint8_t *multiboot)
{
  /* Setup Static Allocation System */
  multiboot_info_t *mb_info = (multiboot_info_t*)multiboot;
  TID_t startup_thread;
  stalloc_init();

  /* Setup video printing */
  polltty_init();

  kwrite("KUDOS - a skeleton OS for exploring OS concepts\n");
  kwrite("===============================================\n");
  kwrite("\n");
  kwrite("KUDOS is heavily based on BUENOS.\n");
  kwrite("\n");
  kwrite("Copyright (C) 2015-2016 Troels Henriksen, Annie Jane Pinder,\n");
  kwrite("      Niels Gustav Westphal Serup, Oleksandr Shturmov,\n");
  kwrite("      Nicklas Warming Jacobsen.\n");
  kwrite("\n");
  kwrite("Copyright (C) 2014 Philip Meulengracht.\n");
  kwrite("\n");
  kwrite("Copyright (C) 2003-2012 Juha Aatrokoski, Timo Lilja,\n");
  kwrite("      Leena Salmela, Teemu Takanen, Aleksi Virtanen.\n");
  kwrite("\n");
  kwrite("See the file COPYING for licensing details.\n");
  kwrite("\n");

  /* Setup GDT/IDT/Exceptions */
  kprintf("Initializing interrupt handling\n");
  interrupt_init(1);

  /* Read boot args */
  kprintf("Reading boot arguments\n");
  bootargs_init((void*)(uint64_t)mb_info->cmdline);

  /* Setup Memory */
  kprintf("Initializing memory system\n");
  physmem_init(multiboot);
  vm_init();

  /* Seed the random number generator. */
  if (bootargs_get("randomseed") == NULL) {
    _set_rand_seed(0);
  } else {
    int seed = atoi((char*)(uint64_t)bootargs_get("randomseed"));
    kprintf("Seeding pseudorandom number generator with %i\n", seed);
    _set_rand_seed(seed);
  }

  /* Setup Threading */
  kprintf("Initializing threading table\n");
  thread_table_init();

  kprintf("Initializing sleep queue\n");
  sleepq_init();

  kprintf("Initializing semaphores\n");
  semaphore_init();

  /* Start scheduler */
  kprintf("Initializing scheduler\n");
  scheduler_init();

  /* Setup Drivers */
  kprintf("Initializing device drivers\n");
  device_init();

  /* Initialize modules */
  kprintf("Initializing kernel modules\n");
  modules_init();

  kprintf("Initializing virtual filesystem\n");
  vfs_init();

  kprintf("Creating initialization thread\n");
  startup_thread = thread_create(init_startup_thread, 0);
  thread_run(startup_thread);

  kprintf("Starting threading system and SMP\n");

  /* Enter context switch, scheduler will be run automatically,
     since thread_switch() behaviour is identical to timer tick
     (thread timeslice is over). */
  thread_switch();

  return 0xDEADBEEF;
}