Skip to content

Commit

Permalink
media: cxd2841er: avoid too many status inquires
Browse files Browse the repository at this point in the history
I2C ops are expensive, as the I2C bus typical speed is 100kbps.

Also, stats reading take some time, as it requires to retrieve a
certain number of packets to complete.

While we don't know the minimal for CXD2841er, trying to do it
too quickly is still a very bad idea.

So, add some sanity logic there, preventing to retrieve stats
faster than one second.

This shouldn't cause any issues with well behavior apps, as they
usually take stats on a polling rate slower than 1 second.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
Mauro Carvalho Chehab committed Oct 16, 2019
1 parent 75564e3 commit d9aeaa6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/media/dvb-frontends/cxd2841er.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct cxd2841er_priv {
enum cxd2841er_xtal xtal;
enum fe_caps caps;
u32 flags;
unsigned long stats_time;
};

static const struct cxd2841er_cnr_data s_cn_data[] = {
Expand Down Expand Up @@ -3279,9 +3280,15 @@ static int cxd2841er_get_frontend(struct dvb_frontend *fe,
p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;

if (status & FE_HAS_LOCK) {
if (priv->stats_time &&
(!time_after(jiffies, priv->stats_time)))
return 0;

/* Prevent retrieving stats faster than once per second */
priv->stats_time = jiffies + msecs_to_jiffies(1000);

cxd2841er_read_snr(fe);
cxd2841er_read_ucblocks(fe);

cxd2841er_read_ber(fe);
} else {
p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
Expand Down Expand Up @@ -3360,6 +3367,9 @@ static int cxd2841er_set_frontend_s(struct dvb_frontend *fe)
p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;

/* Reset the wait for jiffies logic */
priv->stats_time = 0;

return ret;
}

Expand Down

0 comments on commit d9aeaa6

Please sign in to comment.