Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / include / linux / lprocfs_status.h
index 14a713c..5ce5e98 100644 (file)
 #ifndef _LPROCFS_SNMP_H
 #define _LPROCFS_SNMP_H
 
+#ifdef __KERNEL__
 #include <linux/autoconf.h>
 #include <linux/proc_fs.h>
+#endif
 
 #ifndef LPROCFS
 #ifdef  CONFIG_PROC_FS  /* Ensure that /proc is configured */
@@ -34,7 +36,7 @@
 #endif
 
 struct lprocfs_vars {
-        char *name;
+        const char   *name;
         read_proc_t *read_fptr;
         write_proc_t *write_fptr;
         void *data;
@@ -45,12 +47,120 @@ struct lprocfs_static_vars {
         struct lprocfs_vars *obd_vars;
 };
 
+/* Lprocfs counters are can be configured using the enum bit masks below.
+ *
+ * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
+ * protects this counter from concurrent updates. If not specified,
+ * lprocfs an internal per-counter lock variable. External locks are
+ * not used to protect counter increments, but are used to protect
+ * counter readout and resets.
+ *
+ * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
+ * (i.e. counter can be incremented by more than "1"). When specified,
+ * the counter maintains min, max and sum in addition to a simple
+ * invocation count. This allows averages to be be computed.
+ * If not specified, the counter is an increment-by-1 counter.
+ * min, max, sum, etc. are not maintained.
+ *
+ * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
+ * squares (for multi-valued counter samples only). This allows
+ * external computation of standard deviation, but involves a 64-bit
+ * multiply per counter increment.
+ */
+
+enum {
+        LPROCFS_CNTR_EXTERNALLOCK = 1,
+        LPROCFS_CNTR_AVGMINMAX    = 2,
+        LPROCFS_CNTR_STDDEV       = 4,
+};
+
+struct lprocfs_counter {
+        union {
+                spinlock_t    internal; /* when there is no external lock */
+                spinlock_t   *external; /* external lock, when available */
+        } l;
+        unsigned int  config;
+        __u64         count;
+        __u64         sum;
+        __u64         min;
+        __u64         max;
+        __u64         sumsquare;
+        const char    *name;   /* must be static */
+        const char    *units;  /* must be static */
+};
+
+
+struct lprocfs_counters {
+        unsigned int           num;
+        unsigned int           padto8byteboundary;
+        struct lprocfs_counter cntr[0];
+};
+
+
 /* class_obd.c */
 extern struct proc_dir_entry *proc_lustre_root;
+struct obd_device;
 
-extern void lprocfs_init_vars(struct lprocfs_static_vars *var);
-extern void lprocfs_init_multi_vars(unsigned int idx, 
-                                    struct lprocfs_static_vars *var);
+#ifdef LPROCFS
+
+/* Two optimized LPROCFS counter increment macros are provided:
+ *     LPROCFS_COUNTER_INCR(cntr, value) - use for multi-valued counters
+ *     LPROCFS_COUNTER_INCBY1(cntr) - optimized for by-one counters
+ * Counter data layout allows config flag, counter lock and the
+ * count itself to reside within a single cache line.
+ */
+
+#define LPROCFS_COUNTER_INCR(cntr, value)                         \
+        do {                                                      \
+               struct lprocfs_counter *c = (cntr);                \
+               LASSERT(c != NULL);                                \
+               if (!(c->config & LPROCFS_CNTR_EXTERNALLOCK))      \
+                     spin_lock(&c->l.internal);                   \
+               c->count++;                                        \
+               if (c->config & LPROCFS_CNTR_AVGMINMAX) {          \
+                      __u64 val = (__u64) (value);                \
+                      c->sum += val;                              \
+                      if (c->config & LPROCFS_CNTR_STDDEV)        \
+                         c->sumsquare += (val*val);               \
+                      if (val < c->min) c->min = val;             \
+                      if (val > c->max) c->max = val;             \
+               }                                                  \
+               if (!(c->config & LPROCFS_CNTR_EXTERNALLOCK))      \
+                      spin_unlock(&c->l.internal);                \
+      } while (0)
+
+#define LPROCFS_COUNTER_INCBY1(cntr)                              \
+        do {                                                      \
+               struct lprocfs_counter *c = (cntr);                \
+               LASSERT(c != NULL);                                \
+               if (!(c->config & LPROCFS_CNTR_EXTERNALLOCK))      \
+                     spin_lock(&c->l.internal);                   \
+               c->count++;                                        \
+               if (!(c->config & LPROCFS_CNTR_EXTERNALLOCK))      \
+                      spin_unlock(&c->l.internal);                \
+      } while (0)
+
+#define LPROCFS_COUNTER_INIT(cntr, conf, lck, nam, un)                 \
+        do {                                                           \
+               struct lprocfs_counter *c = (cntr);                     \
+               LASSERT(c != NULL);                                     \
+               memset(c, 0, sizeof(struct lprocfs_counter));           \
+               if (conf & LPROCFS_CNTR_EXTERNALLOCK) c->l.external = (lck); \
+               else spin_lock_init(&c->l.internal);                    \
+               c->config = conf;                                       \
+               c->min = (~(__u64)0);                                   \
+               c->name = (nam);                                        \
+               c->units = (un);                                        \
+        } while (0)
+
+extern struct lprocfs_counters* lprocfs_alloc_counters(unsigned int num);
+extern void lprocfs_free_counters(struct lprocfs_counters* cntrs);
+extern int lprocfs_alloc_obd_counters(struct obd_device *obddev,
+                                      unsigned int num_private_counters);
+extern void lprocfs_free_obd_counters(struct obd_device *obddev);
+extern int lprocfs_register_counters(struct proc_dir_entry *root,
+                                     const char* name,
+                                     struct lprocfs_counters *cntrs);
 
 #define LPROCFS_INIT_MULTI_VARS(array, size)                              \
 void lprocfs_init_multi_vars(unsigned int idx,                            \
@@ -70,7 +180,9 @@ void lprocfs_init_vars(struct lprocfs_static_vars *x)  \
         x->obd_vars = vinstance;                       \
 }                                                      \
 
-#ifdef LPROCFS
+extern void lprocfs_init_vars(struct lprocfs_static_vars *var);
+extern void lprocfs_init_multi_vars(unsigned int idx,
+                                    struct lprocfs_static_vars *var);
 /* lprocfs_status.c */
 extern int lprocfs_add_vars(struct proc_dir_entry *root,
                             struct lprocfs_vars *var,
@@ -83,7 +195,6 @@ extern struct proc_dir_entry *lprocfs_register(const char *name,
 
 extern void lprocfs_remove(struct proc_dir_entry *root);
 
-struct obd_device;
 extern int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list);
 extern int lprocfs_obd_detach(struct obd_device *dev);
 
@@ -117,22 +228,53 @@ extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
                                  int count, int *eof, struct statfs *sfs);
 
-#define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)      \
-int fct_name(char *page, char **start, off_t off,                \
-             int count, int *eof, void *data)                    \
-{                                                                \
-        struct statfs sfs;                                       \
-        int rc = get_statfs_fct((struct obd_device*)data, &sfs); \
-        return (rc==0                                            \
-                ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
-                : rc);                                       \
+/* lprocfs_status.c: counter read/write functions */
+struct file;
+extern int lprocfs_counter_read(char *page, char **start, off_t off,
+                                int count, int *eof, void *data);
+extern int lprocfs_counter_write(struct file *file, const char *buffer,
+                                 unsigned long count, void *data);
+
+#define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)               \
+int fct_name(char *page, char **start, off_t off,                         \
+             int count, int *eof, void *data)                             \
+{                                                                         \
+        struct statfs sfs;                                                \
+        int rc = get_statfs_fct((struct obd_device*)data, &sfs);          \
+        return (rc == 0 ?                                                 \
+                lprocfs_##fct_name (page, start, off, count, eof, &sfs) : \
+                rc);                                                      \
 }
 
 #else
+/* LPROCFS is not defined */
+#define LPROCFS_COUNTER_INCR(cntr, value)
+#define LPROCFS_COUNTER_INCBY1(cntr)
+#define LPROCFS_COUNTER_INIT(cntr, conf, lock, nam, un)
+
+static inline struct lprocfs_counters* lprocfs_alloc_counters(unsigned int num)
+{ return NULL; }
+static inline void lprocfs_free_counters(struct lprocfs_counters* cntrs)
+{ return; }
+
+static inline int lprocfs_register_counters(struct proc_dir_entry *root,
+                                            const char* name,
+                                            struct lprocfs_counters *cntrs)
+{ return 0; }
+static inline int lprocfs_alloc_obd_counters(struct obd_device *obddev,
+                                             unsigned int num_private_counters)
+{ return 0; }
+static inline void lprocfs_free_obd_counters(struct obd_device *obddev)
+{ return; }
 
 static inline struct proc_dir_entry *
 lprocfs_register(const char *name, struct proc_dir_entry *parent,
                  struct lprocfs_vars *list, void *data) { return NULL; }
+#define LPROCFS_INIT_MULTI_VARS(array, size)
+static inline void lprocfs_init_multi_vars(unsigned int idx,
+                                           struct lprocfs_static_vars *x) { return; }
+#define LPROCFS_INIT_VARS(vclass, vinstance)
+static inline void lprocfs_init_vars(struct lprocfs_static_vars *x) { return; }
 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
                                    struct lprocfs_vars *var,
                                    void *data) { return 0; }
@@ -174,6 +316,13 @@ int lprocfs_rd_filesfree(char *page, char **start, off_t off,
 static inline
 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
                           int count, int *eof, struct statfs *sfs) { return 0; }
+static inline
+int lprocfs_counter_read(char *page, char **start, off_t off,
+                         int count, int *eof, void *data) { return 0; }
+struct file;
+static inline
+int lprocfs_counter_write(struct file *file, const char *buffer,
+                          unsigned long count, void *data) { return 0; }
 
 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)  \
 int fct_name(char *page, char **start, off_t off,            \