Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[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: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Jay Lan <jlan@engr.sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Shailabh Nagar and committed by
Linus Torvalds
c8924363 9e06d3f9

+12 -1
+12 -1
include/linux/taskstats_kern.h
··· 9 9 10 10 #include <linux/taskstats.h> 11 11 #include <linux/sched.h> 12 + #include <net/genetlink.h> 12 13 13 14 enum { 14 15 TASKSTATS_MSG_UNICAST, /* send data only to requester */ ··· 20 19 extern kmem_cache_t *taskstats_cache; 21 20 extern struct mutex taskstats_exit_mutex; 22 21 22 + static inline int taskstats_has_listeners(void) 23 + { 24 + if (!genl_sock) 25 + return 0; 26 + return netlink_has_listeners(genl_sock, TASKSTATS_LISTEN_GROUP); 27 + } 28 + 29 + 23 30 static inline void taskstats_exit_alloc(struct taskstats **ptidstats) 24 31 { 25 - *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); 32 + *ptidstats = NULL; 33 + if (taskstats_has_listeners()) 34 + *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); 26 35 } 27 36 28 37 static inline void taskstats_exit_free(struct taskstats *tidstats)