Exemple #1
0
static void * alloc_zero_map(struct map *map, int prot, const char *name)
{
	struct map *tmpmap = map;
	int fd;
	unsigned long size = 0;

	if (!tmpmap)
		tmpmap = alloc_map();

	fd = open("/dev/zero", O_RDWR);
	if (!fd) {
		printf("open /dev/zero failure\n");
		exit(EXIT_FAILURE);
	}

	/* Pick a random sized mmap. */
	switch (rand() % 4) {
	case 0:	size = page_size;
		break;
	case 1:	size = 1024*1024;
		break;
	case 2:	size = 2 * (1024*1024);
		break;
	case 3:	size = 4 * (1024*1024);
		break;
	default:
		break;
	}

	/* page_size * 2, so we have a guard page afterwards.
	 * This is necessary for when we want to test page boundaries.
	 * see end of _get_address() for details.
	 */
	size *= 2;

	tmpmap->ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_SHARED, -1, 0);

	if (tmpmap->ptr == MAP_FAILED) {
		printf("mmap /dev/zero failure\n");
		exit(EXIT_FAILURE);
	}

	tmpmap->size = size;

	tmpmap->name = malloc(80);
	if (!tmpmap->name) {
		fprintf(stderr, "malloc() failed in %s().", __func__);
		exit(EXIT_FAILURE);
	}

	sprintf(tmpmap->name, "/dev/zero(%s)", name);
	num_mappings++;

	output(2, "mapping[%d]: (zeropage %s) %p (%lu bytes)\n",
			num_mappings - 1, name, tmpmap->ptr, size);

	close(fd);
	return tmpmap;
}
void Chip_to_Chip_Direct_to_Hypervisor_Zero_Copy_Endpoint::allocate_huge_pages() {
  // total_data_buf_size = data_buf_size * TILEPCI_MAX_C2C_NCMD;
  static const int cmds_per_endpoint = 1;
  static const int endpoints_per_chip = 2;
  int num_cmds = The_Tilera_Chip_to_Chip_Message_Queue.num_chips * cmds_per_endpoint * endpoints_per_chip;
  total_data_buf_size =  data_buf_size * num_cmds;
  alloc_attr_t attr = ALLOC_INIT;
  alloc_set_huge(&attr);
  all_data_bufs = (char*)alloc_map(&attr, total_data_buf_size); // UG227 pg 85
  if (!all_data_bufs) {
    lprintf("alloc for Chip_to_Chip_Direct_to_Hypervisor_Zero_Copy_Endpoint buffer memory failed: %d bytes\n", total_data_buf_size);
    fatal("");
  }
}
Exemple #3
0
int		cmd_msz(t_gfx *s, char *token)
{
  char		*tok;

  if ((tok = strtok(token, " ")) == NULL)
    return (EXIT_FAILURE);
  if ((tok = strtok(NULL, " ")) == NULL)
    return (EXIT_FAILURE);
  s->width = atoi(tok);
  if ((tok = strtok(NULL, " ")) == NULL)
    return (EXIT_FAILURE);
  s->height = atoi(tok);
  if (alloc_map(s) == EXIT_FAILURE)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
Exemple #4
0
void setup_maps(void)
{
	struct map *tmpmap;

	tmpmap = maps_list = alloc_map();

	/* Add a bunch of /dev/zero mappings */
	tmpmap->next = alloc_zero_map(tmpmap, PROT_READ | PROT_WRITE, "PROT_READ | PROT_WRITE");
	tmpmap = tmpmap->next;

	tmpmap->next = alloc_zero_map(NULL, PROT_READ, "PROT_READ");
	tmpmap = tmpmap->next;

	tmpmap->next = alloc_zero_map(NULL, PROT_WRITE, "PROT_WRITE");

	output(2, "Added /dev/zero mappings.\n");
	dump_maps();
}
Exemple #5
0
Tokenstream * parse_file(const char *path_xml, const char *path_tokens, int n_threads)
{
	char ** chunks;
	chunker_init(path_xml);
	chunker_load_file_content();
	chunks = chunker_compute_chunks(&n_threads);
	
	Tokenstream * t_streams = malloc(n_threads * sizeof(Tokenstream));
	for(int i = 0; i < n_threads; ++i)
	{
		create_tokenstream(t_streams + i, (1024) / sizeof(Token)); //1KB per tokenstream
		if(i != n_threads -1)
		{
			t_streams[i].next = &t_streams[i+1];
		}
	}
	
	Map * map = alloc_map(path_tokens);
//	print_map(map);

	int tid;
	Parser * parser;
#pragma omp parallel num_threads(n_threads) firstprivate(map,chunks) private(tid, parser)
	{
		tid = omp_get_thread_num() % n_threads;
//		tid = 0;
		char * chunk_begin, * chunk_end;
		chunk_begin = chunks[tid];
		chunk_end = chunks[tid + 1];

		parser = alloc_parser(chunk_begin, chunk_end);
		init_parser(parser, map);
		Tokenstream * ts = t_streams + tid; 
		Token * current = get_new_token_pointer(&ts);
		while(get_next_token(parser, current) == 1)
		{
			current = get_new_token_pointer(&ts);
		}
		free(parser);
	}
	free(chunks);
	destroy_map(map);
	return t_streams;
}
Exemple #6
0
static tmx_map *parse_root_map(xmlTextReaderPtr reader, const char *filename) {
	tmx_map *res = NULL;
	int curr_depth;
	const char *name;
	char *value;

	name = (char*) xmlTextReaderConstName(reader);
	curr_depth = xmlTextReaderDepth(reader);

	if (strcmp(name, "map")) {
		tmx_err(E_XDATA, "xml parser: root is not a 'map' element");
		return NULL;
	}

	if (!(res = alloc_map())) return NULL;

	/* parses each attribute */
	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"orientation"))) { /* orientation */
		if (res->orient = parse_orient(value), res->orient == O_NONE) {
			tmx_err(E_XDATA, "xml parser: unsupported 'orientation' '%s'", value);
			goto cleanup;
		}
		tmx_free_func(value);
	} else {
		tmx_err(E_MISSEL, "xml parser: missing 'orientation' attribute in the 'map' element");
		goto cleanup;
	}

	value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"renderorder"); /* renderorder */
	if (res->renderorder = parse_renderorder(value), res->renderorder == R_NONE) {
		tmx_err(E_XDATA, "xml parser: unsupported 'renderorder' '%s'", value);
		goto cleanup;
	}
	tmx_free_func(value);

	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"height"))) { /* height */
		res->height = atoi(value);
		tmx_free_func(value);
	} else {
		tmx_err(E_MISSEL, "xml parser: missing 'height' attribute in the 'map' element");
		goto cleanup;
	}

	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"width"))) { /* width */
		res->width = atoi(value);
		tmx_free_func(value);
	} else {
		tmx_err(E_MISSEL, "xml parser: missing 'width' attribute in the 'map' element");
		goto cleanup;
	}

	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"tileheight"))) { /* tileheight */
		res->tile_height = atoi(value);
		tmx_free_func(value);
	} else {
		tmx_err(E_MISSEL, "xml parser: missing 'tileheight' attribute in the 'map' element");
		goto cleanup;
	}

	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"tilewidth"))) { /* tilewidth */
		res->tile_width = atoi(value);
		tmx_free_func(value);
	} else {
		tmx_err(E_MISSEL, "xml parser: missing 'tilewidth' attribute in the 'map' element");
		goto cleanup;
	}

	if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"backgroundcolor"))) { /* backgroundcolor */
		res->backgroundcolor = get_color_rgb(value);
		tmx_free_func(value);
	}

	/* Parse each child */
	do {
		if (xmlTextReaderRead(reader) != 1) goto cleanup; /* error_handler has been called */

		if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) {
			name = (char*)xmlTextReaderConstName(reader);
			if (!strcmp(name, "tileset")) {
				if (!parse_tileset(reader, &(res->ts_head), filename)) goto cleanup;
			} else if (!strcmp(name, "layer")) {
				if (!parse_layer(reader, &(res->ly_head), res->height, res->width, L_LAYER, filename)) goto cleanup;
			} else if (!strcmp(name, "objectgroup")) {
				if (!parse_layer(reader, &(res->ly_head), res->height, res->width, L_OBJGR, filename)) goto cleanup;
			} else if (!strcmp(name, "imagelayer")) {
				if (!parse_layer(reader, &(res->ly_head), res->height, res->width, L_IMAGE, filename)) goto cleanup;
			} else if (!strcmp(name, "properties")) {
				if (!parse_properties(reader, &(res->properties))) goto cleanup;
			} else {
				/* Unknow element, skip its tree */
				if (xmlTextReaderNext(reader) != 1) goto cleanup;
			}
		}
	} while (xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT ||
	         xmlTextReaderDepth(reader) != curr_depth);
	return res;
