Beispiel #1
0
int main(int argc, char* argv[])
{
	float result[ORDER];
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(vectorSum);
	PTHREAD_CREATE(vectorSum);
#endif
	PTHREAD_DECL(Sender);
	PTHREAD_CREATE(Sender);

	uint8_t idx;
	


	read_float32_n("out_data_pipe",result,ORDER);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"Result = %f, expected = %f.\n", result[idx],expected_result[idx]);
	}
	PTHREAD_CANCEL(Sender);
#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(vectorSum);
#endif
	return(0);
}
Beispiel #2
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "obj_tx_mt");

	if (argc != 2)
		UT_FATAL("usage: %s [file]", argv[0]);

	if ((pop = pmemobj_create(argv[1], "mt", PMEMOBJ_MIN_POOL,
			S_IWUSR | S_IRUSR)) == NULL)
		UT_FATAL("!pmemobj_create");

	int i = 0;
	long ncpus = sysconf(_SC_NPROCESSORS_ONLN);
	pthread_t *threads = MALLOC(2 * ncpus * sizeof(threads[0]));

	for (int j = 0; j < ncpus; ++j) {
		PTHREAD_CREATE(&threads[i++], NULL, tx_alloc_free, NULL);
		PTHREAD_CREATE(&threads[i++], NULL, tx_snap, NULL);
	}

	while (i > 0)
		PTHREAD_JOIN(threads[--i], NULL);

	pmemobj_close(pop);

	FREE(threads);

	DONE(NULL);
}
Beispiel #3
0
int main(int argc, char* argv[])
{
	float result[ORDER];
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

#ifdef SW
#ifdef USE_GNUPTH
	pth_init();
#endif
	init_pipe_handler();
	PTHREAD_DECL(conversionTest);
	PTHREAD_CREATE(conversionTest);
#endif
	PTHREAD_DECL(Sender);
	PTHREAD_CREATE(Sender);

	uint8_t idx;
	


	read_uint64_n("out_data",((uint64_t*) result),ORDER/2);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"Result = %f, expected = %f.\n", result[idx],expected_result[idx]);
	}
	PTHREAD_CANCEL(Sender);
