Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
0002 /*
0003  * Copyright (c) 2019, Mellanox Technologies inc.  All rights reserved.
0004  */
0005 
0006 #include <linux/dim.h>
0007 
0008 bool dim_on_top(struct dim *dim)
0009 {
0010     switch (dim->tune_state) {
0011     case DIM_PARKING_ON_TOP:
0012     case DIM_PARKING_TIRED:
0013         return true;
0014     case DIM_GOING_RIGHT:
0015         return (dim->steps_left > 1) && (dim->steps_right == 1);
0016     default: /* DIM_GOING_LEFT */
0017         return (dim->steps_right > 1) && (dim->steps_left == 1);
0018     }
0019 }
0020 EXPORT_SYMBOL(dim_on_top);
0021 
0022 void dim_turn(struct dim *dim)
0023 {
0024     switch (dim->tune_state) {
0025     case DIM_PARKING_ON_TOP:
0026     case DIM_PARKING_TIRED:
0027         break;
0028     case DIM_GOING_RIGHT:
0029         dim->tune_state = DIM_GOING_LEFT;
0030         dim->steps_left = 0;
0031         break;
0032     case DIM_GOING_LEFT:
0033         dim->tune_state = DIM_GOING_RIGHT;
0034         dim->steps_right = 0;
0035         break;
0036     }
0037 }
0038 EXPORT_SYMBOL(dim_turn);
0039 
0040 void dim_park_on_top(struct dim *dim)
0041 {
0042     dim->steps_right  = 0;
0043     dim->steps_left   = 0;
0044     dim->tired        = 0;
0045     dim->tune_state   = DIM_PARKING_ON_TOP;
0046 }
0047 EXPORT_SYMBOL(dim_park_on_top);
0048 
0049 void dim_park_tired(struct dim *dim)
0050 {
0051     dim->steps_right  = 0;
0052     dim->steps_left   = 0;
0053     dim->tune_state   = DIM_PARKING_TIRED;
0054 }
0055 EXPORT_SYMBOL(dim_park_tired);
0056 
0057 void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
0058             struct dim_stats *curr_stats)
0059 {
0060     /* u32 holds up to 71 minutes, should be enough */
0061     u32 delta_us = ktime_us_delta(end->time, start->time);
0062     u32 npkts = BIT_GAP(BITS_PER_TYPE(u32), end->pkt_ctr, start->pkt_ctr);
0063     u32 nbytes = BIT_GAP(BITS_PER_TYPE(u32), end->byte_ctr,
0064                  start->byte_ctr);
0065     u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
0066                  start->comp_ctr);
0067 
0068     if (!delta_us)
0069         return;
0070 
0071     curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
0072     curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
0073     curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
0074                     delta_us);
0075     curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
0076     if (curr_stats->epms != 0)
0077         curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL(
0078             curr_stats->cpms * 100, curr_stats->epms);
0079     else
0080         curr_stats->cpe_ratio = 0;
0081 
0082 }
0083 EXPORT_SYMBOL(dim_calc_stats);