/** * Retrieve a size parameter and check its format * @return 0 on success * ENOENT if the parameter does not exist in the block * EINVAL if the parameter does not satisfy restrictions */ int GetSizeParam(config_item_t block, const char *block_name, const char *var_name, param_flags_t flags, unsigned long long *target, char ***extra_args_tab, unsigned int *nb_extra_args, char *err_msg) { config_item_t curr_item; int rc; int extra = 0; unsigned long long sizeval; char *name; char *value; err_msg[0] = '\0'; if ( nb_extra_args ) *nb_extra_args = 0; if ( extra_args_tab ) *extra_args_tab = NULL; rc = get_cfg_param(block, block_name, var_name, flags, &name, &value, &extra, &curr_item, err_msg); if (rc) return rc; sizeval = str2size( value ); if ( sizeval == ( unsigned long long ) -1 ) { sprintf( err_msg, "Invalid value for '%s::%s', line %d: size expected. Eg: 10MB", block_name, var_name, rh_config_GetItemLine( curr_item ) ); return EINVAL; } if ((flags & PFLG_NOT_NULL) && (sizeval == 0)) { sprintf( err_msg, "'%s::%s' must not be null, line %d.", block_name, var_name, rh_config_GetItemLine( curr_item ) ); return EINVAL; } *target = sizeval; if ( extra ) { if ( !extra_args_tab || !nb_extra_args ) { sprintf( err_msg, "Unexpected options for parameter '%s::%s', line %d", block_name, var_name, rh_config_GetItemLine( curr_item ) ); return EINVAL; } else { *nb_extra_args = rh_config_GetExtraArgs( curr_item, extra_args_tab ); } } return 0; }
/** * \retval DB_NOT_EXISTS if the recovery table does not exist */ int ListMgr_RecovStatus( lmgr_t * p_mgr, lmgr_recov_stat_t * p_stats ) { int rc, i; result_handle_t result; char * status[3]; /* test if a RECOVERY table already exist, and contains entries */ rc = db_exec_sql_quiet( &p_mgr->conn, "SELECT recov_status,COUNT(*),SUM(size) FROM "RECOV_TABLE " GROUP BY recov_status", &result ); if (rc) return rc; /* table exists, fill status tab */ p_stats->total = 0; for (i = 0; i < RS_COUNT; i++ ) { p_stats->status_count[i] = 0; p_stats->status_size[i] = 0; } while ( (rc = db_next_record( &p_mgr->conn, &result, status, 3 )) != DB_END_OF_LIST ) { long long cnt; uint64_t sz; if (rc) return rc; cnt = str2bigint( status[1] ); if ( cnt == -1LL) return DB_INVALID_ARG; sz = str2size( status[2] ); if ( sz == -1LL) return DB_INVALID_ARG; p_stats->total += cnt; if ( status[0] != NULL ) { int idx = str2int( status[0] ); if ((idx >= RS_COUNT) || (idx == -1) ) return DB_REQUEST_FAILED; p_stats->status_count[idx] = cnt; p_stats->status_size[idx] = sz; } } db_result_free( &p_mgr->conn, &result ); return 0; }
int main(int argc, char *argv[]) { off_t sz; struct stat sb; char buf[80]; prog = basename(argv[0]); if (argc != 2) { fprintf(stderr, "Usage: %s [file|string]\n", prog); exit(1); } if (stat(argv[1], &sb) < 0) { if (*argv[1] == '/') { fprintf(stderr, "%s: could not stat special file\n", prog); exit(1); } sz = str2size(argv[1]); if (sz == 0) { fprintf(stderr, "%s: error parsing size string\n", prog); exit(1); } } else { if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) { if (getsize(argv[1], &sz) < 0) { fprintf(stderr, "%s: %s: %s\n", prog, argv[1], strerror(errno)); exit(1); } } else { sz = sb.st_size; } } if (sz != 0) { size2str(buf, sizeof(buf), sz); printf("%s\n", buf); } exit(0); }
/** * \retval DB_NOT_EXISTS if the recovery table does not exist */ static int expected_recov_status( lmgr_t * p_mgr, lmgr_recov_stat_t * p_stats ) { int rc, i; result_handle_t result; char * status[5]; /* test if a RECOVERY table already exist, and contains entries */ rc = db_exec_sql_quiet( &p_mgr->conn, "SELECT status,type,COUNT(*),(size=0) as empty,SUM(size) FROM "RECOV_TABLE " GROUP BY status,type,empty", &result ); if (rc) return rc; /* @TODO manage dirs and symlinks differently */ p_stats->total = 0; for (i = 0; i < RS_COUNT; i++ ) { p_stats->status_count[i] = 0; p_stats->status_size[i] = 0; } while ( (rc = db_next_record( &p_mgr->conn, &result, status, 5 )) != DB_END_OF_LIST ) { long long cnt; uint64_t sz; int isempty; if (rc) return rc; cnt = str2bigint( status[2] ); if ( cnt == -1LL) return DB_INVALID_ARG; isempty = str2int( status[3] ); if ( isempty == -1) return DB_INVALID_ARG; sz = str2size( status[4] ); if ( sz == -1LL) return DB_INVALID_ARG; p_stats->total += cnt; if ( status[0] != NULL ) { int st = str2int( status[0] ); /* archived entries: file and (optionally) symlinks */ if (!strcasecmp(status[1], STR_TYPE_FILE)) { if (isempty) { p_stats->status_count[RS_FILE_EMPTY] += cnt; p_stats->status_size[RS_FILE_EMPTY] += sz; } else { switch (st) { case STATUS_NEW: p_stats->status_count[RS_NOBACKUP] += cnt; p_stats->status_size[RS_NOBACKUP] += sz; break; case STATUS_MODIFIED: case STATUS_ARCHIVE_RUNNING: p_stats->status_count[RS_FILE_DELTA] += cnt; p_stats->status_size[RS_FILE_DELTA] += sz; break; case STATUS_SYNCHRO: case STATUS_RELEASED: p_stats->status_count[RS_FILE_OK] += cnt; p_stats->status_size[RS_FILE_OK] += sz; break; } } } else if (!strcasecmp(status[1], STR_TYPE_LINK) || !strcasecmp(status[1], STR_TYPE_DIR)) { /* symlinks and dirs always recoverable from DB */ p_stats->status_count[RS_NON_FILE] += cnt; p_stats->status_size[RS_NON_FILE] += sz; } else { /* non recoverable : special entry like fifo, blk, ... */ p_stats->status_count[RS_NOBACKUP] += cnt; p_stats->status_size[RS_NOBACKUP] += sz; } } } db_result_free( &p_mgr->conn, &result ); return 0; }
int main(int argc, char *argv[]) { MPI_Status status; MPI_Request recv_request; MPI_Request send_request; unsigned char *rbuf; unsigned char *tbuf; int c; int i; int bytes; int nproc; int peer; int proc; int r; int tag = 0x666; /* * default options / arguments */ int reps = 10000; int blocking = 0; int check = 0; int overlap = 0; int warmup = 0; int inc_bytes = 0; int max_bytes = 0; int min_bytes = 0; int alloc_mem = 0; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &proc); MPI_Comm_size(MPI_COMM_WORLD, &nproc); while ((c = getopt(argc, argv, "BCOWAr:h")) != -1) { switch (c) { case 'B': blocking = 1; break; case 'C': check = 1; break; case 'O': overlap = 1; break; case 'W': warmup = 1; break; case 'A': alloc_mem=1; break; case 'r': if ((reps = str2size(optarg)) <= 0) { usage(); } break; case 'h': help(); default: usage(); } } if (optind == argc) { min_bytes = 0; } else if ((min_bytes = str2size(argv[optind++])) < 0) { usage(); } if (optind == argc) { max_bytes = min_bytes; } else if ((max_bytes = str2size(argv[optind++])) < min_bytes) { usage(); } if (optind == argc) { inc_bytes = 0; } else if ((inc_bytes = str2size(argv[optind++])) < 0) { usage(); } if (nproc == 1) { exit(EXIT_SUCCESS); } #if MPI_ALLOC_MEM if(alloc_mem) { MPI_Alloc_mem(max_bytes ? max_bytes: 8, MPI_INFO_NULL, &rbuf); MPI_Alloc_mem(max_bytes ? max_bytes: 8, MPI_INFO_NULL, &tbuf); } else { #endif if ((rbuf = (unsigned char *) malloc(max_bytes ? max_bytes : 8)) == NULL) { perror("malloc"); exit(EXIT_FAILURE); } if ((tbuf = (unsigned char *) malloc(max_bytes ? max_bytes : 8)) == NULL) { perror("malloc"); exit(EXIT_FAILURE); } #if MPI_ALLOC_MEM } #endif if (check) { for (i = 0; i < max_bytes; i++) { tbuf[i] = i & 255; rbuf[i] = 0; } } if (proc == 0) { if (overlap) { printf("mpi-ping: overlapping ping-pong\n"); } else if (blocking) { printf("mpi-ping: ping-pong (using blocking send/recv)\n"); } else { printf("mpi-ping: ping-pong\n"); } if (check) { printf("data checking enabled\n"); } printf("nprocs=%d, reps=%d, min bytes=%d, max bytes=%d inc bytes=%d\n", nproc, reps, min_bytes, max_bytes, inc_bytes); fflush(stdout); } MPI_Barrier(MPI_COMM_WORLD); peer = proc ^ 1; if ((peer < nproc) && (peer & 1)) { printf("%d pings %d\n", proc, peer); fflush(stdout); } MPI_Barrier(MPI_COMM_WORLD); if (warmup) { if (proc == 0) { puts("warm-up phase"); fflush(stdout); } for (r = 0; r < reps; r++) { if (peer >= nproc) { break; } MPI_Irecv(rbuf, max_bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &recv_request); MPI_Isend(tbuf, max_bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &send_request); MPI_Wait(&send_request, &status); MPI_Wait(&recv_request, &status); } if (proc == 0) { puts("warm-up phase done"); fflush(stdout); } } MPI_Barrier(MPI_COMM_WORLD); /* * Main loop */ for (bytes = min_bytes; bytes <= max_bytes; bytes = inc_bytes ? bytes + inc_bytes : bytes ? 2 * bytes : 1) { double t = 0.0; double tv[2]; r = reps; MPI_Barrier(MPI_COMM_WORLD); if (peer < nproc) { if (overlap) { /* * MPI_Isend / MPI_Irecv overlapping ping-pong */ tv[0] = MPI_Wtime(); for (r = 0; r < reps; r++) { MPI_Irecv(rbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &recv_request); MPI_Isend(tbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &send_request); MPI_Wait(&send_request, &status); MPI_Wait(&recv_request, &status); if (check) { for (i = 0; i < bytes; i++) { if (rbuf[i] != (unsigned char)(i & 255)) { fprintf(stderr, "Error: index=%d sent %d received %d\n", i, ((unsigned char)i)&255, (unsigned char)rbuf[i]); } rbuf[i] = 0; } } } tv[1] = MPI_Wtime(); } else if (blocking) { /* * MPI_Send / MPI_Recv ping-pong */ tv[0] = MPI_Wtime(); if (peer < nproc) { if (proc & 1) { r--; MPI_Recv(rbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &status); if (check) { for (i = 0; i < bytes; i++) { if (rbuf[i] != (unsigned char)(i & 255)) { fprintf(stderr, "Error: index=%d sent %d received %d\n", i, ((unsigned char)i)&255, (unsigned char)rbuf[i]); } rbuf[i] = 0; } } } while (r-- > 0) { MPI_Send(tbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD); MPI_Recv(rbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &status); if (check) { for (i = 0; i < bytes; i++) { if (rbuf[i] != (unsigned char)(i & 255)) { fprintf(stderr, "Error: index=%d sent %d received %d\n", i, ((unsigned char)i)&255, (unsigned char)rbuf[i]); } rbuf[i] = 0; } } } if (proc & 1) { MPI_Send(tbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD); } } tv[1] = MPI_Wtime(); } else { /* * MPI_Isend / MPI_Irecv ping-pong */ tv[0] = MPI_Wtime(); if (peer < nproc) { if (proc & 1) { r--; MPI_Irecv(rbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &recv_request); MPI_Wait(&recv_request, &status); if (check) { for (i = 0; i < bytes; i++) { if (rbuf[i] != (unsigned char)(i & 255)) { fprintf(stderr, "Error: index=%d sent %d received %d\n", i, ((unsigned char)i)&255, (unsigned char)rbuf[i]); } rbuf[i] = 0; } } } while (r-- > 0) { MPI_Isend(tbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &send_request); MPI_Wait(&send_request, &status); MPI_Irecv(rbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &recv_request); MPI_Wait(&recv_request, &status); if (check) { for (i = 0; i < bytes; i++) { if (rbuf[i] != (unsigned char)(i & 255)) { fprintf(stderr, "Error: index=%d sent %d received %d\n", i, ((unsigned char)i)&255, (unsigned char)rbuf[i]); } rbuf[i] = 0; } } } if (proc & 1) { MPI_Isend(tbuf, bytes, MPI_BYTE, peer, tag, MPI_COMM_WORLD, &send_request); MPI_Wait(&send_request, &status); } } tv[1] = MPI_Wtime(); } /* * Calculate time interval in useconds (half round trip) */ t = (tv[1] - tv[0]) * 1000000.0 / (2 * reps); } MPI_Barrier(MPI_COMM_WORLD); if ((peer < nproc) && (peer & 1)) { printf("%3d pinged %3d: %8d bytes %9.2f uSec %8.2f MB/s\n", proc, peer, bytes, t, bytes / (t)); fflush(stdout); } } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return EXIT_SUCCESS; }
static int scan_sys_cache_info (void) { long page_size = sysconf (_SC_PAGESIZE); if (page_size <= 0) { error (0, errno, "unable to get pagesize"); return -1; } /* versionsort sort by index number */ struct dirent ** list; int nb_dir = scandir (SYSPATH, &list, scandir_filter, alphasort); if (nb_dir < 0) { error (0, errno, "scandir(%s)", SYSPATH); return -1; } // alloc table (will set found to 0) caches = calloc (nb_dir, sizeof (struct cache_info)); if (caches == NULL) error (EXIT_FAILURE, errno, "calloc"); nb_cache_levels = nb_dir; for (int i = 0; i < nb_dir; i++) { const char * d = list[i]->d_name; int ok; char buf[BUF_SIZE]; struct cache_info cinfo; // ensure type includes Data if (read_sys_cache_file (d, "type", buf) == -1) continue; if (strcmp (buf, "Data") == 0) cinfo.type = "Data"; else if (strcmp (buf, "Unified") == 0) cinfo.type = "Unified"; else continue; // read size, assoc, level if (read_sys_cache_file (d, "size", buf) == -1) continue; cinfo.size = str2size (buf, &ok); if (!(ok && cinfo.size > 0)) continue; if (read_sys_cache_file (d, "ways_of_associativity", buf) == -1) continue; cinfo.assoc = checked_strtoul (buf, &ok, NULL); if (! (ok && cinfo.assoc > 0)) continue; if (read_sys_cache_file (d, "level", buf) == -1) continue; int level = checked_strtoul (buf, &ok, NULL); if (! (ok && level < nb_cache_levels)) continue; cinfo.nb_colors = cinfo.size / (page_size * cinfo.assoc); cinfo.found = 1; caches[level] = cinfo; } return 0; }