Esempio n. 1
0
void	init(int policy, int prot)
{
	allegro_init();
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, XMAX, YMAX, 0, 0);
	clear_to_color(screen, BGC);
	install_keyboard();
	print_grid(policy, prot);
	
	if (prot == PIP) ptask_init(policy, GLOBAL, PRIO_INHERITANCE);
	else if (prot == PCP) ptask_init(policy, GLOBAL, PRIO_CEILING);
	else {
	  allegro_exit();
	  ptask_syserror("pcp.c", "Wrong protocol");
	}

	if (prot == PIP) { 
	  pmux_create_pi(&mxa);
	  pmux_create_pi(&muxA);
	  pmux_create_pi(&muxB);
	}
	else if (prot == PCP) {
	  pmux_create_pc(&mxa, prio[1]);
	  pmux_create_pc(&muxA, prio[1]);
	  pmux_create_pc(&muxB, prio[1]);
	}
}
Esempio n. 2
0
int main() {
    ptask_init(SCHED_FIFO, GLOBAL, PRIO_INHERITANCE);

    tpars params = TASK_SPEC_DFL;
    params.priority = 2;
    params.act_flag = NOW;

    printf("Creating aperiodic task\n");
    aperiodic_id = ptask_create_param(myaperiodic, &params);

    if (aperiodic_id < 0) {
        printf("Cannot create aperiodic task\n");
        exit(-1);
    }

    params = TASK_SPEC_DFL;
    params.period = tspec_from(1, MILLI);
    params.priority = 1;
    params.act_flag = NOW;

    printf("Creating periodic task\n");
    int pid = ptask_create_param(myperiodic, &params);
    if (pid < 0) {
        printf("Cannot create aperiodic task\n");
        exit(-1);
    }

    pthread_join(ptask_get_threadid(pid), 0);
    pthread_join(ptask_get_threadid(aperiodic_id), 0);

    assert(ca == 5);

    return 0;
}
Esempio n. 3
0
File: ball.c Progetto: glipari/ptask
/*--------------------------------------------------------------*/
void init() {
    allegro_init();
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, XWIN, YWIN, 0, 0);
    clear_to_color(screen, BGC);
    install_keyboard();
    srand(time(NULL));

    rect(screen, XMIN - L - 1, BASE - 1, XMAX + L + 1, TOP + BASE + L + 1, 14);
    textout_centre_ex(screen, font, "SPACE to create a fly", XWIN / 2, YWIN / 2,
                      14, 0);
    textout_centre_ex(screen, font, "ESC exit", XWIN / 2, YWIN / 2 + 30, 14, 0);

    pmux_create_pi(&mxa);
    pmux_create_pi(&mxv);

    ptask_init(SCHED_FIFO, GLOBAL, PRIO_INHERITANCE);
}
Esempio n. 4
0
int main(void) {

    int ret = 0, nc;
    int c;
    int key = 0;
    int part = PARTITIONED; // PARTITIONED, GLOBAL
    int sched = SCHED_FIFO;

    get_data();
    init();
    ret = select_prot();
    if (ret == -1) {
        allegro_exit();
        return 0;
    }

    print_grid(ret);
    ptask_init(sched, part, ret);
    t_start = ptask_gettime(MILLI);
    set_sem_sezC(ret);

    nc = ptask_getnumcores();
    textprintf_ex(screen, font, 480, 10, 7, BGC, "(NumCores = %d)", nc);

    int gen_id = ptask_create_prio(gen, 100, 30, NOW);
    if (gen_id < 0) {
        printf("Could not create task gen\n");
        exit(-1);
    }

    while (key != KEY_ESC) {

        if (keypressed()) {
            c = readkey();
            key = c >> 8;
        }
    }

    pmux_destroy(&mx_sezNorm);
    pmux_destroy(&mx_sezA);
    pmux_destroy(&mx_sezB);

    allegro_exit();
    return 0;
}
int main(int argc,char *argv[])
{
   vm_instance_t *vm;

#ifdef PROFILE
   atexit(profiler_savestat);
#endif

   printf("Cisco Router Simulation Platform (version %s)\n",sw_version);
   printf("Copyright (c) 2005-2007 Christophe Fillot.\n");
   printf("Build date: %s %s\n\n",__DATE__,__TIME__);

   /* Register platforms */
   register_default_platforms();

   /* Initialize timers */
   timer_init();

   /* Initialize object registry */
   registry_init();
   
   /* Initialize ATM module (for HEC checksums) */
   atm_init();

   /* Initialize CRC functions */
   crc_init();

   /* Initialize NetIO code */
   netio_rxl_init();

   /* Initialize NetIO packet filters */
   netio_filter_load_all();

   /* Initialize VTTY code */
   vtty_init();
   
   /* Parse standard command line */
   if (!run_hypervisor(argc,argv))
      parse_std_cmd_line(argc,argv);

   /* Create general log file */
   create_log_file();

   /* Periodic tasks initialization */
   if (ptask_init(0) == -1)
      exit(EXIT_FAILURE);

   /* Create instruction lookup tables */
   mips64_jit_create_ilt();
   mips64_exec_create_ilt();
   ppc32_jit_create_ilt();
   ppc32_exec_create_ilt();
   
   setup_signals();

   if (!hypervisor_mode) {
      /* Initialize the default instance */
      vm = vm_acquire("default");
      assert(vm != NULL);

      if (vm->platform->init_instance(vm) == -1) {
         fprintf(stderr,"Unable to initialize router instance.\n");
         exit(EXIT_FAILURE);
      }

      /* Start GDB server before the image to allow debugging from
         the begining of it's execution */ 
      if (vm->gdb_server_running)
      {
        /* Stop main CPU */
        vm_suspend(vm);
//         cpu_stop(vm->boot_cpu);
      
        if (gdb_server_start_listener(vm) < 0) {
            fprintf(stderr,"GDB server unable to create TCP sockets.\n");
            exit(EXIT_FAILURE);
        }
      }

#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0)
      {
         m_uint32_t counter,prev = 0,delta;
         while(vm->status == VM_STATUS_RUNNING) {
            counter = cpu_get_perf_counter(vm->boot_cpu);
            delta = counter - prev;
            prev = counter;
            printf("delta = %u\n",delta);
            sleep(1);
         }
      }
#else
      /* Start instance monitoring */
      vm_monitor(vm);
#endif

      // FIXME: remove this kludge
      if (vm->gdb_server_running)
      {
         //while (vm->gdb_conn->active)
         //   usleep(1000000);
         gdb_server_close_control_sockets();
      }

      /* Free resources used by instance */
      vm_release(vm);

   } else {
      hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port);
   }

   dynamips_reset();
   close_log_file();
   return(0);
}
Esempio n. 6
0
int main(int argc,char *argv[])
{
    vm_instance_t *vm;

#ifdef PROFILE
    atexit(profiler_savestat);
#endif

#ifdef USE_UNSTABLE
    printf("Cisco Router Simulation Platform (version %s/%s unstable)\n",
           sw_version,os_name);
#else
    printf("Cisco Router Simulation Platform (version %s/%s stable)\n",
           sw_version,os_name);
#endif

    printf("Copyright (c) 2005-2011 Christophe Fillot.\n");
    printf("Build date: %s %s\n\n",__DATE__,__TIME__);

    gen_uuid_init();

    /* Register platforms */
    register_default_platforms();

    /* Initialize timers */
    timer_init();

    /* Initialize object registry */
    registry_init();

    /* Initialize ATM module (for HEC checksums) */
    atm_init();

    /* Initialize CRC functions */
    crc_init();

    /* Initialize NetIO code */
    netio_rxl_init();

    /* Initialize NetIO packet filters */
    netio_filter_load_all();

    /* Initialize VTTY code */
    vtty_init();

    /* Parse standard command line */
    atexit(destroy_cmd_line_vars);
    if (!run_hypervisor(argc,argv))
        parse_std_cmd_line(argc,argv);

    /* Create general log file */
    create_log_file();

    /* Periodic tasks initialization */
    if (ptask_init(0) == -1)
        exit(EXIT_FAILURE);

    /* Create instruction lookup tables */
    mips64_jit_create_ilt();
    mips64_exec_create_ilt();
    ppc32_jit_create_ilt();
    ppc32_exec_create_ilt();

    setup_signals();

    if (!hypervisor_mode) {
        /* Initialize the default instance */
        vm = vm_acquire("default");
        assert(vm != NULL);

        if (vm_init_instance(vm) == -1) {
            fprintf(stderr,"Unable to initialize router instance.\n");
            exit(EXIT_FAILURE);
        }

#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0)
        {
            m_uint32_t counter,prev = 0,delta;
            while(vm->status == VM_STATUS_RUNNING) {
                counter = cpu_get_perf_counter(vm->boot_cpu);
                delta = counter - prev;
                prev = counter;
                printf("delta = %u\n",delta);
                sleep(1);
            }
        }
#else
        /* Start instance monitoring */
        vm_monitor(vm);
#endif

        /* Free resources used by instance */
        vm_release(vm);
    } else {
        hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port);
    }

    dynamips_reset();
    close_log_file();
    return(0);
}
Esempio n. 7
0
void init() {
    srand(time(NULL));
    ptask_init(SCHED_DEADLINE, GLOBAL, PRIO_INHERITANCE);
    calibrate();
}
Esempio n. 8
0
int	main(void)
{
	  int 	unit = MILLI;
	  int	i, id, k;
	  int	c;						/* character from keyboard	*/
	  int   ntasks 	= 0;        	/* total number of activated tasks*/
	  int 	ret		= 0;
	  int 	tipo_prio = PRIO_EQUAL;
	  int 	sched 	= SCHED_RR;
	  int 	part	= GLOBAL;
	  int 	prot 	= NO_PROTOCOL;
	  int 	test 	= TASK_FUN;
	  int 	modeACT = MOD_NOW;		/* {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2} */
	  int   act_flag = NOW;

	  init(TASK_FUN);

	  int 	num_tasks = NUM_T_TEST;
	  int 	priority[num_tasks];
	  ptime v_offset[num_tasks];	/* time offset vector */

	  for(i = 0; i < num_tasks; i++) v_offset[i] = 0;

	  modeACT = select_act (v_offset, num_tasks); // {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
	  if ( modeACT == -1 ) {
		  allegro_exit();
	   	  return 0;
	   }

	   ptask_init(sched, part, prot);

	   /* Time reference for timeoffset */
	   time_t0 = ptask_gettime(MILLI);
	   ptime time_tmp;

	   if(modeACT == 0) {	// {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
		   act_flag = NOW;
	   }
	   else {
		   act_flag = DEFERRED;
	   }

	   init_vettore_prio(tipo_prio, priority, num_tasks);

	   draw_system_info(sched, part, prot, modeACT, tipo_prio, test, false);

	   draw_Timetask_info(modeACT);

	   pthread_mutex_lock(&mxa);
	   textprintf_ex(screen, font, 2, 25 + 15, FGC, BGC, " Time reference t0 = %ld (time creation/visualization of this screen)", time_t0);
	   pthread_mutex_unlock(&mxa);
	   const char* str_offset = "Time offset(ms) inseriti = ";

	   /* Creation of aperiodic task */
	   for ( i = 0; i < num_tasks; i++) {

	    	if (modeACT != MOD_DEF_OFFSET) {

	    		/* MODE WITHOUT OFFSET */
	    		time_tmp = ptask_gettime(MILLI);
	    		if(act_flag == NOW) {
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + i * ALT_RIGA, FGC, BGC, "%ld            ", time_tmp);
	    			pthread_mutex_unlock(&mxa);
	    		}
	    		id = ptask_create(periodicLine_testSystemTask, PER, priority[i], act_flag);
	    	}
	    	else {
	    			/* MODE WITH OFFSET */
	    			time_tmp = ptask_gettime(MILLI);
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, (X_LINE_VERT0 + X_LINE_VERT1)/2, Y_TIMES + i * ALT_RIGA, FGC, BGC, "-");
	    			pthread_mutex_unlock(&mxa);
	    			id = ptask_create(periodicLine_testSystemTaskOFFSET, PER, priority[i], act_flag);
	    			printf("act_flag = %d, id = %d, v_offset[%d] = %ld\n", act_flag, id+1, id, v_offset[id]);
	    			ret = ptask_activate_at(id, v_offset[i]);

	    			if (ret != -1) {
	    				draw_activation (ntasks, i, priority[i], false);
	    				ntasks++;
	    				if (i == 0) {
	    					pthread_mutex_lock(&mxa);
	    					textout_ex(screen, font, str_offset, XMIN, BASE1 + 2 * ALT_RIGA, FGC, 0);
	    					pthread_mutex_unlock(&mxa);
	    				}
	    				pthread_mutex_lock(&mxa);
	    				textprintf_ex(screen, font, XMIN + (strlen(str_offset)+i*(NUM_CIF_OFFSET))*PIXEL_CHAR, BASE1 + 2 * ALT_RIGA,FGC, BGC, "%ld", v_offset[i]);
	    				pthread_mutex_unlock(&mxa);
	    			}
	    			else fprintf(stderr, "Task %d non può essere attivato o già avviato!!!\n", i+1);

	    	}
	       	if (id != -1) {
	       		char* temp = " e attivato!\n";
	       		if(act_flag == DEFERRED) {
	       			temp = "!\n";
	       		}
	       		printf("Task %d creato%s", id+1, temp);
	       	}
	       	else {
	       	    allegro_exit();
	       	    printf("Errore nella creazione(o anche attivazione NOW) del task!\n");
	       	    exit(-1);
	       	}
	   }

	   do {

		   	k = 0;
	   	   	if (keypressed()) {
	   	   		c = readkey();
	   	   		k = c >> 8;
	   	   	}

		   if ((k >= KEY_1) && (k <= KEY_0 + num_tasks) && (modeACT != MOD_DEF_OFFSET)) {

			   id = k - KEY_0 - 1;
			   time_tmp = ptask_gettime(unit);
			   ret = ptask_activate(id);

			   if (ret != -1) {
				   printf("Task %d attivato\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + (id) * ALT_RIGA,
						   FGC, BGC, "%ld            ", time_tmp);
				   pthread_mutex_unlock(&mxa);
				   draw_activation (ntasks, id, priority[id], false);
				   ntasks++;
			   }
			   else{

				   printf("Task %d non può essere attivato o già avviato!!!\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + id * ALT_RIGA,FGC, BGC, "T%d: Gia' attivo!   ", id);
				   pthread_mutex_unlock(&mxa);
			   }
		   }

	   } while (k != KEY_ESC);
	   allegro_exit();
	   return 0;
}
Esempio n. 9
0
/**
 * Entry point of the Timer application.
 * It takes the name of the configuration file (use
 * example_timer_config.xml).
 *
 * @see example_timer_config.xml
 */
