void read_init_vars(struct mlx5_context *ctx) { pthread_mutex_lock(&ctx->env_mtx); if (!ctx->env_initialized) { mlx5_single_threaded = single_threaded_app(&ctx->ibv_ctx); mlx5_use_mutex = get_use_mutex(&ctx->ibv_ctx); open_debug_file(ctx); set_debug_mask(&ctx->ibv_ctx); set_freeze_on_error(&ctx->ibv_ctx); ctx->prefer_bf = get_always_bf(&ctx->ibv_ctx); ctx->shut_up_bf = get_shut_up_bf(&ctx->ibv_ctx); mlx5_read_env(ctx); ctx->env_initialized = 1; } pthread_mutex_unlock(&ctx->env_mtx); }
int main(void) { size_t i; for (i=0; i<sizeof(char_to_symbol)/sizeof(char_to_symbol[0]); i += 1) { const mask_char_to_symbol_t *ptr = char_to_symbol + i; set_debug_mask( ptr->str ); if ( (debug_mask & ptr->bit) != ptr->bit ) { fprintf(stderr, "debug_mask for '%s' is wrong.\n", ptr->str); exit(EX_ERROR); } } printf("All O.K.\n"); return 0; }
int process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass) { static int lastmode = -1; (void) name; /* suppress compiler warning */ (void) precedence; /* suppress compiler warning */ (void) pass; /* suppress compiler warning */ if (option == 1) { /* If getopt's RETURN_IN_ORDER behavior */ switch (lastmode) { case 'n': case 's': option = lastmode; break; default: fprintf(stderr, "File names may only be given after -n or -s options.\n"); } } switch (option) { case 'c': read_config_file(val, false, false, PR_CFG_USER, longopts_bogotune); /*@fallthrough@*/ /* fall through to suppress reading config files */ case 'C': suppress_config_file = true; break; case 'd': ds_path = xstrdup(val); ds_flag = (ds_flag == DS_NONE) ? DS_DSK : DS_ERR; break; case 'D': ds_flag = (ds_flag == DS_NONE) ? DS_RAM : DS_ERR; break; case 'e': exit_zero = true; break; case 'E': esf_flag ^= true; break; case 'M': bogolex_file = val; break; case 'n': lastmode = 'n'; filelist_add(ham_files, val); break; case 'q': quiet = true; break; case 'r': user_robx = atof(val); break; case 's': lastmode = 's'; filelist_add(spam_files, val); break; #ifdef TEST case 't': test += 1; break; #endif case 'T': coerced_target = atoi(val); break; case 'v': verbose += 1; break; case 'V': print_version(); exit(EX_OK); case 'x': if (strcmp(val, "MakeCheck") == 0) fMakeCheck = true; else set_debug_mask(val); break; case O_MAX_TOKEN_LEN: max_token_len = atoi(val); break; case O_MIN_TOKEN_LEN: min_token_len = atoi(val); break; case O_MAX_MULTI_TOKEN_LEN: max_multi_token_len=atoi(val); break; case O_MULTI_TOKEN_COUNT: multi_token_count=atoi(val); break; case O_BLOCK_ON_SUBNETS: block_on_subnets = get_bool(name, val); break; case O_REPLACE_NONASCII_CHARACTERS: replace_nonascii_characters = get_bool(name, val); break; case O_TOKEN_COUNT_FIX: token_count_fix = atoi(val); break; case O_TOKEN_COUNT_MIN: token_count_min = atoi(val); break; case O_TOKEN_COUNT_MAX: token_count_max = atoi(val); break; default: help(); exit(EX_ERROR); } return 0; }
int process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass) { int count = 0; (void) precedence; /* suppress compiler warning */ (void) pass; /* suppress compiler warning */ switch (option) { case '?': fprintf(stderr, "Unknown option '%s'.\n", name); break; case 'd': flag = M_DUMP; count += 1; ds_file = val; break; case O_CONFIG_FILE: read_config_file(val, false, false, PR_COMMAND, longopts_bogoutil); /*@fallthrough@*/ /* fall through to suppress reading config files */ case 'C': suppress_config_file = true; break; case 'k': db_cachesize=(uint) atoi(val); break; case 'l': flag = M_LOAD; count += 1; ds_file = val; break; case 'm': flag = M_MAINTAIN; count += 1; ds_file = val; break; case 'p': prob = true; /*@fallthrough@*/ case 'w': flag = M_WORD; count += 1; ds_file = val; break; case O_DB_PRINT_LEAFPAGE_COUNT: flag = M_LEAFPAGES; count += 1; ds_file = val; break; case O_DB_PRINT_PAGESIZE: flag = M_PAGESIZE; count += 1; ds_file = val; break; case 'r': onlyprint = true; case 'R': flag = M_ROBX; count += 1; ds_file = val; break; case 'u': upgrade_wordlist_version = true; flag = M_MAINTAIN; count += 1; ds_file = val; break; case 'v': verbose++; break; case ':': fprintf(stderr, "Option %s requires an argument.\n", name); exit(EX_ERROR); case 'h': help(stdout); exit(EX_OK); case 'H': flag = M_HIST; count += 1; ds_file = val; break; case 'V': print_version(); exit(EX_OK); case 'x': set_debug_mask(val); break; case 'X': set_bogotest(val); break; case 'a': maintain = true; thresh_date = string_to_date(val); break; case 'c': maintain = true; thresh_count = (uint) atoi(val); break; case 's': { unsigned long mi, ma; maintain = true; if (2 == sscanf(val, "%lu,%lu", &mi, &ma)) { size_min = mi; size_max = ma; } else { fprintf(stderr, "syntax error in argument \"%s\" of -s\n.", val); exit(EX_ERROR); } } break; case 'n': maintain = true; replace_nonascii_characters ^= true; break; case 'y': /* date as YYYYMMDD */ { YYYYMMDD date = string_to_date(val); maintain = true; if (date != 0 && date < 19990000) { fprintf(stderr, "Date format for '-y' option is YYYYMMDD\n"); exit(EX_ERROR); } set_date( date ); break; } case 'I': fpin = fopen(val, "r"); if (fpin == NULL) { fprintf(stderr, "Can't read file '%s'\n", val); exit(EX_ERROR); } break; case 'O': fpo = fopen(val, "wt"); if (fpo == NULL) { fprintf(stderr, "Can't write file '%s'\n", val); exit(EX_ERROR); } break; case 'D': dbgout = stdout; break; case O_DB_VERIFY: flag = M_VERIFY; count += 1; ds_file = val; break; case O_UNICODE: encoding = str_to_bool(val) ? E_UNICODE : E_RAW; break; case O_MAX_TOKEN_LEN: max_token_len = atoi(val); break; case O_MIN_TOKEN_LEN: min_token_len = atoi(val); break; case O_MAX_MULTI_TOKEN_LEN: max_multi_token_len=atoi(val); break; case O_MULTI_TOKEN_COUNT: multi_token_count=atoi(val); break; default: if (!dsm_options_bogoutil(option, &flag, &count, &ds_file, name, val)) { fprintf(stderr, "Invalid option '%s'\n", name); exit(EX_ERROR); } } return count; }
static int mlx5_alloc_context(struct verbs_device *vdev, struct ibv_context *ctx, int cmd_fd) { struct mlx5_context *context; struct mlx5_alloc_ucontext req; struct mlx5_alloc_ucontext_resp resp; struct ibv_device *ibdev = &vdev->device; struct verbs_context *verbs_ctx = verbs_get_ctx(ctx); int i; int page_size = to_mdev(ibdev)->page_size; int tot_uuars; int low_lat_uuars; int gross_uuars; int j; off_t offset; mlx5_single_threaded = single_threaded_app(); context = to_mctx(ctx); context->ibv_ctx.cmd_fd = cmd_fd; memset(&resp, 0, sizeof(resp)); open_debug_file(context); set_debug_mask(); set_freeze_on_error(); if (gethostname(context->hostname, sizeof(context->hostname))) strcpy(context->hostname, "host_unknown"); tot_uuars = get_total_uuars(); if (tot_uuars <= 0) { if (tot_uuars == 0) errno = EINVAL; else errno = -tot_uuars; goto err_free; } gross_uuars = tot_uuars / MLX5_NUM_UUARS_PER_PAGE * 4; context->bfs = calloc(gross_uuars, sizeof *context->bfs); if (!context->bfs) { errno = ENOMEM; goto err_free; } low_lat_uuars = get_num_low_lat_uuars(); if (low_lat_uuars < 0) { errno = ENOMEM; goto err_free_bf; } if (low_lat_uuars > tot_uuars - 1) { errno = ENOMEM; goto err_free_bf; } memset(&req, 0, sizeof(req)); req.total_num_uuars = tot_uuars; req.num_low_latency_uuars = low_lat_uuars; if (ibv_cmd_get_context(&context->ibv_ctx, &req.ibv_req, sizeof req, &resp.ibv_resp, sizeof resp)) goto err_free_bf; context->max_num_qps = resp.qp_tab_size; context->bf_reg_size = resp.bf_reg_size; context->tot_uuars = resp.tot_uuars; context->low_lat_uuars = low_lat_uuars; context->cache_line_size = resp.cache_line_size; context->max_sq_desc_sz = resp.max_sq_desc_sz; context->max_rq_desc_sz = resp.max_rq_desc_sz; context->max_send_wqebb = resp.max_send_wqebb; context->num_ports = resp.num_ports; context->max_recv_wr = resp.max_recv_wr; context->max_srq_recv_wr = resp.max_srq_recv_wr; context->max_desc_sz_sq_dc = resp.max_desc_sz_sq_dc; context->atomic_sizes_dc = resp.atomic_sizes_dc; pthread_mutex_init(&context->rsc_table_mutex, NULL); pthread_mutex_init(&context->srq_table_mutex, NULL); for (i = 0; i < MLX5_QP_TABLE_SIZE; ++i) context->rsc_table[i].refcnt = 0; context->db_list = NULL; pthread_mutex_init(&context->db_list_mutex, NULL); for (i = 0; i < resp.tot_uuars / MLX5_NUM_UUARS_PER_PAGE; ++i) { offset = 0; set_command(MLX5_MMAP_GET_REGULAR_PAGES_CMD, &offset); set_index(i, &offset); context->uar[i] = mmap(NULL, to_mdev(ibdev)->page_size, PROT_WRITE, MAP_SHARED, cmd_fd, page_size * offset); if (context->uar[i] == MAP_FAILED) { context->uar[i] = NULL; goto err_free_bf; } } for (j = 0; j < gross_uuars; ++j) { context->bfs[j].reg = context->uar[j / 4] + MLX5_BF_OFFSET + (j % 4) * context->bf_reg_size; context->bfs[j].need_lock = need_uuar_lock(context, j); mlx5_spinlock_init(&context->bfs[j].lock); context->bfs[j].offset = 0; if (j) context->bfs[j].buf_size = context->bf_reg_size / 2; context->bfs[j].uuarn = j; } mlx5_spinlock_init(&context->lock32); context->prefer_bf = get_always_bf(); context->shut_up_bf = get_shut_up_bf(); mlx5_read_env(ibdev, context); mlx5_spinlock_init(&context->hugetlb_lock); INIT_LIST_HEAD(&context->hugetlb_list); pthread_mutex_init(&context->task_mutex, NULL); ctx->ops = mlx5_ctx_ops; set_extended(verbs_ctx); set_experimental(ctx); return 0; err_free_bf: free(context->bfs); err_free: for (i = 0; i < MLX5_MAX_UAR_PAGES; ++i) { if (context->uar[i]) munmap(context->uar[i], page_size); } close_debug_file(context); return errno; }
int process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass) { //pass = 0; /* suppress compiler warning */ switch (option) { case ':': fprintf(stderr, "Option %s requires an argument.\n", name); exit(EX_ERROR); case '?': fprintf(stderr, "Unknown option '%s'.\n", name); break; case 'c': case O_CONFIG_FILE: read_config_file(val, false, false, precedence, longopts_bogolexer); /*@fallthrough@*/ /* fall through to suppress reading config files */ case 'C': suppress_config_file = true; break; case O_USER_CONFIG_FILE: user_config_file = get_string(name, val); break; case 'D': dbgout = stdout; break; case 'h': help(); exit(EX_OK); case 'H': header_line_markup = false; break; case 'I': bogoreader_name(val); break; case 'O': fpo = fopen(val, "wt"); if (fpo == NULL) { fprintf(stderr, "Can't write file '%s'\n", val); exit(EX_ERROR); } break; case 'n': replace_nonascii_characters = true; break; case O_CHARSET_DEFAULT: charset_default = get_string(name, val); break; case O_UNICODE: encoding = get_bool(name, val) ? E_UNICODE : E_RAW; break; case O_REPLACE_NONASCII_CHARACTERS: replace_nonascii_characters = get_bool(name, val); break; case 'p': passthrough = true; break; case 'q': quiet = true; break; case 'v': verbose += 1; break; case 'V': print_version(); exit(EX_OK); case 'x': set_debug_mask(val); break; case 'X': set_bogotest(val); break; case O_BLOCK_ON_SUBNETS: block_on_subnets = get_bool(name, val); break; case O_MAX_TOKEN_LEN: max_token_len = atoi(val); break; case O_MIN_TOKEN_LEN: min_token_len = atoi(val); break; case O_MAX_MULTI_TOKEN_LEN: max_multi_token_len=atoi(val); break; case O_MULTI_TOKEN_COUNT: multi_token_count=atoi(val); break; default: /* config file options: ** ok - if from config file ** error - if on command line */ if (pass == PASS_2_CFG) { fprintf(stderr, "Invalid option '%s'.\n", name); exit(EX_ERROR); } } return 0; }