public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Helsley <matthltc@us.ibm.com>
To: Linux-Kernel <linux-kernel@vger.kernel.org>
Cc: Jes Sorensen <jes@sgi.com>,
	LSE-Tech <lse-tech@lists.sourceforge.net>,
	Chandra S Seetharaman <sekharan@us.ibm.com>,
	John T Kohl <jtk@us.ibm.com>, Christoph Hellwig <hch@lst.de>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Steve Grubb <sgrubb@redhat.com>,
	linux-audit@redhat.com, Paul Jackson <pj@sgi.com>
Subject: [RFC][PATCH 02/10] Task watchers v2 Benchmark
Date: Thu, 28 Sep 2006 19:02:34 -0700	[thread overview]
Message-ID: <20060929021300.034805000@us.ibm.com> (raw)
In-Reply-To: 20060929020232.756637000@us.ibm.com

[-- Attachment #1: task-watchers-benchmark --]
[-- Type: text/plain, Size: 4476 bytes --]

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 <matthltc@us.ibm.com>
---
 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

--

  parent reply	other threads:[~2006-09-29  2:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-29  2:02 [RFC][PATCH 00/10] Task watchers v2 Introduction Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 01/10] Task watchers v2 Task watchers v2 Matt Helsley
2006-09-29  2:02 ` Matt Helsley [this message]
2006-09-29  2:32   ` [Lse-tech] [RFC][PATCH 02/10] Task watchers v2 Benchmark Paul Jackson
2006-09-29 19:38     ` Matt Helsley
2006-09-29 20:13       ` Paul Jackson
2006-09-30  0:01         ` Matt Helsley
2006-09-30  0:04           ` Paul Jackson
2006-09-29  2:02 ` [RFC][PATCH 03/10] Task watchers v2 Register audit task watcher Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 04/10] Task watchers v2 Register semundo " Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 05/10] Task watchers v2 Register cpuset " Matt Helsley
2006-09-29  2:31   ` Paul Jackson
2006-09-29  7:52     ` [Lse-tech] " Matt Helsley
2006-09-29  8:03       ` Paul Jackson
2006-09-29  2:02 ` [RFC][PATCH 06/10] Task watchers v2 Register NUMA mempolicy " Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 07/10] Task watchers v2 Register IRQ flag tracing " Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 08/10] Task watchers v2 Register lockdep " Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 09/10] Task watchers v2 Register process keyrings " Matt Helsley
2006-09-29  2:02 ` [RFC][PATCH 10/10] Task watchers v2 Register process events connector Matt Helsley
2006-09-29  2:41 ` [RFC][PATCH 00/10] Task watchers v2 Introduction Paul Jackson
2006-09-29  8:16   ` [RFC][PATCH] Task watchers and modules (WAS Re: [RFC][PATCH 00/10] Task watchers v2 Introduction) Matt Helsley
2006-09-29 16:22   ` [RFC][PATCH 00/10] Task watchers v2 Introduction Paul Menage

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060929021300.034805000@us.ibm.com \
    --to=matthltc@us.ibm.com \
    --cc=hch@lst.de \
    --cc=jes@sgi.com \
    --cc=jtk@us.ibm.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lse-tech@lists.sourceforge.net \
    --cc=pj@sgi.com \
    --cc=sekharan@us.ibm.com \
    --cc=sgrubb@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox