diff mbox series

[RFC,4/7] core/metricfs: expose softirq information through metricfs

Message ID 20200807212916.2883031-5-jwadams@google.com (mailing list archive)
State New, archived
Headers show
Series metricfs metric file system and examples | expand

Commit Message

Jonathan Adams Aug. 7, 2020, 9:29 p.m. UTC
Add metricfs support for displaying percpu softirq counters.  The
top directory is /sys/kernel/debug/metricfs/softirq.  Then there
is a subdirectory for each softirq type.  For example:

    cat /sys/kernel/debug/metricfs/softirq/NET_RX/values

Signed-off-by: Jonathan Adams <jwadams@google.com>

---

jwadams@google.com: rebased to 5.8-pre6
	This is work originally done by another engineer at
	google, who would rather not have their name associated with this
	patchset. They're okay with me sending it under my name.
---
 kernel/softirq.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Greg Kroah-Hartman Aug. 8, 2020, 5:46 a.m. UTC | #1
On Fri, Aug 07, 2020 at 02:29:13PM -0700, Jonathan Adams wrote:
> Add metricfs support for displaying percpu softirq counters.  The
> top directory is /sys/kernel/debug/metricfs/softirq.  Then there
> is a subdirectory for each softirq type.  For example:
> 
>     cat /sys/kernel/debug/metricfs/softirq/NET_RX/values
> 
> Signed-off-by: Jonathan Adams <jwadams@google.com>
> 
> ---
> 
> jwadams@google.com: rebased to 5.8-pre6
> 	This is work originally done by another engineer at
> 	google, who would rather not have their name associated with this
> 	patchset. They're okay with me sending it under my name.
> ---
>  kernel/softirq.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
> 
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index c4201b7f42b1..1ae3a540b789 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -25,6 +25,8 @@
>  #include <linux/smpboot.h>
>  #include <linux/tick.h>
>  #include <linux/irq.h>
> +#include <linux/jump_label.h>
> +#include <linux/metricfs.h>
>  
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/irq.h>
> @@ -738,3 +740,46 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
>  {
>  	return from;
>  }
> +
> +#ifdef CONFIG_METRICFS
> +
> +#define METRICFS_ITEM(name) \
> +static void \
> +metricfs_##name(struct metric_emitter *e, int cpu) \
> +{ \
> +	int64_t v = kstat_softirqs_cpu(name##_SOFTIRQ, cpu); \
> +	METRIC_EMIT_PERCPU_INT(e, cpu, v); \
> +} \
> +METRIC_EXPORT_PERCPU_COUNTER(name, #name " softirq", metricfs_##name)
> +
> +METRICFS_ITEM(HI);
> +METRICFS_ITEM(TIMER);
> +METRICFS_ITEM(NET_TX);
> +METRICFS_ITEM(NET_RX);
> +METRICFS_ITEM(BLOCK);
> +METRICFS_ITEM(IRQ_POLL);
> +METRICFS_ITEM(TASKLET);
> +METRICFS_ITEM(SCHED);
> +METRICFS_ITEM(HRTIMER);
> +METRICFS_ITEM(RCU);
> +
> +static int __init init_softirq_metricfs(void)
> +{
> +	struct metricfs_subsys *subsys;
> +
> +	subsys = metricfs_create_subsys("softirq", NULL);
> +	metric_init_HI(subsys);
> +	metric_init_TIMER(subsys);
> +	metric_init_NET_TX(subsys);
> +	metric_init_NET_RX(subsys);
> +	metric_init_BLOCK(subsys);
> +	metric_init_IRQ_POLL(subsys);
> +	metric_init_TASKLET(subsys);
> +	metric_init_SCHED(subsys);
> +	metric_init_RCU(subsys);
> +
> +	return 0;
> +}
> +module_init(init_softirq_metricfs);

I like the "simple" ways these look, and think you will be better off
just adding this type of api to debugfs.  That way people can use them
anywhere they currently use debugfs.

But note, we already have simple ways of exporting single variable data
in debugfs, so why do we need yet-another-macro for them?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/kernel/softirq.c b/kernel/softirq.c
index c4201b7f42b1..1ae3a540b789 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -25,6 +25,8 @@ 
 #include <linux/smpboot.h>
 #include <linux/tick.h>
 #include <linux/irq.h>
+#include <linux/jump_label.h>
+#include <linux/metricfs.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/irq.h>
@@ -738,3 +740,46 @@  unsigned int __weak arch_dynirq_lower_bound(unsigned int from)
 {
 	return from;
 }
+
+#ifdef CONFIG_METRICFS
+
+#define METRICFS_ITEM(name) \
+static void \
+metricfs_##name(struct metric_emitter *e, int cpu) \
+{ \
+	int64_t v = kstat_softirqs_cpu(name##_SOFTIRQ, cpu); \
+	METRIC_EMIT_PERCPU_INT(e, cpu, v); \
+} \
+METRIC_EXPORT_PERCPU_COUNTER(name, #name " softirq", metricfs_##name)
+
+METRICFS_ITEM(HI);
+METRICFS_ITEM(TIMER);
+METRICFS_ITEM(NET_TX);
+METRICFS_ITEM(NET_RX);
+METRICFS_ITEM(BLOCK);
+METRICFS_ITEM(IRQ_POLL);
+METRICFS_ITEM(TASKLET);
+METRICFS_ITEM(SCHED);
+METRICFS_ITEM(HRTIMER);
+METRICFS_ITEM(RCU);
+
+static int __init init_softirq_metricfs(void)
+{
+	struct metricfs_subsys *subsys;
+
+	subsys = metricfs_create_subsys("softirq", NULL);
+	metric_init_HI(subsys);
+	metric_init_TIMER(subsys);
+	metric_init_NET_TX(subsys);
+	metric_init_NET_RX(subsys);
+	metric_init_BLOCK(subsys);
+	metric_init_IRQ_POLL(subsys);
+	metric_init_TASKLET(subsys);
+	metric_init_SCHED(subsys);
+	metric_init_RCU(subsys);
+
+	return 0;
+}
+module_init(init_softirq_metricfs);
+
+#endif