Skip to content

Commit d4e7592

Browse files
committed
Merge branch 'ocelot-stats'
Colin Foster says: ==================== use bulk reads for ocelot statistics Ocelot loops over memory regions to gather stats on different ports. These regions are mostly continuous, and are ordered. This patch set uses that information to break the stats reads into regions that can get read in bulk. The motiviation is for general cleanup, but also for SPI. Performing two back-to-back reads on a SPI bus require toggling the CS line, holding, re-toggling the CS line, sending 3 address bytes, sending N padding bytes, then actually performing the read. Bulk reads could reduce almost all of that overhead, but require that the reads are performed via regmap_bulk_read. Verified with eth0 hooked up to the CPU port: NIC statistics: Good Rx Frames: 905 Rx Octets: 78848 Good Tx Frames: 691 Tx Octets: 52516 Rx + Tx 65-127 Octet Frames: 1574 Rx + Tx 128-255 Octet Frames: 22 Net Octets: 131364 Rx DMA chan 0: head_enqueue: 1 Rx DMA chan 0: tail_enqueue: 1032 Rx DMA chan 0: busy_dequeue: 628 Rx DMA chan 0: good_dequeue: 905 Tx DMA chan 0: head_enqueue: 346 Tx DMA chan 0: tail_enqueue: 345 Tx DMA chan 0: misqueued: 345 Tx DMA chan 0: empty_dequeue: 346 Tx DMA chan 0: good_dequeue: 691 p00_rx_octets: 52516 p00_rx_unicast: 691 p00_rx_frames_65_to_127_octets: 691 p00_tx_octets: 78848 p00_tx_unicast: 905 p00_tx_frames_65_to_127_octets: 883 p00_tx_frames_128_255_octets: 22 p00_tx_green_prio_0: 905 And with swp2 connected to swp3 with STP enabled: NIC statistics: tx_packets: 379 tx_bytes: 19708 rx_packets: 1 rx_bytes: 46 rx_octets: 64 rx_multicast: 1 rx_frames_below_65_octets: 1 rx_classified_drops: 1 tx_octets: 44630 tx_multicast: 387 tx_broadcast: 290 tx_frames_below_65_octets: 379 tx_frames_65_to_127_octets: 294 tx_frames_128_255_octets: 4 tx_green_prio_0: 298 tx_green_prio_7: 379 NIC statistics: tx_packets: 1 tx_bytes: 52 rx_packets: 713 rx_bytes: 34148 rx_octets: 46982 rx_multicast: 407 rx_broadcast: 306 rx_frames_below_65_octets: 399 rx_frames_65_to_127_octets: 310 rx_frames_128_to_255_octets: 4 rx_classified_drops: 399 rx_green_prio_0: 314 tx_octets: 64 tx_multicast: 1 tx_frames_below_65_octets: 1 tx_green_prio_7: 1 v1 > v2: reword commit messages v2 > v3: correctly mark this for net-next when sending v3 > v4: calloc array instead of zalloc per review v4 > v5: Apply CR suggestions for whitespace Fix calloc / zalloc mixup Properly destroy workqueues Add third commit to split long macros v5 > v6: Fix functionality - v5 was improperly tested Add bugfix for ethtool mutex lock Remove unnecessary ethtool stats reads v6 > v7: Remove mutex bug patch that was applied via net Rename function based on CR Add missed error check ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4cf91f8 + d87b1c0 commit d4e7592

File tree

3 files changed

+133
-32
lines changed

3 files changed

+133
-32
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,58 +1746,77 @@ void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
17461746
EXPORT_SYMBOL(ocelot_get_strings);
17471747

17481748
/* Caller must hold &ocelot->stats_lock */
1749-
static void ocelot_update_stats(struct ocelot *ocelot)
1749+
static int ocelot_port_update_stats(struct ocelot *ocelot, int port)
17501750
{
1751-
int i, j;
1751+
unsigned int idx = port * ocelot->num_stats;
1752+
struct ocelot_stats_region *region;
1753+
int err, j;
17521754

1753-
for (i = 0; i < ocelot->num_phys_ports; i++) {
1754-
/* Configure the port to read the stats from */
1755-
ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
1755+
/* Configure the port to read the stats from */
1756+
ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port), SYS_STAT_CFG);
17561757