#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(conversionTest);
#endif
	return(0);
}
Beispiel #4
0
void
start_daemons (FILE * fp, int trace_on)
{
  __report_log_file__ = fp;
  __trace_on__ = trace_on;
  __init_aa_globals__ ();
  PTHREAD_CREATE (stage_0);
  PTHREAD_CREATE (stage_1);
  PTHREAD_CREATE (stage_2);
  PTHREAD_CREATE (stage_3);
}
Beispiel #5
0
int main(int argc, char* argv[])
{
    float result;
    signal(SIGINT,  Exit);
    signal(SIGTERM, Exit);

#ifdef SW
    init_pipe_handler();
    PTHREAD_DECL(dotProduct);
    PTHREAD_CREATE(dotProduct);
#endif

    uint8_t idx;
    float expected_result = 0.0;
    for(idx = 0; idx < ORDER; idx++)
    {
        float val = drand48();
        expected_result += (val*val);
        write_float32("in_data_pipe",val);
    }


    result = read_float32("out_data_pipe");
    fprintf(stdout,"Result = %f, expected = %f.\n", result, expected_result);
#ifdef SW
    close_pipe_handler();
    PTHREAD_CANCEL(dotProduct);
    return(0);
#endif
}
Beispiel #6
0
static void
test_open(unsigned nthreads)
{
	size_t len = strlen(Dir) + 50;	/* reserve some space for pool id */
	char *filename = MALLOC(sizeof(*filename) * len);

	/* create all the pools */
	for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id) {
		snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
				Dir, pool_id);
		UT_OUT("%s", filename);

		Pools[pool_id] = pmemcto_create(filename, "test",
			PMEMCTO_MIN_POOL, 0600);
		UT_ASSERTne(Pools[pool_id], NULL);
	}

	for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id)
		pmemcto_close(Pools[pool_id]);

	for (unsigned t = 0; t < nthreads; t++) {
		Pool_idx[t] = Npools * t;
		PTHREAD_CREATE(&Threads[t], NULL, thread_func_open,
				&Pool_idx[t]);
	}

	for (unsigned t = 0; t < nthreads; t++)
		PTHREAD_JOIN(&Threads[t], NULL);

	FREE(filename);
}
Beispiel #7
0
int main(int argc, char* argv[])
{
#ifdef SW
	init_pipe_handler_with_log("pipelog.txt");
	PTHREAD_DECL(maxDaemon);   // declare the Daemon thread.
	PTHREAD_CREATE(maxDaemon); // start the Daemon..
#endif
	while(1)
	{
		uint32_t a, b;
		scanf("%d", &a);
		scanf("%d", &b);
		write_uint32("in_data",a);
		write_uint32("in_data",b);
		uint32_t c = read_uint32("out_data");
		fprintf(stdout,"Result = %d.\n", c);

		if(a == 0)
			break;
	}

#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(maxDaemon);
#endif
	return(0);
}
Beispiel #8
0
int main(int argc, char* argv[])
{
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

	PTHREAD_DECL(Sender);
	PTHREAD_CREATE(Sender);

	uint8_t idx;
	uint32_t result[ORDER];
	

	read_uint32_n("out_data", result, ORDER);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"%d. Result = %x, expected %x\n", idx, result[idx], (idx + 1));
	}
	PTHREAD_CANCEL(Sender);

	for(idx = 0; idx < ORDER; idx++)
	{
		write_uint32("in_data", idx);
		uint32_t res = read_uint32("out_data");
		fprintf(stdout,"%d. Result = %x, expected %x\n", idx, res, (idx + 1));
	}

	return(0);
}
Beispiel #9
0
int main(int argc, char* argv[])
{

#ifdef SW
PTHREAD_DECL(runDaemon)
PTHREAD_CREATE(runDaemon)
#endif

	uint32_t idx;
	for(idx = 0; idx < 16; idx++)
	{
		write_uint32("in_pipe", idx);
	}

	fprintf(stderr, "Observed:\t");
	for(idx = 0; idx < 16; idx++)
	{
		uint32_t fidx = read_uint32("out_pipe");
		fprintf(stderr," %d", fidx);
	}
	fprintf(stderr,"\n");
	fprintf(stderr,"Expected:\t 4 5 6 7 4 5 6 8 9 9 10 11 10 11 0 0\n");

	return(0);
}
Beispiel #10
0
int main(int argc, char* argv[])
{
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(vectorSum);
	PTHREAD_CREATE(vectorSum);
#endif


	write_uint32("in_data",1);
	write_uint32("in_data",2);
	write_uint32("in_data",3);
	write_uint32("in_data",4);

	uint32_t rval = read_uint32("out_data");
	fprintf(stdout,"Result = %d.\n", rval);

#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(vectorSum);
#endif
	return(0);
}
Beispiel #11
0
int main(int argc, char* argv[])
{
        FILE* ofile1;
        FILE* ofile2;
        char ostr[17];
	uint16_t N[ORDER];

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(gcd_daemon);
	PTHREAD_CREATE(gcd_daemon);
#endif

        ofile1 = fopen("gcd_inputs.txt","w");
        ofile2 = fopen("gcd_result.txt","w");

	int err = 0;
   
	uint16_t S = 1;
	if(argc > 1)
		S = atoi(argv[1]);
	fprintf(stderr,"Scale-factor = %d.\n",S);


	srand48(19);

	uint16_t i;
	for(i = 0; i < ORDER; i++)
	{
		N[i] = ((uint16_t) (0x0fff * drand48())) * S;
		fprintf(stderr,"N[%d] = %d\n", i, N[i]);
		write_uint16("in_data",N[i]);
		to_string(ostr,N[i]);
		fprintf(ofile1,"%s\n", ostr);
	}

	uint16_t g = read_uint16("out_data");
	fprintf(stderr,"GCD = %d.\n",g);
	to_string(ostr,g);
	fprintf(ofile2,"%s\n",ostr);

	uint32_t et = read_uint32("elapsed_time");
	fprintf(stderr,"Elapsed time = %u.\n", et);

	fclose(ofile1);
	fclose(ofile2);

#ifdef SW
	PTHREAD_CANCEL(gcd_daemon);
	close_pipe_handler();
#endif

	return(0);
}
Beispiel #12
0
int main(int argc, char* argv[])
{
	float result;
	int I, J;

	if(argc < 2)
	{
		fprintf(stderr,"Supply data set file.\n");
		return(1);
	}


	signal(SIGINT,  Exit);
	signal(SIGTERM, Exit);

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(bestFit);
	PTHREAD_DECL(qrsDet);
	PTHREAD_CREATE(bestFit);
	PTHREAD_CREATE(qrsDet);
#endif
	PTHREAD_DECL(Sender);
	PTHREAD_DECL(Receiver);	
	PTHREAD_CREATE_WITH_ARG(Sender, argv[1]);
	PTHREAD_CREATE(Receiver);

	PTHREAD_JOIN(Sender);
	PTHREAD_CANCEL(Receiver);
	



#ifdef SW
	PTHREAD_CANCEL(qrsDet);
	PTHREAD_CANCEL(bestFit);
	close_pipe_handler();
	return(0);
#endif
}
Beispiel #13
0
int main(int argc, char* argv[])
{
	float result[ORDER];
	signal(SIGINT,  Exit);
	signal(SIGTERM, Exit);

	uint8_t idx;
	for(idx = 0; idx < ORDER; idx++)
	{
		op[idx] = idx % 4;
		x[idx] = drand48();
		y[idx] = drand48();
	}
#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(streamProcessor);
	PTHREAD_CREATE(streamProcessor);
#endif
	PTHREAD_DECL(sendX);
	PTHREAD_CREATE(sendX);
	PTHREAD_DECL(sendY);
	PTHREAD_CREATE(sendY);
	PTHREAD_DECL(sendOp);
	PTHREAD_CREATE(sendOp);



	read_float32_n("z_pipe",result,ORDER);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"Result = %f, expected = %f.\n", result[idx],expectedResult(op[idx], x[idx], y[idx]));
	}
