Пример #1
0
int main (int argc, char** argv) {
  assert (NUM_PRODUCERS == NUM_CONSUMERS);

  spinlock_create(&item_lock);
  spinlock_create(&producer_wait_count_lock);
  spinlock_create(&consumer_wait_count_lock);

  uthread_init(NUM_PRODUCERS + NUM_CONSUMERS);
  uthread_t producers[NUM_PRODUCERS];
  uthread_t consumers[NUM_CONSUMERS];

  for (int i = 0; i < NUM_PRODUCERS; i++) {
    consumers[i] = uthread_create(consumer, NULL);
    producers[i] = uthread_create(producer, NULL);
  }

  for (int i = 0; i < NUM_PRODUCERS; i++) {
    uthread_join(consumers[i], NULL);
    uthread_join(producers[i], NULL);
  }

  printf("Producer Wait Time: %d\t\tConsumer Wait Time: %d\n",
         producer_wait_count, consumer_wait_count);

  printf("Histogram: [ ");
  int sum = 0;
  for (int i = 0; i < MAX_ITEMS + 1; i++) {
    sum += histogram[i];
    printf("%d ", histogram[i]);
  }
  printf("]\tSum: %d\n", sum);
}
Пример #2
0
/**
 * See header
 */
void utils_init()
{
#ifdef WIN32
	windows_init();
#endif

#if !defined(HAVE_GCC_ATOMIC_OPERATIONS) && !defined(HAVE_GCC_SYNC_OPERATIONS)
	ref_lock = spinlock_create();
	cas_lock = spinlock_create();
#endif

	strerror_init();
}
Пример #3
0
int main (int argc, char** argv) {
  // TODO create threads to run the producers and consumers
  spinlock_create(&lock);
  uthread_init(4);
  uthread_t producerThread1;
  uthread_t producerThread2;
  uthread_t consumerThread1;
  uthread_t consumerThread2;
  producerThread1 = uthread_create(producer, 0);
  producerThread2 = uthread_create(producer, 0);
  consumerThread1 = uthread_create(consumer, 0);
  consumerThread2 = uthread_create(consumer, 0);
  uthread_join(producerThread1, 0);
  uthread_join(producerThread2, 0);
  uthread_join(consumerThread1, 0);
  uthread_join(consumerThread2, 0);
  printf("Producer wait: %d\nConsumer wait: %d\n",
         producer_wait_count, consumer_wait_count);
  for(int i=0;i<MAX_ITEMS+1;i++)
    printf("items %d count %d\n", i, histogram[i]);
/*   uthread_join(producerThread1, 0);
  uthread_join(producerThread2, 0);
  uthread_join(consumerThread1, 0);
  uthread_join(consumerThread2, 0); */
}
Пример #4
0
aio_client_t* aio_client_create(const char* host, int port, struct aio_client_handler_t* handler, void* param)
{
	size_t len;
	struct aio_client_t* client;

	len = strlen(host ? host : "");
	if (len < 1) return NULL;

	client = (struct aio_client_t*)calloc(1, sizeof(*client) + len + 1);
	if (!client) return NULL;

	client->ref = 1;
	client->port = port;
	client->host = (char*)(client + 1);
	memcpy(client->host, host, len + 1);
	
	spinlock_create(&client->locker);
	client->socket = invalid_aio_socket;
	client->ctimeout = TIMEOUT_CONN;
	client->rtimeout = TIMEOUT_RECV;
	client->wtimeout = TIMEOUT_SEND;
	
	client->param = param;
	memcpy(&client->handler, handler, sizeof(client->handler));
	return client;
}
Пример #5
0
struct workqueue *workqueue_create(struct workqueue *wq, int flags)
{
	KOBJ_CREATE(wq, flags, WORKQUEUE_KMALLOC);
	heap_create(&wq->tasks, HEAP_LOCKLESS, HEAPMODE_MAX);
	spinlock_create(&wq->lock);
	return wq;
}
Пример #6
0
struct ticker *ticker_create(struct ticker *ticker, int flags)
{
	KOBJ_CREATE(ticker, flags, TICKER_KMALLOC);
	ticker->tick = 0;
	heap_create(&ticker->heap, HEAP_LOCKLESS, HEAPMODE_MIN);
	spinlock_create(&ticker->lock);
	return ticker;
}
Пример #7
0
struct stack *stack_create(struct stack *stack, int flags)
{
	KOBJ_CREATE(stack, flags, STACK_KMALLOC);
	spinlock_create(&stack->lock);
	memset(&__sentry, 0, sizeof(__sentry));
	stack->top = &__sentry;
	return stack;
}
Пример #8
0
int module_install(void)
{
	printk(1, "[keyboard]: Driver loading\n");
	spinlock_create(&lock);
	irqk = cpu_interrupt_register_handler(IRQ1, __int_handle);
	flush_port();
	keyboard_major = dm_device_register(&kbkd);
	sys_mknod("/dev/keyboard", S_IFCHR | 0644, GETDEV(keyboard_major, 0));
	printk(1, "[keyboard]: initialized keyboard\n");
	return 0;
}
Пример #9
0
void disk_start (void (*interruptServiceRoutine) ()) {
  isr = interruptServiceRoutine;
  spinlock_create (&prq_mutex);
  sigemptyset (& TIMER_SIGSET);
  sigaddset   (& TIMER_SIGSET, TIMER_SIGNO);
  struct sigaction sa;
  sa .sa_sigaction = handleTimerInterrupt;
  sigemptyset (& sa .sa_mask);
  sa .sa_flags     = SA_SIGINFO;
  int ok = sigaction (TIMER_SIGNO, &sa, NULL);
  if (ok == -1) {
    printf ("DISK sigaction: %s\n", strerror (errno));
    exit (EXIT_FAILURE);
  }
  ualarm (READ_LATENCY_USEC / 10, READ_LATENCY_USEC / 10);
}
Пример #10
0
void arch_cpu_processor_init_1(void)
{
#if _DBOS_KERNEL_HAVE_CPU_SMP
	primary_cpu = &cpu_array[0];
	primary_cpu->knum = 0;
	spinlock_create(&ipi_lock);
	memset(cpu_array, 0, sizeof(struct cpu) * MAX_CPUS);
	cpu_array_num = 1;
	load_tables_ap(primary_cpu);
#else
	primary_cpu = &primary_cpu_data;
	memset(primary_cpu, 0, sizeof(struct cpu) * MAX_CPUS);
	load_tables_ap(primary_cpu);
#endif
	ASSERT(primary_cpu);
	cpu_interrupt_set(0);
	primary_cpu->flags = CPU_UP;
	printk(KERN_MSG, "Initializing CPU...\n");
	parse_cpuid(primary_cpu);
	x86_cpu_init_fpu(primary_cpu);
	x86_cpu_init_sse(primary_cpu);
	printk(KERN_EVERY, "Done\n");
}
Пример #11
0
void tm_init_multitasking(void)
{
	printk(KERN_DEBUG, "[sched]: Starting multitasking system...\n");
	sysgate_page = mm_physical_allocate(PAGE_SIZE, true);
	mm_physical_memcpy((void *)sysgate_page,
				(void *)signal_return_injector, MEMMAP_SYSGATE_ADDRESS_SIZE, PHYS_MEMCPY_MODE_DEST);

	process_table = hash_create(0, 0, 128);

	process_list = linkedlist_create(0, LINKEDLIST_MUTEX);
	mutex_create(&process_refs_lock, 0);
	mutex_create(&thread_refs_lock, 0);
	
	thread_table = hash_create(0, 0, 128);

	struct thread *thread = kmalloc(sizeof(struct thread));
	struct process *proc = kernel_process = kmalloc(sizeof(struct process));

	proc->refs = 2;
	thread->refs = 1;
	hash_insert(process_table, &proc->pid, sizeof(proc->pid), &proc->hash_elem, proc);
	hash_insert(thread_table, &thread->tid, sizeof(thread->tid), &thread->hash_elem, thread);
	linkedlist_insert(process_list, &proc->listnode, proc);

	valloc_create(&proc->mmf_valloc, MEMMAP_MMAP_BEGIN, MEMMAP_MMAP_END, PAGE_SIZE, 0);
	linkedlist_create(&proc->threadlist, 0);
	mutex_create(&proc->map_lock, 0);
	mutex_create(&proc->stacks_lock, 0);
	mutex_create(&proc->fdlock, 0);
	hash_create(&proc->files, HASH_LOCKLESS, 64);
	proc->magic = PROCESS_MAGIC;
	blocklist_create(&proc->waitlist, 0, "process-waitlist");
	mutex_create(&proc->fdlock, 0);
	memcpy(&proc->vmm_context, &kernel_context, sizeof(kernel_context));
	thread->process = proc; /* we have to do this early, so that the vmm system can use the lock... */
	thread->state = THREADSTATE_RUNNING;
	thread->magic = THREAD_MAGIC;
	workqueue_create(&thread->resume_work, 0);
	thread->kernel_stack = (addr_t)&initial_kernel_stack;
	spinlock_create(&thread->status_lock);

	primary_cpu->active_queue = tqueue_create(0, 0);
	primary_cpu->idle_thread = thread;
	primary_cpu->numtasks=1;
	ticker_create(&primary_cpu->ticker, 0);
	workqueue_create(&primary_cpu->work, 0);
	tm_thread_add_to_process(thread, proc);
	tm_thread_add_to_cpu(thread, primary_cpu);
	atomic_fetch_add_explicit(&running_processes, 1, memory_order_relaxed);
	atomic_fetch_add_explicit(&running_threads, 1, memory_order_relaxed);
	set_ksf(KSF_THREADING);
	*(struct thread **)(thread->kernel_stack) = thread;
	primary_cpu->flags |= CPU_RUNNING;

#if CONFIG_MODULES
	loader_add_kernel_symbol(tm_thread_delay_sleep);
	loader_add_kernel_symbol(tm_thread_delay);
	loader_add_kernel_symbol(tm_timing_get_microseconds);
	loader_add_kernel_symbol(tm_thread_set_state);
	loader_add_kernel_symbol(tm_thread_exit);
	loader_add_kernel_symbol(tm_thread_poke);
	loader_add_kernel_symbol(tm_thread_block);
	loader_add_kernel_symbol(tm_thread_got_signal);
	loader_add_kernel_symbol(tm_thread_unblock);
	loader_add_kernel_symbol(tm_blocklist_wakeall);
	loader_add_kernel_symbol(kthread_create);
	loader_add_kernel_symbol(kthread_wait);
	loader_add_kernel_symbol(kthread_join);
	loader_add_kernel_symbol(kthread_kill);
	loader_add_kernel_symbol(tm_schedule);
	loader_add_kernel_symbol(arch_tm_get_current_thread);
#endif
}