1757-
for (j = 0; j < ocelot->num_stats; j++) {
1758-
u32 val;
1759-
unsigned int idx = i * ocelot->num_stats + j;
1758+
list_for_each_entry(region, &ocelot->stats_regions, node) {
1759+
err = ocelot_bulk_read_rix(ocelot, SYS_COUNT_RX_OCTETS,
1760+
region->offset, region->buf,
1761+
region->count);
1762+
if (err)
1763+
return err;
17601764

1761-
val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS,
1762-
ocelot->stats_layout[j].offset);
1765+
for (j = 0; j < region->count; j++) {
1766+
u64 *stat = &ocelot->stats[idx + j];
1767+
u64 val = region->buf[j];
17631768

1764-
if (val < (ocelot->stats[idx] & U32_MAX))
1765-
ocelot->stats[idx] += (u64)1 << 32;
1769+
if (val < (*stat & U32_MAX))
1770+
*stat += (u64)1 << 32;
17661771

1767-
ocelot->stats[idx] = (ocelot->stats[idx] &
1768-
~(u64)U32_MAX) + val;
1772+
*stat = (*stat & ~(u64)U32_MAX) + val;
17691773
}
1774+
1775+
idx += region->count;
17701776
}
1777+
1778+
return err;
17711779
}
17721780

17731781
static void ocelot_check_stats_work(struct work_struct *work)
17741782
{
17751783
struct delayed_work *del_work = to_delayed_work(work);
17761784
struct ocelot *ocelot = container_of(del_work, struct ocelot,
17771785
stats_work);
1786+
int i, err;
17781787

17791788
mutex_lock(&ocelot->stats_lock);
1780-
ocelot_update_stats(ocelot);
1789+
for (i = 0; i < ocelot->num_phys_ports; i++) {
1790+
err = ocelot_port_update_stats(ocelot, i);
1791+
if (err)
1792+
break;
1793+
}
17811794
mutex_unlock(&ocelot->stats_lock);
17821795

1796+
if (err)
1797+
dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err);
1798+
17831799
queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
17841800
OCELOT_STATS_CHECK_DELAY);
17851801
}
17861802

17871803
void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
17881804
{
1789-
int i;
1805+
int i, err;
17901806

17911807
mutex_lock(&ocelot->stats_lock);
17921808

17931809
/* check and update now */
1794-
ocelot_update_stats(ocelot);
1810+
err = ocelot_port_update_stats(ocelot, port);
17951811

17961812
/* Copy all counters */
17971813
for (i = 0; i < ocelot->num_stats; i++)
17981814
*data++ = ocelot->stats[port * ocelot->num_stats + i];
17991815

18001816
mutex_unlock(&ocelot->stats_lock);
1817+
1818+
if (err)
1819+
dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err);
18011820
}
18021821
EXPORT_SYMBOL(ocelot_get_ethtool_stats);
18031822

@@ -1810,6 +1829,41 @@ int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
18101829
}
18111830
EXPORT_SYMBOL(ocelot_get_sset_count);
18121831

1832+
static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
1833+
{
1834+
struct ocelot_stats_region *region = NULL;
1835+
unsigned int last;
1836+
int i;
1837+
1838+
INIT_LIST_HEAD(&ocelot->stats_regions);
1839+
1840+
for (i = 0; i < ocelot->num_stats; i++) {
1841+
if (region && ocelot->stats_layout[i].offset == last + 1) {
1842+
region->count++;
1843+
} else {
1844+
region = devm_kzalloc(ocelot->dev, sizeof(*region),
1845+
GFP_KERNEL);
1846+
if (!region)
1847+
return -ENOMEM;
1848+
1849+
region->offset = ocelot->stats_layout[i].offset;
1850+
region->count = 1;
1851+
list_add_tail(&region->node, &ocelot->stats_regions);
1852+
}
1853+
1854+
last = ocelot->stats_layout[i].offset;
1855+
}
1856+
1857+
list_for_each_entry(region, &ocelot->stats_regions, node) {
1858+
region->buf = devm_kcalloc(ocelot->dev, region->count,
1859+
sizeof(*region->buf), GFP_KERNEL);
1860+
if (!region->buf)
1861+
return -ENOMEM;
1862+
}
1863+
1864+
return 0;
1865+
}
1866+
18131867
int ocelot_get_ts_info(struct ocelot *ocelot, int port,
18141868
struct ethtool_ts_info *info)
18151869
{
@@ -2810,6 +2864,13 @@ int ocelot_init(struct ocelot *ocelot)
28102864
ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6),
28112865
ANA_CPUQ_8021_CFG, i);
28122866

2867+
ret = ocelot_prepare_stats_regions(ocelot);
2868+
if (ret) {
2869+
destroy_workqueue(ocelot->stats_queue);
2870+
destroy_workqueue(ocelot->owq);
2871+
return ret;
2872+
}
2873+
28132874
INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work);
28142875
queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
28152876
OCELOT_STATS_CHECK_DELAY);

drivers/net/ethernet/mscc/ocelot_io.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
#include "ocelot.h"
1212

