public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] per-task delay accounting: avoid send without listeners
@ 2006-06-26 22:27 Shailabh Nagar
  2006-06-26 22:33 ` Shailabh Nagar
  0 siblings, 1 reply; 2+ messages in thread
From: Shailabh Nagar @ 2006-06-26 22:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Balbir Singh, Jay Lan, Chris Sturtivant, linux-kernel

Don't send taskstats (per-pid or per-tgid) on thread exit when no one is
listening for such data.

Currently the taskstats interface allocates a structure, fills it in
and calls netlink to send out per-pid and per-tgid stats regardless of whether
a userspace listener for the data exists (netlink layer would check for that
and avoid the multicast).

As a result of this patch, the check for the no-listener case is performed
early, avoiding the redundant allocation and filling up of the taskstats
structures.

Signed-off-by: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Shailabh Nagar <nagar@watson.ibm.com>

---

 include/linux/taskstats_kern.h |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletion(-)

Index: linux-2.6.17/include/linux/taskstats_kern.h
===================================================================
--- linux-2.6.17.orig/include/linux/taskstats_kern.h	2006-06-26 16:45:33.000000000 -0400
+++ linux-2.6.17/include/linux/taskstats_kern.h	2006-06-26 16:47:08.000000000 -0400
@@ -9,6 +9,7 @@

 #include <linux/taskstats.h>
 #include <linux/sched.h>
+#include <net/genetlink.h>

 enum {
 	TASKSTATS_MSG_UNICAST,		/* send data only to requester */
@@ -19,9 +20,19 @@ enum {
 extern kmem_cache_t *taskstats_cache;
 extern struct mutex taskstats_exit_mutex;

+static inline int taskstats_has_listeners(void)
+{
+	if (!genl_sock)
+		return 0;
+	return netlink_has_listeners(genl_sock, TASKSTATS_LISTEN_GROUP);
+}
+
+
 static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
 {
-	*ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
+	*ptidstats = NULL;
+	if (taskstats_has_listeners())
+		*ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
 }

 static inline void taskstats_exit_free(struct taskstats *tidstats)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-26 23:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-26 22:27 [RFC][PATCH] per-task delay accounting: avoid send without listeners Shailabh Nagar
2006-06-26 22:33 ` Shailabh Nagar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox