2006-09-29 02:13:06

by Matt Helsley

[permalink] [raw]
Subject: [RFC][PATCH 02/10] Task watchers v2 Benchmark

This optional patch adds a fork/exit rate measurement facility using task
watchers. It is intended to be a tool for measuring the impact of task watchers
on fork and exit-heavy workloads.

Signed-off-by: Matt Helsley <[email protected]>
---
kernel/Makefile | 1
kernel/twbench.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig.debug | 12 ++++++
3 files changed, 116 insertions(+)

Index: linux-2.6.18-mm1/kernel/twbench.c
===================================================================
--- /dev/null
+++ linux-2.6.18-mm1/kernel/twbench.c
@@ -0,0 +1,103 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/task_watchers.h>
+
+#include <linux/debugfs.h>
+#include <linux/time.h>
+#include <linux/preempt.h>
+
+#include <asm/atomic.h>
+#include <asm/div64.h>
+
+struct twb_counter {
+ atomic_t count;
+ u64 reset_time_ns;
+};
+
+static u64 read_reset_rate(void *p)
+{
+ u64 rate, ts_ns;
+ struct timespec ts;
+ struct twb_counter *ctr = p;
+
+ /* begin pseudo-atomic region */
+ preempt_disable();
+ rate = atomic_xchg(((atomic_t*)&ctr->count), 0);
+ ktime_get_ts(&ts);
+ preempt_enable();
+ /* end pseudo-atomic region */
+
+ ts_ns = timespec_to_ns(&ts);
+ rate *= NSEC_PER_SEC;
+ do_div(rate, (u32)(ts_ns - ctr->reset_time_ns));
+ ctr->reset_time_ns = ts_ns;
+ return rate;
+}
+
+/* Counter bits */
+static struct twb_counter num_clones;
+static struct twb_counter num_exits;
+
+#ifndef MODULE
+static int inc_clone(unsigned long val, struct task_struct *task)
+{
+ atomic_inc(&num_clones.count);
+ return 0;
+}
+task_watcher_func(clone, inc_clone);
+
+static int inc_exit(unsigned long val, struct task_struct *task)
+{
+ atomic_inc(&num_exits.count);
+ return 0;
+}
+task_watcher_func(exit, inc_exit);
+#endif
+
+/* Debugfs bits */
+static struct dentry *twb_root, *twb_clone_file, *twb_exit_file;
+
+/*
+ * NOTE: Because open doesn't reset the count nor the reset time,
+ * userspace must discard the first values read before starting
+ * to monitor the rates.
+ */
+DEFINE_SIMPLE_ATTRIBUTE(rrr, read_reset_rate, NULL, "%llu\n");
+
+static int __init twb_debugfs_init(void)
+{
+ twb_root = debugfs_create_dir("twbench", NULL);
+ if (!twb_root)
+ return -ENOMEM;
+ twb_clone_file = debugfs_create_file("clones", 0744, twb_root,
+ &num_clones, &rrr);
+ twb_exit_file = debugfs_create_file("exits", 0744, twb_root,
+ &num_exits, &rrr);
+ return 0;
+}
+#ifndef MODULE
+__initcall(twb_debugfs_init);
+#endif
+
+static void __exit twb_debugfs_exit(void)
+{
+ debugfs_remove(twb_clone_file);
+ debugfs_remove(twb_exit_file);
+ debugfs_remove(twb_root);
+}
+
+static int __init twb_mod_init(void)
+{
+ int ret;
+
+ ret = twb_debugfs_init();
+ return ret;
+}
+
+static void __exit twb_mod_exit(void)
+{
+ twb_debugfs_exit();
+}
+
+module_init(twb_mod_init);
+module_exit(twb_mod_exit);
Index: linux-2.6.18-mm1/lib/Kconfig.debug
===================================================================
--- linux-2.6.18-mm1.orig/lib/Kconfig.debug
+++ linux-2.6.18-mm1/lib/Kconfig.debug
@@ -443,10 +443,22 @@ config RCU_TORTURE_TEST
Say Y here if you want RCU torture tests to start automatically
at boot time (you probably don't).
Say M if you want the RCU torture tests to build as a module.
Say N if you are unsure.

+config TWBENCH
+ bool "Output fork/clone and exit rates"
+ depends on DEBUG_KERNEL && DEBUG_FS
+ default n
+ help
+ Print out the rate at which the system is fork/cloning new
+ processes to <debugfs>/twbench/clone
+ Print out the rate at which the system is exitting existing
+ processes to <debugfs>/twbench/exit
+
+ If unsure, say N.
+
config LKDTM
tristate "Linux Kernel Dump Test Tool Module"
depends on KPROBES
default n
help
Index: linux-2.6.18-mm1/kernel/Makefile
===================================================================
--- linux-2.6.18-mm1.orig/kernel/Makefile
+++ linux-2.6.18-mm1/kernel/Makefile
@@ -45,10 +45,11 @@ obj-$(CONFIG_KPROBES) += kprobes.o
obj-$(CONFIG_SYSFS) += ksysfs.o
obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
obj-$(CONFIG_SECCOMP) += seccomp.o
obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
+obj-$(CONFIG_TWBENCH) += twbench.o
obj-$(CONFIG_DEBUG_SYNCHRO_TEST) += synchro-test.o
obj-$(CONFIG_RELAY) += relay.o
obj-$(CONFIG_UTS_NS) += utsname.o
obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o

--


2006-09-29 02:32:58

by Paul Jackson

[permalink] [raw]
Subject: Re: [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark

Matt wrote:
> It is intended to be a tool for measuring the impact of task watchers
> on fork and exit-heavy workloads.

So ... you're keeping us in suspense ... what was the measured impact
of task watcher?

--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401

2006-09-29 19:38:57

by Matt Helsley

[permalink] [raw]
Subject: Re: [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark

On Thu, 2006-09-28 at 19:32 -0700, Paul Jackson wrote:
> Matt wrote:
> > It is intended to be a tool for measuring the impact of task watchers
> > on fork and exit-heavy workloads.
>
> So ... you're keeping us in suspense ... what was the measured impact
> of task watcher?

Heh, sorry about that. I do have some initial kernbench numbers. I
performed 10 successive runs of kernbench after each patch on an old
8-way:

[PATCH 01/10] Task watchers v2 Task watchers v2
815.80user 113.69system 2:04.36elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
814.55user 114.25system 2:03.80elapsed 750%CPU (0avgtext+0avgdata 0maxresident)k
815.09user 115.11system 2:04.42elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
815.84user 114.08system 2:04.25elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
814.60user 114.28system 2:04.41elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
814.52user 113.09system 2:04.51elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
816.23user 114.42system 2:04.64elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
816.45user 113.39system 2:04.72elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
815.62user 114.74system 2:04.71elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
814.40user 112.94system 2:04.45elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 02/10] Task watchers v2 Benchmark
806.39user 113.23system 2:04.30elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k
806.21user 112.87system 2:03.40elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
811.69user 113.59system 2:03.59elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
803.16user 113.37system 2:03.53elapsed 741%CPU (0avgtext+0avgdata 0maxresident)k
804.82user 112.25system 2:03.62elapsed 741%CPU (0avgtext+0avgdata 0maxresident)k
804.45user 113.37system 2:03.34elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
806.35user 112.34system 2:02.96elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
804.35user 112.61system 2:02.96elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
804.19user 112.98system 2:02.91elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
804.54user 113.23system 2:03.80elapsed 741%CPU (0avgtext+0avgdata 0maxresident)k

Seems like this benchmark patch resulted in a consistent decrease in time
spent in userspace. I'm rerunning kernbench without this patch and will post the
results by Monday afternoon at the latest.

[PATCH 03/10] Task watchers v2 Register audit task watcher
802.30user 113.37system 2:02.36elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
802.19user 111.93system 2:03.68elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k
800.90user 113.33system 2:03.02elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
800.08user 112.56system 2:01.95elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
801.53user 111.66system 2:02.87elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
803.62user 112.22system 2:02.34elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
803.65user 112.05system 2:03.07elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
804.35user 112.35system 2:03.85elapsed 740%CPU (0avgtext+0avgdata 0maxresident)k
805.20user 112.25system 2:02.80elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
802.46user 113.74system 2:03.75elapsed 740%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 04/10] Task watchers v2 Register semundo task watcher
799.99user 113.19system 2:02.50elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
802.11user 112.51system 2:03.62elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k
802.19user 112.40system 2:04.19elapsed 736%CPU (0avgtext+0avgdata 0maxresident)k
803.87user 113.05system 2:02.96elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
802.56user 113.38system 2:02.52elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
803.14user 113.11system 2:02.95elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
802.57user 113.66system 2:02.56elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
803.26user 113.90system 2:03.37elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
806.66user 113.95system 2:03.20elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
805.21user 113.31system 2:04.20elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 05/10] Task watchers v2 Register cpuset task watcher
807.24user 112.35system 2:03.11elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
804.43user 112.62system 2:03.08elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
805.80user 113.85system 2:04.10elapsed 741%CPU (0avgtext+0avgdata 0maxresident)k
806.28user 114.07system 2:03.47elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
807.08user 114.10system 2:04.14elapsed 742%CPU (0avgtext+0avgdata 0maxresident)k
807.39user 113.68system 2:03.57elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
807.60user 113.27system 2:03.69elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
807.06user 113.25system 2:03.89elapsed 742%CPU (0avgtext+0avgdata 0maxresident)k
808.79user 112.62system 2:03.31elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
805.21user 113.96system 2:03.75elapsed 742%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 06/10] Task watchers v2 Register NUMA mempolicy task watcher
804.88user 113.50system 2:03.04elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
807.87user 114.55system 2:04.05elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
812.19user 113.81system 2:04.21elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
810.73user 114.06system 2:04.26elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
808.18user 113.48system 2:03.06elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
810.50user 112.26system 2:04.32elapsed 742%CPU (0avgtext+0avgdata 0maxresident)k
808.79user 113.65system 2:04.58elapsed 740%CPU (0avgtext+0avgdata 0maxresident)k
807.73user 113.55system 2:03.85elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
806.90user 113.25system 2:03.83elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k
804.28user 113.75system 2:03.45elapsed 743%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 07/10] Task watchers v2 Register IRQ flag tracing task watcher
795.59user 111.36system 2:02.19elapsed 742%CPU (0avgtext+0avgdata 0maxresident)k
795.09user 112.89system 2:02.74elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k
796.29user 112.05system 2:01.58elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
796.95user 112.99system 2:03.24elapsed 738%CPU (0avgtext+0avgdata 0maxresident)k
798.78user 111.45system 2:01.75elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
796.52user 112.00system 2:01.73elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
797.40user 112.65system 2:02.02elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
797.02user 112.55system 2:01.50elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
799.72user 111.69system 2:02.36elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
799.39user 111.93system 2:02.24elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 08/10] Task watchers v2 Register lockdep task watcher
804.79user 111.78system 2:03.03elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
805.81user 110.94system 2:03.13elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
803.87user 112.09system 2:02.96elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
805.32user 113.28system 2:03.35elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
803.45user 112.53system 2:02.89elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
803.69user 112.29system 2:02.90elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
801.01user 112.27system 2:02.15elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
802.30user 112.59system 2:02.87elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
802.19user 111.69system 2:02.66elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
801.97user 111.75system 2:02.66elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 09/10] Task watchers v2 Register process keyrings task watcher
792.91user 111.19system 2:00.91elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
793.50user 110.64system 2:02.37elapsed 738%CPU (0avgtext+0avgdata 0maxresident)k
795.85user 111.00system 2:01.39elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
794.46user 112.29system 2:01.17elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
794.04user 111.91system 2:01.44elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
797.07user 110.94system 2:01.55elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
796.84user 110.37system 2:01.41elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
796.13user 110.69system 2:02.44elapsed 740%CPU (0avgtext+0avgdata 0maxresident)k
805.46user 110.87system 2:02.66elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
796.70user 111.36system 2:02.80elapsed 739%CPU (0avgtext+0avgdata 0maxresident)k

