Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 1 | /* 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 Nagar | c892436 | 2006-07-14 00:24:46 -0700 | [diff] [blame] | 12 | #include <net/genetlink.h> |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 13 | |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 14 | #ifdef CONFIG_TASKSTATS |
| 15 | extern kmem_cache_t *taskstats_cache; |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 16 | extern struct mutex taskstats_exit_mutex; |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 17 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 18 | static inline void taskstats_exit_free(struct taskstats *tidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 19 | { |
| 20 | if (tidstats) |
| 21 | kmem_cache_free(taskstats_cache, tidstats); |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 24 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
| 25 | { |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 26 | sig->stats = NULL; |
| 27 | } |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 28 | |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 29 | static inline void taskstats_tgid_alloc(struct task_struct *tsk) |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 30 | { |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 31 | struct signal_struct *sig = tsk->signal; |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 32 | struct taskstats *stats; |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 33 | |
Oleg Nesterov | 17b0269 | 2006-10-28 10:38:52 -0700 | [diff] [blame] | 34 | if (sig->stats != NULL) |
| 35 | return; |
| 36 | |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 37 | /* No problem if kmem_cache_zalloc() fails */ |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame^] | 38 | stats = kmem_cache_zalloc(taskstats_cache, GFP_KERNEL); |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 39 | |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 40 | spin_lock_irq(&tsk->sighand->siglock); |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 41 | if (!sig->stats) { |
| 42 | sig->stats = stats; |
| 43 | stats = NULL; |
| 44 | } |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 45 | spin_unlock_irq(&tsk->sighand->siglock); |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 46 | |
| 47 | if (stats) |
| 48 | kmem_cache_free(taskstats_cache, stats); |
| 49 | } |
| 50 | |
| 51 | static inline void taskstats_tgid_free(struct signal_struct *sig) |
| 52 | { |
Oleg Nesterov | 093a8e8 | 2006-10-28 10:38:51 -0700 | [diff] [blame] | 53 | if (sig->stats) |
| 54 | kmem_cache_free(taskstats_cache, sig->stats); |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Shailabh Nagar | f9fd891 | 2006-07-14 00:24:47 -0700 | [diff] [blame] | 57 | extern void taskstats_exit_alloc(struct taskstats **, unsigned int *); |
| 58 | extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int); |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 59 | extern void taskstats_init_early(void); |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 60 | #else |
Shailabh Nagar | f9fd891 | 2006-07-14 00:24:47 -0700 | [diff] [blame] | 61 | static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 62 | {} |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 63 | static inline void taskstats_exit_free(struct taskstats *ptidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 64 | {} |
| 65 | static inline void taskstats_exit_send(struct task_struct *tsk, |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 66 | struct taskstats *tidstats, |
Shailabh Nagar | f9fd891 | 2006-07-14 00:24:47 -0700 | [diff] [blame] | 67 | int group_dead, unsigned int cpu) |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 68 | {} |
| 69 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
| 70 | {} |
Oleg Nesterov | b8534d7 | 2006-10-28 10:38:53 -0700 | [diff] [blame] | 71 | static inline void taskstats_tgid_alloc(struct task_struct *tsk) |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame] | 72 | {} |
| 73 | static inline void taskstats_tgid_free(struct signal_struct *sig) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 74 | {} |
| 75 | static inline void taskstats_init_early(void) |
| 76 | {} |
| 77 | #endif /* CONFIG_TASKSTATS */ |
| 78 | |
| 79 | #endif |
| 80 | |