Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1dc4d1e6 authored by Stefano Brivio's avatar Stefano Brivio Committed by David S. Miller
Browse files

rc80211-pid: add sharpening factor



This patch introduces a PID sharpening factor for faster response after
association and low activity events.

Signed-off-by: default avatarStefano Brivio <stefano.brivio@polimi.it>
Signed-off-by: default avatarMattias Nissler <mattias.nissler@gmx.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 90d501d6
Loading
Loading
Loading
Loading
+27 −8
Original line number Original line Diff line number Diff line
@@ -23,13 +23,16 @@
 *
 *
 * The controller basically computes the following:
 * The controller basically computes the following:
 *
 *
 * adj = CP * err + CI * err_avg + CD * (err - last_err)
 * adj = CP * err + CI * err_avg + CD * (err - last_err) * (1 + sharpening)
 *
 *
 * where
 * where
 * 	adj	adjustment value that is used to switch TX rate (see below)
 * 	adj	adjustment value that is used to switch TX rate (see below)
 * 	err	current error: target vs. current failed frames percentage
 * 	err	current error: target vs. current failed frames percentage
 * 	last_err	last error
 * 	last_err	last error
 * 	err_avg	average (i.e. poor man's integral) of recent errors
 * 	err_avg	average (i.e. poor man's integral) of recent errors
 *	sharpening	non-zero when fast response is needed (i.e. right after
 *			association or no frames sent for a long time), heading
 * 			to zero over time
 * 	CP	Proportional coefficient
 * 	CP	Proportional coefficient
 * 	CI	Integral coefficient
 * 	CI	Integral coefficient
 * 	CD	Derivative coefficient
 * 	CD	Derivative coefficient
@@ -65,6 +68,10 @@
#define RC_PID_SMOOTHING_SHIFT 3
#define RC_PID_SMOOTHING_SHIFT 3
#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)


/* Sharpening factor (used for D part of PID controller) */
#define RC_PID_SHARPENING_FACTOR 0
#define RC_PID_SHARPENING_DURATION 0

/* Fixed point arithmetic shifting amount. */
/* Fixed point arithmetic shifting amount. */
#define RC_PID_ARITH_SHIFT 8
#define RC_PID_ARITH_SHIFT 8


@@ -131,8 +138,11 @@ struct rc_pid_sta_info {
	 */
	 */
	s32 err_avg_sc;
	s32 err_avg_sc;


	/* Last framed failes percentage sample */
	/* Last framed failes percentage sample. */
	u32 last_pf;
	u32 last_pf;

	/* Sharpening needed. */
	u8 sharp_cnt;
};
};


/* Algorithm parameters. We keep them on a per-algorithm approach, so they can
/* Algorithm parameters. We keep them on a per-algorithm approach, so they can
@@ -267,19 +277,25 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,


	mode = local->oper_hw_mode;
	mode = local->oper_hw_mode;
	spinfo = sta->rate_ctrl_priv;
	spinfo = sta->rate_ctrl_priv;

	/* In case nothing happened during the previous control interval, turn
	 * the sharpening factor on. */
	if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
		spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;

	spinfo->last_sample = jiffies;
	spinfo->last_sample = jiffies;


	/* If no frames were transmitted, we assume the old sample is
	/* This should never happen, but in case, we assume the old sample is
	 * still a good measurement and copy it. */
	 * still a good measurement and copy it. */
	if (spinfo->tx_num_xmit == 0)
	if (unlikely(spinfo->tx_num_xmit == 0))
		pf = spinfo->last_pf;
		pf = spinfo->last_pf;
	else {
	else {
		pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
		pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
		pf <<= RC_PID_ARITH_SHIFT;
		pf <<= RC_PID_ARITH_SHIFT;
	}


	spinfo->tx_num_xmit = 0;
	spinfo->tx_num_xmit = 0;
	spinfo->tx_num_failed = 0;
	spinfo->tx_num_failed = 0;
	}


	/* If we just switched rate, update the rate behaviour info. */
	/* If we just switched rate, update the rate behaviour info. */
	if (pinfo->oldrate != sta->txrate) {
	if (pinfo->oldrate != sta->txrate) {
@@ -302,8 +318,11 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
	spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
	spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
	err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
	err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;


	err_der = pf - spinfo->last_pf;
	err_der = pf - spinfo->last_pf
		  * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
	spinfo->last_pf = pf;
	spinfo->last_pf = pf;
	if (spinfo->sharp_cnt)
			spinfo->sharp_cnt--;


	/* Compute the controller output. */
	/* Compute the controller output. */
	adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
	adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i