Exemplo n.º 1
0
TEST_F(TransactionTests, AbortTest) {
  for (auto test_type : TEST_TYPES) {
    concurrency::TransactionManagerFactory::Configure(test_type);
    auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
    std::unique_ptr<storage::DataTable> table(
        TransactionTestsUtil::CreateTable());
    {
      TransactionScheduler scheduler(2, table.get(), &txn_manager);
      scheduler.Txn(0).Update(0, 100);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(0);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      EXPECT_EQ(RESULT_ABORTED, scheduler.schedules[0].txn_result);
      EXPECT_EQ(RESULT_SUCCESS, scheduler.schedules[1].txn_result);
      //printf("==========result=%d\n", int(scheduler.schedules[1].results[0]));
      EXPECT_EQ(0, scheduler.schedules[1].results[0]);
    }

    {
      TransactionScheduler scheduler(2, table.get(), &txn_manager);
      scheduler.Txn(0).Insert(100, 0);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(100);
      scheduler.Txn(1).Commit();

      scheduler.Run();
      EXPECT_EQ(RESULT_ABORTED, scheduler.schedules[0].txn_result);
      EXPECT_EQ(RESULT_SUCCESS, scheduler.schedules[1].txn_result);
      EXPECT_EQ(-1, scheduler.schedules[1].results[0]);
    }
  }
}
Exemplo n.º 2
0
TEST_F(MVCCTest, AbortVersionChainTest) {
  LOG_INFO("AbortVersionChainTest");

  for (auto protocol : TEST_TYPES) {
    concurrency::TransactionManagerFactory::Configure(
        protocol, ISOLATION_LEVEL_TYPE_FULL);

    auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
    std::unique_ptr<storage::DataTable> table(
        TransactionTestsUtil::CreateTable());
    {
      TransactionScheduler scheduler(2, table.get(), &txn_manager);
      scheduler.Txn(0).Update(0, 100);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(0);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      ValidateMVCC_OldToNew(table.get());
    }

    {
      TransactionScheduler scheduler(2, table.get(), &txn_manager);
      scheduler.Txn(0).Insert(100, 0);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(100);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      ValidateMVCC_OldToNew(table.get());
    }
  }
}
Exemplo n.º 3
0
/**********************************************************************
												 TLB_HANDLER

	Caricato all'arrivo di una eccezione di tipo TLBTRAP.
	Affida il controllo del thread corrente ad un Trap Manager, se 
	specificato, altrimenti viene terminato tutto	il sottoalbero 
	corrispondente.

**********************************************************************/
void tlb_handler(){

	tcb_t *manager;

	/* TUTTE le operazioni sono equivalenti a quelle per SYSBP */
	current_thread->cpu_slice += (GET_TODLOW - current_thread_tod);
	current_thread->cpu_time += (GET_TODLOW - current_thread_tod);

	save_state(tlbtrap_oldarea, &(current_thread->t_state));

	manager = current_thread->tlbtrap_manager_thread;

	if (manager == NULL) {
		terminate(current_thread);
		current_thread = NULL;

		scheduler();
	}


	else {

		send(current_thread, manager, tlbtrap_oldarea->cause);

		current_thread->waiting_for = manager;

		insertThread(&wait_queue, current_thread);

		current_thread = NULL;

		scheduler();
	}

}
TEST_F(SerializableTransactionTests, AbortTest) {
  for (auto protocol_type : PROTOCOL_TYPES) {
    concurrency::TransactionManagerFactory::Configure(protocol_type);
    auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
    storage::DataTable *table = TestingTransactionUtil::CreateTable();
    {
      TransactionScheduler scheduler(2, table, &txn_manager);
      scheduler.Txn(0).Update(0, 100);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(0);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      EXPECT_EQ(ResultType::ABORTED, scheduler.schedules[0].txn_result);
      EXPECT_EQ(ResultType::SUCCESS, scheduler.schedules[1].txn_result);
      EXPECT_EQ(0, scheduler.schedules[1].results[0]);
    }

    {
      TransactionScheduler scheduler(2, table, &txn_manager);
      scheduler.Txn(0).Insert(100, 0);
      scheduler.Txn(0).Abort();
      scheduler.Txn(1).Read(100);
      scheduler.Txn(1).Commit();

      scheduler.Run();
      EXPECT_EQ(ResultType::ABORTED, scheduler.schedules[0].txn_result);
      EXPECT_EQ(ResultType::SUCCESS, scheduler.schedules[1].txn_result);
      EXPECT_EQ(-1, scheduler.schedules[1].results[0]);
    }
  }
}
void DirtyReadTest() {
  auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
  std::unique_ptr<storage::DataTable> table(
      TransactionTestsUtil::CreateTable());

  {
    TransactionScheduler scheduler(2, table.get(), &txn_manager);

    // T1 updates (0, ?) to (0, 1)
    // T2 reads (0, ?)
    // T1 commit
    // T2 commit
    scheduler.Txn(0).Update(0, 1);
    scheduler.Txn(1).Read(0);
    scheduler.Txn(0).Commit();
    scheduler.Txn(1).Commit();

    scheduler.Run();

    if (RESULT_SUCCESS == scheduler.schedules[0].txn_result &&
        RESULT_SUCCESS == scheduler.schedules[1].txn_result) {
      // Don't read uncommited value
      EXPECT_EQ(0, scheduler.schedules[1].results[0]);
    }
  }

  {
    TransactionScheduler scheduler(2, table.get(), &txn_manager);

    scheduler.Txn(0).Update(1, 1);
    scheduler.Txn(1).Read(1);
    scheduler.Txn(1).Commit();
    scheduler.Txn(0).Commit();

    scheduler.Run();

    if (RESULT_SUCCESS == scheduler.schedules[0].txn_result &&
        RESULT_SUCCESS == scheduler.schedules[1].txn_result) {
      // Don't read uncommited value
      EXPECT_EQ(0, scheduler.schedules[1].results[0]);
    }
  }

  {
    TransactionScheduler scheduler(2, table.get(), &txn_manager);

    scheduler.Txn(0).Delete(2);
    scheduler.Txn(1).Read(2);
    scheduler.Txn(0).Commit();
    scheduler.Txn(1).Commit();

    scheduler.Run();

    if (RESULT_SUCCESS == scheduler.schedules[0].txn_result &&
        RESULT_SUCCESS == scheduler.schedules[1].txn_result) {
      // Don't read uncommited value
      EXPECT_EQ(0, scheduler.schedules[1].results[0]);
    }
  }
}
Exemplo n.º 6
0
/* Nota, hay que mandarle el EOI al PIC porque scheduler() NO vuelve,
 * Si no le mandamos el EOI nosotros no se lo manda nadie.
 * Además, hay que mandarle el EOI antes de hacer el cambio de contexto,
 * si lo hacemos después lo vamos a estar haciendo dos veces.
 * Una vez cuando nos vuelve a tocar la ejecución y volvemos de scheduler()
 * y la otra cuando volvemos al despachador de interrupciones.
 */
