1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
8 static int rdma_dim_step(struct dim *dim)
10 if (dim->tune_state == DIM_GOING_RIGHT) {
11 if (dim->profile_ix == (RDMA_DIM_PARAMS_NUM_PROFILES - 1))
16 if (dim->tune_state == DIM_GOING_LEFT) {
17 if (dim->profile_ix == 0)
26 static int rdma_dim_stats_compare(struct dim_stats *curr,
27 struct dim_stats *prev)
31 return DIM_STATS_SAME;
33 if (IS_SIGNIFICANT_DIFF(curr->cpms, prev->cpms))
34 return (curr->cpms > prev->cpms) ? DIM_STATS_BETTER :
37 if (IS_SIGNIFICANT_DIFF(curr->cpe_ratio, prev->cpe_ratio))
38 return (curr->cpe_ratio > prev->cpe_ratio) ? DIM_STATS_BETTER :
41 return DIM_STATS_SAME;
44 static bool rdma_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
46 int prev_ix = dim->profile_ix;
47 u8 state = dim->tune_state;
51 if (state != DIM_PARKING_ON_TOP && state != DIM_PARKING_TIRED) {
52 stats_res = rdma_dim_stats_compare(curr_stats,
57 if (curr_stats->cpe_ratio <= 50 * prev_ix)
63 case DIM_STATS_BETTER:
64 step_res = rdma_dim_step(dim);
65 if (step_res == DIM_ON_EDGE)
71 dim->prev_stats = *curr_stats;
73 return dim->profile_ix != prev_ix;
76 void rdma_dim(struct dim *dim, u64 completions)
78 struct dim_sample *curr_sample = &dim->measuring_sample;
79 struct dim_stats curr_stats;
82 dim_update_sample_with_comps(curr_sample->event_ctr + 1, 0, 0,
83 curr_sample->comp_ctr + completions,
84 &dim->measuring_sample);
87 case DIM_MEASURE_IN_PROGRESS:
88 nevents = curr_sample->event_ctr - dim->start_sample.event_ctr;
89 if (nevents < DIM_NEVENTS)
91 if (!dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats))
93 if (rdma_dim_decision(&curr_stats, dim)) {
94 dim->state = DIM_APPLY_NEW_PROFILE;
95 schedule_work(&dim->work);
99 case DIM_START_MEASURE:
100 dim->state = DIM_MEASURE_IN_PROGRESS;
101 dim_update_sample_with_comps(curr_sample->event_ctr, 0, 0,
102 curr_sample->comp_ctr,
105 case DIM_APPLY_NEW_PROFILE:
109 EXPORT_SYMBOL(rdma_dim);