#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(streamProcessor);
#endif
	return(0);
}
Beispiel #14
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "vmem_multiple_pools");

	if (argc < 4)
		UT_FATAL("usage: %s directory npools nthreads", argv[0]);

	dir = argv[1];
	npools = atoi(argv[2]);
	int nthreads = atoi(argv[3]);

	UT_OUT("create %d pools in %d thread(s)", npools, nthreads);

	const unsigned mem_pools_size = (npools / 2 + npools % 2) * nthreads;
	mem_pools = MALLOC(mem_pools_size * sizeof(char *));
	pools = CALLOC(npools * nthreads, sizeof(VMEM *));
	os_thread_t *threads = CALLOC(nthreads, sizeof(os_thread_t));
	UT_ASSERTne(threads, NULL);
	int *pool_idx = CALLOC(nthreads, sizeof(int));
	UT_ASSERTne(pool_idx, NULL);

	for (unsigned pool_id = 0; pool_id < mem_pools_size; ++pool_id) {
		/* allocate memory for function vmem_create_in_region() */
		mem_pools[pool_id] = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
	}

	/* create and destroy pools multiple times */
	for (int t = 0; t < nthreads; t++) {
		pool_idx[t] = npools * t;
		PTHREAD_CREATE(&threads[t], NULL, thread_func, &pool_idx[t]);
	}

	for (int t = 0; t < nthreads; t++)
		PTHREAD_JOIN(&threads[t], NULL);

	for (int pool_id = 0; pool_id < npools * nthreads; ++pool_id) {
		if (pools[pool_id] != NULL) {
			vmem_delete(pools[pool_id]);
			pools[pool_id] = NULL;
		}
	}

	FREE(mem_pools);
	FREE(pools);
	FREE(threads);
	FREE(pool_idx);

	DONE(NULL);
}
Beispiel #15
0
static void
run_mt_test(void *(*worker)(void *))
{
	pthread_t thread[NUM_THREADS];
	int ver[NUM_THREADS];

	for (int i = 0; i < NUM_THREADS; ++i) {
		ver[i] = 10000 + i;
		PTHREAD_CREATE(&thread[i], NULL, worker, &ver[i]);
	}
	for (int i = 0; i < NUM_THREADS; ++i) {
		PTHREAD_JOIN(thread[i], NULL);
	}
}
Beispiel #16
0
int main(int argc, char* argv[])
{
	uint8_t result[ORDER];
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

	PTHREAD_DECL(Write_Sender);
	PTHREAD_CREATE(Write_Sender);
	PTHREAD_DECL(Read_Sender);
	PTHREAD_CREATE(Read_Sender);

	uint8_t idx;
	
	read_uint8_n("read_response",result,ORDER);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"Result = %x, expected = %x.\n", result[idx],idx);
	}
	PTHREAD_CANCEL(Write_Sender);
	PTHREAD_CANCEL(Read_Sender);
	return(0);
}
Beispiel #17
0
int main(int argc, char* argv[])
{
	uint32_t result[ORDER];
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

	PTHREAD_DECL(Sender_1);
	PTHREAD_CREATE(Sender_1);
	PTHREAD_DECL(Sender_2);
	PTHREAD_CREATE(Sender_2);

	uint8_t idx;
	
	read_uint32_n("o_data",result,ORDER);

	for(idx = 0; idx < ORDER; idx++)
	{
		fprintf(stdout,"Result = %x.\n", result[idx]);
	}
	PTHREAD_CANCEL(Sender_1);
	PTHREAD_CANCEL(Sender_2);
	return(0);
}
int main(int argc, char* argv[])
{
#ifdef SW
	init_pipe_handler_with_log("pipelog.txt");
	PTHREAD_DECL(vector_control_daemon);   // declare the Daemon thread.
	PTHREAD_CREATE(vector_control_daemon); // start the Daemon..
#endif

	double	*iq, 
		*iq_prev,
		*id,
		*id_prev,
		*flq,
		*flq_prev,
		*fld,
		*fld_prev,
		*spd,
		*spd_prev,
		vd,
		vq,
		torque,
		load_torque,
		*time = 0;
	
	double speed_ref
		
	int i=0;
	int no_of_cycles = 4000 ; // 100u/25n (Ideal time necessary for conputation for FPGA/Motor_iteration_step)
				
	while(1)
	{
		for(i = 0; i< no_of_cycles; i++){
			im_zep(&iq,&iq_prev,&id,&id_prev,&flq,&flq_prev,&fld,&fld_prev,&spd_prev,vd,vq,&torque,load_torque,&time)
		}
		
		write_float32("in_data",*id);
		write_float32("in_data",*iq);
		write_float32("in_data",speed_ref);

		vd = read_float32("out_data");
		vq = read_float32("out_data");
	}

#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(vector_control_daemon);
#endif
	return(0);
}
Beispiel #19
0
/*
 * test_persist -- test case for persist operation
 */