int timer( struct registers *r ) {
#define TIEMPO_ACTUALIZCION 10  //Totalmente arbitrario
    if (tarea_activa == -1) {
        pic8259A_send_EOI( r->nro );
        scheduler();
    }

    //Referente a la actualizacion de pantalla activa
    /*++contador_actualizar_pantalla;
    if(contador_actualizar_pantalla > TIEMPO_ACTUALIZCION) {
    	contador_actualizar_pantalla = 0;
    	if( tarea_en_pantalla != -1 )mostrar_slot(tarea_en_pantalla+1);
    }*/


    //Referente a la decrementacion de quantum de tarea_activa
    //Decrementamos quantum
    --tareas[tarea_activa].quantum_actual;

    //si termino, reestablecemos y cambiamos a la proxima llamando a scheduler
    if (tareas[tarea_activa].quantum_actual<=0) {
        //Restablecemos quantums gastado
        tareas[tarea_activa].quantum_actual = tareas[tarea_activa].quantum_fijo;
        //Llamamos al scheduler para que elija proxima tarea
        pic8259A_send_EOI( r->nro );
        scheduler();
    }

    return 0;
}
Exemplo n.º 7
0
bool IncidenceChanger::changeIncidence( Incidence *oldinc, Incidence *newinc,
                                        int action, bool counter )
{
kdDebug(5850)<<"IncidenceChanger::changeIncidence for incidence \""<<newinc->summary()<<"\" ( old one was \""<<oldinc->summary()<<"\")"<<endl;
  if( incidencesEqual( newinc, oldinc ) ) {
    // Don't do anything
    kdDebug(5850) << "Incidence not changed\n";
    if ( counter ) {
      KCal::MailScheduler scheduler( mCalendar );
      scheduler.performTransaction( newinc, Scheduler::Reply );
    }
  } else {
    kdDebug(5850) << "Incidence changed\n";
    bool statusChanged = myAttendeeStatusChanged( oldinc, newinc );
    int revision = newinc->revision();
    newinc->setRevision( revision + 1 );
    // FIXME: Use a generic method for this! Ideally, have an interface class
    //        for group cheduling. Each implementation could then just do what
    //        it wants with the event. If no groupware is used,use the null
    //        pattern...
    bool revert = KOPrefs::instance()->mUseGroupwareCommunication;
    if ( !counter && revert &&
        KOGroupware::instance()->sendICalMessage( 0,
                                                  KCal::Scheduler::Request,
                                                  newinc, false, statusChanged ) ) {
      // Accept the event changes
      if ( action<0 ) {
        emit incidenceChanged( oldinc, newinc );
      } else {
        emit incidenceChanged( oldinc, newinc, action );
      }
      revert = false;
    }
    if ( counter && revert ) {
      // pseudo counter as done by outlook
      Event *e = dynamic_cast<Event*>( newinc );
      if ( e ) {
        Incidence* tmp = oldinc->clone();
        tmp->setSummary( i18n("Counter proposal: %1").arg( e->summary() ) );
        tmp->setDescription( e->description() );
        tmp->addComment( i18n("Proposed new meeting time: %1 - %2").arg( e->dtStartStr() ).arg( e->dtEndStr() ) );
        KCal::MailScheduler scheduler( mCalendar );
        scheduler.performTransaction( tmp, Scheduler::Reply );
      } else {
        kdWarning(5850) << k_funcinfo << "Counter proposals only supported for events" << endl;
      }
    }

    if ( revert ) {
      assignIncidence( newinc, oldinc );
      return false;
    }
  }
  return true;
}
Exemplo n.º 8
0
void
interruptHandler(IntType which)
{
  switch (which) {
  case TimerInt:
    DEBUG('e', "TimerInt interruput\n");
    if(current!=NULL){
      //printf("reinserting pid %d\n",current->pid);
      l_insert(readyq,current);
    }
    else{
      //printf("current is NULL at timer interrupt\n");
    }
    scheduler();
    break;
  case ConsoleReadInt:
    DEBUG('e', "ConsoleReadInt interrupt\n");
    if(consolewait !=NULL){
      V_kt_sem(consolewait);
    }
    
    if(current!=NULL){
      l_insert(readyq,current);
    }
    scheduler();
    
    break;
  case ConsoleWriteInt:
    DEBUG('e', "ConsoleWriteInt interrupt\n");
    
    if(writeok!=NULL){
      //printf("increment writeok\n");
      
      V_kt_sem(writeok);
    }
    /*
      if(current!=NULL){
      printf("reinserting pid %d\n",p->pid);
      l_insert(readyq,*p);
      }
    */
    else{
      //printf("this shouldn't happen\n");
    }
    scheduler();
    break;
  default:
    DEBUG('e', "Unknown interrupt\n");
    scheduler();
    break;
  }
  
}
// test with concurrent transactions
TEST_F(SerializableTransactionTests, ConcurrentTransactionsTest) {
  for (auto protocol_type : PROTOCOL_TYPES) {
    concurrency::TransactionManagerFactory::Configure(protocol_type, ISOLATION_LEVEL_TYPE);
    auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
    {
      concurrency::EpochManagerFactory::GetInstance().Reset();
      storage::DataTable *table = TestingTransactionUtil::CreateTable();
      
      TransactionScheduler scheduler(2, table, &txn_manager);
      scheduler.Txn(0).Insert(100, 1);
      scheduler.Txn(1).Read(100);
      scheduler.Txn(0).Read(100);
      scheduler.Txn(0).Commit();
      scheduler.Txn(1).Read(100);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      EXPECT_EQ(ResultType::SUCCESS, scheduler.schedules[0].txn_result);
      EXPECT_EQ(ResultType::SUCCESS, scheduler.schedules[1].txn_result);
      
      EXPECT_EQ(1, scheduler.schedules[0].results[0]);
      EXPECT_EQ(-1, scheduler.schedules[1].results[0]);
      // TODO: phantom problem. 
      // In fact, txn 1 should not see the inserted tuple.
      EXPECT_EQ(1, scheduler.schedules[1].results[1]);
    }

    {
      concurrency::EpochManagerFactory::GetInstance().Reset();
      storage::DataTable *table = TestingTransactionUtil::CreateTable();
      
      TransactionScheduler scheduler(2, table, &txn_manager);
      scheduler.Txn(0).Update(0, 1);
      scheduler.Txn(1).Read(0);
      scheduler.Txn(0).Read(0);
      scheduler.Txn(0).Commit();
      scheduler.Txn(1).Read(0);
      scheduler.Txn(1).Commit();

      scheduler.Run();

      EXPECT_EQ(ResultType::SUCCESS, scheduler.schedules[0].txn_result);
      EXPECT_EQ(ResultType::ABORTED, scheduler.schedules[1].txn_result);
      
      EXPECT_EQ(1, scheduler.schedules[0].results[0]);
    }
  }
}
Exemplo n.º 10
0
void
Region::UpdateSound() {

	std::string sound = params.sound;

	std::map<std::string,Sound>::iterator it = Sounds.find(sound);
	if ( it == Sounds.end() ) {
		NosuchDebug("Hey, Updatesound found invalid sound, region=%d sound=%s",id,sound.c_str());
		return;
	}

	NosuchDebug(1,"Region::UpdateSound region=%d sound=%s",
		id,params.sound.c_str());

	int ch = palette->findSoundChannel(sound,id);
	if ( ch < 0 ) {
		NosuchDebug("Region::UpdateSound Unable to find channel for sound=%s, using existing channel 1",sound.c_str());
		ch = 1;
	}
	if ( ch != _channel ) {
		NosuchDebug(1,"Existing channel for region %d is %d, new channel needs to be %d",
			id,_channel,ch);
		// Tempting to send ANO for the old channel, but the whole point
		// of the dynamic channel stuff is to avoid the need to cut off
		// old sounds when changing to new ones.
		_channel = ch;
		// Send ANO on the new channel, to terminate
		// anything currently playing there.
		scheduler()->ANO(_channel);
	} else {
		NosuchDebug(1,"Existing channel for region %d is %d",id,_channel);
	}
	MidiProgramChange* msg = Sound::ProgramChangeMsg(_channel,sound);
	if ( msg == NULL ) {
		NosuchDebug("HEY!! ProgramChangeMsg returned null for sound=%s",sound.c_str());
		return;
	}
	NosuchDebug("CHANGE rgn=%d sound=%s ch=%d",
		id,sound.c_str(),ch);
	NosuchDebug(1,"   progchange=%s", msg->DebugString().c_str());
	int loopid;
	if ( _loop == NULL )
		loopid = -1;
	else
		loopid = _loop->id();
	scheduler()->SendMidiMsg(msg,loopid);
	Sleep(150);  // Lame attempt to avoid Alchemy bug when it gets lots of Program Change messages
}
Exemplo n.º 11
0
void useExStVec(int type){
    if(currentProcess!=NULL)  {
        /* Se ho già fatto spectrapvec per il tipo di eccezione*/
        if (currentProcess->excStVec[type*2]!=NULL){
            /* Salvo lo stato nella oldarea adeguata*/
            switch(type){
                case SPECTLB:
                	saveStateIn(tlb_old, currentProcess->excStVec[type*2]);
                    break;
                case SPECPGMT:
                	saveStateIn(pgmtrap_old, currentProcess->excStVec[type*2]);
                    break;
                case SPECSYSBP:
                	saveStateIn(sysbp_old, currentProcess->excStVec[type*2]);
                    break;
            }
            /* Carico lo stato dalla newarea */
            LDST(currentProcess->excStVec[(type*2)+1]);
        }else{
           /* Altrimenti tratto come una SYS2  */
           terminateProcess(currentProcess); 
           scheduler();
        }
    } 
}
Exemplo n.º 12
0
int main (int argc, char *argv []) {
    int listen_fd, port;
    int client_fd;
    socklen_t socket_length;
    struct sockaddr_in client_socket;

    pthread_mutex_init(&mutex_lock, NULL);
    init_cache();
    Signal (SIGPIPE, SIG_IGN);
    if (argc != 2) {
	    fprintf(stderr, "usage: %s <port>\n", argv[0]);
	    exit(0);
    }

    port = atoi(argv[1]);
    listen_fd = Open_listenfd(port);
    socket_length = sizeof(client_socket);

    while (1) {
        client_fd = Accept(listen_fd, (SA*)&client_socket, &socket_length);   
        scheduler(client_fd);
    }
    pthread_mutex_destroy(&mutex_lock);
    clean_cache();
}
Exemplo n.º 13
0
/* Does not return - goes to scheduler */
void
GCFromMutator(Thread_t* curThread)
{
	Proc_t *proc = (Proc_t *) curThread->proc;
	mem_t alloc = (mem_t) curThread->saveregs[ALLOCPTR];
	mem_t limit = (mem_t) curThread->saveregs[ALLOCLIMIT];
	mem_t sysAllocLimit = proc->allocLimit;

	/* Put registers in stacklet */
	int i;
	Stacklet_t *stacklet = CurrentStacklet(curThread->stack);
	volatile reg_t* primaryRegs =
		&stacklet->bottomBaseRegs[primaryStackletOffset == 0 ? 0 : 32];
	for (i=0; i<32; i++)
		primaryRegs[i] = curThread->saveregs[i];

	/*
		Check that we are running on own stack and allocation pointers
		consistent
	*/
	if (paranoid)
		assert(proc == (getProc())); /* getProc is slow */
	assert(proc->userThread == curThread);
	assert((proc->stack - (int) (&proc)) < 1024) ;
	assert((limit == sysAllocLimit) || (limit == StopHeapLimit));
	assert(alloc <= sysAllocLimit);

	/* ReleaseJob(proc) */
	/* Update processor's info, GCRelease thread, but don't unmap */
	UpdateJob(proc);
	procChangeState(proc, Scheduler, 1003);
	scheduler(proc);
	DIE("scheduler returned");
}
Exemplo n.º 14
0
// This is executed as part of the current running thread
// Activities to be done :
// 1. System time updating.
// 2. Timer object value decrementing and setting the flag
//    for time out event processing.
// 3. Set if necessary priority recomputation flag.
// 4. Update the time quantum left and cpu usage for the current thread.
//    If necessary call the scheduler function after enablig the timer.
// flags : runrun, kprunrun, priocompute, timeoutflag
void timer_handler (int irq)
{
    unsigned long oflags;

    /* Update system time value. HZ = 50 */
    millesecs += 20;
    if (millesecs >= 1000)
    {
        secs++;
        millesecs -= 1000;
        priocompute = 1;// Once in every one second recompute
        //priorities by applying decay factor.
    }

    // Without locking only the first timer object is observed.
    if (timers != NULL)
    {
        timers->timer_count -=  20;
        if (timers->timer_count <= 0) timeoutflag = 1;
    }

    // Update current thread cpu usage statistics
    rr_cl_tick((struct kthread *)current_thread);
    if (current_thread->kt_schedinf.sc_tqleft <= 0 || runrun == 1 || kprunrun == 1)
    {
        // Start scheduler function
        CLI;
        enable_timer();
        scheduler();
        STI;
    }
    return;
}
Exemplo n.º 15
0
// Not possible to add tasks in a scheduled task atm
void
schedule5(TaskManager::ThreadManager& manager) {
    TaskManager::Scheduler scheduler(2, manager);
    bool stop = false;

    std::this_thread::sleep_for(std::chrono::milliseconds(10));

    TaskManager::Task task([&stop, &scheduler]() {
        unsigned int i = 1;
        while (!stop) {
            auto future = scheduler.runIn([i]() {
                return std::to_string(i) + " second elapsed";
            },
            std::chrono::milliseconds(60));
            std::cout << future.get() << " " << (int)stop << std::endl;
            ++i;
        }
    });
    task.setStopFunction([&stop]() {
        stop = true;
    });
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
    scheduler.runAt(task, std::chrono::steady_clock::now());
    getchar();
}
Exemplo n.º 16
0
void start_scheduler()
{
    SchedulerTask.sigint_handler = NULL;
    SchedulerTask.tss.cr3 = (uint32_t)PAGE_DIR;
    SchedulerTask.tss.eflags = 0xE0000011;
    GDT[7].limit_low = 0x67;
    GDT[7].base_low = (uint32_t)&SchedulerTask.tss & 0xFFFF;
    GDT[7].base_mid = ((uint32_t)&SchedulerTask.tss & 0xFF0000) >> 16;
    GDT[7]._FIXED_0 = 9;
    GDT[7]._FIXED_1 = 0;
    GDT[7].priv_level = 0;
    GDT[7].present = 1;
    GDT[7].limit_high = 0;
    GDT[7].AVL_to_sys = 0;
    GDT[7]._FIXED_2 = 0;
    GDT[7].big = 0;
    GDT[7].granularity = 0;
    GDT[7].base_high = (uint32_t)&SchedulerTask.tss >> 24;
    __asm__ volatile(
        ".intel_syntax noprefix;"
        "ltr ax;"
        ".att_syntax;"
        ::"a"(7 << 3):
    );
    scheduler();
}
Exemplo n.º 17
0
void dispatcher_body()
{
  int err, t0, t1;
  task_t* next; // Tarefa que ocupara o processador.

  enable_preemption(0);

  // Caso haver alguma tarefa na lista de prontas
  // o while eh executado.
  while (list_size(ready_list) > 0) {
    t0 = systime();
    next = scheduler();

    if (next) {
      ticks = 20;
      enable_preemption(1);
      t1 = systime();
      curr_task->proc_time += t0 - t1;   
      
      t0 = systime();
      err = task_switch(next); 
      t1 = systime();
      
      next->proc_time += t1 - t0;
      
      if (err == -1) {
        perror("dispatcher_body: task_switch failed.\n");
        return;
      }
    }
  }

  // Finaliza o dispatcher, voltando para o main.
  task_exit(0);
}
Exemplo n.º 18
0
void TestScheduler(const char* msg, const PrimeMap& value, time_sec serialTime)
{
	ticks_t start = now();
	SCHEDULER scheduler(CoreCount);
	std::map<std::size_t, std::size_t> tasks;
	for (std::size_t i = 0; i < Count; i++)
	{
#ifdef VOID_TEST
		tasks[i] = scheduler.add_task([i]() -> void {Test(i); });
		tasks[MaxNum - i] = scheduler.add_task([i]() -> void {Test(MaxNum - i); });
#else
		tasks[i] = scheduler.add_task([i]() -> bool { return IsPrime(i); });
		tasks[MaxNum - i] = scheduler.add_task([i]() -> bool { return IsPrime(MaxNum - i); });
#endif
	}

	for (auto i = tasks.begin(); i != tasks.end(); ++i)
	{
#ifdef VOID_TEST
        scheduler.get_task_result(i->second);
#else
		if (value.at(i->first) != scheduler.get_task_result(i->second))
			throw 0;
#endif
	}
	time_sec parallelTime = ticks_to_time(now() - start);
	std::cout << msg << " time = " << parallelTime << " [s]  -  Serial time portion = " << parallelTime / (serialTime / 100.0) << " [%]" << std::endl;
	std::cout << msg << " calculation correct" << std::endl;
}
Exemplo n.º 19
0
    thread_pool_os_executor<Scheduler>::thread_pool_os_executor(
            std::size_t num_punits, std::string const& affinity_desc)
      : scheduler_(nullptr),
        executor_name_(get_unique_name()),
        notifier_(get_notification_policy(executor_name_.c_str())),
        pool_(nullptr),
        num_threads_(num_punits)
    {
        if (num_punits > hpx::threads::hardware_concurrency())
        {
            HPX_THROW_EXCEPTION(bad_parameter,
                "thread_pool_os_executor<Scheduler>::thread_pool_os_executor",
                "max_punit shouldn't be larger than number of available "
                "OS-threads");
            return;
        }

        std::unique_ptr<Scheduler> scheduler(new Scheduler(num_punits));
        scheduler_ = scheduler.get();

        pool_.reset(new threads::detail::scheduled_thread_pool<Scheduler>(
            std::move(scheduler), notifier_, 0, executor_name_.c_str()));

        std::unique_lock<mutex_type> lk(mtx_);
        pool_->init(num_threads_, 0);

        if (!pool_->run(lk, num_threads_))
        {
            lk.unlock();
            HPX_THROW_EXCEPTION(invalid_status,
                "thread_pool_os_executor<Scheduler>::thread_pool_os_executor",
                "couldn't start thread_pool");
        }
    }