13+
int __ocelot_bulk_read_ix(struct ocelot *ocelot, u32 reg, u32 offset, void *buf,
14+
int count)
15+
{
16+
u16 target = reg >> TARGET_OFFSET;
17+
18+
WARN_ON(!target);
19+
20+
return regmap_bulk_read(ocelot->targets[target],
21+
ocelot->map[target][reg & REG_MASK] + offset,
22+
buf, count);
23+
}
24+
EXPORT_SYMBOL_GPL(__ocelot_bulk_read_ix);
25+
1326
u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset)
1427
{
1528
u16 target = reg >> TARGET_OFFSET;

include/soc/mscc/ocelot.h

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,13 @@ struct ocelot_stat_layout {
540540
char name[ETH_GSTRING_LEN];
541541
};
542542

543+
struct ocelot_stats_region {
544+
struct list_head node;
545+
u32 offset;
546+
int count;
547+
u32 *buf;
548+
};
549+
543550
enum ocelot_tag_prefix {
544551
OCELOT_TAG_PREFIX_DISABLED = 0,
545552
OCELOT_TAG_PREFIX_NONE,
@@ -671,6 +678,7 @@ struct ocelot {
671678
struct regmap_field *regfields[REGFIELD_MAX];
672679
const u32 *const *map;
673680
const struct ocelot_stat_layout *stats_layout;
681+
struct list_head stats_regions;
674682
unsigned int num_stats;
675683

676684
u32 pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];
@@ -742,25 +750,42 @@ struct ocelot_policer {
742750
u32 burst; /* bytes */
743751
};
744752

745-
#define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
746-
#define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
747-
#define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
748-
#define ocelot_read(ocelot, reg) __ocelot_read_ix(ocelot, reg, 0)
749-
750-
#define ocelot_write_ix(ocelot, val, reg, gi, ri) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
751-
#define ocelot_write_gix(ocelot, val, reg, gi) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
752-
#define ocelot_write_rix(ocelot, val, reg, ri) __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
753+
#define ocelot_bulk_read_rix(ocelot, reg, ri, buf, count) \
754+
__ocelot_bulk_read_ix(ocelot, reg, reg##_RSZ * (ri), buf, count)
755+
756+
#define ocelot_read_ix(ocelot, reg, gi, ri) \
757+
__ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
758+
#define ocelot_read_gix(ocelot, reg, gi) \
759+
__ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
760+
#define ocelot_read_rix(ocelot, reg, ri) \
761+
__ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
762+
#define ocelot_read(ocelot, reg) \
763+
__ocelot_read_ix(ocelot, reg, 0)
764+
765+
#define ocelot_write_ix(ocelot, val, reg, gi, ri) \
766+
__ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
767+
#define ocelot_write_gix(ocelot, val, reg, gi) \
768+
__ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
769+
#define ocelot_write_rix(ocelot, val, reg, ri) \
770+
__ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
753771
#define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
754772

755-
#define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
756-
#define ocelot_rmw_gix(ocelot, val, m, reg, gi) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
757-
#define ocelot_rmw_rix(ocelot, val, m, reg, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
773+
#define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) \
774+
__ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
775+
#define ocelot_rmw_gix(ocelot, val, m, reg, gi) \
776+
__ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
777+
#define ocelot_rmw_rix(ocelot, val, m, reg, ri) \
778+
__ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
758779
#define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
759780

760-
#define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
761-
#define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
762-
#define ocelot_fields_write(ocelot, id, reg, val) regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
763-
#define ocelot_fields_read(ocelot, id, reg, val) regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
781+
#define ocelot_field_write(ocelot, reg, val) \
782+
regmap_field_write((ocelot)->regfields[(reg)], (val))
783+
#define ocelot_field_read(ocelot, reg, val) \
784+
regmap_field_read((ocelot)->regfields[(reg)], (val))
785+
#define ocelot_fields_write(ocelot, id, reg, val) \
786+
regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
787+
#define ocelot_fields_read(ocelot, id, reg, val) \
788+
regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
764789

765790
#define ocelot_target_read_ix(ocelot, target, reg, gi, ri) \
766791
__ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
@@ -784,6 +809,8 @@ struct ocelot_policer {
784809
u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
785810
void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
786811
void ocelot_port_rmwl(struct ocelot_port *port, u32 val, u32 mask, u32 reg);
812+
int __ocelot_bulk_read_ix(struct ocelot *ocelot, u32 reg, u32 offset, void *buf,
813+
int count);
787814
u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset);
788815
void __ocelot_write_ix(struct ocelot *ocelot, u32 val, u32 reg, u32 offset);
789816
void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,

0 commit comments

Comments
 (0)