| 1 | |
| 2 | |
| 3 | * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
|
| 4 |
|
| 5 |
|
| 6 | #include <linux/dim.h>
|
| 7 |
|
| 8 | bool dim_on_top(struct dim *dim)
|
| 9 | {
|
| 10 | switch (dim->tune_state) {
|
| 11 | case DIM_PARKING_ON_TOP:
|
| 12 | case DIM_PARKING_TIRED:
|
| 13 | return true;
|
| 14 | case DIM_GOING_RIGHT:
|
| 15 | return (dim->steps_left > 1) && (dim->steps_right == 1);
|
| 16 | default:
|
| 17 | return (dim->steps_right > 1) && (dim->steps_left == 1);
|
| 18 | }
|
| 19 | }
|
| 20 | EXPORT_SYMBOL(dim_on_top);
|
| 21 |
|
| 22 | void dim_turn(struct dim *dim)
|
| 23 | {
|
| 24 | switch (dim->tune_state) {
|
| 25 | case DIM_PARKING_ON_TOP:
|
| 26 | case DIM_PARKING_TIRED:
|
| 27 | break;
|
| 28 | case DIM_GOING_RIGHT:
|
| 29 | dim->tune_state = DIM_GOING_LEFT;
|
| 30 | dim->steps_left = 0;
|
| 31 | break;
|
| 32 | case DIM_GOING_LEFT:
|
| 33 | dim->tune_state = DIM_GOING_RIGHT;
|
| 34 | dim->steps_right = 0;
|
| 35 | break;
|
| 36 | }
|
| 37 | }
|
| 38 | EXPORT_SYMBOL(dim_turn);
|
| 39 |
|
| 40 | void dim_park_on_top(struct dim *dim)
|
| 41 | {
|
| 42 | dim->steps_right = 0;
|
| 43 | dim->steps_left = 0;
|
| 44 | dim->tired = 0;
|
| 45 | dim->tune_state = DIM_PARKING_ON_TOP;
|
| 46 | }
|
| 47 | EXPORT_SYMBOL(dim_park_on_top);
|
| 48 |
|
| 49 | void dim_park_tired(struct dim *dim)
|
| 50 | {
|
| 51 | dim->steps_right = 0;
|
| 52 | dim->steps_left = 0;
|
| 53 | dim->tune_state = DIM_PARKING_TIRED;
|
| 54 | }
|
| 55 | EXPORT_SYMBOL(dim_park_tired);
|
| 56 |
|
| 57 | bool dim_calc_stats(const struct dim_sample *start,
|
| 58 | const struct dim_sample *end,
|
| 59 | struct dim_stats *curr_stats)
|
| 60 | {
|
| 61 |
|
| 62 | u32 delta_us = ktime_us_delta(end->time, start->time);
|
| 63 | u32 npkts = BIT_GAP(BITS_PER_TYPE(u32), end->pkt_ctr, start->pkt_ctr);
|
| 64 | u32 nbytes = BIT_GAP(BITS_PER_TYPE(u32), end->byte_ctr,
|
| 65 | start->byte_ctr);
|
| 66 | u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
|
| 67 | start->comp_ctr);
|
| 68 |
|
| 69 | if (!delta_us)
|
| 70 | return false;
|
| 71 |
|
| 72 |
|
| 73 | curr_stats->ppms = DIV_ROUND_UP_ULL((u64)npkts * USEC_PER_MSEC,
|
| 74 | delta_us);
|
| 75 | curr_stats->bpms = DIV_ROUND_UP_ULL((u64)nbytes * USEC_PER_MSEC,
|
| 76 | delta_us);
|
| 77 | curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
|
| 78 | delta_us);
|
| 79 | curr_stats->cpms = DIV_ROUND_UP_ULL((u64)ncomps * USEC_PER_MSEC,
|
| 80 | delta_us);
|
| 81 | if (curr_stats->epms != 0)
|
| 82 | curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL(
|
| 83 | curr_stats->cpms * 100, curr_stats->epms);
|
| 84 | else
|
| 85 | curr_stats->cpe_ratio = 0;
|
| 86 |
|
| 87 | return true;
|
| 88 | }
|
| 89 | EXPORT_SYMBOL(dim_calc_stats);
|
| 90 |
|
| 91 | MODULE_DESCRIPTION("Dynamic Interrupt Moderation (DIM) library");
|
| 92 | MODULE_LICENSE("Dual BSD/GPL");
|