Exemplo n.º 20
0
KOS() {
  
  /* Semaphores */
  writeOK =  make_kt_sem(0);
  writers = make_kt_sem(1);	
  readers = make_kt_sem(1);
  nElem = make_kt_sem(0);
  consoleWait = make_kt_sem(0);

  /* Generics */
  sys_stop_read = 0;
  current_pid = 0;
  console_size = 256;
  buffer_head, buffer_tail;
  
  // Zero out memory
  bzero(main_memory, MemorySize);
  bzero(memory_space_array, 8);
  
  /* Initializers */
  currentProcess = (PCB *) malloc(sizeof(PCB));
  initialize_console_buffer(&buffer_head, &buffer_tail);
  readyQ = new_dllist();
  found_node = make_jrb();
  pid_tree = make_jrb();
  kt_fork(initialize_user_process, (void *)kos_argv);
  kt_fork(console_buf_read, (void *)kos_argv[0]);
  kt_joinall();
  start_timer(10);
  scheduler();
}
Exemplo n.º 21
0
Arquivo: main.c Projeto: epsil/tunge
int main(void)
{
   wdtdrv_disable();
   Clear_prescaler();
   scheduler();
   return 0;
}
Exemplo n.º 22
0
// 다음 수행될 task를 선택하는 함수
void scheduler(void)		
{
	TaskInfo task;
	// gh_sch의 running_task가 가르키고 있는 taskinfo 받음
	task = task_get_runningtask();

	switch ( task->status ) {		
		// task상태가 TASK_RUN이나 TASK_SLEEP이면 선택됨
		case TASK_RUN:
		case TASK_SLEEP:
			break;
		// task상태가 TASK_KILL이면 delete하고, swiching함수 다시 호출
		case TASK_KILL:	
			task_delete(task);
			scheduler();
			break;
		// task상태가 TASK_YIELD이면 상태를 TASK_RUN으로 바꾸고 선택됨
		case TASK_YIELD:
			task->status = TASK_RUN;
			break;
		// task상태가 TASK_READY이면 싱테를 TASK_RUN으로 바꾸고 선택됨
		case TASK_READY:
			task->status = TASK_RUN;
			break;
	}
	// gh_sch의 running_task를 linkedlist의 다음 task로 설정
	task_next();
}
Exemplo n.º 23
0
void thread_switch()
{
	asm("pushl %eax");
	asm("pushl %ebx");
	asm("pushl %ecx");
	asm("pushl %edx");
	asm("pushl %esi");
	asm("pushl %edi");
	asm("pushl %ebp");
	asm("pushl %ebp"); 
	asm("movl %esp, spsave");

	gh_sch.running_task->sp = spsave;

	// 다음 수행될 task를 선택하는 함수
	scheduler();	
	sptmp = gh_sch.running_task->sp;

	asm("movl sptmp, %esp");
	asm("popl %ebp"); 
	asm("popl %ebp");  
	asm("popl %edi");
	asm("popl %esi");
	asm("popl %edx");
	asm("popl %ecx");
	asm("popl %ebx");
	asm("popl %eax");
}
Exemplo n.º 24
0
void kmain (void)
{
    cpu = &cpus[0];

    uart_init (P2V(UART0));

    init_vmm ();
    kpt_freerange (align_up(&end, PT_SZ), P2V_WO(INIT_KERNMAP));
    paging_init (INIT_KERNMAP, PHYSTOP);

    kmem_init ();
    kmem_init2(P2V(INIT_KERNMAP), P2V(PHYSTOP));

    trap_init ();				// vector table and stacks for models
   
    gic_init(P2V(VIC_BASE));			// arm v2 gic init
    uart_enable_rx ();				// interrupt for uart
    consoleinit ();				// console
    pinit ();					// process (locks)

    binit ();					// buffer cache
    fileinit ();				// file table
    iinit ();					// inode cache
    ideinit ();					// ide (memory block device)

#ifdef INCLUDE_REMOVED
    timer_init (HZ);				// the timer (ticker)
#endif

    sti ();
    userinit();					// first user process
    scheduler();				// start running processes
}
Exemplo n.º 25
0
DomainSet consensusDomains(WeightedDomainEnsemble& dEnsemble) {
    using PersistenceMap = map<Domain, double>;
    PersistenceMap pmap;

    for (auto dSetIdx : boost::irange(size_t{0}, dEnsemble.domainSets.size())) {
        auto& dSet = dEnsemble.domainSets[dSetIdx];
        auto weight = dEnsemble.weights[dSetIdx];
        for (auto& domain : dSet) {
            if ( pmap.find(domain) == pmap.end() ) pmap[domain] = 0;
            pmap[domain] += weight;
        }
    }

    Intervals ivals;

    for (auto domainPersistence : pmap) {
        auto domain = domainPersistence.first;
        auto persistence = domainPersistence.second;
        ivals.push_back(WeightedInterval(domain.start, domain.end, persistence));      
    }

    IntervalScheduler scheduler(ivals);
    scheduler.computeSchedule();

    DomainSet dSet;
    for (auto ival : scheduler.extractIntervals()) {
        dSet.push_back(Domain(ival.start, ival.end));
    }

    sort(dSet.begin(), dSet.end());

    return dSet;
}
Exemplo n.º 26
0
 // fmap case
 void create_graph(const paracel::list_type<paracel::str_type> & linelst,
                   paracel::bigraph<paracel::str_type> & grp,
                   paracel::dict_type<size_t, int> & dm,
                   paracel::dict_type<size_t, int> & col_dm) {
   paracel::scheduler scheduler(m_comm, pattern, mix); // TODO
   // hash lines into slotslst
   auto result = scheduler.lines_organize(linelst, parserfunc);
   std::cout << "procs " << m_comm.get_rank() << " slotslst generated" << std::endl;
   m_comm.sync();
   // alltoall exchange
   auto stf = scheduler.exchange(result);
   std::cout << "procs " << m_comm.get_rank() << " get desirable lines" << std::endl;
   m_comm.sync();
   // mapping inds to ids, get rmap, cmap, std_new...
   paracel::list_type<std::tuple<size_t, size_t, double> > stf_new;
   paracel::dict_type<size_t, paracel::str_type> rm, cm;
   scheduler.index_mapping(stf, stf_new, rm, cm, dm, col_dm);
   std::cout << "procs " << m_comm.get_rank() << " index mapping" << std::endl;
   paracel::dict_type<paracel::str_type, 
       paracel::dict_type<paracel::str_type, double> > dct;
   for(auto & tpl : stf_new) {
     dct[rm[std::get<0>(tpl)]][cm[std::get<1>(tpl)]] = std::get<2>(tpl);  
   }
   grp.construct_from_dict(dct);
 }
