void bc_prepare(struct bufferchain *bc, size_t pool_size, size_t bufblock) { bc_poolsize(bc, pool_size, bufblock); bc->pool = NULL; bc->pool_fill = 0; bc_init(bc); /* Ensure that members are zeroed for read-only use. */ }
void open_bad( mpg123_handle_t *mh ) { mh->rd = &bad_reader; mh->rdat.flags = 0; bc_init( &mh->rdat.buffer ); mh->rdat.filelen = -1; }
static int feed_init(mpg123_handle *fr) { bc_init(&fr->rdat.buffer); fr->rdat.filelen = 0; fr->rdat.filepos = 0; fr->rdat.flags |= READER_BUFFERED; return 0; }
void open_bad(mpg123_handle *mh) { #ifndef NO_ICY clear_icy(&mh->icy); #endif mh->rd = &bad_reader; mh->rdat.flags = 0; bc_init(&mh->rdat.buffer); }
int main(int argc, char *argv[]) { int *in, *out, i; /* Initialise libbc using MPI. */ MPI_Init(&argc, &argv); bc_init(BC_ERR); if (bc_size != 9) { if (bc_rank == 0) printf("ERROR: 9 processes are required.\n" "\n\tUSAGE: mpirun -c 9 pipeline_farm\n\n"); bc_final(); MPI_Finalize(); return -1; } /* SPMD, per process stage function. */ switch(bc_rank) { case 0: in = (int *) malloc(sizeof(int)*100); printf("[%d] Input:\n", bc_rank); for (i = 0; i < 100; i++) { in[i] = i; printf("%d ", in[i]); } printf("\n"); stage_0(in); free(in); break; case 1: stage_1(); break; case 2: stage_3(); break; case 3: out = (int *) malloc(sizeof(int)*2); stage_4(out); printf("[%d] Sum: %d\n", bc_rank, out[0]); free(out); break; case 4: case 5: case 6: case 7: case 8: stage_2(); break; default : break; } bc_final(); MPI_Finalize(); return 0; }
static void bc_reset(struct bufferchain *bc) { /* Free current chain, possibly stuffing back into the pool. */ while(bc->first) { struct buffy* buf = bc->first; bc->first = buf->next; bc_free(bc, buf); } bc_fill_pool(bc); /* Ignoring an error here... */ bc_init(bc); }
static void bc_reset(struct bufferchain *bc) { /* free the buffer chain */ struct buffy *b = bc->first; while(b != NULL) { struct buffy *n = b->next; free(b->data); free(b); b = n; } bc_init(bc); }
void open_bad(mpg123_handle *mh) { debug("open_bad"); #ifndef NO_ICY clear_icy(&mh->icy); #endif mh->rd = &bad_reader; mh->rdat.flags = 0; #ifndef NO_FEEDER bc_init(&mh->rdat.buffer); #endif mh->rdat.filelen = -1; }
static void bc_reset( bufferchain_t *bc ) { // free current chain, possibly stuffing back into the pool. while( bc->first ) { buffy_t *buf = bc->first; bc->first = buf->next; bc_free( bc, buf ); } bc_fill_pool( bc ); // ignoring an error here... bc_init( bc ); }
// Initialize the file system void fs_init(void) { static_assert(sizeof(struct File) == 256); // Find a JOS disk. Use the second IDE disk (number 1) if available. if (ide_probe_disk1()) ide_set_disk(1); else ide_set_disk(0); bc_init(); // Set "super" to point to the super block. super = diskaddr(1); check_super(); }
/* Initializes the file system module. If FORMAT is true, reformats the file system. */ void filesys_init (bool format) { fs_device = block_get_role (BLOCK_FILESYS); if (fs_device == NULL) PANIC ("No file system device found, can't initialize file system."); inode_init (); bc_init (); free_map_init (); if (format) do_format (); free_map_open (); thread_current()->thread_dir = dir_open_root(); }
int main(int argc, char *argv[]) { int i, limit = 21; MPI_Init(&argc, &argv); bc_init(BC_ERR | BC_PLIST_XALL); FILE *f; char fname[128]; sprintf(fname, "scatter_bc_%d.dat", bc_rank); f = fopen(fname, "w"); for (i = 0; i < limit; i++) { fprintf(f, "%d %ld %f\n", i, 1L << i, scatter_bc(11, 1L << i)); } fclose(f); bc_final(); MPI_Finalize(); return 0; }
static int default_init( mpg123_handle_t *fr ) { fr->rdat.fdread = plain_read; fr->rdat.read = fr->rdat.r_read != NULL ? fr->rdat.r_read : read; fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : lseek; fr->rdat.filelen = get_fileinfo( fr ); fr->rdat.filepos = 0; // don't enable seeking on ICY streams, just plain normal files. // this check is necessary since the client can enforce ICY parsing on files that would otherwise be seekable. // it is a task for the future to make the ICY parsing safe with seeks ... or not. if( fr->rdat.filelen >= 0 ) { fr->rdat.flags |= READER_SEEKABLE; if( !strncmp((char *)fr->id3buf,"TAG", 3 )) { fr->rdat.flags |= READER_ID3TAG; fr->metaflags |= MPG123_NEW_ID3; } } else if( fr->p.flags & MPG123_SEEKBUFFER ) { // switch reader to a buffered one, if allowed. if( fr->rd == &readers[READER_STREAM] ) { fr->rd = &readers[READER_BUF_STREAM]; fr->rdat.fullread = plain_fullread; } else { return -1; } bc_init( &fr->rdat.buffer ); fr->rdat.filelen = 0; // we carry the offset, but never know how big the stream is. fr->rdat.flags |= READER_BUFFERED; } return 0; }
// Initialize the file system void fs_init(void) { static_assert(sizeof(struct File) == 256); // Find a JOS disk. Use the second IDE disk (number 1) if available. if (ide_probe_disk1()) ide_set_disk(1); else ide_set_disk(0); bc_init(); LOG(DEBUG_FS, "bc_init done\n"); // Set "super" to point to the super block. super = diskaddr(1); // Set "bitmap" to the beginning of the first bitmap block. bitmap = diskaddr(2); check_super(); check_bitmap(); }
int main(int argc, char *argv[]) { int i, limit = 21; MPI_Init(&argc, &argv); bc_init(BC_ERR); FILE *f; char fname[128]; sprintf(fname, "get_latency_%d.dat", bc_rank); f = fopen(fname, "w"); for (i = 0; i < limit; i++) { fprintf(f, "%d %ld %f\n", i, 1L << i, get_latency_bc(1001, 1L << i)); } fclose(f); sleep(1); sprintf(fname, "recv_latency_%d.dat", bc_rank); f = fopen(fname, "w"); for (i = 0; i < limit; i++) { fprintf(f, "%d %ld %f\n", i, 1L << i, get_latency_mpi_blk(1001, 1L << i)); } fclose(f); sleep(1); sprintf(fname, "irecv_latency_%d.dat", bc_rank); f = fopen(fname, "w"); for (i = 0; i < limit; i++) { fprintf(f, "%d %ld %f\n", i, 1L << i, get_latency_mpi_nblk(1001, 1L << i)); } fclose(f); bc_final(); MPI_Finalize(); return 0; }
int main( int argc, char *argv[]) { MPI_Init (&argc, &argv); bc_init (BC_ERR|BC_PLIST_XALL); if (argc != 2) { fprintf (stderr, "USAGE: mva <data file>\n\n" "Data file format:\n\n" "<num classes> <num queues> <error tolerance>\n" "<queue type vector> (1 means QUEUE, 0 means DELAY)\n" "<Load intensity vector>\n" "<Visitation vector>\n" "<service demand array>\n\nSee example file.\n"); exit(0); } init(argv[1]); mva(0); print_results(); cleanup(0); bc_final(); MPI_Finalize(); return 0; }
// Initialize the file system void fs_init(void) { static_assert(sizeof(struct File) == 256); #ifndef VMM_GUEST // Find a JOS disk. Use the second IDE disk (number 1) if available. if (ide_probe_disk1()) ide_set_disk(1); else ide_set_disk(0); #else host_ipc_init(); #endif bc_init(); // Set "super" to point to the super block. super = diskaddr(1); check_super(); // Set "bitmap" to the beginning of the first bitmap block. bitmap = diskaddr(2); check_bitmap(); }
static int default_init(mpg123_handle *fr) { #if (!defined (WIN32) || defined (__CYGWIN__)) if(fr->p.timeout > 0) { int flags; if(fr->rdat.r_read != NULL) { error("Timeout reading does not work with user-provided read function. Implement it yourself!"); return -1; } flags = fcntl(fr->rdat.filept, F_GETFL); flags |= O_NONBLOCK; fcntl(fr->rdat.filept, F_SETFL, flags); fr->rdat.fdread = timeout_read; fr->rdat.timeout_sec = fr->p.timeout; fr->rdat.flags |= READER_NONBLOCK; } else #endif fr->rdat.fdread = plain_read; fr->rdat.read = fr->rdat.r_read != NULL ? fr->rdat.r_read : posix_read; fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : posix_lseek; fr->rdat.filelen = get_fileinfo(fr); fr->rdat.filepos = 0; if(fr->rdat.filelen >= 0) { fr->rdat.flags |= READER_SEEKABLE; if(!strncmp((char*)fr->id3buf,"TAG",3)) { fr->rdat.flags |= READER_ID3TAG; fr->metaflags |= MPG123_NEW_ID3; } } /* Switch reader to a buffered one, if allowed. */ else if(fr->p.flags & MPG123_SEEKBUFFER) { #ifdef NO_FEEDER error("Buffered readers not supported in this build."); fr->err = MPG123_MISSING_FEATURE; return -1; #else if (fr->rd == &readers[READER_STREAM]) { fr->rd = &readers[READER_BUF_STREAM]; fr->rdat.fullread = plain_fullread; } #ifndef NO_ICY else if(fr->rd == &readers[READER_ICY_STREAM]) { fr->rd = &readers[READER_BUF_ICY_STREAM]; fr->rdat.fullread = icy_fullread; } #endif else { if(NOQUIET) error("mpg123 Programmer's fault: invalid reader"); return -1; } bc_init(&fr->rdat.buffer); fr->rdat.filelen = 0; /* We carry the offset, but never know how big the stream is. */ fr->rdat.flags |= READER_BUFFERED; #endif /* NO_FEEDER */ } return 0; }
static int default_init(mpg123_handle *fr) { #ifdef TIMEOUT_READ if(fr->p.timeout > 0) { int flags; if(fr->rdat.r_read != NULL) { error("Timeout reading does not work with user-provided read function. Implement it yourself!"); return -1; } flags = fcntl(fr->rdat.filept, F_GETFL); flags |= O_NONBLOCK; fcntl(fr->rdat.filept, F_SETFL, flags); fr->rdat.fdread = timeout_read; fr->rdat.timeout_sec = fr->p.timeout; fr->rdat.flags |= READER_NONBLOCK; } else #endif fr->rdat.fdread = plain_read; fr->rdat.read = fr->rdat.r_read != NULL ? fr->rdat.r_read : posix_read; fr->rdat.lseek = fr->rdat.r_lseek != NULL ? fr->rdat.r_lseek : posix_lseek; #ifndef NO_ICY /* ICY streams of any sort shall not be seekable. */ if(fr->p.icy_interval > 0) fr->rdat.lseek = nix_lseek; #endif fr->rdat.filelen = fr->p.flags & MPG123_NO_PEEK_END ? -1 : get_fileinfo(fr); fr->rdat.filepos = 0; if(fr->p.flags & MPG123_FORCE_SEEKABLE) fr->rdat.flags |= READER_SEEKABLE; /* Don't enable seeking on ICY streams, just plain normal files. This check is necessary since the client can enforce ICY parsing on files that would otherwise be seekable. It is a task for the future to make the ICY parsing safe with seeks ... or not. */ if(fr->rdat.filelen >= 0) { fr->rdat.flags |= READER_SEEKABLE; if(!strncmp((char*)fr->id3buf,"TAG",3)) { fr->rdat.flags |= READER_ID3TAG; fr->metaflags |= MPG123_NEW_ID3; } } /* Switch reader to a buffered one, if allowed. */ else if(fr->p.flags & MPG123_SEEKBUFFER) { #ifdef NO_FEEDER error("Buffered readers not supported in this build."); fr->err = MPG123_MISSING_FEATURE; return -1; #else if (fr->rd == &readers[READER_STREAM]) { fr->rd = &readers[READER_BUF_STREAM]; fr->rdat.fullread = plain_fullread; } #ifndef NO_ICY else if(fr->rd == &readers[READER_ICY_STREAM]) { fr->rd = &readers[READER_BUF_ICY_STREAM]; fr->rdat.fullread = icy_fullread; } #endif else { if(NOQUIET) error("mpg123 Programmer's fault: invalid reader"); return -1; } bc_init(&fr->rdat.buffer); fr->rdat.filelen = 0; /* We carry the offset, but never know how big the stream is. */ fr->rdat.flags |= READER_BUFFERED; #endif /* NO_FEEDER */ } return 0; }
/* Initialize the page allocator, return 1 on success, 0 otherwise. */ int lm_init_page_alloc(lm_chunk_t* chunk, ljmm_opt_t* mm_opt) { if (!chunk) { /* Trunk is not yet allocated */ return 0; } if (alloc_info) { /* This function was succesfully invoked before */ return 1; } int page_num = chunk->page_num; if (unlikely(mm_opt != NULL)) { int pn = mm_opt->dbg_alloc_page_num; if (((pn > 0) && (pn > page_num)) || !pn) return 0; else if (pn > 0) { page_num = pn; } if (!bc_set_parameter(mm_opt->enable_block_cache, mm_opt->blk_cache_in_page)) { return 0; } } int alloc_sz = sizeof(lm_alloc_t) + sizeof(lm_page_t) * (page_num + 1); alloc_info = (lm_alloc_t*) MYMALLOC(alloc_sz); if (!alloc_info) { errno = ENOMEM; return 0; } alloc_info->first_page = chunk->base; alloc_info->page_num = page_num; alloc_info->page_size = chunk->page_size; alloc_info->page_size_log2 = log2_int32(chunk->page_size); /* Init the page-info */ char* p = (char*)(alloc_info + 1); int align = __alignof__(lm_page_t); p = (char*)((((intptr_t)p) + align - 1) & ~align); alloc_info->page_info = (lm_page_t*)p; int i; lm_page_t* pi = alloc_info->page_info; for (i = 0; i < page_num; i++) { pi[i].order = INVALID_ORDER; pi[i].flags = 0; } /* Init the buddy allocator */ int e; rb_tree_t* free_blks = &alloc_info->free_blks[0]; for (i = 0, e = MAX_ORDER; i < e; i++) rbt_init(&free_blks[i]); rbt_init(&alloc_info->alloc_blks); /* Determine the max order */ int max_order = 0; unsigned int bitmask; for (bitmask = 0x80000000/*2G*/, max_order = 31; bitmask; bitmask >>= 1, max_order --) { if (bitmask & page_num) break; } alloc_info->max_order = max_order; /* So, the ID of biggest block's first page is "1 << order". e.g. * Suppose the chunk contains 11 pages, which will be divided into 3 * blocks, eaching containing 1, 2 and 8 pages. The indices of these * blocks are 0, 1, 3 respectively, and their IDs are 5, 6, and 8 * respectively. In this case: * alloc_info->idx_2_id_adj == 5 == page_id(*) - page_idx(*) */ int idx_2_id_adj = (1 << max_order) - (page_num & ((1 << max_order) - 1)); alloc_info->idx_2_id_adj = idx_2_id_adj; /* Divide the chunk into blocks, smaller block first. Smaller blocks * are likely allocated and deallocated frequently. Therefore, they are * better off residing closer to data segment. */ int page_idx = 0; int order = 0; for (bitmask = 1, order = 0; bitmask != 0; bitmask = bitmask << 1, order++) { if (page_num & bitmask) { add_free_block(page_idx, order); page_idx += (1 << order); } } /*init the block cache */ bc_init(); return 1; }