1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Intel Corporation
9 * Author: Hariharan Thantry
10 * File Name: lprocfs.h
12 * Header file for the LProcFS file system
18 #ifndef LPROCFS_EXISTS
19 #define LPROCFS_EXISTS
22 #define LPROCFS_SUCCESS 1
23 #define LPROCFS_FAILURE -1
25 #include <linux/time.h>
26 #include <linux/proc_fs.h>
27 #include <linux/config.h>
28 #include <linux/param.h>
29 /* #include <linux/msr.h> */
31 typedef enum lprofilers {
37 typedef struct lprocfs_vars{
39 read_proc_t* read_fptr;
40 write_proc_t* write_fptr;
43 typedef struct lprocfs_group {
45 lprocfs_vars_t* count_func_namespace;
46 lprofilers_e prof_type;
49 typedef struct lprocfs_obd_nm {
51 lprocfs_group_t* obd_names;
52 unsigned int cntr_blk_sz;
58 * Structure defining the variables to be maintained
59 * on a per attribute basis for entries. The size of
60 * the profiling entry needs to be passed during registration
61 * with LProcFS, to enable it to allocate space. It is expected
62 * that on a per-device class basis, there would exist only
66 struct lprofiler_gen {
72 * Default, used for storing intermediate
75 unsigned long long start_time;
79 struct lprofiler_ldlm {
88 __u64 num_zerolatency;
89 __u64 num_zerolatency_inflight;
90 __u64 num_zerolatency_done;
91 __u64 non_zero_mintime;
92 __u64 non_zero_maxtime;
93 __u64 non_zero_sumtime;
96 struct lprofiler_ptlrpc {
102 * Default, used for storing intermediate
114 __u64 portal_kmemory;
121 struct namespace_index{
125 struct groupspace_index{
127 struct namespace_index* directory;
128 struct namespace_index* counters;
133 * Used for connections and such
137 typedef enum te_leafType {
146 struct lprocfs_conn_namespace{
159 #ifdef LPROCFS_EXISTS
162 * Utility functions to return the timeofday
165 static inline unsigned long lprocfs_util_gettime(void)
169 struct timeval myTime;
171 do_gettimeofday(&myTime);
172 temp=((__u64)(myTime.tv_usec))&0xFFFFFFFF;
173 temp|=(((__u64)(myTime.tv_sec))<<(8*sizeof(unsigned long)));
178 static inline unsigned long lprocfs_util_getdiff(unsigned long x,
181 return ((x>y)?(x-y):(y-x));
185 tempSec=((y>>8*sizeof(unsigned long))-(x>>8*sizeof(unsigned long)));
186 if(tempSec<0)tempSec=-tempSec;
187 tempuSec=((y&0xFFFFFFFF)-(x&0xFFFFFFFF));
188 if(tempuSec<0)tempuSec=-tempuSec;
189 return(tempSec*1000000+tempuSec);
194 #define LPROCFS_NAMESPACE_ENUM(CLASS, NAME) e_ ##CLASS## _##NAME
197 #define DEV_PROF_START(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) \
199 struct lprofiler_##PROF_CLASS *x; \
200 int index=LPROCFS_NAMESPACE_ENUM(DEV_CLASS, ATTRIBUTE); \
201 x=(struct lprofiler_##PROF_CLASS *)((OBD)->counters); \
203 /* rdtscl(x->start_time); */ \
204 x->start_time=lprocfs_util_gettime(); \
208 #define DEV_PROF_END(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) \
210 unsigned long end_time, delta; \
211 int index=LPROCFS_NAMESPACE_ENUM(DEV_CLASS, ATTRIBUTE); \
212 struct lprofiler_##PROF_CLASS *x= \
213 (struct lprofiler_##PROF_CLASS*)((OBD)->counters); \
215 end_time=lprocfs_util_gettime(); \
216 delta=lprocfs_util_getdiff(x->start_time, end_time); \
217 if((delta<x->min_time)||(x->min_time==0))x->min_time=delta; \
218 if(delta>x->max_time)x->max_time=delta; \
219 x->sum_time+=delta; \
224 #define DEV_PROF_END(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) \
226 __u64 end_time, delta; \
227 int index=LPROCFS_NAMESPACE_ENUM(DEV_CLASS, ATTRIBUTE); \
228 struct lprofiler_##PROF_CLASS *x= \
229 (struct lprofiler_##PROF_CLASS*)((OBD)->counters); \
231 end_time=lprocfs_util_gettime(); \
232 delta=lprocfs_util_getdiff(x->start_time, end_time); \
233 if((delta<x->min_time)||(x->min_time==0))x->min_time=delta; \
234 if(delta>x->max_time)x->max_time=delta; \
235 x->sum_time+=delta; \
240 #define DEV_PRINT_CNTR(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) \
242 int index=LPROCFS_NAMESPACE_ENUM(DEV_CLASS, ATTRIBUTE); \
243 struct lprofiler_##PROF_CLASS *x= \
244 (struct lprofiler_##PROF_CLASS *)&((OBD)->counters); \
246 printk("Max_time=%lld(usec)\n", x->max_time); \
247 printk("Min_time=%lld(usec)\n", x->min_time); \
248 printk("Sum_time=%lld(usec)\n", x->sum_time); \
249 printk("Num_ops=%lld\n", x->num_ops); \
255 * This enum is used as an array index into the counts
256 * that are maintained for the MDS device. The number of
257 * entries here determine the amount of memory allocated
258 * for counters for every instance of this class of
264 LPROCFS_NAMESPACE_ENUM(mdc, mgmt_setup),
265 LPROCFS_NAMESPACE_ENUM(mdc, mgmt_cleanup),
266 LPROCFS_NAMESPACE_ENUM(mdc, mgmt_connect),
267 LPROCFS_NAMESPACE_ENUM(mdc, mgmt_disconnect),
268 LPROCFS_NAMESPACE_ENUM(mdc, reint),
269 LPROCFS_NAMESPACE_ENUM(mdc, getstatus),
270 LPROCFS_NAMESPACE_ENUM(mdc, getattr),
271 LPROCFS_NAMESPACE_ENUM(mdc, setattr),
272 LPROCFS_NAMESPACE_ENUM(mdc, open),
273 LPROCFS_NAMESPACE_ENUM(mdc, readpage),
274 LPROCFS_NAMESPACE_ENUM(mdc, create),
275 LPROCFS_NAMESPACE_ENUM(mdc, unlink),
276 LPROCFS_NAMESPACE_ENUM(mdc, link),
277 LPROCFS_NAMESPACE_ENUM(mdc, rename),
278 LPROCFS_MAX_ENUM_DIR_MDC
282 LPROCFS_NAMESPACE_ENUM(mds, mgmt_setup),
283 LPROCFS_NAMESPACE_ENUM(mds, mgmt_cleanup),
284 LPROCFS_NAMESPACE_ENUM(mds, mgmt_connect),
285 LPROCFS_NAMESPACE_ENUM(mds, mgmt_disconnect),
286 LPROCFS_NAMESPACE_ENUM(mds, getstatus),
287 LPROCFS_NAMESPACE_ENUM(mds, connect),
288 LPROCFS_NAMESPACE_ENUM(mds, disconnect_callback),
289 LPROCFS_NAMESPACE_ENUM(mds, getattr),
290 LPROCFS_NAMESPACE_ENUM(mds, readpage),
291 LPROCFS_NAMESPACE_ENUM(mds, open),
292 LPROCFS_NAMESPACE_ENUM(mds, close),
293 LPROCFS_NAMESPACE_ENUM(mds, create),
294 LPROCFS_NAMESPACE_ENUM(mds, unlink),
295 LPROCFS_NAMESPACE_ENUM(mds, link),
296 LPROCFS_NAMESPACE_ENUM(mds, rename),
297 LPROCFS_NAMESPACE_ENUM(mds, reint_summary),
298 LPROCFS_NAMESPACE_ENUM(mds, reint_setattr),
299 LPROCFS_NAMESPACE_ENUM(mds, reint_create),
300 LPROCFS_NAMESPACE_ENUM(mds, reint_unlink),
301 LPROCFS_NAMESPACE_ENUM(mds, reint_link),
302 LPROCFS_NAMESPACE_ENUM(mds, reint_rename),
303 LPROCFS_NAMESPACE_ENUM(mds, reint_recreate),
304 LPROCFS_MAX_ENUM_DIR_MDS
308 LPROCFS_NAMESPACE_ENUM(osc, mgmt_setup),
309 LPROCFS_NAMESPACE_ENUM(osc, mgmt_cleanup),
310 LPROCFS_NAMESPACE_ENUM(osc, mgmt_connect),
311 LPROCFS_NAMESPACE_ENUM(osc, mgmt_disconnect),
312 LPROCFS_NAMESPACE_ENUM(osc, create),
313 LPROCFS_NAMESPACE_ENUM(osc, destroy),
314 LPROCFS_NAMESPACE_ENUM(osc, getattr),
315 LPROCFS_NAMESPACE_ENUM(osc, setattr),
316 LPROCFS_NAMESPACE_ENUM(osc, open),
317 LPROCFS_NAMESPACE_ENUM(osc, close),
318 LPROCFS_NAMESPACE_ENUM(osc, brw),
319 LPROCFS_NAMESPACE_ENUM(osc, punch),
320 LPROCFS_NAMESPACE_ENUM(osc, summary),
321 LPROCFS_NAMESPACE_ENUM(osc, cancel),
322 LPROCFS_MAX_ENUM_DIR_OSC
327 LPROCFS_NAMESPACE_ENUM(ost, mgmt_setup),
328 LPROCFS_NAMESPACE_ENUM(ost, mgmt_cleanup),
329 LPROCFS_NAMESPACE_ENUM(ost, mgmt_connect),
330 LPROCFS_NAMESPACE_ENUM(ost, mgmt_disconnect),
331 LPROCFS_NAMESPACE_ENUM(ost, create),
332 LPROCFS_NAMESPACE_ENUM(ost, destroy),
333 LPROCFS_NAMESPACE_ENUM(ost, getattr),
334 LPROCFS_NAMESPACE_ENUM(ost, setattr),
335 LPROCFS_NAMESPACE_ENUM(ost, open),
336 LPROCFS_NAMESPACE_ENUM(ost, close),
337 LPROCFS_NAMESPACE_ENUM(ost, brw),
338 LPROCFS_NAMESPACE_ENUM(ost, punch),
339 LPROCFS_NAMESPACE_ENUM(ost, summary),
340 LPROCFS_NAMESPACE_ENUM(ost, cancel),
341 LPROCFS_NAMESPACE_ENUM(ost, getinfo),
342 LPROCFS_MAX_ENUM_DIR_OST
348 LPROCFS_NAMESPACE_ENUM(lov, mgmt_setup),
349 LPROCFS_NAMESPACE_ENUM(lov, mgmt_cleanup),
350 LPROCFS_NAMESPACE_ENUM(lov, mgmt_connect),
351 LPROCFS_NAMESPACE_ENUM(lov, mgmt_disconnect),
352 LPROCFS_NAMESPACE_ENUM(lov, create),
353 LPROCFS_NAMESPACE_ENUM(lov, destroy),
354 LPROCFS_NAMESPACE_ENUM(lov, getattr),
355 LPROCFS_NAMESPACE_ENUM(lov, setattr),
356 LPROCFS_NAMESPACE_ENUM(lov, open),
357 LPROCFS_NAMESPACE_ENUM(lov, close),
358 LPROCFS_NAMESPACE_ENUM(lov, brw),
359 LPROCFS_NAMESPACE_ENUM(lov, punch),
360 LPROCFS_NAMESPACE_ENUM(lov, summary),
361 LPROCFS_NAMESPACE_ENUM(lov, cancel),
362 LPROCFS_NAMESPACE_ENUM(lov, getinfo),
363 LPROCFS_MAX_ENUM_DIR_LOV
369 LPROCFS_NAMESPACE_ENUM(obdfilter, mgmt_setup),
370 LPROCFS_NAMESPACE_ENUM(obdfilter, mgmt_cleanup),
371 LPROCFS_NAMESPACE_ENUM(obdfilter, mgmt_connect),
372 LPROCFS_NAMESPACE_ENUM(obdfilter, mgmt_disconnect),
373 LPROCFS_NAMESPACE_ENUM(obdfilter, create),
374 LPROCFS_NAMESPACE_ENUM(obdfilter, destroy),
375 LPROCFS_NAMESPACE_ENUM(obdfilter, getattr),
376 LPROCFS_NAMESPACE_ENUM(obdfilter, setattr),
377 LPROCFS_NAMESPACE_ENUM(obdfilter, open),
378 LPROCFS_NAMESPACE_ENUM(obdfilter, close),
379 LPROCFS_NAMESPACE_ENUM(obdfilter, brw),
380 LPROCFS_NAMESPACE_ENUM(obdfilter, punch),
381 LPROCFS_NAMESPACE_ENUM(obdfilter, summary),
382 LPROCFS_NAMESPACE_ENUM(obdfilter, cancel),
383 LPROCFS_NAMESPACE_ENUM(obdfilter, getinfo),
384 LPROCFS_MAX_ENUM_DIR_OBDFILTER
390 LPROCFS_NAMESPACE_ENUM(ldlm, mgmt_setup),
391 LPROCFS_NAMESPACE_ENUM(ldlm, mgmt_cleanup),
392 LPROCFS_NAMESPACE_ENUM(ldlm, mgmt_connect),
393 LPROCFS_NAMESPACE_ENUM(ldlm, mgmt_disconnect),
394 LPROCFS_NAMESPACE_ENUM(ldlm, locks_enqueus),
395 LPROCFS_NAMESPACE_ENUM(ldlm, locks_cancels),
396 LPROCFS_NAMESPACE_ENUM(ldlm, locks_converts),
397 LPROCFS_NAMESPACE_ENUM(ldlm, locks_matches),
398 LPROCFS_MAX_ENUM_DIR_LDLM
403 LPROCFS_NAMESPACE_ENUM(ptlrpc, mgmt_setup),
404 LPROCFS_NAMESPACE_ENUM(ptlrpc, mgmt_cleanup),
405 LPROCFS_NAMESPACE_ENUM(ptlrpc, mgmt_connect),
406 LPROCFS_NAMESPACE_ENUM(ptlrpc, mgmt_disconnect),
407 LPROCFS_NAMESPACE_ENUM(ptlrpc, counters),
408 LPROCFS_NAMESPACE_ENUM(ptlrpc, network),
409 LPROCFS_MAX_ENUM_DIR_PTLRPC
413 #define LPROCFS_DIR_INDEX(CLASS, DIR) \
414 [LPROCFS_NAMESPACE_ENUM(CLASS, DIR)]={#DIR}
417 * Similar rule for profiling counters
422 LPROCFS_NAMESPACE_ENUM(mdc, min_time),
423 LPROCFS_NAMESPACE_ENUM(mdc, max_time),
424 LPROCFS_NAMESPACE_ENUM(mdc, sum_time),
425 LPROCFS_NAMESPACE_ENUM(mdc, num_ops),
431 LPROCFS_NAMESPACE_ENUM(mds, min_time),
432 LPROCFS_NAMESPACE_ENUM(mds, max_time),
433 LPROCFS_NAMESPACE_ENUM(mds, sum_time),
434 LPROCFS_NAMESPACE_ENUM(mds, num_ops),
440 LPROCFS_NAMESPACE_ENUM(osc, min_time),
441 LPROCFS_NAMESPACE_ENUM(osc, max_time),
442 LPROCFS_NAMESPACE_ENUM(osc, sum_time),
443 LPROCFS_NAMESPACE_ENUM(osc, num_ops),
450 LPROCFS_NAMESPACE_ENUM(ost, min_time),
451 LPROCFS_NAMESPACE_ENUM(ost, max_time),
452 LPROCFS_NAMESPACE_ENUM(ost, sum_time),
453 LPROCFS_NAMESPACE_ENUM(ost, num_ops),
459 LPROCFS_NAMESPACE_ENUM(lov, min_time),
460 LPROCFS_NAMESPACE_ENUM(lov, max_time),
461 LPROCFS_NAMESPACE_ENUM(lov, sum_time),
462 LPROCFS_NAMESPACE_ENUM(lov, num_ops),
468 LPROCFS_NAMESPACE_ENUM(obdfilter, min_time),
469 LPROCFS_NAMESPACE_ENUM(obdfilter, max_time),
470 LPROCFS_NAMESPACE_ENUM(obdfilter, sum_time),
471 LPROCFS_NAMESPACE_ENUM(obdfilter, num_ops),
479 LPROCFS_NAMESPACE_ENUM(ldlm, min_time),
480 LPROCFS_NAMESPACE_ENUM(ldlm, max_time),
481 LPROCFS_NAMESPACE_ENUM(ldlm, sum_time),
482 LPROCFS_NAMESPACE_ENUM(ldlm, num_ops),
483 LPROCFS_NAMESPACE_ENUM(ldlm, num_total),
484 LPROCFS_NAMESPACE_ENUM(ldlm, num_zerolatency),
485 LPROCFS_NAMESPACE_ENUM(ldlm, num_zerolatency_inflight),
486 LPROCFS_NAMESPACE_ENUM(ldlm, num_zerolatency_done),
487 LPROCFS_NAMESPACE_ENUM(ldlm, nonzero_mintime),
488 LPROCFS_NAMESPACE_ENUM(ldlm, nonzero_maxtime),
489 LPROCFS_NAMESPACE_ENUM(ldlm, nonzero_sumtime),
495 LPROCFS_NAMESPACE_ENUM(ptlrpc, min_time),
496 LPROCFS_NAMESPACE_ENUM(ptlrpc, max_time),
497 LPROCFS_NAMESPACE_ENUM(ptlrpc, sum_time),
498 LPROCFS_NAMESPACE_ENUM(ptlrpc, num_ops),
500 LPROCFS_NAMESPACE_ENUM(ptlrpc, msgs_alloc),
501 LPROCFS_NAMESPACE_ENUM(ptlrpc, msgs_max),
502 LPROCFS_NAMESPACE_ENUM(ptlrpc, recv_count),
503 LPROCFS_NAMESPACE_ENUM(ptlrpc, recv_length),
504 LPROCFS_NAMESPACE_ENUM(ptlrpc, send_count),
505 LPROCFS_NAMESPACE_ENUM(ptlrpc, send_length),
506 LPROCFS_NAMESPACE_ENUM(ptlrpc, portal_kmemory),
517 #define LPROCFS_ENUM(X) e_##X
525 LPROCFS_ENUM(obdfilter),
527 LPROCFS_ENUM(ptlrpc),
532 #define LPROCFS_CNTR_INDEX(CLASS, NAME) \
533 [LPROCFS_NAMESPACE_ENUM(CLASS, NAME)]={#NAME}
535 #define LPROCFS_GROUP_CREATE(CLASS) \
536 [LPROCFS_ENUM(CLASS)]={#CLASS, dir_##CLASS##_index, prof_##CLASS##_index}
539 * OBD Namespace API: Obtain the namespace group index, given a name
541 int lprocfs_get_nm(char* name,
542 lprocfs_obd_nm_t* collection);
550 int lprocfs_reg_dev(struct obd_device* device,
551 lprocfs_group_t* namespace,
552 unsigned int cnt_struct_size);
554 int lprocfs_dereg_dev(struct obd_device* device);
559 int lprocfs_reg_conn(unsigned int conn_number,
560 struct lprocfs_conn_namespace* namespace);
561 int lprocfs_dereg_conn(unsigned int conn_number);
566 int lprocfs_add_export(unsigned int conn_number,
567 struct obd_device* device);
568 int lprocfs_add_import(unsigned int conn_number,
569 struct obd_device* device);
570 int lprocfs_remove_export(unsigned int conn_number,
571 struct obd_device* device);
572 int lprocfs_remove_import(unsigned int conn_number,
573 struct obd_device* device);
579 struct proc_dir_entry* lprocfs_add_dir(struct proc_dir_entry* root,
582 unsigned int* escape);
585 struct proc_dir_entry* lprocfs_mkdir(const char* dname,
586 struct proc_dir_entry *parent);
589 struct proc_dir_entry* lprocfs_bfs_srch(struct proc_dir_entry* root,
592 struct proc_dir_entry* lprocfs_srch(struct proc_dir_entry* head,
595 int lprocfs_link_dir_counters(struct obd_device* device,
596 struct proc_dir_entry* this_dev_root,
597 lprocfs_group_t* namespace,
598 unsigned int cnt_struct_size,
599 unsigned int class_array_index);
601 int lprocfs_create_dir_namespace(struct proc_dir_entry* this_dev_root,
602 lprocfs_group_t* namespace,
603 unsigned int *num_dirs);
605 int lprocfs_getclass_idx(struct groupspace_index* group,
606 const char* classname);
607 struct proc_dir_entry* lprocfs_mkinitdir(struct obd_device* device);
608 int lprocfs_get_idx(struct namespace_index* class, const char* dir_name);
609 unsigned int lprocfs_add_var(struct obd_device* device,
610 struct proc_dir_entry* root,
611 lprocfs_vars_t* variable,
614 unsigned int cnt_arr_size,
618 void lprocfs_remove_all(struct proc_dir_entry* root);
621 * List of read/write functions that will implement reading
622 * or writing to counters/other variables from userland
623 * processes. Note that the definition allows as many different
624 * functions to be defined as there are counter-variables.
625 * In practice, however, the module implementor is expected
626 * to have a different function only when the variable types are
627 * different, for e.g counter types will have one read/write
628 * function, while strings will have another.
632 int lprocfs_ll_rd(char* page, char **start, off_t off,
633 int count, int *eof, void *data);
634 int lprocfs_ll_wr(struct file* file, const char *buffer,
635 unsigned long count, void *data);
637 int rd_other(char* page, char **start, off_t off,
638 int count, int *eof, void *data);
639 int wr_other(struct file* file, const char *buffer,
640 unsigned long count, void *data);
642 int rd_string(char* page, char **start, off_t off,
643 int count, int *eof, void *data);
644 int wr_string(struct file* file, const char *buffer,
645 unsigned long count, void *data);
650 #else /* LProcFS not compiled */
652 #define DEV_PROF_START(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) 0
653 #define DEV_PROF_END(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) 0
654 #define DEV_PRINT_CNTR(DEV_CLASS, OBD, PROF_CLASS, ATTRIBUTE) 0
656 static inline int lprocfs_get_nm(char* name,
657 lprocfs_obd_nm_t* collection)
661 static inline int lprocfs_reg_dev(struct obd_device* device,
662 lprocfs_group_t* namespace,
663 unsigned int cnt_struct_size)
667 static inline int lprocfs_dereg_dev(struct obd_device* device)
669 return LPROCFS_SUCCESS;
671 static inline int lprocfs_reg_conn(unsigned int conn_number,
672 struct lprocfs_conn_namespace* nm)
676 static inline int lprocfs_dereg_conn(unsigned int conn_number)
680 static inline int lprocfs_add_export(unsigned int conn_number,
681 struct obd_device* device)
685 static inline int lprocfs_add_import(unsigned int conn_number,
686 struct obd_device* device)
690 static inline int lprocfs_remove_export(unsigned int conn_number,
691 struct obd_device* device)
695 static inline int lprocfs_remove_import(unsigned int conn_number,
696 struct obd_device* device)
702 #endif /* LPROCFS_EXISTS */
704 #endif /* __LPROCFS_H__ */