static int
test_persist(const struct test_case *tc, int argc, char *argv[])
{
	if (argc < 4)
		UT_FATAL("usage: test_persist <id> <seed> <nthreads> <nops>");

	int id = atoi(argv[0]);
	UT_ASSERT(id >= 0 && id < MAX_IDS);
	struct pool_entry *pool = &pools[id];

	srand(atoi(argv[1]));

	int nthreads = atoi(argv[2]);
	int nops = atoi(argv[3]);

	uint8_t *buff = (uint8_t *)pool->pool;
	size_t buff_size = pool->size;

	for (size_t i = 0; i < buff_size; i++)
		buff[i] = rand();

	pthread_t *threads = MALLOC(nthreads * sizeof(*threads));
	struct thread_arg *args = MALLOC(nthreads * sizeof(*args));
	size_t size_per_thread = buff_size / nthreads;
	UT_ASSERTeq(buff_size % nthreads, 0);

	for (int i = 0; i < nthreads; i++) {
		args[i].rpp = pool->rpp;
		args[i].nops = nops;
		args[i].lane = (unsigned)i;
		args[i].off = i * size_per_thread;
		size_t size_left = buff_size - size_per_thread * i;
		args[i].size = size_left < size_per_thread ?
				size_left : size_per_thread;
		PTHREAD_CREATE(&threads[i], NULL, persist_thread, &args[i]);
	}

	for (int i = 0; i < nthreads; i++)
		PTHREAD_JOIN(threads[i], NULL);

	FREE(args);
	FREE(threads);

	return 4;
}
Beispiel #20
0
int
main(int argc, char *argv[])
{
    START(argc, argv, "pmem_is_pmem");

    if (argc <  2 || argc > 3)
        UT_FATAL("usage: %s file [env]", argv[0]);

    if (argc == 3)
        UT_ASSERTeq(setenv("PMEM_IS_PMEM_FORCE", argv[2], 1), 0);

    int fd = OPEN(argv[1], O_RDWR);

    ut_util_stat_t stbuf;
    FSTAT(fd, &stbuf);

    Size = stbuf.st_size;
    Addr = MMAP(0, stbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    CLOSE(fd);

    pthread_t threads[NTHREAD];
    int ret[NTHREAD];

    /* kick off NTHREAD threads */
    for (int i = 0; i < NTHREAD; i++)
        PTHREAD_CREATE(&threads[i], NULL, worker, &ret[i]);

    /* wait for all the threads to complete */
    for (int i = 0; i < NTHREAD; i++)
        PTHREAD_JOIN(threads[i], NULL);

    /* verify that all the threads return the same value */
    for (int i = 1; i < NTHREAD; i++)
        UT_ASSERTeq(ret[0], ret[i]);

    UT_OUT("%d", ret[0]);

    UT_ASSERTeq(unsetenv("PMEM_IS_PMEM_FORCE"), 0);

    UT_OUT("%d", pmem_is_pmem(Addr, Size));

    DONE(NULL);
}
Beispiel #21
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_rw_mt");

	if (argc != 6)
		FATAL("usage: %s bsize file seed nthread nops", argv[0]);

	Bsize = strtoul(argv[1], NULL, 0);

	const char *path = argv[2];

	if ((Handle = pmemblk_pool_open(path, Bsize)) == NULL)
		FATAL("!%s: pmemblk_pool_open", path);

	if (Nblock == 0)
		Nblock = pmemblk_nblock(Handle);
	Seed = strtoul(argv[3], NULL, 0);
	Nthread = strtoul(argv[4], NULL, 0);
	Nops = strtoul(argv[5], NULL, 0);

	OUT("%s block size %zu usable blocks %zu", argv[1], Bsize, Nblock);

	pthread_t threads[Nthread];

	/* kick off nthread threads */
	for (int i = 0; i < Nthread; i++)
		PTHREAD_CREATE(&threads[i], NULL, worker, (void *)(long)i);

	/* wait for all the threads to complete */
	for (int i = 0; i < Nthread; i++)
		PTHREAD_JOIN(threads[i], NULL);

	pmemblk_pool_close(Handle);

	/* XXX not ready to pass this part of the test yet */
	int result = pmemblk_pool_check(path);
	if (result < 0)
		OUT("!%s: pmemblk_pool_check", path);
	else if (result == 0)
		OUT("%s: pmemblk_pool_check: not consistent", path);

	DONE(NULL);
}
Beispiel #22
0
static void start_mark_threads()
{
    unsigned i;
    pthread_attr_t attr;

    if (GC_markers > MAX_MARKERS) {
	WARN("Limiting number of mark threads\n", 0);
	GC_markers = MAX_MARKERS;
    }
    if (0 != pthread_attr_init(&attr)) ABORT("pthread_attr_init failed");
	
    if (0 != pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
	ABORT("pthread_attr_setdetachstate failed");

#   if defined(HPUX) || defined(GC_DGUX386_THREADS)
      /* Default stack size is usually too small: fix it. */
      /* Otherwise marker threads or GC may run out of	  */
      /* space.						  */
#     define MIN_STACK_SIZE (8*HBLKSIZE*sizeof(word))
      {
	size_t old_size;
	int code;

        if (pthread_attr_getstacksize(&attr, &old_size) != 0)
	  ABORT("pthread_attr_getstacksize failed\n");
	if (old_size < MIN_STACK_SIZE) {
	  if (pthread_attr_setstacksize(&attr, MIN_STACK_SIZE) != 0)
		  ABORT("pthread_attr_setstacksize failed\n");
	}
      }
#   endif /* HPUX || GC_DGUX386_THREADS */
#   ifdef CONDPRINT
      if (GC_print_stats) {
	GC_printf1("Starting %ld marker threads\n", GC_markers - 1);
      }
#   endif
    for (i = 0; i < GC_markers - 1; ++i) {
      if (0 != PTHREAD_CREATE(GC_mark_threads + i, &attr,
			      GC_mark_thread, (void *)(word)i)) {
	WARN("Marker thread creation failed, errno = %ld.\n", errno);
      }
    }
}
Beispiel #23
0
static void
test_create(unsigned nthreads)
{
	/* create and destroy pools multiple times */
	for (unsigned t = 0; t < nthreads; t++) {
		Pool_idx[t] = Npools * t;
		PTHREAD_CREATE(&Threads[t], NULL, thread_func_create,
				&Pool_idx[t]);
	}

	for (unsigned t = 0; t < nthreads; t++)
		PTHREAD_JOIN(&Threads[t], NULL);

	for (unsigned i = 0; i < Npools * nthreads; ++i) {
		if (Pools[i] != NULL) {
			pmemcto_close(Pools[i]);
			Pools[i] = NULL;
		}
	}
}
Beispiel #24
0
int main(int argc, char* argv[])
{
	signal(SIGINT,  Exit);
	signal(SIGTERM, Exit);
	int idx;
	int expected, diff;
	PTHREAD_DECL(Sender);
	PTHREAD_CREATE(Sender);

	for(idx = 0; idx < ORDER; idx++)
	{
		result[idx] = read_uint32("out_data");
		expected = *((uint32_t*) &expected_result[idx]);
		diff = result[idx] - expected;
		fprintf(stdout,"Result = %x, expected = %x, diff = %d.\n", result[idx], expected,diff);

	}

	PTHREAD_CANCEL(Sender);

	return(0);
}
Beispiel #25
0
int main(void)
{
    BYTE init[16] = {
	0, 1, 2, 3,
	4, 5, 6, 7,
	8, 9, 10, 11,
	12, 13, 14, 15
    };

#ifdef SW
	init_pipe_handler();
	PTHREAD_DECL(Daemon);
	PTHREAD_CREATE(Daemon);
#endif

    sendConstants();

    int i, run;
    long long t1[10], t2[10];

    for (run = 0; run < 10; run++) {
	fprintf(stderr," run %d.\n", run);
	for (i = 0; i < 16; i++) {
	    write_uint8("input_block_pipe", init[i]);
	    fprintf(stderr," wrote %x \n", init[i]);
	}

	for (i = 0; i < 16; i++) {
		uint8_t rV = read_uint8("output_block_pipe");
		fprintf(stderr," read-back %x \n", rV);
	}
    }

#ifdef SW
	close_pipe_handler();
	PTHREAD_CANCEL(Daemon);
#endif
    return 0;
}
Beispiel #26
0
int main(int argc, char* argv[])
{	
	uint64_t result[2];
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);

	PTHREAD_DECL(Sender);
	PTHREAD_CREATE(Sender);
	
	uint8_t idx, jdx;
	
	
	for(idx = 0; idx < ORDER; idx++)
	{
	
		read_uint64_n("out_data",result,2);
		fprintf(stdout,"\n%16llx %16llx", result[0],result[1]);
	}
	
	
	PTHREAD_CANCEL(Sender);
	return(0);
}
Beispiel #27
0
int main(int argc, char* argv[])
{
	signal(SIGINT,  Exit);
  	signal(SIGTERM, Exit);
  	signal(SIGSEGV, Exit);

        int i,j,k;

        srand48(100);

        for(i = 0; i < ORDER; i++)
	{
        	for(j = 0; j < ORDER; j++)
		{
			a_matrix[i][j] = drand48();
			b_matrix[i][j] = drand48();
		}
	}

        for(i = 0; i < ORDER; i++)
	{
        	for(j = 0; j < ORDER; j++)
		{
			expected_c_matrix[i][j] = 0;
        		for(k = 0; k < ORDER; k++)
				expected_c_matrix[i][j] += a_matrix[i][k] * b_matrix[k][j];
		}
	}
	
#ifdef SW
	init_pipe_handler();

	PTHREAD_DECL(mmultiply);
	PTHREAD_DECL(mmultiply_LL);
	PTHREAD_DECL(mmultiply_LH);
	PTHREAD_DECL(mmultiply_HH);
	PTHREAD_DECL(mmultiply_HL);

	PTHREAD_CREATE(mmultiply);
	PTHREAD_CREATE(mmultiply_LL);
	PTHREAD_CREATE(mmultiply_LH);
	PTHREAD_CREATE(mmultiply_HH);
	PTHREAD_CREATE(mmultiply_HL);
#endif

	write_matrices();
	read_result_matrix();



	fprintf(stdout,"results: \n ");
	for(i = 0; i < ORDER; i++)
	{
		for(j = 0; j < ORDER; j++)
		{
			if(expected_c_matrix[i][j] == c_matrix[i][j])
				fprintf(stdout,"result[%d][%d] = %f\n", i, j, c_matrix[i][j]);
			else
				fprintf(stdout,"Error: result[%d][%d] = %f, expected = %f\n", 
						i, j, c_matrix[i][j], expected_c_matrix[i][j]);

		}
	}
	fprintf(stdout,"done\n");

#ifdef SW
	PTHREAD_CANCEL(mmultiply);
	PTHREAD_CANCEL(mmultiply_LL);
	PTHREAD_CANCEL(mmultiply_LH);
	PTHREAD_CANCEL(mmultiply_HH);
	PTHREAD_CANCEL(mmultiply_HL);
	close_pipe_handler();
#endif
}
Beispiel #28
0
/**
 * Main worker thread.  Register FAM events and process.
 */
