blob: f81a5af8a4f8e4dcdba05ea78a550aa546939aed [file] [log] [blame]
Shailabh Nagarc7572492006-07-14 00:24:40 -07001/* taskstats_kern.h - kernel header for per-task statistics interface
2 *
3 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
4 * (C) Balbir Singh, IBM Corp. 2006
5 */
6
7#ifndef _LINUX_TASKSTATS_KERN_H
8#define _LINUX_TASKSTATS_KERN_H
9
10#include <linux/taskstats.h>
11#include <linux/sched.h>
Shailabh Nagarc8924362006-07-14 00:24:46 -070012#include <net/genetlink.h>
Shailabh Nagarc7572492006-07-14 00:24:40 -070013
Shailabh Nagarc7572492006-07-14 00:24:40 -070014#ifdef CONFIG_TASKSTATS
15extern kmem_cache_t *taskstats_cache;
Shailabh Nagar6f449932006-07-14 00:24:41 -070016extern struct mutex taskstats_exit_mutex;
Shailabh Nagarc7572492006-07-14 00:24:40 -070017
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070018static inline void taskstats_exit_free(struct taskstats *tidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070019{
20 if (tidstats)
21 kmem_cache_free(taskstats_cache, tidstats);
Shailabh Nagarc7572492006-07-14 00:24:40 -070022}
23
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070024static inline void taskstats_tgid_init(struct signal_struct *sig)
25{
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070026 sig->stats = NULL;
27}
Shailabh Nagarc7572492006-07-14 00:24:40 -070028
Oleg Nesterovb8534d72006-10-28 10:38:53 -070029static inline void taskstats_tgid_alloc(struct task_struct *tsk)
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070030{
Oleg Nesterovb8534d72006-10-28 10:38:53 -070031 struct signal_struct *sig = tsk->signal;
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070032 struct taskstats *stats;
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070033
Oleg Nesterov17b02692006-10-28 10:38:52 -070034 if (sig->stats != NULL)
35 return;
36
Oleg Nesterovb8534d72006-10-28 10:38:53 -070037 /* No problem if kmem_cache_zalloc() fails */
Christoph Lametere94b1762006-12-06 20:33:17 -080038 stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070039
Oleg Nesterovb8534d72006-10-28 10:38:53 -070040 spin_lock_irq(&tsk->sighand->siglock);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070041 if (!sig->stats) {
42 sig->stats = stats;
43 stats = NULL;
44 }
Oleg Nesterovb8534d72006-10-28 10:38:53 -070045 spin_unlock_irq(&tsk->sighand->siglock);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070046
47 if (stats)
48 kmem_cache_free(taskstats_cache, stats);
49}
50
51static inline void taskstats_tgid_free(struct signal_struct *sig)
52{
Oleg Nesterov093a8e82006-10-28 10:38:51 -070053 if (sig->stats)
54 kmem_cache_free(taskstats_cache, sig->stats);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070055}
56
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070057extern void taskstats_exit_alloc(struct taskstats **, unsigned int *);
58extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070059extern void taskstats_init_early(void);
Shailabh Nagarc7572492006-07-14 00:24:40 -070060#else
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070061static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
Shailabh Nagarc7572492006-07-14 00:24:40 -070062{}
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070063static inline void taskstats_exit_free(struct taskstats *ptidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070064{}
65static inline void taskstats_exit_send(struct task_struct *tsk,
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070066 struct taskstats *tidstats,
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070067 int group_dead, unsigned int cpu)
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070068{}
69static inline void taskstats_tgid_init(struct signal_struct *sig)
70{}
Oleg Nesterovb8534d72006-10-28 10:38:53 -070071static inline void taskstats_tgid_alloc(struct task_struct *tsk)
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070072{}
73static inline void taskstats_tgid_free(struct signal_struct *sig)
Shailabh Nagarc7572492006-07-14 00:24:40 -070074{}
75static inline void taskstats_init_early(void)
76{}
77#endif /* CONFIG_TASKSTATS */
78
79#endif
80