Commit c8924363 authored by Shailabh Nagar's avatar Shailabh Nagar Committed by Linus Torvalds

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

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: default avatarBalbir Singh <balbir@in.ibm.com>
Signed-off-by: default avatarShailabh Nagar <nagar@watson.ibm.com>
Cc: Jay Lan <jlan@engr.sgi.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 9e06d3f9
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/taskstats.h> #include <linux/taskstats.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <net/genetlink.h>
enum { enum {
TASKSTATS_MSG_UNICAST, /* send data only to requester */ TASKSTATS_MSG_UNICAST, /* send data only to requester */
...@@ -19,8 +20,18 @@ enum { ...@@ -19,8 +20,18 @@ enum {
extern kmem_cache_t *taskstats_cache; extern kmem_cache_t *taskstats_cache;
extern struct mutex taskstats_exit_mutex; 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) static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
{ {
*ptidstats = NULL;
if (taskstats_has_listeners())
*ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment