4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/include/lprocfs_status.h
34 * Top level header file for LProc SNMP
36 * Author: Hariharan Thantry thantry@users.sourceforge.net
38 #ifndef _LPROCFS_SNMP_H
39 #define _LPROCFS_SNMP_H
41 #include <linux/debugfs.h>
42 #include <linux/seq_file.h>
43 #include <linux/spinlock.h>
44 #include <linux/types.h>
46 #include "lustre/lustre_idl.h"
50 struct file_operations
*fops
;
58 struct lprocfs_static_vars
{
59 struct lprocfs_vars
*obd_vars
;
60 struct attribute_group
*sysfs_vars
;
63 /* if we find more consumers this could be generalized */
64 #define OBD_HIST_MAX 32
65 struct obd_histogram
{
67 unsigned long oh_buckets
[OBD_HIST_MAX
];
89 struct obd_histogram hist
[BRW_LAST
];
93 RENAME_SAMEDIR_SIZE
= 0,
94 RENAME_CROSSDIR_SRC_SIZE
,
95 RENAME_CROSSDIR_TGT_SIZE
,
100 struct obd_histogram hist
[RENAME_LAST
];
103 /* An lprocfs counter can be configured using the enum bit masks below.
105 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
106 * protects this counter from concurrent updates. If not specified,
107 * lprocfs an internal per-counter lock variable. External locks are
108 * not used to protect counter increments, but are used to protect
109 * counter readout and resets.
111 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
112 * (i.e. counter can be incremented by more than "1"). When specified,
113 * the counter maintains min, max and sum in addition to a simple
114 * invocation count. This allows averages to be be computed.
115 * If not specified, the counter is an increment-by-1 counter.
116 * min, max, sum, etc. are not maintained.
118 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
119 * squares (for multi-valued counter samples only). This allows
120 * external computation of standard deviation, but involves a 64-bit
121 * multiply per counter increment.
125 LPROCFS_CNTR_EXTERNALLOCK
= 0x0001,
126 LPROCFS_CNTR_AVGMINMAX
= 0x0002,
127 LPROCFS_CNTR_STDDEV
= 0x0004,
129 /* counter data type */
130 LPROCFS_TYPE_REGS
= 0x0100,
131 LPROCFS_TYPE_BYTES
= 0x0200,
132 LPROCFS_TYPE_PAGES
= 0x0400,
133 LPROCFS_TYPE_CYCLE
= 0x0800,
136 #define LC_MIN_INIT ((~(__u64)0) >> 1)
138 struct lprocfs_counter_header
{
139 unsigned int lc_config
;
140 const char *lc_name
; /* must be static */
141 const char *lc_units
; /* must be static */
144 struct lprocfs_counter
{
150 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
151 * for irq context counter, i.e. stats with
152 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
155 __s64 lc_array_sum
[1];
158 #define lc_sum lc_array_sum[0]
159 #define lc_sum_irq lc_array_sum[1]
161 struct lprocfs_percpu
{
165 struct lprocfs_counter lp_cntr
[0];
168 #define LPROCFS_GET_NUM_CPU 0x0001
169 #define LPROCFS_GET_SMP_ID 0x0002
171 enum lprocfs_stats_flags
{
172 LPROCFS_STATS_FLAG_NONE
= 0x0000, /* per cpu counter */
173 LPROCFS_STATS_FLAG_NOPERCPU
= 0x0001, /* stats have no percpu
174 * area and need locking
176 LPROCFS_STATS_FLAG_IRQ_SAFE
= 0x0002, /* alloc need irq safe */
179 enum lprocfs_fields_flags
{
180 LPROCFS_FIELDS_FLAGS_CONFIG
= 0x0001,
181 LPROCFS_FIELDS_FLAGS_SUM
= 0x0002,
182 LPROCFS_FIELDS_FLAGS_MIN
= 0x0003,
183 LPROCFS_FIELDS_FLAGS_MAX
= 0x0004,
184 LPROCFS_FIELDS_FLAGS_AVG
= 0x0005,
185 LPROCFS_FIELDS_FLAGS_SUMSQUARE
= 0x0006,
186 LPROCFS_FIELDS_FLAGS_COUNT
= 0x0007,
189 struct lprocfs_stats
{
191 unsigned short ls_num
;
192 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
193 unsigned short ls_biggest_alloc_num
;
194 enum lprocfs_stats_flags ls_flags
;
195 /* Lock used when there are no percpu stats areas; For percpu stats,
196 * it is used to protect ls_biggest_alloc_num change
200 /* has ls_num of counter headers */
201 struct lprocfs_counter_header
*ls_cnt_header
;
202 struct lprocfs_percpu
*ls_percpu
[0];
205 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
207 /* Pack all opcodes down into a single monotonically increasing index */
208 static inline int opcode_offset(__u32 opc
)
210 if (opc
< OST_LAST_OPC
) {
212 return (opc
- OST_FIRST_OPC
);
213 } else if (opc
< MDS_LAST_OPC
) {
215 return (opc
- MDS_FIRST_OPC
+
217 } else if (opc
< LDLM_LAST_OPC
) {
219 return (opc
- LDLM_FIRST_OPC
+
222 } else if (opc
< MGS_LAST_OPC
) {
224 return (opc
- MGS_FIRST_OPC
+
228 } else if (opc
< OBD_LAST_OPC
) {
230 return (opc
- OBD_FIRST_OPC
+
235 } else if (opc
< LLOG_LAST_OPC
) {
237 return (opc
- LLOG_FIRST_OPC
+
243 } else if (opc
< QUOTA_LAST_OPC
) {
245 return (opc
- QUOTA_FIRST_OPC
+
252 } else if (opc
< SEQ_LAST_OPC
) {
254 return (opc
- SEQ_FIRST_OPC
+
262 } else if (opc
< SEC_LAST_OPC
) {
264 return (opc
- SEC_FIRST_OPC
+
273 } else if (opc
< FLD_LAST_OPC
) {
275 return (opc
- FLD_FIRST_OPC
+
291 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
302 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
306 PTLRPC_REQWAIT_CNTR
= 0,
307 PTLRPC_REQQDEPTH_CNTR
,
308 PTLRPC_REQACTIVE_CNTR
,
310 PTLRPC_REQBUF_AVAIL_CNTR
,
314 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
317 LDLM_GLIMPSE_ENQUEUE
= 0,
334 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
336 extern struct dentry
*debugfs_lustre_root
;
337 extern struct kobject
*lustre_kobj
;
340 struct obd_histogram
;
342 /* Days / hours / mins / seconds format */
347 static inline void s2dhms(struct dhms
*ts
, time64_t secs64
)
351 ts
->d
= div_u64_rem(secs64
, 86400, &secs
);
358 #define DHMS_FMT "%dd%dh%02dm%02ds"
359 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
361 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
362 #define JOBSTATS_DISABLE "disable"
363 #define JOBSTATS_PROCNAME_UID "procname_uid"
364 #define JOBSTATS_NODELOCAL "nodelocal"
366 int lprocfs_write_frac_helper(const char __user
*buffer
,
367 unsigned long count
, int *val
, int mult
);
368 int lprocfs_read_frac_helper(char *buffer
, unsigned long count
,
370 int lprocfs_stats_alloc_one(struct lprocfs_stats
*stats
, unsigned int cpuid
);
373 * < 0 : on error (only possible for opc as LPROCFS_GET_SMP_ID)
375 static inline int lprocfs_stats_lock(struct lprocfs_stats
*stats
, int opc
,
376 unsigned long *flags
)
384 case LPROCFS_GET_SMP_ID
:
385 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) {
386 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
387 spin_lock_irqsave(&stats
->ls_lock
, *flags
);
389 spin_lock(&stats
->ls_lock
);
392 unsigned int cpuid
= get_cpu();
394 if (unlikely(!stats
->ls_percpu
[cpuid
])) {
395 rc
= lprocfs_stats_alloc_one(stats
, cpuid
);
404 case LPROCFS_GET_NUM_CPU
:
405 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) {
406 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
407 spin_lock_irqsave(&stats
->ls_lock
, *flags
);
409 spin_lock(&stats
->ls_lock
);
412 return stats
->ls_biggest_alloc_num
;
416 static inline void lprocfs_stats_unlock(struct lprocfs_stats
*stats
, int opc
,
417 unsigned long *flags
)
423 case LPROCFS_GET_SMP_ID
:
424 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) {
425 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
426 spin_unlock_irqrestore(&stats
->ls_lock
, *flags
);
428 spin_unlock(&stats
->ls_lock
);
434 case LPROCFS_GET_NUM_CPU
:
435 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) {
436 if (stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
)
437 spin_unlock_irqrestore(&stats
->ls_lock
, *flags
);
439 spin_unlock(&stats
->ls_lock
);
445 static inline unsigned int
446 lprocfs_stats_counter_size(struct lprocfs_stats
*stats
)
448 unsigned int percpusize
;
450 percpusize
= offsetof(struct lprocfs_percpu
, lp_cntr
[stats
->ls_num
]);
452 /* irq safe stats need lc_array_sum[1] */
453 if ((stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0)
454 percpusize
+= stats
->ls_num
* sizeof(__s64
);
456 if ((stats
->ls_flags
& LPROCFS_STATS_FLAG_NOPERCPU
) == 0)
457 percpusize
= L1_CACHE_ALIGN(percpusize
);
462 static inline struct lprocfs_counter
*
463 lprocfs_stats_counter_get(struct lprocfs_stats
*stats
, unsigned int cpuid
,
466 struct lprocfs_counter
*cntr
;
468 cntr
= &stats
->ls_percpu
[cpuid
]->lp_cntr
[index
];
470 if ((stats
->ls_flags
& LPROCFS_STATS_FLAG_IRQ_SAFE
) != 0)
471 cntr
= (void *)cntr
+ index
* sizeof(__s64
);
476 /* Two optimized LPROCFS counter increment functions are provided:
477 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
478 * lprocfs_counter_add(cntr) - use for multi-valued counters
479 * Counter data layout allows config flag, counter lock and the
480 * count itself to reside within a single cache line.
483 void lprocfs_counter_add(struct lprocfs_stats
*stats
, int idx
, long amount
);
484 void lprocfs_counter_sub(struct lprocfs_stats
*stats
, int idx
, long amount
);
486 #define lprocfs_counter_incr(stats, idx) \
487 lprocfs_counter_add(stats, idx, 1)
488 #define lprocfs_counter_decr(stats, idx) \
489 lprocfs_counter_sub(stats, idx, 1)
491 __s64
lprocfs_read_helper(struct lprocfs_counter
*lc
,
492 struct lprocfs_counter_header
*header
,
493 enum lprocfs_stats_flags flags
,
494 enum lprocfs_fields_flags field
);
495 static inline __u64
lprocfs_stats_collector(struct lprocfs_stats
*stats
,
497 enum lprocfs_fields_flags field
)
500 unsigned int num_cpu
;
501 unsigned long flags
= 0;
506 num_cpu
= lprocfs_stats_lock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
507 for (i
= 0; i
< num_cpu
; i
++) {
508 if (!stats
->ls_percpu
[i
])
510 ret
+= lprocfs_read_helper(
511 lprocfs_stats_counter_get(stats
, i
, idx
),
512 &stats
->ls_cnt_header
[idx
], stats
->ls_flags
,
515 lprocfs_stats_unlock(stats
, LPROCFS_GET_NUM_CPU
, &flags
);
519 extern struct lprocfs_stats
*
520 lprocfs_alloc_stats(unsigned int num
, enum lprocfs_stats_flags flags
);
521 void lprocfs_clear_stats(struct lprocfs_stats
*stats
);
522 void lprocfs_free_stats(struct lprocfs_stats
**stats
);
523 void lprocfs_counter_init(struct lprocfs_stats
*stats
, int index
,
524 unsigned conf
, const char *name
, const char *units
);
526 int lprocfs_exp_cleanup(struct obd_export
*exp
);
527 struct dentry
*ldebugfs_add_simple(struct dentry
*root
,
530 struct file_operations
*fops
);
532 int ldebugfs_register_stats(struct dentry
*parent
,
534 struct lprocfs_stats
*stats
);
536 /* lprocfs_status.c */
537 int ldebugfs_add_vars(struct dentry
*parent
,
538 struct lprocfs_vars
*var
,
541 struct dentry
*ldebugfs_register(const char *name
,
542 struct dentry
*parent
,
543 struct lprocfs_vars
*list
,
546 void ldebugfs_remove(struct dentry
**entryp
);
548 int lprocfs_obd_setup(struct obd_device
*obd
, struct lprocfs_vars
*list
,
549 struct attribute_group
*attrs
);
550 int lprocfs_obd_cleanup(struct obd_device
*obd
);
552 int ldebugfs_seq_create(struct dentry
*parent
,
555 const struct file_operations
*seq_fops
,
557 int ldebugfs_obd_seq_create(struct obd_device
*dev
,
560 const struct file_operations
*seq_fops
,
563 /* Generic callbacks */
565 int lprocfs_rd_uint(struct seq_file
*m
, void *data
);
566 int lprocfs_wr_uint(struct file
*file
, const char __user
*buffer
,
567 unsigned long count
, void *data
);
568 int lprocfs_rd_server_uuid(struct seq_file
*m
, void *data
);
569 int lprocfs_rd_conn_uuid(struct seq_file
*m
, void *data
);
570 int lprocfs_rd_import(struct seq_file
*m
, void *data
);
571 int lprocfs_rd_state(struct seq_file
*m
, void *data
);
572 int lprocfs_rd_connect_flags(struct seq_file
*m
, void *data
);
574 struct adaptive_timeout
;
575 int lprocfs_at_hist_helper(struct seq_file
*m
, struct adaptive_timeout
*at
);
576 int lprocfs_rd_timeouts(struct seq_file
*m
, void *data
);
577 int lprocfs_wr_ping(struct file
*file
, const char __user
*buffer
,
578 size_t count
, loff_t
*off
);
579 int lprocfs_wr_import(struct file
*file
, const char __user
*buffer
,
580 size_t count
, loff_t
*off
);
581 int lprocfs_rd_pinger_recov(struct seq_file
*m
, void *n
);
582 int lprocfs_wr_pinger_recov(struct file
*file
, const char __user
*buffer
,
583 size_t count
, loff_t
*off
);
587 int lprocfs_write_helper(const char __user
*buffer
, unsigned long count
,
589 int lprocfs_write_u64_helper(const char __user
*buffer
,
590 unsigned long count
, __u64
*val
);
591 int lprocfs_write_frac_u64_helper(const char __user
*buffer
,
593 __u64
*val
, int mult
);
594 char *lprocfs_find_named_value(const char *buffer
, const char *name
,
596 void lprocfs_oh_tally(struct obd_histogram
*oh
, unsigned int value
);
597 void lprocfs_oh_tally_log2(struct obd_histogram
*oh
, unsigned int value
);
598 void lprocfs_oh_clear(struct obd_histogram
*oh
);
599 unsigned long lprocfs_oh_sum(struct obd_histogram
*oh
);
601 void lprocfs_stats_collect(struct lprocfs_stats
*stats
, int idx
,
602 struct lprocfs_counter
*cnt
);
604 int lprocfs_single_release(struct inode
*, struct file
*);
605 int lprocfs_seq_release(struct inode
*, struct file
*);
607 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
608 * proc entries; otherwise, you will define name##_seq_write function also for
609 * a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
610 * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
612 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
613 static int name##_single_open(struct inode *inode, struct file *file) \
615 return single_open(file, name##_seq_show, inode->i_private); \
617 static struct file_operations name##_fops = { \
618 .owner = THIS_MODULE, \
619 .open = name##_single_open, \
621 .write = custom_seq_write, \
622 .llseek = seq_lseek, \
623 .release = lprocfs_single_release, \
626 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
627 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
629 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
630 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
632 return lprocfs_rd_##type(m, m->private); \
634 LPROC_SEQ_FOPS_RO(name##_##type)
636 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
637 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
639 return lprocfs_rd_##type(m, m->private); \
641 static ssize_t name##_##type##_seq_write(struct file *file, \
642 const char __user *buffer, size_t count, \
645 struct seq_file *seq = file->private_data; \
646 return lprocfs_wr_##type(file, buffer, \
647 count, seq->private); \
649 LPROC_SEQ_FOPS(name##_##type)
651 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
652 static ssize_t name##_##type##_write(struct file *file, \
653 const char __user *buffer, size_t count, \
656 return lprocfs_wr_##type(file, buffer, count, off); \
658 static int name##_##type##_open(struct inode *inode, struct file *file) \
660 return single_open(file, NULL, inode->i_private); \
662 static struct file_operations name##_##type##_fops = { \
663 .open = name##_##type##_open, \
664 .write = name##_##type##_write, \
665 .release = lprocfs_single_release, \
669 struct attribute attr
;
670 ssize_t (*show
)(struct kobject
*kobj
, struct attribute
*attr
,
672 ssize_t (*store
)(struct kobject
*kobj
, struct attribute
*attr
,
673 const char *buf
, size_t len
);
676 #define LUSTRE_ATTR(name, mode, show, store) \
677 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
679 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
680 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
682 extern const struct sysfs_ops lustre_sysfs_ops
;
684 /* all quota proc functions */
685 int lprocfs_quota_rd_bunit(char *page
, char **start
,
686 loff_t off
, int count
,
687 int *eof
, void *data
);
688 int lprocfs_quota_wr_bunit(struct file
*file
, const char *buffer
,
689 unsigned long count
, void *data
);
690 int lprocfs_quota_rd_btune(char *page
, char **start
,
691 loff_t off
, int count
,
692 int *eof
, void *data
);
693 int lprocfs_quota_wr_btune(struct file
*file
, const char *buffer
,
694 unsigned long count
, void *data
);
695 int lprocfs_quota_rd_iunit(char *page
, char **start
,
696 loff_t off
, int count
,
697 int *eof
, void *data
);
698 int lprocfs_quota_wr_iunit(struct file
*file
, const char *buffer
,
699 unsigned long count
, void *data
);
700 int lprocfs_quota_rd_itune(char *page
, char **start
,
701 loff_t off
, int count
,
702 int *eof
, void *data
);
703 int lprocfs_quota_wr_itune(struct file
*file
, const char *buffer
,
704 unsigned long count
, void *data
);
705 int lprocfs_quota_rd_type(char *page
, char **start
, loff_t off
, int count
,
706 int *eof
, void *data
);
707 int lprocfs_quota_wr_type(struct file
*file
, const char *buffer
,
708 unsigned long count
, void *data
);
709 int lprocfs_quota_rd_switch_seconds(char *page
, char **start
, loff_t off
,
710 int count
, int *eof
, void *data
);
711 int lprocfs_quota_wr_switch_seconds(struct file
*file
,
713 unsigned long count
, void *data
);
714 int lprocfs_quota_rd_sync_blk(char *page
, char **start
, loff_t off
,
715 int count
, int *eof
, void *data
);
716 int lprocfs_quota_wr_sync_blk(struct file
*file
, const char *buffer
,
717 unsigned long count
, void *data
);
718 int lprocfs_quota_rd_switch_qs(char *page
, char **start
, loff_t off
,
719 int count
, int *eof
, void *data
);
720 int lprocfs_quota_wr_switch_qs(struct file
*file
,
721 const char *buffer
, unsigned long count
,
723 int lprocfs_quota_rd_boundary_factor(char *page
, char **start
, loff_t off
,
724 int count
, int *eof
, void *data
);
725 int lprocfs_quota_wr_boundary_factor(struct file
*file
,
726 const char *buffer
, unsigned long count
,
728 int lprocfs_quota_rd_least_bunit(char *page
, char **start
, loff_t off
,
729 int count
, int *eof
, void *data
);
730 int lprocfs_quota_wr_least_bunit(struct file
*file
,
731 const char *buffer
, unsigned long count
,
733 int lprocfs_quota_rd_least_iunit(char *page
, char **start
, loff_t off
,
734 int count
, int *eof
, void *data
);
735 int lprocfs_quota_wr_least_iunit(struct file
*file
,
736 const char *buffer
, unsigned long count
,
738 int lprocfs_quota_rd_qs_factor(char *page
, char **start
, loff_t off
,
739 int count
, int *eof
, void *data
);
740 int lprocfs_quota_wr_qs_factor(struct file
*file
,
741 const char *buffer
, unsigned long count
,
743 #endif /* LPROCFS_SNMP_H */