1c757249aSShailabh Nagar /* taskstats_kern.h - kernel header for per-task statistics interface
2c757249aSShailabh Nagar  *
3c757249aSShailabh Nagar  * Copyright (C) Shailabh Nagar, IBM Corp. 2006
4c757249aSShailabh Nagar  *           (C) Balbir Singh,   IBM Corp. 2006
5c757249aSShailabh Nagar  */
6c757249aSShailabh Nagar 
7c757249aSShailabh Nagar #ifndef _LINUX_TASKSTATS_KERN_H
8c757249aSShailabh Nagar #define _LINUX_TASKSTATS_KERN_H
9c757249aSShailabh Nagar 
10c757249aSShailabh Nagar #include <linux/taskstats.h>
11c757249aSShailabh Nagar #include <linux/sched.h>
12c8924363SShailabh Nagar #include <net/genetlink.h>
13c757249aSShailabh Nagar 
14c757249aSShailabh Nagar #ifdef CONFIG_TASKSTATS
15e18b890bSChristoph Lameter extern struct kmem_cache *taskstats_cache;
166f44993fSShailabh Nagar extern struct mutex taskstats_exit_mutex;
17c757249aSShailabh Nagar 
18ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_init(struct signal_struct *sig)
19ad4ecbcbSShailabh Nagar {
20ad4ecbcbSShailabh Nagar 	sig->stats = NULL;
21ad4ecbcbSShailabh Nagar }
22c757249aSShailabh Nagar 
23b8534d7bSOleg Nesterov static inline void taskstats_tgid_alloc(struct task_struct *tsk)
24ad4ecbcbSShailabh Nagar {
25b8534d7bSOleg Nesterov 	struct signal_struct *sig = tsk->signal;
26ad4ecbcbSShailabh Nagar 	struct taskstats *stats;
27ad4ecbcbSShailabh Nagar 
2817b02695SOleg Nesterov 	if (sig->stats != NULL)
2917b02695SOleg Nesterov 		return;
3017b02695SOleg Nesterov 
31b8534d7bSOleg Nesterov 	/* No problem if kmem_cache_zalloc() fails */
32e94b1766SChristoph Lameter 	stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL);
33ad4ecbcbSShailabh Nagar 
34b8534d7bSOleg Nesterov 	spin_lock_irq(&tsk->sighand->siglock);
35ad4ecbcbSShailabh Nagar 	if (!sig->stats) {
36ad4ecbcbSShailabh Nagar 		sig->stats = stats;
37ad4ecbcbSShailabh Nagar 		stats = NULL;
38ad4ecbcbSShailabh Nagar 	}
39b8534d7bSOleg Nesterov 	spin_unlock_irq(&tsk->sighand->siglock);
40ad4ecbcbSShailabh Nagar 
41ad4ecbcbSShailabh Nagar 	if (stats)
42ad4ecbcbSShailabh Nagar 		kmem_cache_free(taskstats_cache, stats);
43ad4ecbcbSShailabh Nagar }
44ad4ecbcbSShailabh Nagar 
45ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig)
46ad4ecbcbSShailabh Nagar {
47093a8e8aSOleg Nesterov 	if (sig->stats)
48093a8e8aSOleg Nesterov 		kmem_cache_free(taskstats_cache, sig->stats);
49ad4ecbcbSShailabh Nagar }
50ad4ecbcbSShailabh Nagar 
51115085eaSOleg Nesterov extern void taskstats_exit(struct task_struct *, int group_dead);
52ad4ecbcbSShailabh Nagar extern void taskstats_init_early(void);
53c757249aSShailabh Nagar #else
54115085eaSOleg Nesterov static inline void taskstats_exit(struct task_struct *tsk, int group_dead)
55ad4ecbcbSShailabh Nagar {}
56ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_init(struct signal_struct *sig)
57ad4ecbcbSShailabh Nagar {}
58b8534d7bSOleg Nesterov static inline void taskstats_tgid_alloc(struct task_struct *tsk)
59ad4ecbcbSShailabh Nagar {}
60ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig)
61c757249aSShailabh Nagar {}
62c757249aSShailabh Nagar static inline void taskstats_init_early(void)
63c757249aSShailabh Nagar {}
64c757249aSShailabh Nagar #endif /* CONFIG_TASKSTATS */
65c757249aSShailabh Nagar 
66c757249aSShailabh Nagar #endif
67c757249aSShailabh Nagar 
68