Пример #1
0
/*
 * Spawns a dequeuer thread that constantly tries to dequeue,
 * and the main thread enqueues 1..n_to_enqueue values. Dequeuer thread
 * will exit after it dequeues a zero or after TIMELIMIT seconds,
 * whichever comes first.
 *
 * delay_mode controls the interval between successive enqueues.
 * 0 means enqueue as fast as possible
 * 1 means random small delays
 * 2 means large delay (0.5s) in the beginning, then fast enqueue
 * 3 means large delay, then random small delays.
 */
void test_queue_parallel_1 (int q_size, int n_to_enqueue, int delay_mode) {
    struct l_queue *q = create_queues(1, q_size);

    pthread_t dqr;
    pthread_create(&dqr, NULL, eternal_dqr, (void *) q);

    switch(delay_mode) {
        case 0:
            eqr0(q, n_to_enqueue);
            break;
        case 1:
            eqr1(q, n_to_enqueue);
            break;
        case 2:
            eqr2(q, n_to_enqueue);
            break;
        case 3:
            eqr3(q, n_to_enqueue);
            break;
    }

    pthread_join(dqr, NULL);
    destroy_queues(1, q);
    return;
}
Пример #2
0
/* init_conn:
 *  This just chains to the channel initialiser, basically.
 */
static int init_conn (NET_CONN *conn, const char *addr)
{
	struct conn_data_t *data;
	
	conn->peer_addr[0] = '\0';	
	conn->data = data = malloc (sizeof *data);
	if (!data) return 1;
	
	if (create_queues (conn)) {
		free (data);
		return 2;
	}
	
	data->conns = NULL;
	data->referer = NULL;
	
	data->chan = net_openchannel (conn->type, addr);
	if (!data->chan) {
		destroy_queues (conn);
		free (data);
		return 3;
	}

	return 0; /* success */
}
Пример #3
0
int scheduler_suite_init(void)
{
	odp_cpumask_t mask;
	odp_shm_t shm;
	odp_pool_t pool;
	test_globals_t *globals;
	thread_args_t *args;
	odp_pool_param_t params;

	odp_pool_param_init(&params);
	params.buf.size  = BUF_SIZE;
	params.buf.align = 0;
	params.buf.num   = MSG_POOL_SIZE;
	params.type      = ODP_POOL_BUFFER;

	pool = odp_pool_create(MSG_POOL_NAME, &params);

	if (pool == ODP_POOL_INVALID) {
		printf("Pool creation failed (msg).\n");
		return -1;
	}

	shm = odp_shm_reserve(GLOBALS_SHM_NAME,
			      sizeof(test_globals_t), ODP_CACHE_LINE_SIZE, 0);

	globals = odp_shm_addr(shm);

	if (!globals) {
		printf("Shared memory reserve failed (globals).\n");
		return -1;
	}

	memset(globals, 0, sizeof(test_globals_t));

	globals->num_workers = odp_cpumask_default_worker(&mask, 0);
	if (globals->num_workers > MAX_WORKERS)
		globals->num_workers = MAX_WORKERS;

	shm = odp_shm_reserve(SHM_THR_ARGS_NAME, sizeof(thread_args_t),
			      ODP_CACHE_LINE_SIZE, 0);
	args = odp_shm_addr(shm);

	if (!args) {
		printf("Shared memory reserve failed (args).\n");
		return -1;
	}

	memset(args, 0, sizeof(thread_args_t));

	/* Barrier to sync test case execution */
	odp_barrier_init(&globals->barrier, globals->num_workers);
	odp_ticketlock_init(&globals->lock);
	odp_spinlock_init(&globals->atomic_lock);

	if (create_queues() != 0)
		return -1;

	return 0;
}
Пример #4
0
/* poll_listen:
 *  Here we check for an incoming connection, and if there is one we
 *  fill in `newconn' with our data pointer for it and the addresses,
 *  and return nonzero.  Otherwise return 0.
 */
