Skip to content

Commit

Permalink
ocelot: Clean up stats update deferred work
Browse files Browse the repository at this point in the history
This is preventive cleanup that may save troubles later.
No need to cancel repeateadly queued work if code is properly
refactored.
Don't let the ethtool -s process interfere with the stat workqueue
scheduling.

Signed-off-by: Claudiu Manoil <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
claudiu-m authored and davem330 committed Apr 17, 2019
1 parent a8fd48b commit 1e1caa9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions drivers/net/ethernet/mscc/ocelot.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,8 @@ static void ocelot_get_strings(struct net_device *netdev, u32 sset, u8 *data)
ETH_GSTRING_LEN);
}

static void ocelot_check_stats(struct work_struct *work)
static void ocelot_update_stats(struct ocelot *ocelot)
{
struct delayed_work *del_work = to_delayed_work(work);
struct ocelot *ocelot = container_of(del_work, struct ocelot, stats_work);
int i, j;

mutex_lock(&ocelot->stats_lock);
Expand All @@ -986,11 +984,19 @@ static void ocelot_check_stats(struct work_struct *work)
}
}

cancel_delayed_work(&ocelot->stats_work);
mutex_unlock(&ocelot->stats_lock);
}

static void ocelot_check_stats_work(struct work_struct *work)
{
struct delayed_work *del_work = to_delayed_work(work);
struct ocelot *ocelot = container_of(del_work, struct ocelot,
stats_work);

ocelot_update_stats(ocelot);

queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
OCELOT_STATS_CHECK_DELAY);

mutex_unlock(&ocelot->stats_lock);
}

static void ocelot_get_ethtool_stats(struct net_device *dev,
Expand All @@ -1001,7 +1007,7 @@ static void ocelot_get_ethtool_stats(struct net_device *dev,
int i;

/* check and update now */
ocelot_check_stats(&ocelot->stats_work.work);
ocelot_update_stats(ocelot);

/* Copy all counters */
for (i = 0; i < ocelot->num_stats; i++)
Expand Down Expand Up @@ -1809,7 +1815,7 @@ int ocelot_init(struct ocelot *ocelot)
ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
ANA_CPUQ_8021_CFG, i);

INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats);
INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work);
queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
OCELOT_STATS_CHECK_DELAY);
return 0;
Expand Down

0 comments on commit 1e1caa9

Please sign in to comment.