blob: 664224008fb2ec600a1a32ca7b3ea395e60a964a [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>
Shailabh Nagarc8924362006-07-14 00:24:46 -070012#include <net/genetlink.h>
Shailabh Nagarc7572492006-07-14 00:24:40 -070013
Shailabh Nagarc7572492006-07-14 00:24:40 -070014#ifdef CONFIG_TASKSTATS
15extern kmem_cache_t *taskstats_cache;
Shailabh Nagar6f449932006-07-14 00:24:41 -070016extern struct mutex taskstats_exit_mutex;
Shailabh Nagarc7572492006-07-14 00:24:40 -070017
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070018static inline void taskstats_exit_free(struct taskstats *tidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070019{
20 if (tidstats)
21 kmem_cache_free(taskstats_cache, tidstats);
Shailabh Nagarc7572492006-07-14 00:24:40 -070022}
23
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070024static inline void taskstats_tgid_init(struct signal_struct *sig)
25{
26 spin_lock_init(&sig->stats_lock);
27 sig->stats = NULL;
28}
Shailabh Nagarc7572492006-07-14 00:24:40 -070029
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070030static inline void taskstats_tgid_alloc(struct signal_struct *sig)
31{
32 struct taskstats *stats;
33 unsigned long flags;
34
Oleg Nesterov17b02692006-10-28 10:38:52 -070035 if (sig->stats != NULL)
36 return;
37
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070038 stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
39 if (!stats)
40 return;
41
42 spin_lock_irqsave(&sig->stats_lock, flags);
43 if (!sig->stats) {
44 sig->stats = stats;
45 stats = NULL;
46 }
47 spin_unlock_irqrestore(&sig->stats_lock, flags);
48
49 if (stats)
50 kmem_cache_free(taskstats_cache, stats);
51}
52
53static inline void taskstats_tgid_free(struct signal_struct *sig)
54{
Oleg Nesterov093a8e82006-10-28 10:38:51 -070055 if (sig->stats)
56 kmem_cache_free(taskstats_cache, sig->stats);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070057}
58
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070059extern void taskstats_exit_alloc(struct taskstats **, unsigned int *);
60extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int, unsigned int);
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070061extern void taskstats_init_early(void);
62extern void taskstats_tgid_alloc(struct signal_struct *);
Shailabh Nagarc7572492006-07-14 00:24:40 -070063#else
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070064static inline void taskstats_exit_alloc(struct taskstats **ptidstats, unsigned int *mycpu)
Shailabh Nagarc7572492006-07-14 00:24:40 -070065{}
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070066static inline void taskstats_exit_free(struct taskstats *ptidstats)
Shailabh Nagarc7572492006-07-14 00:24:40 -070067{}
68static inline void taskstats_exit_send(struct task_struct *tsk,
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070069 struct taskstats *tidstats,
Shailabh Nagarf9fd8912006-07-14 00:24:47 -070070 int group_dead, unsigned int cpu)
Shailabh Nagarad4ecbc2006-07-14 00:24:44 -070071{}
72static inline void taskstats_tgid_init(struct signal_struct *sig)
73{}
74static inline void taskstats_tgid_alloc(struct signal_struct *sig)
75{}
76static inline void taskstats_tgid_free(struct signal_struct *sig)
Shailabh Nagarc7572492006-07-14 00:24:40 -070077{}
78static inline void taskstats_init_early(void)
79{}
80#endif /* CONFIG_TASKSTATS */
81
82#endif
83