static int poll_listen (NET_CONN *conn, NET_CONN *newconn)
{
	struct conn_data_t *data;
	char buffer[12], buffer2[8+NET_MAX_ADDRESS_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 };
	char addr[NET_MAX_ADDRESS_LENGTH];
	int x;

	int count = 32; /* maximum number of packets to process */
	while (net_query (((struct conn_data_t *)conn->data)->chan) && count-- > 0) {
		if ((net_receive (((struct conn_data_t *)conn->data)->chan, buffer, 12, addr) == 12) && !memcmp (buffer, "connect", 8)) {
			newconn->data = data = malloc (sizeof *data);
			if (!data) continue;

			if (create_queues (newconn)) {
				free (data);
				continue;
			}

			data->conns = NULL;
			
			x = get_channel (
				((struct conn_data_t *)conn->data)->conns, addr,
				(buffer[8] << 24) + (buffer[9] << 16) +
				(buffer[10] << 8) + buffer[11],
				conn->type, NULL, &data->chan, data
			);
			
			if (x) {
				data->referer = conn->data;

				/* tell new channel where to send in future */
				net_assigntarget (data->chan, addr);

				/* send reply now with address of new channel, through
				 * listening conn so it can get through NATs */
				net_assigntarget (((struct conn_data_t *)conn->data)->chan, addr);
				strcpy (buffer2+8, net_getlocaladdress (data->chan));
				net_send (((struct conn_data_t *)conn->data)->chan, buffer2, 8+NET_MAX_ADDRESS_LENGTH);
			}
			
			if (x >= 0) {
				destroy_queues (newconn);
				free (data);
				continue;
			}

			strcpy (newconn->peer_addr, addr);

			return 1;
		}
	}

	return 0;
}
Пример #5
0
int main(int args, char** argv)
{
    Message message = {0};
    setup_signal_handling();
    create_queues();

    receive(&message);

    exit_server();
    return 0;
}
int main (
	int argc
	, char **argv
	, char **envp
)
{
	parse_argv(argc, argv);

	create_queues( /* no args */ );
	create_players( /* no args */ );

	signal(SIGINT, parent_sig_int);
	sleep(sleep_time_seconds);
	scorer(scorer_queue);

	stop_players( /* no args */ );
	close_queues( /* no args */ );
	remove_queues( /* no args */ );

	return(EXIT_SUCCESS);
}
Пример #7
0
void serial_queue(int n_packets, int n_src, int q_depth, long mean, int seed, int distr) {
    Packet_t **rcvd_packets = malloc (n_packets * n_src * sizeof(Packet_t *));
    PacketSource_t *source = createPacketSource (mean, n_src, seed);
    int packet_ctr = 0;
    long fp_sum = 0;

    StopWatch_t watch;
    startTimer(&watch);

    Packet_t *(*pkt_fn)(PacketSource_t *, int) = distr ? getUniformPacket : getExponentialPacket;
    struct l_queue *queues = create_queues (n_src, q_depth);

    for (int i = 0; i < n_packets; i++) {
        for (int j = 0; j < n_src; j++) {
            Packet_t *pkt = pkt_fn (source, j);
            rcvd_packets[packet_ctr] = pkt;
            enq (queues + j, (void *) pkt);
            packet_ctr++;
            deq (queues + j, (void **) &pkt);
            fp_sum += getFingerprint (pkt->iterations, pkt->seed);
        }
    }
    destroy_queues (n_src, queues);
    stopTimer(&watch);

    deletePacketSource (source);
    // Free all the packets...
    for (int i = 0; i < packet_ctr; i++)
        free (rcvd_packets[i]);
    free (rcvd_packets);

#ifdef PERF
    printf("%f\n", getElapsedTime(&watch));
#else
    printf("%ld\n", fp_sum);
#endif
    return;
}
Пример #8
0
/*
 * Tests serial correctness of the queue. Takes the queue capacity as a parameter
 * 
 * This function will wait for input on stdin. Input of the form "e (number)"
 * will enqueue the number, and input consisting of "d" will dequeue and print
 * to stdout. Function exits on "x".
 *
 * Unsuccessful enqueueing will output a line containing "F", unsuccessful dequeuing 
 * will output a line containing "E".
 */
void test_queue_serial(int q_size) {
    struct l_queue *q = create_queues(1, q_size);
    char *line_in = calloc(500, sizeof(char));

    long i = 0;
    while (1) {
        if(!fgets(line_in, 500, stdin))
            break;
        for (int j = 0; j < 500; j++) {
            if (line_in[j] == '\n') {
                line_in[j] = '\0';
                break;
            }
        }
        if (!strcmp(line_in, "x"))
            break;

        if (line_in[0] == 'e') {
            i = strtol (line_in + 2, NULL, 10);
            if (enq (q, (void *) i)) {
                printf("F\n");
            }
        }
        else {
            if (deq (q, (void **) &i)) {
                printf("E\n");
            }
            else {
                printf("%ld\n", i);
            }
        }
        fflush(stdout);
    }
    free (line_in);
    destroy_queues(1, q);
    return;
}
int main (
	int argc
	, char **argv
	, char **envp
)
{
	parse_argv(argc, argv);

	create_queues( /* no args */ );
	create_players( /* no args */ );
	//size_queues();

	// i should probably install a SIGCHLD handler too.  I'd have to
	// keep track of if the child is exiting on an error or as expected.
	signal(SIGINT, parent_sig_int);
	sleep(sleep_time_seconds);
	scorer(scorer_queue);

	stop_players_threads( /* no args */ );
	close_queues( /* no args */ );
	remove_queues( /* no args */ );

	return(EXIT_SUCCESS);
}
Пример #10
0
/**
 * Starts the initialization, the tasks and then the scheduler.
 */
