~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/dim/rdma_dim.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  2 /*
  3  * Copyright (c) 2019, Mellanox Technologies inc.  All rights reserved.
  4  */
  5 
  6 #include <linux/dim.h>
  7 
  8 static int rdma_dim_step(struct dim *dim)
  9 {
 10         if (dim->tune_state == DIM_GOING_RIGHT) {
 11                 if (dim->profile_ix == (RDMA_DIM_PARAMS_NUM_PROFILES - 1))
 12                         return DIM_ON_EDGE;
 13                 dim->profile_ix++;
 14                 dim->steps_right++;
 15         }
 16         if (dim->tune_state == DIM_GOING_LEFT) {
 17                 if (dim->profile_ix == 0)
 18                         return DIM_ON_EDGE;
 19                 dim->profile_ix--;
 20                 dim->steps_left++;
 21         }
 22 
 23         return DIM_STEPPED;
 24 }
 25 
 26 static int rdma_dim_stats_compare(struct dim_stats *curr,
 27                                   struct dim_stats *prev)
 28 {
 29         /* first stat */
 30         if (!prev->cpms)
 31                 return DIM_STATS_SAME;
 32 
 33         if (IS_SIGNIFICANT_DIFF(curr->cpms, prev->cpms))
 34                 return (curr->cpms > prev->cpms) ? DIM_STATS_BETTER :
 35                                                 DIM_STATS_WORSE;
 36 
 37         if (IS_SIGNIFICANT_DIFF(curr->cpe_ratio, prev->cpe_ratio))
 38                 return (curr->cpe_ratio > prev->cpe_ratio) ? DIM_STATS_BETTER :
 39                                                 DIM_STATS_WORSE;
 40 
 41         return DIM_STATS_SAME;
 42 }
 43 
 44 static bool rdma_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
 45 {
 46         int prev_ix = dim->profile_ix;
 47         u8 state = dim->tune_state;
 48         int stats_res;
 49         int step_res;
 50 
 51         if (state != DIM_PARKING_ON_TOP && state != DIM_PARKING_TIRED) {
 52                 stats_res = rdma_dim_stats_compare(curr_stats,
 53                                                    &dim->prev_stats);
 54 
 55                 switch (stats_res) {
 56                 case DIM_STATS_SAME:
 57                         if (curr_stats->cpe_ratio <= 50 * prev_ix)
 58                                 dim->profile_ix = 0;
 59                         break;
 60                 case DIM_STATS_WORSE:
 61                         dim_turn(dim);
 62                         fallthrough;
 63                 case DIM_STATS_BETTER:
 64                         step_res = rdma_dim_step(dim);
 65                         if (step_res == DIM_ON_EDGE)
 66                                 dim_turn(dim);
 67                         break;
 68                 }
 69         }
 70 
 71         dim->prev_stats = *curr_stats;
 72 
 73         return dim->profile_ix != prev_ix;
 74 }
 75 
 76 void rdma_dim(struct dim *dim, u64 completions)
 77 {
 78         struct dim_sample *curr_sample = &dim->measuring_sample;
 79         struct dim_stats curr_stats;
 80         u32 nevents;
 81 
 82         dim_update_sample_with_comps(curr_sample->event_ctr + 1, 0, 0,
 83                                      curr_sample->comp_ctr + completions,
 84                                      &dim->measuring_sample);
 85 
 86         switch (dim->state) {
 87         case DIM_MEASURE_IN_PROGRESS:
 88                 nevents = curr_sample->event_ctr - dim->start_sample.event_ctr;
 89                 if (nevents < DIM_NEVENTS)
 90                         break;
 91                 if (!dim_calc_stats(&dim->start_sample, curr_sample, &curr_stats))
 92                         break;
 93                 if (rdma_dim_decision(&curr_stats, dim)) {
 94                         dim->state = DIM_APPLY_NEW_PROFILE;
 95                         schedule_work(&dim->work);
 96                         break;
 97                 }
 98                 fallthrough;
 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,
103                                              &dim->start_sample);
104                 break;
105         case DIM_APPLY_NEW_PROFILE:
106                 break;
107         }
108 }
109 EXPORT_SYMBOL(rdma_dim);
110 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php