vserver 1.9.5.x5
[linux-2.6.git] / kernel / vserver / cvirt_proc.h
1 #ifndef _VX_CVIRT_PROC_H
2 #define _VX_CVIRT_PROC_H
3
4 #include <linux/sched.h>
5
6
7 #define LOAD_INT(x) ((x) >> FSHIFT)
8 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
9
10 static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
11 {
12         int length = 0;
13         int a, b, c;
14
15         length += sprintf(buffer + length,
16                 "BiasUptime:\t%lu.%02lu\n",
17                         (unsigned long)cvirt->bias_uptime.tv_sec,
18                         (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19         length += sprintf(buffer + length,
20                 "SysName:\t%.*s\n"
21                 "NodeName:\t%.*s\n"
22                 "Release:\t%.*s\n"
23                 "Version:\t%.*s\n"
24                 "Machine:\t%.*s\n"
25                 "DomainName:\t%.*s\n"
26                 ,__NEW_UTS_LEN, cvirt->utsname.sysname
27                 ,__NEW_UTS_LEN, cvirt->utsname.nodename
28                 ,__NEW_UTS_LEN, cvirt->utsname.release
29                 ,__NEW_UTS_LEN, cvirt->utsname.version
30                 ,__NEW_UTS_LEN, cvirt->utsname.machine
31                 ,__NEW_UTS_LEN, cvirt->utsname.domainname
32                 );
33
34         a = cvirt->load[0] + (FIXED_1/200);
35         b = cvirt->load[1] + (FIXED_1/200);
36         c = cvirt->load[2] + (FIXED_1/200);
37         length += sprintf(buffer + length,
38                 "nr_threads:\t%d\n"
39                 "nr_running:\t%d\n"
40                 "nr_unintr:\t%d\n"
41                 "nr_onhold:\t%d\n"
42                 "load_updates:\t%d\n"
43                 "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
44                 "total_forks:\t%d\n"
45                 ,atomic_read(&cvirt->nr_threads)
46                 ,atomic_read(&cvirt->nr_running)
47                 ,atomic_read(&cvirt->nr_uninterruptible)
48                 ,atomic_read(&cvirt->nr_onhold)
49                 ,atomic_read(&cvirt->load_updates)
50                 ,LOAD_INT(a), LOAD_FRAC(a)
51                 ,LOAD_INT(b), LOAD_FRAC(b)
52                 ,LOAD_INT(c), LOAD_FRAC(c)
53                 ,atomic_read(&cvirt->total_forks)
54                 );
55         return length;
56 }
57
58
59 static inline long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
60 {
61         return atomic_read(&cacct->sock[type][pos].count);
62 }
63
64
65 static inline long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
66 {
67         return atomic_read(&cacct->sock[type][pos].total);
68 }
69
70 static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
71 {
72         int i,j, length = 0;
73         static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
74
75         for (i=0; i<5; i++) {
76                 length += sprintf(buffer + length,
77                         "%s:", type[i]);
78                 for (j=0; j<3; j++) {
79                         length += sprintf(buffer + length,
80                                 "\t%12lu/%-12lu"
81                                 ,vx_sock_count(cacct, i, j)
82                                 ,vx_sock_total(cacct, i, j)
83                                 );
84                 }
85                 buffer[length++] = '\n';
86         }
87         length += sprintf(buffer + length,
88                 "forks:\t%lu\n", cacct->total_forks);
89         return length;
90 }
91
92 #endif  /* _VX_CVIRT_PROC_H */