From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933100AbWFZW2R (ORCPT ); Mon, 26 Jun 2006 18:28:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S933101AbWFZW2R (ORCPT ); Mon, 26 Jun 2006 18:28:17 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:9161 "EHLO e34.co.us.ibm.com") by vger.kernel.org with ESMTP id S933100AbWFZW2Q (ORCPT ); Mon, 26 Jun 2006 18:28:16 -0400 Message-ID: <44A05F4F.8060503@watson.ibm.com> Date: Mon, 26 Jun 2006 18:27:27 -0400 From: Shailabh Nagar User-Agent: Debian Thunderbird 1.0.2 (X11/20051002) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrew Morton CC: Balbir Singh , Jay Lan , Chris Sturtivant , linux-kernel Subject: [RFC][PATCH] per-task delay accounting: avoid send without listeners Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Shailabh Nagar --- 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 #include +#include 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)