Exemplo n.º 27
0
BOOST_FIXTURE_TEST_CASE(Events, SchedulerFixture)
{
  boost::asio::io_service io; 

  Scheduler scheduler(io);
  scheduler.scheduleEvent(time::seconds(0.1), bind(&SchedulerFixture::event1, this));
  
  EventId i = scheduler.scheduleEvent(time::seconds(0.2), bind(&SchedulerFixture::event2, this));
  scheduler.cancelEvent(i);

  scheduler.scheduleEvent(time::seconds(0.05), bind(&SchedulerFixture::event3, this));

  i = scheduler.scheduleEvent(time::seconds(0.01), bind(&SchedulerFixture::event2, this));
  scheduler.cancelEvent(i);

  i = scheduler.schedulePeriodicEvent(time::seconds(0.3), time::seconds(0.1), bind(&SchedulerFixture::event4, this));
  scheduler.scheduleEvent(time::seconds(0.69), bind(&Scheduler::cancelEvent, &scheduler, i));
  
  io.run();

  BOOST_CHECK_EQUAL(count1, 1);
  BOOST_CHECK_EQUAL(count2, 0);
  BOOST_CHECK_EQUAL(count3, 1);
  BOOST_CHECK_EQUAL(count4, 4);
}
Exemplo n.º 28
0
  // fmap case
  void create_matrix(const paracel::list_type<paracel::str_type> & linelst,
                     Eigen::SparseMatrix<double, Eigen::RowMajor> & blk_mtx,
                     paracel::dict_type<size_t, paracel::str_type> & rm, 
                     paracel::dict_type<size_t, paracel::str_type> & cm,
                     paracel::dict_type<size_t, int> & dm,
                     paracel::dict_type<size_t, int> & col_dm) {

    paracel::scheduler scheduler(m_comm, pattern, mix); // TODO
    // hash lines into slotslst
    auto result = scheduler.lines_organize(linelst, parserfunc);
    std::cout << "procs " << m_comm.get_rank() << " slotslst generated" << std::endl;
    m_comm.sync();
    // alltoall exchange
    auto stf = scheduler.exchange(result);
    std::cout << "procs " << m_comm.get_rank() << " get desirable lines" << std::endl;
    m_comm.sync();
    // mapping inds to ids, get rmap, cmap, std_new...
    paracel::list_type<std::tuple<size_t, size_t, double> > stf_new;
    scheduler.index_mapping(stf, stf_new, rm, cm, dm, col_dm);
    std::cout << "procs " << m_comm.get_rank() << " index mapping" << std::endl;
    // create block sparse matrix
    paracel::list_type<eigen_triple> nonzero_tpls;
    for(auto & tpl : stf_new) {
      nonzero_tpls.push_back(eigen_triple(std::get<0>(tpl), std::get<1>(tpl), std::get<2>(tpl)));
    }
    blk_mtx.resize(rm.size(), cm.size());
    blk_mtx.setFromTriplets(nonzero_tpls.begin(), nonzero_tpls.end());
  }
