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 15c757249aSShailabh Nagar extern kmem_cache_t *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 spin_lock_init(&sig->stats_lock); 27ad4ecbcbSShailabh Nagar sig->stats = NULL; 28ad4ecbcbSShailabh Nagar } 29c757249aSShailabh Nagar 30ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_alloc(struct signal_struct *sig) 31ad4ecbcbSShailabh Nagar { 32ad4ecbcbSShailabh Nagar struct taskstats *stats; 33ad4ecbcbSShailabh Nagar unsigned long flags; 34ad4ecbcbSShailabh Nagar 35ad4ecbcbSShailabh Nagar stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); 36ad4ecbcbSShailabh Nagar if (!stats) 37ad4ecbcbSShailabh Nagar return; 38ad4ecbcbSShailabh Nagar 39ad4ecbcbSShailabh Nagar spin_lock_irqsave(&sig->stats_lock, flags); 40ad4ecbcbSShailabh Nagar if (!sig->stats) { 41ad4ecbcbSShailabh Nagar sig->stats = stats; 42ad4ecbcbSShailabh Nagar stats = NULL; 43ad4ecbcbSShailabh Nagar } 44ad4ecbcbSShailabh Nagar spin_unlock_irqrestore(&sig->stats_lock, flags); 45ad4ecbcbSShailabh Nagar 46ad4ecbcbSShailabh Nagar if (stats) 47ad4ecbcbSShailabh Nagar kmem_cache_free(taskstats_cache, stats); 48ad4ecbcbSShailabh Nagar } 49ad4ecbcbSShailabh Nagar 50ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig) 51ad4ecbcbSShailabh Nagar { 52ad4ecbcbSShailabh Nagar struct taskstats *stats = NULL; 53ad4ecbcbSShailabh Nagar unsigned long flags; 54ad4ecbcbSShailabh Nagar 55ad4ecbcbSShailabh Nagar spin_lock_irqsave(&sig->stats_lock, flags); 56ad4ecbcbSShailabh Nagar if (sig->stats) { 57ad4ecbcbSShailabh Nagar stats = sig->stats; 58ad4ecbcbSShailabh Nagar sig->stats = NULL; 59ad4ecbcbSShailabh Nagar } 60ad4ecbcbSShailabh Nagar spin_unlock_irqrestore(&sig->stats_lock, flags); 61ad4ecbcbSShailabh Nagar if (stats) 62ad4ecbcbSShailabh Nagar kmem_cache_free(taskstats_cache, stats); 63ad4ecbcbSShailabh Nagar } 64ad4ecbcbSShailabh Nagar 65f9fd8914SShailabh Nagar extern void taskstats_exit_alloc(struct taskstats **, unsigned int *); 66f9fd8914SShailabh Nagar extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int); 67ad4ecbcbSShailabh Nagar extern void taskstats_init_early(void); 68ad4ecbcbSShailabh Nagar extern void taskstats_tgid_alloc(struct signal_struct *); 69c757249aSShailabh Nagar #else 70f9fd8914SShailabh Nagar static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) 71c757249aSShailabh Nagar {} 72ad4ecbcbSShailabh Nagar static inline void taskstats_exit_free(struct taskstats *ptidstats) 73c757249aSShailabh Nagar {} 74c757249aSShailabh Nagar static inline void taskstats_exit_send(struct task_struct *tsk, 75c757249aSShailabh Nagar struct taskstats *tidstats, 76f9fd8914SShailabh Nagar int group_dead, unsigned int cpu) 77ad4ecbcbSShailabh Nagar {} 78ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_init(struct signal_struct *sig) 79ad4ecbcbSShailabh Nagar {} 80ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_alloc(struct signal_struct *sig) 81ad4ecbcbSShailabh Nagar {} 82ad4ecbcbSShailabh Nagar static inline void taskstats_tgid_free(struct signal_struct *sig) 83c757249aSShailabh Nagar {} 84c757249aSShailabh Nagar static inline void taskstats_init_early(void) 85c757249aSShailabh Nagar {} 86c757249aSShailabh Nagar #endif /* CONFIG_TASKSTATS */ 87c757249aSShailabh Nagar 88c757249aSShailabh Nagar #endif 89c757249aSShailabh Nagar 90