cleanup:
	tmx_map_free(res);
	return NULL;
}
/* Setup information needed for a specific process.  The debugger
 * assumes that this will hang something onto the process, if nothing
 * is attached to it, then TV will believe that this process has no
 * message queue information.
 */
int mpidbg_init_per_process(mqs_process *process, 
                            const mqs_process_callbacks *pcb,
                            struct mpidbg_handle_info_t *handle_types)
{ 
    mqs_image *image;
    mpi_image_info *i_info;

    /* Extract the addresses of the global variables we need and save
       them away */
    mpi_process_info *p_info = 
        (mpi_process_info *) mqs_malloc(sizeof(mpi_process_info));
    printf("mpidbg_init_per_process\n");

    if (NULL == p_info) {
        return MPIDBG_ERR_NO_MEM;
    }

    /* Setup the callbacks first */
    p_info->process_callbacks = pcb;

    /* Nothing extra (yet) */
    p_info->extra = NULL;

    /* Now we can get the rest of the info */
    image = mqs_get_image(process);
    i_info = (mpi_image_info *) mqs_get_image_info(image);

    /* Get process info sizes */
    mqs_get_type_sizes (process, &p_info->sizes);

    /* Save the info */
    mqs_put_process_info(process, (mqs_process_info *) p_info);

