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_exit_free(struct taskstats *tidstats) 19c757249aSShailabh Nagar { 20c757249aSShailabh Nagar if (tidstats) 21c757249aSShailabh Nagar kmem_cache_free(taskstats_cache, tidstats); 22c757249aSShailabh Nagar } 23c757249aSShailabh Nagar 24ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_init(struct signal_struct *sig) 25ad4ecbcbSShailabh Nagar { 26ad4ecbcbSShailabh Nagar sig->stats = NULL; 27ad4ecbcbSShailabh Nagar } 28c757249aSShailabh Nagar 29b8534d7bSOleg Nesterov static inline void taskstats_tgid_alloc(struct task_struct *tsk) 30ad4ecbcbSShailabh Nagar { 31b8534d7bSOleg Nesterov struct signal_struct *sig = tsk->signal; 32ad4ecbcbSShailabh Nagar struct taskstats *stats; 33ad4ecbcbSShailabh Nagar 3417b02695SOleg Nesterov if (sig->stats != NULL) 3517b02695SOleg Nesterov return; 3617b02695SOleg Nesterov 37b8534d7bSOleg Nesterov /* No problem if kmem_cache_zalloc() fails */ 38e94b1766SChristoph Lameter stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL); 39ad4ecbcbSShailabh Nagar 40b8534d7bSOleg Nesterov spin_lock_irq(&tsk->sighand->siglock); 41ad4ecbcbSShailabh Nagar if (!sig->stats) { 42ad4ecbcbSShailabh Nagar sig->stats = stats; 43ad4ecbcbSShailabh Nagar stats = NULL; 44ad4ecbcbSShailabh Nagar } 45b8534d7bSOleg Nesterov spin_unlock_irq(&tsk->sighand->siglock); 46ad4ecbcbSShailabh Nagar 47ad4ecbcbSShailabh Nagar if (stats) 48ad4ecbcbSShailabh Nagar kmem_cache_free(taskstats_cache, stats); 49ad4ecbcbSShailabh Nagar } 50ad4ecbcbSShailabh Nagar 51ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig) 52ad4ecbcbSShailabh Nagar { 53093a8e8aSOleg Nesterov if (sig->stats) 54093a8e8aSOleg Nesterov kmem_cache_free(taskstats_cache, sig->stats); 55ad4ecbcbSShailabh Nagar } 56ad4ecbcbSShailabh Nagar 57f9fd8914SShailabh Nagar extern void taskstats_exit_alloc(struct taskstats **, unsigned int *); 58f9fd8914SShailabh Nagar extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int); 59ad4ecbcbSShailabh Nagar extern void taskstats_init_early(void); 60c757249aSShailabh Nagar #else 61f9fd8914SShailabh Nagar static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) 62c757249aSShailabh Nagar {} 63ad4ecbcbSShailabh Nagar static inline void taskstats_exit_free(struct taskstats *ptidstats) 64c757249aSShailabh Nagar {} 65c757249aSShailabh Nagar static inline void taskstats_exit_send(struct task_struct *tsk, 66c757249aSShailabh Nagar struct taskstats *tidstats, 67f9fd8914SShailabh Nagar int group_dead, unsigned int cpu) 68ad4ecbcbSShailabh Nagar {} 69ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_init(struct signal_struct *sig) 70ad4ecbcbSShailabh Nagar {} 71b8534d7bSOleg Nesterov static inline void taskstats_tgid_alloc(struct task_struct *tsk) 72ad4ecbcbSShailabh Nagar {} 73ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig) 74c757249aSShailabh Nagar {} 75c757249aSShailabh Nagar static inline void taskstats_init_early(void) 76c757249aSShailabh Nagar {} 77c757249aSShailabh Nagar #endif /* CONFIG_TASKSTATS */ 78c757249aSShailabh Nagar 79c757249aSShailabh Nagar #endif 80c757249aSShailabh Nagar 81