[RFC][PATCH] per-task delay accounting: avoid send without listeners

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <[email protected]>
Signed-off-by: Shailabh Nagar <[email protected]>

---

 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)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux