updated from vs0.09.28
[util-vserver.git] / util-vserver / kernel / cvirt.h
1 #if     defined(__KERNEL__) && defined(_VX_INFO_DEF_)
2
3 #include <linux/utsname.h>
4 #include <linux/rwsem.h>
5 #include <linux/jiffies.h>
6 #include <linux/time.h>
7 #include <asm/atomic.h>
8
9 /* context sub struct */
10
11 struct sock_acc {
12         atomic_t count;
13         atomic_t total;
14 };
15
16 struct _vx_cvirt {
17         int nr_threads;
18         int nr_running;
19         int max_threads;
20         unsigned long total_forks;
21
22         unsigned int bias_cswtch;
23         long bias_jiffies;
24         long bias_idle;
25         struct timespec bias_tp;
26
27         struct new_utsname utsname;
28
29         struct sock_acc sock[5][3];
30 };
31
32
33 static inline long vx_sock_count(struct _vx_cvirt *cvirt, int type, int pos)
34 {
35         return atomic_read(&cvirt->sock[type][pos].count);
36 }
37
38
39 static inline long vx_sock_total(struct _vx_cvirt *cvirt, int type, int pos)
40 {
41         return atomic_read(&cvirt->sock[type][pos].total);
42 }
43
44
45 static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
46 {
47         int i,j;
48
49         cvirt->nr_threads = 1;
50         // new->virt.bias_cswtch = kstat.context_swtch;
51         cvirt->bias_jiffies = jiffies;
52         /* new->virt.bias_idle = init_tasks[0]->times.tms_utime +
53                 init_tasks[0]->times.tms_stime;
54         */
55         do_posix_clock_monotonic_gettime(&cvirt->bias_tp);
56
57         down_read(&uts_sem);
58         cvirt->utsname = system_utsname;
59         up_read(&uts_sem);
60
61         for (i=0; i<5; i++) {
62                 for (j=0; j<3; j++) {
63                         atomic_set(&cvirt->sock[i][j].count, 0);
64                         atomic_set(&cvirt->sock[i][j].total, 0);
65                 }
66         }
67 }
68
69 static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
70 {
71         int i,j, length = 0;
72         static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
73
74         for (i=0; i<5; i++) {
75                 length += sprintf(buffer + length,
76                         "%s:", type[i]);
77                 for (j=0; j<3; j++) {
78                         length += sprintf(buffer + length,
79                                 "\t%12lu/%-12lu"
80                                 ,vx_sock_count(cvirt, i, j)
81                                 ,vx_sock_total(cvirt, i, j)
82                                 );
83                 }       
84                 buffer[length++] = '\n';
85         }
86         return length;
87 }
88
89 #else   /* _VX_INFO_DEF_ */
90 #ifndef _VX_CVIRT_H
91 #define _VX_CVIRT_H
92
93 #include "switch.h"
94
95 /*  cvirt vserver commands */
96
97
98 #ifdef  __KERNEL__
99
100 struct timespec;
101
102 void vx_vsi_uptime(struct timespec *uptime);
103
104 #endif  /* __KERNEL__ */
105
106 #endif  /* _VX_CVIRT_H */
107 #endif