static void * worker(void * arg) {
  DIC * cls = arg;
  int i;
  int more;
  int wasMore;
  int ret;
  void * unused;
  char * fn;
  PTHREAD_T helperThread;

  cls->log(cls->logContext,
	   DOODLE_LOG_VERY_VERBOSE,
	   _("Main worker thread created.\n"));
  cls->eventCount = 0;
  cls->continueRunning = 1;
  cls->events = NULL;
  cls->signal = SEMAPHORE_NEW(0);
  if (0 != PTHREAD_CREATE(&helperThread,
			  &processEvents,
			  cls,
			  64 * 1024)) {
    cls->log(cls->logContext,
	     DOODLE_LOG_CRITICAL,
	     _("Failed to spawn event processing thread.\n"));
    run_shutdown(0);
    return NULL;
  }

  cls->log(cls->logContext,
	   DOODLE_LOG_VERBOSE,
	   _("Registering with FAM for file system events.\n"));
  for (i=0;i<cls->argc;i++) {
    char * exp;

    cls->log(cls->logContext,
	     DOODLE_LOG_VERY_VERBOSE,
	     _("Indexing '%s'\n"),
	     cls->argv[i]);
    exp = expandFileName(cls->argv[i]);
    if (-1 == do_index(exp,
		       cls)) {
      ret = -1;
      free(exp);
      break;
    }
    free(exp);
  }
  DOODLE_tree_destroy(cls->tree);
  cls->treePresent = 0;
  cls->tree = NULL;

  cls->log(cls->logContext,
	   DOODLE_LOG_VERBOSE,
	   _("doodled startup complete.  Now waiting for FAM events.\n"));

  wasMore = 0;
  while ( (cls->continueRunning) &&
	  (0 == testShutdown()) ) {
    SEMAPHORE_DOWN(cls->signal);
    cls->log(cls->logContext,
	     DOODLE_LOG_INSANELY_VERBOSE,
	     "Received signal to process fam event.\n");
    MUTEX_LOCK(&cls->lock);
    if (cls->eventCount > 0) {
      fn = cls->events[cls->eventCount-1];
      GROW(cls->events,
	   cls->eventCount,
	   cls->eventCount-1);
      more = cls->eventCount > 0;
      cls->log(cls->logContext,
	       DOODLE_LOG_INSANELY_VERBOSE,
	       "Processing fam event '%s'.\n",
	       fn);
    } else {
      fn = NULL;
      more = 0;
    }
    if (! wasMore) {
      cls->treePresent++;
      if (cls->treePresent == 1)
	cls->tree = DOODLE_tree_create((DOODLE_Logger) cls->log,
				       cls->logContext,
				       cls->ename);
    }
    MUTEX_UNLOCK(&cls->lock);
    if (fn != NULL) {
      do_index(fn, cls);
      free(fn);
    }
    MUTEX_LOCK(&cls->lock);
    if (! more) {
      cls->treePresent--;
      if (cls->treePresent == 0)
	DOODLE_tree_destroy(cls->tree);
    }
    MUTEX_UNLOCK(&cls->lock);
    wasMore = more;
  } /* forever (until signal) */

  cls->continueRunning = 0;
  if (0 != FAMClose(&cls->fc)) {
    cls->log(cls->logContext,
	   DOODLE_LOG_CRITICAL,
	   _("Error disconnecting from fam.\n"));
  }
  PTHREAD_KILL(&helperThread, SIGTERM);
  PTHREAD_JOIN(&helperThread, &unused);
  SEMAPHORE_FREE(cls->signal);

  if (cls->treePresent > 0)
    DOODLE_tree_destroy(cls->tree);
  return NULL;
}
Beispiel #29
0
/**
 * Make sure the DB is current and then go into FAM-monitored mode
 * updating the DB all the time in the background.  Exits after a
 * signal (i.e.  SIGHUP/SIGINT) is received.
 */
