blob: 0ae8f67af1fd29d72f396bac891a81e72ed05711 [file] [log] [blame]
Shailabh Nagarc7572492006-07-14 00:24:40 -07001/* 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
13enum {
14 TASKSTATS_MSG_UNICAST, /* send data only to requester */
15 TASKSTATS_MSG_MULTICAST, /* send data to a group */
16};
17
18#ifdef CONFIG_TASKSTATS
19extern kmem_cache_t *taskstats_cache;
Shailabh Nagar6f449932006-07-14 00:24:41 -070020extern struct mutex taskstats_exit_mutex;
Shailabh Nagarc7572492006-07-14 00:24:40 -070021
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070022static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070023{
24 *ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
Shailabh Nagarc7572492006-07-14 00:24:40 -070025}
26
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070027static inline void taskstats_exit_free(struct taskstats *tidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070028{
29 if (tidstats)
30 kmem_cache_free(taskstats_cache, tidstats);
Shailabh Nagarc7572492006-07-14 00:24:40 -070031}
32
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070033static inline void taskstats_tgid_init(struct signal_struct *sig)
34{
35 spin_lock_init(&sig->stats_lock);
36 sig->stats = NULL;
37}
Shailabh Nagarc7572492006-07-14 00:24:40 -070038
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070039static 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
59static 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
74extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int);
75extern void taskstats_init_early(void);
76extern void taskstats_tgid_alloc(struct signal_struct *);
Shailabh Nagarc7572492006-07-14 00:24:40 -070077#else
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070078static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070079{}
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070080static inline void taskstats_exit_free(struct taskstats *ptidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070081{}
82static inline void taskstats_exit_send(struct task_struct *tsk,
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070083 struct taskstats *tidstats,
84 int group_dead)
85{}
86static inline void taskstats_tgid_init(struct signal_struct *sig)
87{}
88static inline void taskstats_tgid_alloc(struct signal_struct *sig)
89{}
90static inline void taskstats_tgid_free(struct signal_struct *sig)
Shailabh Nagarc7572492006-07-14 00:24:40 -070091{}
92static inline void taskstats_init_early(void)
93{}
94#endif /* CONFIG_TASKSTATS */
95
96#endif
97