anolis: dim: optimize dim lib

ANBZ: #8042

Tune the dim algorithm.

We need to void the impact of virtio's dim optimization
on other nics.

Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/3227
This commit is contained in:
Heng Qi 2024-01-16 15:43:34 +08:00 committed by 小龙
parent 5b08313176
commit f005614f4c
4 changed files with 59 additions and 6 deletions

View File

@ -52,6 +52,9 @@ module_param(napi_tx, bool, 0644);
module_param(force_xdp, bool, 0644);
module_param(lro, bool, 0644);
#define VIRTNET_DIM_TUNE_TRAFFIC 1
#define VIRTNET_DIM_NEVENTS 128
/* FIXME: MTU in config. */
#define GOOD_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
#define GOOD_COPY_LEN 128
@ -1979,7 +1982,8 @@ static void virtnet_rx_dim_update(struct virtnet_info *vi, struct receive_queue
&cur_sample);
u64_stats_update_end(&rq->stats.syncp);
net_dim(&rq->dim, cur_sample);
net_dim_tune(&rq->dim, cur_sample, VIRTNET_DIM_NEVENTS,
VIRTNET_DIM_TUNE_TRAFFIC);
rq->packets_in_napi = 0;
}

View File

@ -25,6 +25,8 @@ struct net_device;
*/
#define DIM_NEVENTS 64
#define DIM_RATIO 5
/*
* Is a difference between values justifies taking an action.
* We consider 10% difference as significant.
@ -32,6 +34,10 @@ struct net_device;
#define IS_SIGNIFICANT_DIFF(val, ref) \
((ref) && (((100UL * abs((val) - (ref))) / (ref)) > 10))
/* Consider 1% difference as traffic is stable. */
#define IS_SIGNIFICANT_DIFF_1(val, ref) \
((ref) && (((100UL * abs((val) - (ref))) / (ref)) <= 1))
/*
* Calculate the gap between two values.
* Take wrap-around and variable size into consideration.
@ -425,6 +431,18 @@ struct dim_cq_moder net_dim_get_def_tx_moderation(u8 cq_period_mode);
*/
void net_dim(struct dim *dim, struct dim_sample end_sample);
/**
* net_dim_tune - DIM algorithm entry point with tunable params
* @dim: DIM instance information
* @end_sample: Current data measurement
* @sample_events: Sampling event interval
* @tune_traffic: non-high load traffic decision optimization
*
* This provides more tuning parameter settings than the net_dim interface.
*/
void net_dim_tune(struct dim *dim, struct dim_sample end_sample,
u16 sample_events, bool tune_traffic);
/* RDMA DIM */
/*

View File

@ -64,13 +64,15 @@ void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
start->byte_ctr);
u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
start->comp_ctr);
u16 nevents = BIT_GAP(BITS_PER_TYPE(u16), end->event_ctr,
start->event_ctr);
if (!delta_us)
return;
curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
curr_stats->epms = DIV_ROUND_UP(nevents * USEC_PER_MSEC,
delta_us);
curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
if (curr_stats->epms != 0)

View File

@ -294,7 +294,8 @@ static int net_dim_stats_compare(struct dim_stats *curr,
return DIM_STATS_SAME;
}
static bool net_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
static bool net_dim_decision(struct dim_stats *curr_stats, struct dim *dim,
bool tune_traffic)
{
int prev_state = dim->tune_state;
int prev_ix = dim->profile_ix;
@ -317,6 +318,16 @@ static bool net_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
case DIM_GOING_RIGHT:
case DIM_GOING_LEFT:
/* A new local optimum for tune. Other states are cleared.*/
if (tune_traffic && dim->prev_stats.ppms && curr_stats->epms &&
IS_SIGNIFICANT_DIFF_1(curr_stats->ppms, dim->prev_stats.ppms) &&
(curr_stats->ppms / curr_stats->epms) <= DIM_RATIO) {
dim_park_on_top(dim);
dim->profile_ix = 1;
dim->prev_stats = *curr_stats;
return true;
}
stats_res = net_dim_stats_compare(curr_stats,
&dim->prev_stats);
if (stats_res != DIM_STATS_BETTER)
@ -347,7 +358,8 @@ static bool net_dim_decision(struct dim_stats *curr_stats, struct dim *dim)
return dim->profile_ix != prev_ix;
}
void net_dim(struct dim *dim, struct dim_sample end_sample)
static void net_dim_impl(struct dim *dim, struct dim_sample end_sample,
u16 sample_events, bool tune_traffic)
{
struct dim_stats curr_stats;
u16 nevents;
@ -357,10 +369,15 @@ void net_dim(struct dim *dim, struct dim_sample end_sample)
nevents = BIT_GAP(BITS_PER_TYPE(u16),
end_sample.event_ctr,
dim->start_sample.event_ctr);
if (nevents < DIM_NEVENTS)
/* Compared with the timer method, judging the minimum
* interval of an iteration with a larger sample_nevents
* has a better results.
*/
if (nevents < sample_events)
break;
dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats);
if (net_dim_decision(&curr_stats, dim)) {
if (net_dim_decision(&curr_stats, dim, tune_traffic)) {
dim->state = DIM_APPLY_NEW_PROFILE;
schedule_work(&dim->work);
break;
@ -375,4 +392,16 @@ void net_dim(struct dim *dim, struct dim_sample end_sample)
break;
}
}
void net_dim(struct dim *dim, struct dim_sample end_sample)
{
net_dim_impl(dim, end_sample, DIM_NEVENTS, false);
}
EXPORT_SYMBOL(net_dim);
void net_dim_tune(struct dim *dim, struct dim_sample end_sample,
u16 sample_events, bool tune_traffic)
{
net_dim_impl(dim, end_sample, sample_events, tune_traffic);
}
EXPORT_SYMBOL(net_dim_tune);