    /* Fill in pre-defined MPI handle name mappings (because OMPI uses
       #define's for the pre-defined names, such as "#define
       MPI_COMM_WORLD &ompi_mpi_comm_world"). */
    /* Communicators */
    mpidbg_comm_name_map = alloc_map(image, 4);
    if (NULL != mpidbg_comm_name_map) {
        int i = 0;
        fill_map(image, "MPI_COMM_WORLD", "ompi_mpi_comm_world",
                 &mpidbg_comm_name_map[i++]);
        fill_map(image, "MPI_COMM_SELF", "ompi_mpi_comm_self",
                 &mpidbg_comm_name_map[i++]);
        fill_map(image, "MPI_COMM_NULL", "ompi_mpi_comm_null",
                 &mpidbg_comm_name_map[i++]);

        /* Sentinel value */
        mpidbg_comm_name_map[i].map_name = NULL;
    }

    /* Error handlers */
    mpidbg_errhandler_name_map = alloc_map(image, 4);
    if (NULL != mpidbg_errhandler_name_map) {
        int i = 0;
        fill_map(image, "MPI_ERRORS_ARE_FATAL", "ompi_mpi_errors_are_fatal",
                 &mpidbg_errhandler_name_map[i++]);
        fill_map(image, "MPI_ERRORS_RETURN", "ompi_mpi_errors_return",
                 &mpidbg_errhandler_name_map[i++]);
        fill_map(image, "MPI_ERRHANDLER_NULL", "ompi_mpi_errhandler_null",
                 &mpidbg_errhandler_name_map[i++]);
        /* MPI::ERRORS_THROW_EXCEPTIONS exists as a symbol in OMPI; no
           need to alias it here */

        /* Sentinel value */
        mpidbg_errhandler_name_map[i].map_name = NULL;
    }

    /* Requests */
    mpidbg_request_name_map = alloc_map(image, 2);
    if (NULL != mpidbg_request_name_map) {
        int i = 0;
        fill_map(image, "MPI_REQUEST_NULL", "ompi_request_null",
                 &mpidbg_request_name_map[i++]);

        /* Sentinel value */
        mpidbg_request_name_map[i].map_name = NULL;
    }

    /* Statuses */
    mpidbg_status_name_map = alloc_map(image, 2);
    if (NULL != mpidbg_status_name_map) {
        int i = 0;
        fill_map(image, "MPI_STATUS_IGNORE", NULL,
                 &mpidbg_status_name_map[i++]);

        /* Sentinel value */
        mpidbg_status_name_map[i].map_name = NULL;
    }

    /* All done */
    return MPIDBG_SUCCESS;
}
Exemple #8
0
// Need to read, the total number of agents, line of chars, number of this agent, map dims, map
clientinfo_t* setup() {
    char line[80];
    uint agcount;
    uint agnum;
    struct sigaction sa;
    sa.sa_handler=pipehandler;
    sa.sa_flags=SA_RESTART;
    sigaction(SIGPIPE, 0, &sa);     
    if (!fgets(line, 80, stdin) || (line[strlen(line)-1]!='\n')) {
        return 0;
    } 
    if (!sscanf(line, "%u", &agcount)) {
        return 0;
    }
        // we can't use a fixed size buffer here because we don't know how many agents
    char* cs=malloc(sizeof(char)*(agcount+1));
    for (int i=0;i<agcount;++i) {
        cs[i]=fgetc(stdin);
	if (feof(stdin) || (cs[i]=='\n')) {
	    free(cs);
	    return 0;
	}
    }
    (void)getchar();	// to clear end of line char
    cs[agcount]='\0';	// to make it easier for debug printing
    if (!fgets(line, 80, stdin) || (line[strlen(line)-1]!='\n')) {
        free(cs);
        return 0;
    }

    if (!sscanf(line, "%u", &agnum)) {
        free(cs);
        return 0;
    }
    agnum-=1;	// to make array lookups easier
    if ((agnum<0) || (agnum>=agcount)) {
        free(cs);
	return 0;
    }
    if (!fgets(line, 80, stdin) || (line[strlen(line)-1]!='\n')) {
        free(cs);
        return 0;
    }
    uint rows, cols;
    if (sscanf(line,"%u %u", &rows, &cols)!=2) {
        free(cs);
        return 0;
    }
    map_t* map=alloc_map(rows, cols);
    if (fill_grid(map, stdin, ' ')) {
        free_map(map);
	free(cs);
        return 0;
    }
    // now we have all the parts
    clientinfo_t* client=malloc(sizeof(clientinfo_t));
    client->agcount=agcount;
    client->agnum=agnum;
    client->chars=cs;
    client->map=map;
    client->pos=malloc(sizeof(uint)*2*agcount);
    return client;
}