int main(int argc, char** argv)
{
    if (argc != 5)
    {
        printf("Usage: %s <config_file> <device_uri> <const_mem> <var_mem>\n"
               " where <config_file> - Address of the configuration file;\n"
               "       <device_uri>  - URI at which the device will be "
               "registered;\n"
               "       <const_mem>   - Additional memory, which will be "
               "allocated all\n"
               "                       the time;\n"
               "       <var_mem>     - Amount of memory which adapter will try "
               "to allocate\n"
               "                       and release periodically.\n", argv[0]);
        return -1;
    }

    // load connection settings from file
    int error = obix_loadConfigFile(argv[1]);
    if (error != OBIX_SUCCESS)
    {
    	log_error("Unable to load configuration file.\n");
        return error;
    }

    // open connection to the server
    error = obix_openConnection(CONNECTION_ID);
    if (error != OBIX_SUCCESS)
    {
    	log_error("Unable to establish connection with oBIX server.\n");
        return error;
    }

    // register timer device at the server
    char* deviceData = getDeviceData(argv[2]);
    int deviceId = obix_registerDevice(CONNECTION_ID, deviceData);
    free(deviceData);
    if (deviceId < 0)
    {
    	log_error("Unable to register device at oBIX server.\n");
        return deviceId;
    }

    // register listener of the "reset" field
    // it will be invoked every time when someone changes
    // "reset" field at the server
    int listenerId = obix_registerListener(CONNECTION_ID,
                                           deviceId,
                                           "reset",
                                           &resetListener);
    if (listenerId < 0)
    {
    	log_error("Unable to register update listener.\n");
        return listenerId;
    }

    // Initialize separate thread for timer
    _taskThread = ptask_init();
    if (_taskThread == NULL)
    {
    	log_error("Unable to start separate thread for timer.\n");
        return -1;
    }
    // start updating time once in a second
    _timerTaskId = ptask_schedule(_taskThread, &timerTask, &deviceId,
                                  1000, EXECUTE_INDEFINITE);

    printf("Test device is successfully registered at the server at the "
           "following address: %s\n", argv[2]);

    // allocate additional memory
    int size = atoi(argv[3]);
    char* additionalMemory = (char*) malloc(size);
    if (additionalMemory == NULL)
    {
        printf("Unable to allocate %d bytes of memory!\n", size);
        log_error("Unable to allocate %d bytes of memory!\n", size);
        return -1;
    }
    // fill allocated memory with very 'sensitive' data :)
    int i;
    for (i = 0; i < size; i++)
    {
        additionalMemory[i] = (char)i;
    }

    printf("%d additional bytes are successfully allocated!\n", size);

    // register more fake listeners
    char* hrefs[] = {"dummy/str1",
                     "dummy/str2",
                     "dummy/str3",
                     "dummy/str4",
                     "dummy/str5/",
                     "dummy/str5/int1",
                     "dummy/str5/int2",
                     "dummy/str5/int3",
                     "dummy/str5/int4",
                     "dummy/str5/int5",
                     "dummy/str5/int6",
                     "dummy/str5/int7",
                     "dummy/str5/int8",
                     "dummy/str5/int9",
                     "dummy/str5/int0"};
    for (i = 0; i < 15; i++)
    {
        error = obix_registerListener(CONNECTION_ID,
                                      deviceId,
                                      hrefs[i],
                                      &dummyListener);
        if (error < 0)
        {
        	log_error("Unable to register the dummy listener number %d!\n", i + 1);
            return -1;
        }
    }

    // register signal handler
    signal(SIGINT, &signalHandler);
    printf("Press Ctrl+C to shutdown.\n");

    // fall into the endless loop
    size = atoi(argv[4]);
    while (_shutDown == FALSE)
    {
        // try to allocate some more memory
        char* buffer = (char*) malloc(size);
        if (buffer == NULL)
        {
            printf("Unable to allocate variable piece of memory - %d bytes!\n",
                   size);
            log_error("Unable to allocate variable piece of memory - "
                      "%d bytes!\n", size);
            return -1;
        }
        buffer[0] = '\0';
        strlen(buffer);
        free(buffer);

        sleep(2);
    }

    // shutdown gracefully
    ptask_dispose(_taskThread, TRUE);

    // release all resources allocated by oBIX client library.
    // No need to close connection or unregister listener explicitly - it is
    // done automatically.
    return obix_dispose();
}