1 /* _VX_CVIRT_H defined below */
3 #if defined(__KERNEL__) && defined(_VX_INFO_DEF_)
5 #include <linux/utsname.h>
6 #include <linux/rwsem.h>
7 #include <linux/jiffies.h>
8 #include <linux/time.h>
9 #include <linux/sched.h>
10 #include <linux/kernel_stat.h>
11 #include <asm/atomic.h>
13 /* context sub struct */
16 int max_threads; /* maximum allowed threads */
17 atomic_t nr_threads; /* number of current threads */
18 atomic_t nr_running; /* number of running threads */
20 atomic_t nr_onhold; /* processes on hold */
21 uint32_t onhold_last; /* jiffies when put on hold */
23 struct timespec bias_idle;
24 struct timespec bias_uptime; /* context creation point */
26 struct new_utsname utsname;
28 spinlock_t load_lock; /* lock for the load averages */
29 uint32_t load_last; /* last time load was cacled */
30 uint32_t load[3]; /* load averages 1,5,15 */
32 struct cpu_usage_stat cpustat[NR_CPUS];
41 unsigned long total_forks;
43 struct sock_acc sock[5][3];
47 static inline long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
49 return atomic_read(&cacct->sock[type][pos].count);
53 static inline long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
55 return atomic_read(&cacct->sock[type][pos].total);
59 extern uint64_t vx_idle_jiffies(void);
61 static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
63 uint64_t idle_jiffies = vx_idle_jiffies();
65 do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
66 jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
67 atomic_set(&cvirt->nr_threads, 0);
68 atomic_set(&cvirt->nr_running, 0);
69 atomic_set(&cvirt->nr_onhold, 0);
72 cvirt->utsname = system_utsname;
75 spin_lock_init(&cvirt->load_lock);
76 cvirt->load_last = jiffies;
82 static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
84 #ifdef CONFIG_VSERVER_DEBUG
87 if ((value = atomic_read(&cvirt->nr_threads)))
88 printk("!!! cvirt: %p[nr_threads] = %d on exit.\n",
90 if ((value = atomic_read(&cvirt->nr_running)))
91 printk("!!! cvirt: %p[nr_running] = %d on exit.\n",
97 static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
101 for (i=0; i<5; i++) {
102 for (j=0; j<3; j++) {
103 atomic_set(&cacct->sock[i][j].count, 0);
104 atomic_set(&cacct->sock[i][j].total, 0);
109 static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
114 #define LOAD_INT(x) ((x) >> FSHIFT)
115 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
118 static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
123 length += sprintf(buffer + length,
124 "BiasUptime:\t%lu.%02lu\n",
125 (unsigned long)cvirt->bias_uptime.tv_sec,
126 (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
127 length += sprintf(buffer + length,
133 "DomainName:\t%.*s\n"
134 ,__NEW_UTS_LEN, cvirt->utsname.sysname
135 ,__NEW_UTS_LEN, cvirt->utsname.nodename
136 ,__NEW_UTS_LEN, cvirt->utsname.release
137 ,__NEW_UTS_LEN, cvirt->utsname.version
138 ,__NEW_UTS_LEN, cvirt->utsname.machine
139 ,__NEW_UTS_LEN, cvirt->utsname.domainname
142 a = cvirt->load[0] + (FIXED_1/200);
143 b = cvirt->load[1] + (FIXED_1/200);
144 c = cvirt->load[2] + (FIXED_1/200);
145 length += sprintf(buffer + length,
149 "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
150 ,atomic_read(&cvirt->nr_threads)
151 ,atomic_read(&cvirt->nr_running)
152 ,atomic_read(&cvirt->nr_onhold)
153 ,LOAD_INT(a), LOAD_FRAC(a)
154 ,LOAD_INT(b), LOAD_FRAC(b)
155 ,LOAD_INT(c), LOAD_FRAC(c)
160 static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
163 static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
165 for (i=0; i<5; i++) {
166 length += sprintf(buffer + length,
168 for (j=0; j<3; j++) {
169 length += sprintf(buffer + length,
171 ,vx_sock_count(cacct, i, j)
172 ,vx_sock_total(cacct, i, j)
175 buffer[length++] = '\n';
177 length += sprintf(buffer + length,
178 "forks:\t%lu\n", cacct->total_forks);
182 #else /* _VX_INFO_DEF_ */
188 /* cvirt vserver commands */
195 void vx_vsi_uptime(struct timespec *, struct timespec *);
199 void vx_update_load(struct vx_info *);
202 #endif /* __KERNEL__ */
204 #endif /* _VX_CVIRT_H */