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