int main(void)
{	
	/* disable ETM at very first */
	PINSEL10 &= ~((unsigned int)(1 << 3));

	/* Initialize BMC hardware */
	global_data.bmc_resetcause = 0x00;

	/* IPMI message sequence counter */
	global_data.seq_counter = 0x00;

	/* site number used for entity instance */
	global_data.bmc_siteno = 0x00;

	/* reset sdr list */
	sdr_list.sdr_count = 0;

	/* init PLL */
	init_clock();
	
	/* init interrupts */
	init_irq();

	/* get reset cause */
	init_resetcause();
	
	/* init port pins */
	init_portpins();
	
	/* CUSTOM BOARD INIT CODE LOCATION 1 */
	custom_init_1();
	
	/* get HW and IPMB address */
	custom_get_hw_ipmb_address();

	uptime_init();

	/* init RTC */
	rtc_init();

	/* create the FreeRTOS queues */
	create_queues();

	uart_init(UART_DEBUG_CONNECTOR, 115200);

	uart_printf("Firmware started...\n");

	/* init SPI/SSP controllers */
	spi_init();

	/* init SPI FLASH */
    spi_flash_init_devices();
	spi_flash_init(&spi_flash);
	
#ifdef CFG_MMC_I2C_MASTER
	/* init BMC master I2C bus */
	master_i2c_init(MASTER_BUS_I2C);
#endif
	/* init EEPROM file system */
	//spi_eeprom_init(&spi_eeprom);

#ifdef CFG_FS
	if (fs_init(&efs, &spi_eeprom) != 0)
	{
		uart_printf("\nEEPROM not accesable!\n");
		/* reboot bmc */
		lpc_watchdog_start(CFG_BL_WATCHDOG_TIMEOUT, WD_RESET_MODE);
		while (1);
	}
#endif

	/* init leds */
	//led_init();	
	
#ifndef CFG_ONCHIP_FLASH_GLOBAL_CONF
	/* check EEPROM areas */
	//eeprom_integrity_check_areas();
#endif

	/* init CLI (and debug console) */
	cli_uart_init(115200);

	/* handle reset type warm/cold? */
	//fru_handle_reset_type();
	
#ifdef CFG_CM
	cm_fru_get_last_known_state();
#endif

#ifdef CFG_EXT_INT
	/* init external interrupts */
	external_interrupt_init();
#endif
	
#ifdef CFG_HELPER
	/* init the helper task */
	helper_init();
#endif

#ifdef CFG_BIOS_FLASH
	/* init BIOS FLASH */
	spi_flash_init(&bios_flash);

	/* init FPGA BIOS flash selection */
	bios_restore_active_flash_from_eeprom();
#endif

	/* CUSTOM BOARD INIT CODE LOCATION 2 */
	//custom_init_2();

	/* get global configuration from EEPROM */
	global_config();
	
	/* CUSTOM BOARD INIT CODE LOCATION 3 */
	//custom_init_3();

	/* parse FRU */
	fru_init(0);

#if defined (CFG_CM) || defined (CFG_MMC) || defined (CFG_IRTM) || defined(CFG_MCMC)
	/* init the IPMB-L interface(s) */
	ipmbl_init();
#endif


#ifdef CFG_LAN
	/* read and set ncsi mac address from fru */
	custom_set_ncsi_mac();
#endif

	/* create message pool for IPMI messages */
	message_pool_init();

    /* init board task */
	board_init();

	/* init the BMC task */
	bmc_init();

#ifdef CFG_PI_SERIAL_BASIC
	/* init the payload interface */
	pi_uart_b_init(CFG_PI_PORT_RATE);
#endif /* CFG_PI_SERIAL_BASIC */

#ifdef CFG_PI_SERIAL_TERMINAL
	/* init the payload interface */
	pi_uart_t_init(CFG_PI_PORT_RATE);
#endif /* CFG_PI_SERIAL_TERMINAL */

#ifdef CFG_PI_KCS
	/* initialise kcs interface */
	kcs_init();
#endif /* CFG_PI_KCS */

#ifdef CFG_ATCA
	if (global_conf.operation_mode == OPERATION_MODE_STANDALONE)
	{
		/* configure IPMB-A and IPMB-B as master only in stanalone mode */
		master_i2c_init(IPMB0A_I2C);
		master_i2c_init(IPMB0B_I2C);

		/* enable IPMB-0 pull ups and buffer */
		ipmb0_bus_ctrl(IPMB0_A, IPMB_ENABLE);
		ipmb0_bus_ctrl(IPMB0_B, IPMB_ENABLE);
	}
	else
	{
		/* init the IPMB-0 interface */
		ipmb0_init();
	}
#endif

#ifdef CFG_LAN_PLUS
	sol_init();
#endif

#ifdef CFG_LAN
	/* init ethernet hardware and Task */
	eth_start();
#endif

	/* init the SDR task */
	/* PORT_NOTE: Needs to be started AFTER BMC task because of Semaphore dependency */
	sdr_init();

	/* parse all PICMG Records in FRU data and store relevant information */
	//fru_parse_picmg();

	/* init the IPMI message hub */
	msg_hub_init();

	/* init the event task */
	event_init();


#ifdef CFG_CM
	/* init the CM task */
	init_cm();
#endif


#ifdef CFG_COOLING_MANAGER
	cool_init();
#endif
	/* do all post tests */
	//post_test();

	/* needs to be done after sdr initialization */
	//hpm_check_bl_flags();

#ifdef CFG_BIOS_FLASH
	/* collect BIOS/NVRAM version info (if payload power is off) */
	if (!(signal_read(&sig_payload_power_enable)))
	{
		bios_redundancy_get_versions();
	}
#endif


#ifdef CFG_WATCHDOG
	/* start the FW watchdog */
	lpc_watchdog_start(CFG_FW_WATCHDOG_TIMEOUT, WD_RESET_MODE);
#endif

	/* set desired debug output mode before starting scheduler */
	global_debug_uart_enabled = CFG_GLOBAL_DEBUG_UART;

	/* all tasks have been initialized, start the scheduler */
	vTaskStartScheduler();

	/* Should never reach here! */
	while (1);
}
Пример #11
0
double parallel_dispatcher
#else
long parallel_dispatcher
#endif
        (int n_packets, 
        int n_src, 
        int q_depth, 
        long mean, 
        int seed, 
#ifdef TESTING
        int n_lazy,
#endif
        int distr) {

    // This array holds packets so we can free them in the end. Shouldn't be too big...
    // also we're putting packet memory management outside the timing for all three.

    Packet_t **rcvd_packets = malloc (n_packets * n_src * sizeof(Packet_t *));
    PacketSource_t *source = createPacketSource (mean, n_src, seed);

    StopWatch_t watch;
    startTimer(&watch);

    struct l_queue *queues = create_queues (n_src, q_depth);

    int n_workers_done = 0;
    int packet_ctr = 0;
    long total_fp_sum = 0;

    pthread_t *workers = calloc (n_src, sizeof(pthread_t));
    struct thread_data *worker_data = calloc (n_src, sizeof(struct thread_data));
    for (int i = 0; i < n_src; i++) {
        worker_data[i].q = queues + i;

#ifdef TESTING
        if (i >= n_lazy)
            worker_data[i].do_work = true;
#endif

        pthread_create (workers + i, NULL, worker_fn, (void *) (worker_data + i));
    }
    
    Packet_t *(*pkt_fn)(PacketSource_t *, int) = distr ? &getUniformPacket : &getExponentialPacket;

    while (n_workers_done < n_src) {
        for (int i = 0; i < n_src; i++) {
            int n_enqs = get_n_enqueues(queues + i);
            if (n_enqs == n_packets + 1)
                continue;
            if (!check_free(queues + i))
                continue;
            
            if (n_enqs == n_packets) {
                enq(queues + i, NULL);
            }
            else {
                Packet_t *pkt = pkt_fn (source, i);
                enq (queues + i, (void *) pkt);

                rcvd_packets[packet_ctr] = pkt;
                packet_ctr += 1;
            }
 
            if (get_n_enqueues(queues + i) == n_packets + 1)
                n_workers_done += 1;
        }
#ifdef TESTING
        if (n_workers_done == n_src - n_lazy)
            break;
#endif
    }

    for (int i = 0; i < n_src; i++) {
        long this_fp = 0;
        pthread_join (workers[i], (void **) &this_fp);
        total_fp_sum += this_fp;
#ifdef TESTING
        printf("%d\n", get_n_enqueues(queues + i) - 1);
#endif
    }


    free (worker_data);
    destroy_queues (n_src, queues);
    stopTimer(&watch);


    deletePacketSource (source);
    // Free all the packets...
    for (int i = 0; i < packet_ctr; i++)
        free (rcvd_packets[i]);
    free (rcvd_packets);

#ifdef PERF
    return getElapsedTime(&watch);
#else
    return total_fp_sum;
#endif
}