This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vserver / 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 _vx_cvirt {
12         int max_threads;
13
14         unsigned int bias_cswtch;
15         struct timespec bias_idle;
16         struct timespec bias_tp;
17         uint64_t bias_jiffies;
18
19         struct new_utsname utsname;
20 };
21
22 struct sock_acc {
23         atomic_t count;
24         atomic_t total;
25 };
26
27 struct _vx_cacct {
28         atomic_t nr_threads;
29         int nr_running;
30
31         unsigned long total_forks;
32
33         struct sock_acc sock[5][3];
34 };
35
36
37 static inline long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
38 {
39         return atomic_read(&cacct->sock[type][pos].count);
40 }
41
42
43 static inline long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
44 {
45         return atomic_read(&cacct->sock[type][pos].total);
46 }
47
48
49 extern uint64_t vx_idle_jiffies(void);
50
51 static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
52 {
53         uint64_t idle_jiffies = vx_idle_jiffies();
54
55         // new->virt.bias_cswtch = kstat.context_swtch;
56         cvirt->bias_jiffies = get_jiffies_64();
57
58         jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
59         do_posix_clock_monotonic_gettime(&cvirt->bias_tp);
60
61         down_read(&uts_sem);
62         cvirt->utsname = system_utsname;
63         up_read(&uts_sem);
64 }
65
66 static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
67 {
68         return;
69 }
70
71 static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
72 {
73         int i,j;
74
75         atomic_set(&cacct->nr_threads, 1);
76         for (i=0; i<5; i++) {
77                 for (j=0; j<3; j++) {
78                         atomic_set(&cacct->sock[i][j].count, 0);
79                         atomic_set(&cacct->sock[i][j].total, 0);
80                 }
81         }
82 }
83
84 static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
85 {
86         return;
87 }
88
89 static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
90 {
91         int length = 0;
92         return length;
93 }
94
95 static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
96 {
97         int i,j, length = 0;
98         static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
99
100         for (i=0; i<5; i++) {
101                 length += sprintf(buffer + length,
102                         "%s:", type[i]);
103                 for (j=0; j<3; j++) {
104                         length += sprintf(buffer + length,
105                                 "\t%12lu/%-12lu"
106                                 ,vx_sock_count(cacct, i, j)
107                                 ,vx_sock_total(cacct, i, j)
108                                 );
109                 }       
110                 buffer[length++] = '\n';
111         }
112         return length;
113 }
114
115 #else   /* _VX_INFO_DEF_ */
116 #ifndef _VX_CVIRT_H
117 #define _VX_CVIRT_H
118
119 #include "switch.h"
120
121 /*  cvirt vserver commands */
122
123
124 #ifdef  __KERNEL__
125
126 struct timespec;
127
128 void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle);
129
130 #endif  /* __KERNEL__ */
131
132 #endif  /* _VX_CVIRT_H */
133 #endif