1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
8 bool dim_on_top(struct dim *dim)
10 switch (dim->tune_state) {
11 case DIM_PARKING_ON_TOP:
12 case DIM_PARKING_TIRED:
15 return (dim->steps_left > 1) && (dim->steps_right == 1);
16 default: /* DIM_GOING_LEFT */
17 return (dim->steps_right > 1) && (dim->steps_left == 1);
20 EXPORT_SYMBOL(dim_on_top);
22 void dim_turn(struct dim *dim)
24 switch (dim->tune_state) {
25 case DIM_PARKING_ON_TOP:
26 case DIM_PARKING_TIRED:
29 dim->tune_state = DIM_GOING_LEFT;
33 dim->tune_state = DIM_GOING_RIGHT;
38 EXPORT_SYMBOL(dim_turn);
40 void dim_park_on_top(struct dim *dim)
45 dim->tune_state = DIM_PARKING_ON_TOP;
47 EXPORT_SYMBOL(dim_park_on_top);
49 void dim_park_tired(struct dim *dim)
53 dim->tune_state = DIM_PARKING_TIRED;
55 EXPORT_SYMBOL(dim_park_tired);
57 void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
58 struct dim_stats *curr_stats)
60 /* u32 holds up to 71 minutes, should be enough */
61 u32 delta_us = ktime_us_delta(end->time, start->time);
62 u32 npkts = BIT_GAP(BITS_PER_TYPE(u32), end->pkt_ctr, start->pkt_ctr);
63 u32 nbytes = BIT_GAP(BITS_PER_TYPE(u32), end->byte_ctr,
65 u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
71 curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
72 curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
73 curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
75 curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
76 if (curr_stats->epms != 0)
77 curr_stats->cpe_ratio =
78 (curr_stats->cpms * 100) / curr_stats->epms;
80 curr_stats->cpe_ratio = 0;
83 EXPORT_SYMBOL(dim_calc_stats);