2 * Hypervisor filesystem for Linux on s390. z/VM implementation.
4 * Copyright IBM Corp. 2006
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
8 #include <linux/types.h>
9 #include <linux/errno.h>
10 #include <linux/string.h>
11 #include <linux/vmalloc.h>
13 #include <asm/ebcdic.h>
14 #include <asm/timex.h>
18 #define DBFS_D2FC_HDR_VERSION 0
20 static char local_guest
[] = " ";
21 static char all_guests
[] = "* ";
22 static char *guest_query
;
45 char guest_name
[NAME_LEN
];
48 struct diag2fc_parm_list
{
49 char userid
[NAME_LEN
];
50 char aci_grp
[NAME_LEN
];
56 static int diag2fc(int size
, char* query
, void *addr
)
58 unsigned long residual_cnt
;
60 struct diag2fc_parm_list parm_list
;
62 memcpy(parm_list
.userid
, query
, NAME_LEN
);
63 ASCEBC(parm_list
.userid
, NAME_LEN
);
64 parm_list
.addr
= (unsigned long) addr
;
65 parm_list
.size
= size
;
67 memset(parm_list
.aci_grp
, 0x40, NAME_LEN
);
70 diag_stat_inc(DIAG_STAT_X2FC
);
75 : "=d" (residual_cnt
), "+d" (rc
) : "0" (&parm_list
) : "memory");
77 if ((rc
!= 0 ) && (rc
!= -2))
84 * Allocate buffer for "query" and store diag 2fc at "offset"
86 static void *diag2fc_store(char *query
, unsigned int *count
, int offset
)
92 size
= diag2fc(0, query
, NULL
);
94 return ERR_PTR(-EACCES
);
95 data
= vmalloc(size
+ offset
);
97 return ERR_PTR(-ENOMEM
);
98 if (diag2fc(size
, query
, data
+ offset
) == 0)
102 *count
= (size
/ sizeof(struct diag2fc_data
));
107 static void diag2fc_free(const void *data
)
112 #define ATTRIBUTE(dir, name, member) \
115 rc = hypfs_create_u64(dir, name, member); \
117 return PTR_ERR(rc); \
120 static int hpyfs_vm_create_guest(struct dentry
*systems_dir
,
121 struct diag2fc_data
*data
)
123 char guest_name
[NAME_LEN
+ 1] = {};
124 struct dentry
*guest_dir
, *cpus_dir
, *samples_dir
, *mem_dir
;
125 int dedicated_flag
, capped_value
;
127 capped_value
= (data
->flags
& 0x00000006) >> 1;
128 dedicated_flag
= (data
->flags
& 0x00000008) >> 3;
131 memcpy(guest_name
, data
->guest_name
, NAME_LEN
);
132 EBCASC(guest_name
, NAME_LEN
);
134 guest_dir
= hypfs_mkdir(systems_dir
, guest_name
);
135 if (IS_ERR(guest_dir
))
136 return PTR_ERR(guest_dir
);
137 ATTRIBUTE(guest_dir
, "onlinetime_us", data
->el_time
);
139 /* logical cpu information */
140 cpus_dir
= hypfs_mkdir(guest_dir
, "cpus");
141 if (IS_ERR(cpus_dir
))
142 return PTR_ERR(cpus_dir
);
143 ATTRIBUTE(cpus_dir
, "cputime_us", data
->used_cpu
);
144 ATTRIBUTE(cpus_dir
, "capped", capped_value
);
145 ATTRIBUTE(cpus_dir
, "dedicated", dedicated_flag
);
146 ATTRIBUTE(cpus_dir
, "count", data
->vcpus
);
148 * Note: The "weight_min" attribute got the wrong name.
149 * The value represents the number of non-stopped (operating)
152 ATTRIBUTE(cpus_dir
, "weight_min", data
->ocpus
);
153 ATTRIBUTE(cpus_dir
, "weight_max", data
->cpu_max
);
154 ATTRIBUTE(cpus_dir
, "weight_cur", data
->cpu_shares
);
156 /* memory information */
157 mem_dir
= hypfs_mkdir(guest_dir
, "mem");
159 return PTR_ERR(mem_dir
);
160 ATTRIBUTE(mem_dir
, "min_KiB", data
->mem_min_kb
);
161 ATTRIBUTE(mem_dir
, "max_KiB", data
->mem_max_kb
);
162 ATTRIBUTE(mem_dir
, "used_KiB", data
->mem_used_kb
);
163 ATTRIBUTE(mem_dir
, "share_KiB", data
->mem_share_kb
);
166 samples_dir
= hypfs_mkdir(guest_dir
, "samples");
167 if (IS_ERR(samples_dir
))
168 return PTR_ERR(samples_dir
);
169 ATTRIBUTE(samples_dir
, "cpu_using", data
->cpu_use_samp
);
170 ATTRIBUTE(samples_dir
, "cpu_delay", data
->cpu_delay_samp
);
171 ATTRIBUTE(samples_dir
, "mem_delay", data
->page_wait_samp
);
172 ATTRIBUTE(samples_dir
, "idle", data
->idle_samp
);
173 ATTRIBUTE(samples_dir
, "other", data
->other_samp
);
174 ATTRIBUTE(samples_dir
, "total", data
->total_samp
);
178 int hypfs_vm_create_files(struct dentry
*root
)
180 struct dentry
*dir
, *file
;
181 struct diag2fc_data
*data
;
182 unsigned int count
= 0;
185 data
= diag2fc_store(guest_query
, &count
, 0);
187 return PTR_ERR(data
);
190 dir
= hypfs_mkdir(root
, "hyp");
195 file
= hypfs_create_str(dir
, "type", "z/VM Hypervisor");
202 dir
= hypfs_mkdir(root
, "cpus");
207 file
= hypfs_create_u64(dir
, "count", data
->lcpus
);
214 dir
= hypfs_mkdir(root
, "systems");
220 for (i
= 0; i
< count
; i
++) {
221 rc
= hpyfs_vm_create_guest(dir
, &(data
[i
]));
233 struct dbfs_d2fc_hdr
{
234 u64 len
; /* Length of d2fc buffer without header */
235 u16 version
; /* Version of header */
236 char tod_ext
[STORE_CLOCK_EXT_SIZE
]; /* TOD clock for d2fc */
237 u64 count
; /* Number of VM guests in d2fc buffer */
239 } __attribute__ ((packed
));
242 struct dbfs_d2fc_hdr hdr
; /* 64 byte header */
243 char buf
[]; /* d2fc buffer */
244 } __attribute__ ((packed
));
246 static int dbfs_diag2fc_create(void **data
, void **data_free_ptr
, size_t *size
)
248 struct dbfs_d2fc
*d2fc
;
251 d2fc
= diag2fc_store(guest_query
, &count
, sizeof(d2fc
->hdr
));
253 return PTR_ERR(d2fc
);
254 get_tod_clock_ext(d2fc
->hdr
.tod_ext
);
255 d2fc
->hdr
.len
= count
* sizeof(struct diag2fc_data
);
256 d2fc
->hdr
.version
= DBFS_D2FC_HDR_VERSION
;
257 d2fc
->hdr
.count
= count
;
258 memset(&d2fc
->hdr
.reserved
, 0, sizeof(d2fc
->hdr
.reserved
));
260 *data_free_ptr
= d2fc
;
261 *size
= d2fc
->hdr
.len
+ sizeof(struct dbfs_d2fc_hdr
);
265 static struct hypfs_dbfs_file dbfs_file_2fc
= {
267 .data_create
= dbfs_diag2fc_create
,
268 .data_free
= diag2fc_free
,
271 int hypfs_vm_init(void)
275 if (diag2fc(0, all_guests
, NULL
) > 0)
276 guest_query
= all_guests
;
277 else if (diag2fc(0, local_guest
, NULL
) > 0)
278 guest_query
= local_guest
;
281 return hypfs_dbfs_create_file(&dbfs_file_2fc
);
284 void hypfs_vm_exit(void)
288 hypfs_dbfs_remove_file(&dbfs_file_2fc
);