static int build(const char * libraries,
		 const char * dbName,
		 size_t mem_limit,
		 const char * log,
		 int argc,		
		 char * argv[]) {
  int i;
  unsigned int ret;
  DIC cls;
  char * ename;
  FILE * logfile;
  PTHREAD_T workerThread;
  void * unused;

  cls.argc = argc;
  cls.argv = argv;
  cls.deferredCount = 0;
  cls.deferredTruncations = NULL;
  logfile = NULL;
  if (log != NULL) {
    logfile = fopen(log, "w+");
    if (logfile == NULL)
      my_log(stderr,
	     DOODLE_LOG_CRITICAL,
	     _("Could not open '%s' for logging: %s.\n"),
	     log,
	     strerror(errno));
  }
  cls.logContext = logfile;
  cls.log = &my_log;


  if (dbName == NULL) {
    my_log(logfile,
	   DOODLE_LOG_CRITICAL,
	   _("No database specified.  Aborting.\n"));
    return -1;
  }
  for (i=strlen(dbName);i>=0;i--) {
    if (dbName[i] == ':') {
      my_log(logfile,
	     DOODLE_LOG_CRITICAL,
	     _("'%s' is an invalid database filename (has a colon) for building database (option '%s').\n"),
	     dbName,
	     "-b");
      return -1;
    }
  }
  ename = expandFileName(dbName);
  if (ename == NULL)
    return -1;
  cls.ename = ename;
  cls.tree = DOODLE_tree_create(&my_log,
				logfile,
				ename);
  cls.treePresent = 1;
  if (cls.tree == NULL)
    return -1;
  if (mem_limit != 0)
    DOODLE_tree_set_memory_limit(cls.tree,
				 mem_limit);
  cls.elist = forkExtractor(do_default,
			    libraries,
			    &my_log,
			    logfile);
  if (cls.elist == NULL) {
    DOODLE_tree_destroy(cls.tree);
    return -1;
  }
  if (0 != FAMOpen2(&cls.fc, "doodled")) {
    my_log(logfile,
	   DOODLE_LOG_CRITICAL,
	   _("Failed to connect to fam.  Aborting.\n"));
    DOODLE_tree_destroy(cls.tree);
    return -1;
  }
  cls.fr = NULL;
  cls.frPos = 0;
  cls.frSize = 0;
  GROW(cls.fr,
       cls.frSize,
       128);
  cls.frNames = NULL;
  ret = 0;
  GROW(cls.frNames,
       ret,
       128);
  ret = 0;


  MUTEX_CREATE(&cls.lock);
  if (0 != PTHREAD_CREATE(&workerThread,
			  &worker,
			  &cls,
			  64 * 1024)) {
    my_log(logfile,
	   DOODLE_LOG_CRITICAL,
	   _("Failed to create worker thread: %s"),
	   strerror(errno));
    ret = -1;
  } else {
    wait_for_shutdown();
    cls.continueRunning = 0;
    SEMAPHORE_UP(cls.signal);
    PTHREAD_JOIN(&workerThread, &unused);
  }
  MUTEX_DESTROY(&cls.lock);

  my_log(logfile,
	 DOODLE_LOG_VERBOSE,
	 _("doodled is shutting down.\n"));
  if (cls.frPos == 0) {
    my_log(logfile,
	   DOODLE_LOG_CRITICAL,
	   _("No files exist that doodled would monitor for changes.  Exiting.\n"));
  }


  for (i=0;i<cls.frSize;i++) {
    if (cls.frNames[i] != NULL) {
      my_log(logfile,
	     DOODLE_LOG_VERBOSE,
	     _("Cancelling fam monitor '%s'.\n"),
	     cls.frNames[i]);
      free(cls.frNames[i]);
    }
  }

  for (i=cls.deferredCount-1;i>=0;i--)
    free(cls.deferredTruncations[i]);
  GROW(cls.deferredTruncations,
       cls.deferredCount,
       0);
  i = cls.frSize;
  GROW(cls.fr,
       cls.frSize,
       0);
  cls.frSize = i;
  GROW(cls.frNames,
       cls.frSize,
       0);
  my_log(logfile,
	 DOODLE_LOG_VERBOSE,
	 _("Unloading libextractor plugins.\n"));
  joinExtractor(cls.elist);
  free(ename);
  if (logfile != NULL)
    fclose(logfile);
  return ret;
}
Beispiel #30
0
int
main(int argc, char *argv[])
{
	if (argc == 4 && argv[3][0] == 't') {
		exit(0);
	}

	START(argc, argv, "vmmalloc_fork");

	if (argc < 4)
		FATAL("usage: %s [c|e] <nfork> <nthread>", argv[0]);

	int nfork = atoi(argv[2]);
	int nthread = atoi(argv[3]);
	ASSERT(nfork >= 0);
	ASSERT(nthread >= 0);

	pthread_t thread[nthread];
	int first_child = 0;

	int **bufs = malloc(nfork * NBUFS * sizeof (void *));
	ASSERTne(bufs, NULL);

	size_t *sizes = malloc(nfork * NBUFS * sizeof (size_t));
	ASSERTne(sizes, NULL);

	int *pids1 = malloc(nfork * sizeof (pid_t));
	ASSERTne(pids1, NULL);

	int *pids2 = malloc(nfork * sizeof (pid_t));
	ASSERTne(pids2, NULL);

	for (int i = 0; i < nfork; i++) {
		for (int j = 0; j < NBUFS; j++) {
			int idx = i * NBUFS + j;

			sizes[idx] = sizeof (int) + 64 * (rand() % 100);
			bufs[idx] = malloc(sizes[idx]);
			ASSERTne(bufs[idx], NULL);
			ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]);
		}

		for (int t = 0; t < nthread; ++t) {
			PTHREAD_CREATE(&thread[t], NULL, do_test, NULL);
		}

		pids1[i] = fork();
		if (pids1[i] == -1)
			OUT("fork failed");
		ASSERTne(pids1[i], -1);

		if (pids1[i] == 0 && argv[1][0] == 'e' && i == nfork - 1) {
			int fd = open("/dev/null", O_RDWR, S_IWUSR);
			int res = dup2(fd, 1);
			ASSERTne(res, -1);
			close(fd);
			execl("/bin/echo", "/bin/echo", "Hello world!", NULL);
		}

		pids2[i] = getpid();

		for (int j = 0; j < NBUFS; j++) {
			*bufs[i * NBUFS + j] = ((unsigned)pids2[i] << 16) + j;
		}

		if (pids1[i]) {
			/* parent */
			for (int t = 0; t < nthread; ++t) {
				PTHREAD_JOIN(thread[t], NULL);
			}
		} else {
			/* child */
			first_child = i + 1;
		}

		for (int ii = 0; ii < i; ii++) {
			for (int j = 0; j < NBUFS; j++) {
				ASSERTeq(*bufs[ii * NBUFS + j],
					((unsigned)pids2[ii] << 16) + j);
			}
		}
	}

	for (int i = first_child; i < nfork; i++) {
		int status;
		waitpid(pids1[i], &status, 0);
		ASSERT(WIFEXITED(status));
		ASSERTeq(WEXITSTATUS(status), 0);
	}

	free(pids1);
	free(pids2);

	for (int i = 0; i < nfork; i++) {
		for (int j = 0; j < NBUFS; j++) {
			int idx = i * NBUFS + j;

			ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]);
			free(bufs[idx]);
		}
	}

	free(bufs);

	if (first_child == 0) {
		DONE(NULL);
	}
}