[PATCH 10/10] Task watchers v2 Register process events connector
807.06user 112.29system 2:04.01elapsed 741%CPU (0avgtext+0avgdata 0maxresident)k
807.76user 113.42system 2:03.14elapsed 748%CPU (0avgtext+0avgdata 0maxresident)k
806.95user 111.51system 2:03.33elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
805.65user 112.95system 2:04.04elapsed 740%CPU (0avgtext+0avgdata 0maxresident)k
803.63user 113.79system 2:03.01elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k
807.15user 111.49system 2:03.32elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
807.75user 112.02system 2:03.47elapsed 744%CPU (0avgtext+0avgdata 0maxresident)k
804.89user 113.48system 2:03.02elapsed 746%CPU (0avgtext+0avgdata 0maxresident)k
806.01user 112.71system 2:02.84elapsed 747%CPU (0avgtext+0avgdata 0maxresident)k
804.40user 112.63system 2:02.94elapsed 745%CPU (0avgtext+0avgdata 0maxresident)k

Cheers,
-Matt Helsley

2006-09-29 20:14:17

by Paul Jackson

[permalink] [raw]
Subject: Re: [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark

Matt wrote:
> Heh, sorry about that. I do have some initial kernbench numbers.

Thanks. You mention that one of the patches, Benchmark, reduced
time spent in user space. I guess that means that patch hurt
something ... though I'm confused ... wouldn't these patches risk
spending more time in system space, not less in user space?

Do you have any analysis of the other runs? Just looking at raw
numbers, when it's not a benchmark I've used recently, kinda fuzzes
over my feeble brain.

--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401

2006-09-30 00:01:18

by Matt Helsley

[permalink] [raw]
Subject: Re: [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark

On Fri, 2006-09-29 at 13:13 -0700, Paul Jackson wrote:
> Matt wrote:
> > Heh, sorry about that. I do have some initial kernbench numbers.
>
> Thanks. You mention that one of the patches, Benchmark, reduced
> time spent in user space. I guess that means that patch hurt
> something ... though I'm confused ... wouldn't these patches risk
> spending more time in system space, not less in user space?

I would have thought so too, but it also appears to consistently reduce
time spent in the kernel. This seems to imply that the performance
improves for the first task watcher that gets added. I'd randomly guess
there's a branch misprediction when no watchers are registered.

My latest results will be more rigorous in that they show what a pure
2.6.18-mm1 run looks like. I've also removed the benchmark patch from
the series of runs. Unfortunately it takes approximately 24 hours to run
so it'll be a little while before I have the numbers.

> Do you have any analysis of the other runs? Just looking at raw
> numbers, when it's not a benchmark I've used recently, kinda fuzzes
> over my feeble brain.

Nope, sorry. I'll see what I can put together.

Cheers,
-Matt Helsley

2006-09-30 00:04:29

by Paul Jackson

[permalink] [raw]
Subject: Re: [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark

Matt wrote:
> I would have thought so too, but it also appears to consistently reduce
> time spent in the kernel.

Interesting. Thanks for the continuing good work.

--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401