Exemplo n.º 29
0
int main(void)
{
    rtosInit();
    
    threadObjectCreate(&thread1,
                        (void *)function1,
                        0,
                        0,
                        0,
                        0,
                        &stack1[1000],
                        10,
                        INITIAL_CPSR_ARM_FUNCTION,
                        "thread1");
                        
    threadObjectCreate(&thread2,
                        (void *)function2,
                        0,
                        0,
                        0,
                        0,
                        &stack2[1000],
                        20,
                        INITIAL_CPSR_ARM_FUNCTION,
                        "thread2");
                        
    mailboxObjectInit(&testMailbox,
                        (void *)mailboxBuffer,
                        4*MAILBOX_SIZE,
                        4);
    
    srand(1);
                        
    scheduler();            //This function will never return.
}                       
Exemplo n.º 30
0
int main()
{
	signal(	SIGABRT, signalHandler); 
	srand(time(NULL));
	system("rm peopleThread.file");
	system("rm sche.file");
	system("rm test.file");
	system("rm test2.file");
	//inicializa as thread dos banheiros
	Bathroom bathroom;

	//incia a thread de criaçao de femino
	PeopleList listW(&bathroom, Bathroom::Women);
	
	//start the thread of creation of males 
	PeopleList listM(&bathroom, Bathroom::Men);
	
	//colonacando em uma list
	list<PeopleList*> plist;
	plist.push_front(&listM);
	plist.push_front(&listW);


	//cria escalonador de dados
	Scheduler scheduler(plist , &bathroom);
	
	while(1){
		scheduler.run();
	}
}