2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* net/core/gen_stats.c
|
|
|
|
*
|
|
|
|
* Authors: Thomas Graf <tgraf@suug.ch>
|
|
|
|
* Jamal Hadi Salim
|
|
|
|
* Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
|
|
|
*
|
2020-04-27 22:01:41 +00:00
|
|
|
* See Documentation/networking/gen_stats.rst
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/gen_stats.h>
|
2008-01-23 06:11:17 +00:00
|
|
|
#include <net/netlink.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <net/gen_stats.h>
|
2021-10-16 08:49:07 +00:00
|
|
|
#include <net/sch_generic.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static inline int
|
2016-04-26 08:06:18 +00:00
|
|
|
gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size, int padattr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-04-26 08:06:18 +00:00
|
|
|
if (nla_put_64bit(d->skb, type, size, buf, padattr))
|
2012-04-02 00:47:35 +00:00
|
|
|
goto nla_put_failure;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-01-23 06:11:17 +00:00
|
|
|
nla_put_failure:
|
2016-06-06 16:37:16 +00:00
|
|
|
if (d->lock)
|
|
|
|
spin_unlock_bh(d->lock);
|
2015-02-13 22:47:05 +00:00
|
|
|
kfree(d->xstats);
|
|
|
|
d->xstats = NULL;
|
|
|
|
d->xstats_len = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gnet_stats_start_copy_compat - start dumping procedure in compatibility mode
|
|
|
|
* @skb: socket buffer to put statistics TLVs into
|
|
|
|
* @type: TLV type for top level statistic TLV
|
|
|
|
* @tc_stats_type: TLV type for backward compatibility struct tc_stats TLV
|
|
|
|
* @xstats_type: TLV type for backward compatibility xstats TLV
|
|
|
|
* @lock: statistics lock
|
|
|
|
* @d: dumping handle
|
2016-06-08 13:19:45 +00:00
|
|
|
* @padattr: padding attribute
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Initializes the dumping handle, grabs the statistic lock and appends
|
|
|
|
* an empty TLV header to the socket buffer for use a container for all
|
|
|
|
* other statistic TLVS.
|
|
|
|
*
|
|
|
|
* The dumping handle is marked to be in backward compatibility mode telling
|
|
|
|
* all gnet_stats_copy_XXX() functions to fill a local copy of struct tc_stats.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gnet_stats_start_copy_compat(struct sk_buff *skb, int type, int tc_stats_type,
|
2016-04-26 08:06:18 +00:00
|
|
|
int xstats_type, spinlock_t *lock,
|
|
|
|
struct gnet_dump *d, int padattr)
|
2008-01-02 05:58:02 +00:00
|
|
|
__acquires(lock)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
memset(d, 0, sizeof(*d));
|
2007-02-09 14:24:36 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (type)
|
2008-01-23 06:11:17 +00:00
|
|
|
d->tail = (struct nlattr *)skb_tail_pointer(skb);
|
2005-04-16 22:20:36 +00:00
|
|
|
d->skb = skb;
|
|
|
|
d->compat_tc_stats = tc_stats_type;
|
|
|
|
d->compat_xstats = xstats_type;
|
2016-04-26 08:06:18 +00:00
|
|
|
d->padattr = padattr;
|
2016-06-06 16:37:16 +00:00
|
|
|
if (lock) {
|
|
|
|
d->lock = lock;
|
|
|
|
spin_lock_bh(lock);
|
|
|
|
}
|
gen_stats: Fix netlink stats dumping in the presence of padding
The gen_stats facility will add a header for the toplevel nlattr of type
TCA_STATS2 that contains all stats added by qdisc callbacks. A reference
to this header is stored in the gnet_dump struct, and when all the
per-qdisc callbacks have finished adding their stats, the length of the
containing header will be adjusted to the right value.
However, on architectures that need padding (i.e., that don't set
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), the padding nlattr is added
before the stats, which means that the stored pointer will point to the
padding, and so when the header is fixed up, the result is just a very
big padding nlattr. Because most qdiscs also supply the legacy TCA_STATS
struct, this problem has been mostly invisible, but we exposed it with
the netlink attribute-based statistics in CAKE.
Fix the issue by fixing up the stored pointer if it points to a padding
nlattr.
Tested-by: Pete Heist <pete@heistp.net>
Tested-by: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-07-02 20:52:20 +00:00
|
|
|
if (d->tail) {
|
|
|
|
int ret = gnet_stats_copy(d, type, NULL, 0, padattr);
|
|
|
|
|
|
|
|
/* The initial attribute added in gnet_stats_copy() may be
|
|
|
|
* preceded by a padding attribute, in which case d->tail will
|
|
|
|
* end up pointing at the padding instead of the real attribute.
|
|
|
|
* Fix this so gnet_stats_finish_copy() adjusts the length of
|
|
|
|
* the right attribute.
|
|
|
|
*/
|
|
|
|
if (ret == 0 && d->tail->nla_type == padattr)
|
|
|
|
d->tail = (struct nlattr *)((char *)d->tail +
|
|
|
|
NLA_ALIGN(d->tail->nla_len));
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_start_copy_compat);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-26 08:06:18 +00:00
|
|
|
* gnet_stats_start_copy - start dumping procedure in compatibility mode
|
2005-04-16 22:20:36 +00:00
|
|
|
* @skb: socket buffer to put statistics TLVs into
|
|
|
|
* @type: TLV type for top level statistic TLV
|
|
|
|
* @lock: statistics lock
|
|
|
|
* @d: dumping handle
|
2016-06-08 13:19:45 +00:00
|
|
|
* @padattr: padding attribute
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Initializes the dumping handle, grabs the statistic lock and appends
|
|
|
|
* an empty TLV header to the socket buffer for use a container for all
|
|
|
|
* other statistic TLVS.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
|
2016-04-26 08:06:18 +00:00
|
|
|
struct gnet_dump *d, int padattr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-04-26 08:06:18 +00:00
|
|
|
return gnet_stats_start_copy_compat(skb, type, 0, 0, lock, d, padattr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_start_copy);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-10-16 08:49:07 +00:00
|
|
|
/* Must not be inlined, due to u64_stats seqcount_t lockdep key */
|
2021-10-16 08:49:09 +00:00
|
|
|
void gnet_stats_basic_sync_init(struct gnet_stats_basic_sync *b)
|
2021-10-16 08:49:07 +00:00
|
|
|
{
|
2021-10-16 08:49:09 +00:00
|
|
|
u64_stats_set(&b->bytes, 0);
|
|
|
|
u64_stats_set(&b->packets, 0);
|
2021-10-16 08:49:07 +00:00
|
|
|
u64_stats_init(&b->syncp);
|
|
|
|
}
|
2021-10-16 08:49:09 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_basic_sync_init);
|
2021-10-16 08:49:07 +00:00
|
|
|
|
2021-10-16 08:49:09 +00:00
|
|
|
static void gnet_stats_add_basic_cpu(struct gnet_stats_basic_sync *bstats,
|
|
|
|
struct gnet_stats_basic_sync __percpu *cpu)
|
2014-09-28 18:52:56 +00:00
|
|
|
{
|
2021-10-16 08:49:08 +00:00
|
|
|
u64 t_bytes = 0, t_packets = 0;
|
2014-09-28 18:52:56 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i) {
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync *bcpu = per_cpu_ptr(cpu, i);
|
2014-09-28 18:52:56 +00:00
|
|
|
unsigned int start;
|
2019-11-05 03:13:14 +00:00
|
|
|
u64 bytes, packets;
|
2014-09-28 18:52:56 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
start = u64_stats_fetch_begin_irq(&bcpu->syncp);
|
2021-10-16 08:49:09 +00:00
|
|
|
bytes = u64_stats_read(&bcpu->bytes);
|
|
|
|
packets = u64_stats_read(&bcpu->packets);
|
2014-09-28 18:52:56 +00:00
|
|
|
} while (u64_stats_fetch_retry_irq(&bcpu->syncp, start));
|
|
|
|
|
2021-10-16 08:49:08 +00:00
|
|
|
t_bytes += bytes;
|
|
|
|
t_packets += packets;
|
2014-09-28 18:52:56 +00:00
|
|
|
}
|
2021-10-16 08:49:08 +00:00
|
|
|
_bstats_update(bstats, t_bytes, t_packets);
|
2014-09-28 18:52:56 +00:00
|
|
|
}
|
|
|
|
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats,
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync __percpu *cpu,
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
struct gnet_stats_basic_sync *b, bool running)
|
2014-09-28 18:52:56 +00:00
|
|
|
{
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
unsigned int start;
|
2021-10-16 08:49:02 +00:00
|
|
|
u64 bytes = 0;
|
|
|
|
u64 packets = 0;
|
2016-06-06 16:37:16 +00:00
|
|
|
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
WARN_ON_ONCE((cpu || running) && !in_task());
|
|
|
|
|
2014-09-28 18:52:56 +00:00
|
|
|
if (cpu) {
|
2021-10-16 08:49:02 +00:00
|
|
|
gnet_stats_add_basic_cpu(bstats, cpu);
|
2016-06-06 16:37:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (running)
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
start = u64_stats_fetch_begin_irq(&b->syncp);
|
2021-10-16 08:49:09 +00:00
|
|
|
bytes = u64_stats_read(&b->bytes);
|
|
|
|
packets = u64_stats_read(&b->packets);
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
} while (running && u64_stats_fetch_retry_irq(&b->syncp, start));
|
2021-10-16 08:49:02 +00:00
|
|
|
|
2021-10-16 08:49:08 +00:00
|
|
|
_bstats_update(bstats, bytes, packets);
|
2014-09-28 18:52:56 +00:00
|
|
|
}
|
2021-10-16 08:49:02 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_add_basic);
|
2014-09-28 18:52:56 +00:00
|
|
|
|
2018-09-26 12:09:45 +00:00
|
|
|
static int
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
___gnet_stats_copy_basic(struct gnet_dump *d,
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync __percpu *cpu,
|
|
|
|
struct gnet_stats_basic_sync *b,
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
int type, bool running)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync bstats;
|
|
|
|
u64 bstats_bytes, bstats_packets;
|
2014-09-28 18:52:56 +00:00
|
|
|
|
2021-10-16 08:49:09 +00:00
|
|
|
gnet_stats_basic_sync_init(&bstats);
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
gnet_stats_add_basic(&bstats, cpu, b, running);
|
2014-09-28 18:52:56 +00:00
|
|
|
|
2021-10-16 08:49:09 +00:00
|
|
|
bstats_bytes = u64_stats_read(&bstats.bytes);
|
|
|
|
bstats_packets = u64_stats_read(&bstats.packets);
|
|
|
|
|
2018-09-21 11:13:54 +00:00
|
|
|
if (d->compat_tc_stats && type == TCA_STATS_BASIC) {
|
2021-10-16 08:49:09 +00:00
|
|
|
d->tc_stats.bytes = bstats_bytes;
|
|
|
|
d->tc_stats.packets = bstats_packets;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 09:36:49 +00:00
|
|
|
if (d->tail) {
|
|
|
|
struct gnet_stats_basic sb;
|
2019-11-05 03:13:15 +00:00
|
|
|
int res;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-08-16 09:36:49 +00:00
|
|
|
memset(&sb, 0, sizeof(sb));
|
2021-10-16 08:49:09 +00:00
|
|
|
sb.bytes = bstats_bytes;
|
|
|
|
sb.packets = bstats_packets;
|
2019-11-05 03:13:15 +00:00
|
|
|
res = gnet_stats_copy(d, type, &sb, sizeof(sb), TCA_STATS_PAD);
|
2021-10-16 08:49:09 +00:00
|
|
|
if (res < 0 || sb.packets == bstats_packets)
|
2019-11-05 03:13:15 +00:00
|
|
|
return res;
|
|
|
|
/* emit 64bit stats only if needed */
|
2021-10-16 08:49:09 +00:00
|
|
|
return gnet_stats_copy(d, TCA_STATS_PKT64, &bstats_packets,
|
|
|
|
sizeof(bstats_packets), TCA_STATS_PAD);
|
2009-08-16 09:36:49 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-09-21 11:13:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gnet_stats_copy_basic - copy basic statistics into statistic TLV
|
|
|
|
* @d: dumping handle
|
|
|
|
* @cpu: copy statistic per cpu
|
|
|
|
* @b: basic statistics
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
* @running: true if @b represents a running qdisc, thus @b's
|
|
|
|
* internal values might change during basic reads.
|
|
|
|
* Only used if @cpu is NULL
|
|
|
|
*
|
|
|
|
* Context: task; must not be run from IRQ or BH contexts
|
2018-09-21 11:13:54 +00:00
|
|
|
*
|
|
|
|
* Appends the basic statistics to the top level TLV created by
|
|
|
|
* gnet_stats_start_copy().
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
gnet_stats_copy_basic(struct gnet_dump *d,
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync __percpu *cpu,
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
struct gnet_stats_basic_sync *b,
|
|
|
|
bool running)
|
2018-09-21 11:13:54 +00:00
|
|
|
{
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
return ___gnet_stats_copy_basic(d, cpu, b, TCA_STATS_BASIC, running);
|
2018-09-21 11:13:54 +00:00
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_copy_basic);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-09-21 11:13:54 +00:00
|
|
|
/**
|
|
|
|
* gnet_stats_copy_basic_hw - copy basic hw statistics into statistic TLV
|
|
|
|
* @d: dumping handle
|
|
|
|
* @cpu: copy statistic per cpu
|
|
|
|
* @b: basic statistics
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
* @running: true if @b represents a running qdisc, thus @b's
|
|
|
|
* internal values might change during basic reads.
|
|
|
|
* Only used if @cpu is NULL
|
|
|
|
*
|
|
|
|
* Context: task; must not be run from IRQ or BH contexts
|
2018-09-21 11:13:54 +00:00
|
|
|
*
|
|
|
|
* Appends the basic statistics to the top level TLV created by
|
|
|
|
* gnet_stats_start_copy().
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
gnet_stats_copy_basic_hw(struct gnet_dump *d,
|
2021-10-16 08:49:09 +00:00
|
|
|
struct gnet_stats_basic_sync __percpu *cpu,
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
struct gnet_stats_basic_sync *b,
|
|
|
|
bool running)
|
2018-09-21 11:13:54 +00:00
|
|
|
{
|
net: sched: Remove Qdisc::running sequence counter
The Qdisc::running sequence counter has two uses:
1. Reliably reading qdisc's tc statistics while the qdisc is running
(a seqcount read/retry loop at gnet_stats_add_basic()).
2. As a flag, indicating whether the qdisc in question is running
(without any retry loops).
For the first usage, the Qdisc::running sequence counter write section,
qdisc_run_begin() => qdisc_run_end(), covers a much wider area than what
is actually needed: the raw qdisc's bstats update. A u64_stats sync
point was thus introduced (in previous commits) inside the bstats
structure itself. A local u64_stats write section is then started and
stopped for the bstats updates.
Use that u64_stats sync point mechanism for the bstats read/retry loop
at gnet_stats_add_basic().
For the second qdisc->running usage, a __QDISC_STATE_RUNNING bit flag,
accessed with atomic bitops, is sufficient. Using a bit flag instead of
a sequence counter at qdisc_run_begin/end() and qdisc_is_running() leads
to the SMP barriers implicitly added through raw_read_seqcount() and
write_seqcount_begin/end() getting removed. All call sites have been
surveyed though, and no required ordering was identified.
Now that the qdisc->running sequence counter is no longer used, remove
it.
Note, using u64_stats implies no sequence counter protection for 64-bit
architectures. This can lead to the qdisc tc statistics "packets" vs.
"bytes" values getting out of sync on rare occasions. The individual
values will still be valid.
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-16 08:49:10 +00:00
|
|
|
return ___gnet_stats_copy_basic(d, cpu, b, TCA_STATS_BASIC_HW, running);
|
2018-09-21 11:13:54 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(gnet_stats_copy_basic_hw);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
|
|
|
* gnet_stats_copy_rate_est - copy rate estimator statistics into statistics TLV
|
|
|
|
* @d: dumping handle
|
2016-12-04 17:48:16 +00:00
|
|
|
* @rate_est: rate estimator
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Appends the rate estimator statistics to the top level TLV created by
|
|
|
|
* gnet_stats_start_copy().
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
pkt_sched: gen_estimator: Dont report fake rate estimators
Jarek Poplawski a écrit :
>
>
> Hmm... So you made me to do some "real" work here, and guess what?:
> there is one serious checkpatch warning! ;-) Plus, this new parameter
> should be added to the function description. Otherwise:
> Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
>
> Thanks,
> Jarek P.
>
> PS: I guess full "Don't" would show we really mean it...
Okay :) Here is the last round, before the night !
Thanks again
[RFC] pkt_sched: gen_estimator: Don't report fake rate estimators
We currently send TCA_STATS_RATE_EST elements to netlink users, even if no estimator
is running.
# tc -s -d qdisc
qdisc pfifo_fast 0: dev eth0 root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 112833764978 bytes 1495081739 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
User has no way to tell if the "rate 0bit 0pps" is a real estimation, or a fake
one (because no estimator is active)
After this patch, tc command output is :
$ tc -s -d qdisc
qdisc pfifo_fast 0: dev eth0 root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 561075 bytes 1196 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
We add a parameter to gnet_stats_copy_rate_est() function so that
it can use gen_estimator_active(bstats, r), as suggested by Jarek.
This parameter can be NULL if check is not necessary, (htb for
example has a mandatory rate estimator)
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-10-02 10:32:18 +00:00
|
|
|
gnet_stats_copy_rate_est(struct gnet_dump *d,
|
2016-12-04 17:48:16 +00:00
|
|
|
struct net_rate_estimator __rcu **rate_est)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-12-04 17:48:16 +00:00
|
|
|
struct gnet_stats_rate_est64 sample;
|
2013-06-06 15:43:22 +00:00
|
|
|
struct gnet_stats_rate_est est;
|
|
|
|
int res;
|
|
|
|
|
2016-12-04 17:48:16 +00:00
|
|
|
if (!gen_estimator_read(rate_est, &sample))
|
pkt_sched: gen_estimator: Dont report fake rate estimators
Jarek Poplawski a écrit :
>
>
> Hmm... So you made me to do some "real" work here, and guess what?:
> there is one serious checkpatch warning! ;-) Plus, this new parameter
> should be added to the function description. Otherwise:
> Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
>
> Thanks,
> Jarek P.
>
> PS: I guess full "Don't" would show we really mean it...
Okay :) Here is the last round, before the night !
Thanks again
[RFC] pkt_sched: gen_estimator: Don't report fake rate estimators
We currently send TCA_STATS_RATE_EST elements to netlink users, even if no estimator
is running.
# tc -s -d qdisc
qdisc pfifo_fast 0: dev eth0 root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 112833764978 bytes 1495081739 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
User has no way to tell if the "rate 0bit 0pps" is a real estimation, or a fake
one (because no estimator is active)
After this patch, tc command output is :
$ tc -s -d qdisc
qdisc pfifo_fast 0: dev eth0 root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 561075 bytes 1196 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
We add a parameter to gnet_stats_copy_rate_est() function so that
it can use gen_estimator_active(bstats, r), as suggested by Jarek.
This parameter can be NULL if check is not necessary, (htb for
example has a mandatory rate estimator)
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-10-02 10:32:18 +00:00
|
|
|
return 0;
|
2016-12-04 17:48:16 +00:00
|
|
|
est.bps = min_t(u64, UINT_MAX, sample.bps);
|
2013-06-06 15:43:22 +00:00
|
|
|
/* we have some time before reaching 2^32 packets per second */
|
2016-12-04 17:48:16 +00:00
|
|
|
est.pps = sample.pps;
|
2013-06-06 15:43:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (d->compat_tc_stats) {
|
2013-06-06 15:43:22 +00:00
|
|
|
d->tc_stats.bps = est.bps;
|
|
|
|
d->tc_stats.pps = est.pps;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:43:22 +00:00
|
|
|
if (d->tail) {
|
2016-04-26 08:06:18 +00:00
|
|
|
res = gnet_stats_copy(d, TCA_STATS_RATE_EST, &est, sizeof(est),
|
|
|
|
TCA_STATS_PAD);
|
2016-12-04 17:48:16 +00:00
|
|
|
if (res < 0 || est.bps == sample.bps)
|
2013-06-06 15:43:22 +00:00
|
|
|
return res;
|
|
|
|
/* emit 64bit stats only if needed */
|
2016-12-04 17:48:16 +00:00
|
|
|
return gnet_stats_copy(d, TCA_STATS_RATE_EST64, &sample,
|
|
|
|
sizeof(sample), TCA_STATS_PAD);
|
2013-06-06 15:43:22 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_copy_rate_est);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-10-16 08:49:03 +00:00
|
|
|
static void gnet_stats_add_queue_cpu(struct gnet_stats_queue *qstats,
|
|
|
|
const struct gnet_stats_queue __percpu *q)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
const struct gnet_stats_queue *qcpu = per_cpu_ptr(q, i);
|
|
|
|
|
|
|
|
qstats->qlen += qcpu->backlog;
|
|
|
|
qstats->backlog += qcpu->backlog;
|
|
|
|
qstats->drops += qcpu->drops;
|
|
|
|
qstats->requeues += qcpu->requeues;
|
|
|
|
qstats->overlimits += qcpu->overlimits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gnet_stats_add_queue(struct gnet_stats_queue *qstats,
|
|
|
|
const struct gnet_stats_queue __percpu *cpu,
|
|
|
|
const struct gnet_stats_queue *q)
|
|
|
|
{
|
|
|
|
if (cpu) {
|
|
|
|
gnet_stats_add_queue_cpu(qstats, cpu);
|
|
|
|
} else {
|
|
|
|
qstats->qlen += q->qlen;
|
|
|
|
qstats->backlog += q->backlog;
|
|
|
|
qstats->drops += q->drops;
|
|
|
|
qstats->requeues += q->requeues;
|
|
|
|
qstats->overlimits += q->overlimits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(gnet_stats_add_queue);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
|
|
|
* gnet_stats_copy_queue - copy queue statistics into statistics TLV
|
|
|
|
* @d: dumping handle
|
2014-09-28 18:54:24 +00:00
|
|
|
* @cpu_q: per cpu queue statistics
|
2005-04-16 22:20:36 +00:00
|
|
|
* @q: queue statistics
|
2014-09-28 18:53:57 +00:00
|
|
|
* @qlen: queue length statistics
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Appends the queue statistics to the top level TLV created by
|
2014-09-28 18:54:24 +00:00
|
|
|
* gnet_stats_start_copy(). Using per cpu queue statistics if
|
|
|
|
* they are available.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
2014-09-28 18:53:57 +00:00
|
|
|
gnet_stats_copy_queue(struct gnet_dump *d,
|
2014-09-28 18:54:24 +00:00
|
|
|
struct gnet_stats_queue __percpu *cpu_q,
|
2014-09-28 18:53:57 +00:00
|
|
|
struct gnet_stats_queue *q, __u32 qlen)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-09-28 18:54:24 +00:00
|
|
|
struct gnet_stats_queue qstats = {0};
|
|
|
|
|
2021-10-16 08:49:05 +00:00
|
|
|
gnet_stats_add_queue(&qstats, cpu_q, q);
|
|
|
|
qstats.qlen = qlen;
|
2014-09-28 18:53:57 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (d->compat_tc_stats) {
|
2014-09-28 18:54:24 +00:00
|
|
|
d->tc_stats.drops = qstats.drops;
|
|
|
|
d->tc_stats.qlen = qstats.qlen;
|
|
|
|
d->tc_stats.backlog = qstats.backlog;
|
|
|
|
d->tc_stats.overlimits = qstats.overlimits;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->tail)
|
2014-09-28 18:54:24 +00:00
|
|
|
return gnet_stats_copy(d, TCA_STATS_QUEUE,
|
2016-04-26 08:06:18 +00:00
|
|
|
&qstats, sizeof(qstats),
|
|
|
|
TCA_STATS_PAD);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_copy_queue);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gnet_stats_copy_app - copy application specific statistics into statistics TLV
|
|
|
|
* @d: dumping handle
|
|
|
|
* @st: application specific statistics data
|
|
|
|
* @len: length of data
|
|
|
|
*
|
2014-09-04 14:44:36 +00:00
|
|
|
* Appends the application specific statistics to the top level TLV created by
|
2005-04-16 22:20:36 +00:00
|
|
|
* gnet_stats_start_copy() and remembers the data for XSTATS if the dumping
|
|
|
|
* handle is in backward compatibility mode.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
|
|
|
|
{
|
|
|
|
if (d->compat_xstats) {
|
2015-02-13 22:47:05 +00:00
|
|
|
d->xstats = kmemdup(st, len, GFP_ATOMIC);
|
|
|
|
if (!d->xstats)
|
|
|
|
goto err_out;
|
2005-04-16 22:20:36 +00:00
|
|
|
d->xstats_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->tail)
|
2016-04-26 08:06:18 +00:00
|
|
|
return gnet_stats_copy(d, TCA_STATS_APP, st, len,
|
|
|
|
TCA_STATS_PAD);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-02-13 22:47:05 +00:00
|
|
|
|
|
|
|
err_out:
|
2016-06-06 16:37:16 +00:00
|
|
|
if (d->lock)
|
|
|
|
spin_unlock_bh(d->lock);
|
2015-02-13 22:47:05 +00:00
|
|
|
d->xstats_len = 0;
|
|
|
|
return -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-07-09 21:22:04 +00:00
|
|
|
EXPORT_SYMBOL(gnet_stats_copy_app);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gnet_stats_finish_copy - finish dumping procedure
|
|
|
|
* @d: dumping handle
|
|
|
|
*
|
|
|
|
* Corrects the length of the top level TLV to include all TLVs added
|
|
|
|
* by gnet_stats_copy_XXX() calls. Adds the backward compatibility TLVs
|
|
|
|
* if gnet_stats_start_copy_compat() was used and releases the statistics
|
|
|
|
* lock.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 with the statistic lock released
|
|
|
|
* if the room in the socket buffer was not sufficient.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
gnet_stats_finish_copy(struct gnet_dump *d)
|
|
|
|
{
|
|
|
|
if (d->tail)
|
2008-01-23 06:11:17 +00:00
|
|
|
d->tail->nla_len = skb_tail_pointer(d->skb) - (u8 *)d->tail;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (d->compat_tc_stats)
|
|
|
|
if (gnet_stats_copy(d, d->compat_tc_stats, &d->tc_stats,
|
2016-04-26 08:06:18 +00:00
|
|
|
sizeof(d->tc_stats), d->padattr) < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (d->compat_xstats && d->xstats) {
|
|
|
|
if (gnet_stats_copy(d, d->compat_xstats, d->xstats,
|
2016-04-26 08:06:18 +00:00
|
|
|
d->xstats_len, d->padattr) < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-06 16:37:16 +00:00
|
|
|
if (d->lock)
|
|
|
|
spin_unlock_bh(d->lock);
|
2015-02-13 22:47:05 +00:00
|
|
|
kfree(d->xstats);
|
|
|
|
d->xstats = NULL;
|
|
|
|
d->xstats_len = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(gnet_stats_finish_copy);
|