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> |
| 12 | |
| 13 | enum { |
| 14 | TASKSTATS_MSG_UNICAST, /* send data only to requester */ |
| 15 | TASKSTATS_MSG_MULTICAST, /* send data to a group */ |
| 16 | }; |
| 17 | |
| 18 | #ifdef CONFIG_TASKSTATS |
| 19 | extern kmem_cache_t *taskstats_cache; |
Shailabh Nagar | 6f44993 | 2006-07-14 00:24:41 -0700 | [diff] [blame] | 20 | extern struct mutex taskstats_exit_mutex; |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 21 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 22 | static inline void taskstats_exit_alloc(struct taskstats **ptidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 23 | { |
| 24 | *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 27 | static inline void taskstats_exit_free(struct taskstats *tidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 28 | { |
| 29 | if (tidstats) |
| 30 | kmem_cache_free(taskstats_cache, tidstats); |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 33 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
| 34 | { |
| 35 | spin_lock_init(&sig->stats_lock); |
| 36 | sig->stats = NULL; |
| 37 | } |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 38 | |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 39 | static inline void taskstats_tgid_alloc(struct signal_struct *sig) |
| 40 | { |
| 41 | struct taskstats *stats; |
| 42 | unsigned long flags; |
| 43 | |
| 44 | stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL); |
| 45 | if (!stats) |
| 46 | return; |
| 47 | |
| 48 | spin_lock_irqsave(&sig->stats_lock, flags); |
| 49 | if (!sig->stats) { |
| 50 | sig->stats = stats; |
| 51 | stats = NULL; |
| 52 | } |
| 53 | spin_unlock_irqrestore(&sig->stats_lock, flags); |
| 54 | |
| 55 | if (stats) |
| 56 | kmem_cache_free(taskstats_cache, stats); |
| 57 | } |
| 58 | |
| 59 | static inline void taskstats_tgid_free(struct signal_struct *sig) |
| 60 | { |
| 61 | struct taskstats *stats = NULL; |
| 62 | unsigned long flags; |
| 63 | |
| 64 | spin_lock_irqsave(&sig->stats_lock, flags); |
| 65 | if (sig->stats) { |
| 66 | stats = sig->stats; |
| 67 | sig->stats = NULL; |
| 68 | } |
| 69 | spin_unlock_irqrestore(&sig->stats_lock, flags); |
| 70 | if (stats) |
| 71 | kmem_cache_free(taskstats_cache, stats); |
| 72 | } |
| 73 | |
| 74 | extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int); |
| 75 | extern void taskstats_init_early(void); |
| 76 | extern void taskstats_tgid_alloc(struct signal_struct *); |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 77 | #else |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 78 | static inline void taskstats_exit_alloc(struct taskstats **ptidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 79 | {} |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 80 | static inline void taskstats_exit_free(struct taskstats *ptidstats) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 81 | {} |
| 82 | static inline void taskstats_exit_send(struct task_struct *tsk, |
Shailabh Nagar | ad4ecbc | 2006-07-14 00:24:44 -0700 | [diff] [blame^] | 83 | struct taskstats *tidstats, |
| 84 | int group_dead) |
| 85 | {} |
| 86 | static inline void taskstats_tgid_init(struct signal_struct *sig) |
| 87 | {} |
| 88 | static inline void taskstats_tgid_alloc(struct signal_struct *sig) |
| 89 | {} |
| 90 | static inline void taskstats_tgid_free(struct signal_struct *sig) |
Shailabh Nagar | c757249 | 2006-07-14 00:24:40 -0700 | [diff] [blame] | 91 | {} |
| 92 | static inline void taskstats_init_early(void) |
| 93 | {} |
| 94 | #endif /* CONFIG_TASKSTATS */ |
| 95 | |
| 96 | #endif |
| 97 | |