Whamcloud - gitweb
- warn if HMAC's don't match
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
index a10a273..b70efe1 100644 (file)
@@ -35,9 +35,6 @@ static struct lprocfs_vars lprocfs_obd_vars[]  = { {0} };
 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
 #else
 
-#define OSC_MAX_RIF_MAX 32
-#define OSC_MAX_DIRTY_MB_MAX 4096 /* totally arbitrary */
-
 int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off, int count,
                              int *eof, void *data)
 {
@@ -62,7 +59,7 @@ int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
-        if (val < 1 || val > PTL_MD_MAX_PAGES)
+        if (val < 1 || val > PTLRPC_MAX_BRW_PAGES)
                 return -ERANGE;
 
         spin_lock(&cli->cl_loi_list_lock);
@@ -80,7 +77,7 @@ int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off, int count,
         int rc;
 
         spin_lock(&cli->cl_loi_list_lock);
-        rc = snprintf(page, count, "%d\n", cli->cl_max_rpcs_in_flight);
+        rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
         spin_unlock(&cli->cl_loi_list_lock);
         return rc;
 }
@@ -111,14 +108,13 @@ int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
 {
         struct obd_device *dev = data;
         struct client_obd *cli = &dev->u.cli;
-        int val;
-        int rc;
+        unsigned val;
 
         spin_lock(&cli->cl_loi_list_lock);
         val = cli->cl_dirty_max >> 20;
-        rc = snprintf(page, count, "%d\n", val);
         spin_unlock(&cli->cl_loi_list_lock);
-        return rc;
+
+        return snprintf(page, count, "%u\n", val);
 }
 
 int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
@@ -132,12 +128,13 @@ int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
-        if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX)
+        if (val < 0 || val > OSC_MAX_DIRTY_MB_MAX ||
+            val > num_physpages >> (20 - PAGE_SHIFT - 2)) /* 1/4 of RAM */
                 return -ERANGE;
 
         spin_lock(&cli->cl_loi_list_lock);
         cli->cl_dirty_max = (obd_count)val * 1024 * 1024;
-        osc_adjust_cache(cli);
+        osc_wake_cache_waiters(cli);
         spin_unlock(&cli->cl_loi_list_lock);
 
         return count;
@@ -151,133 +148,22 @@ int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off, int count,
         int rc;
 
         spin_lock(&cli->cl_loi_list_lock);
-        rc = snprintf(page, count, LPU64"\n", cli->cl_dirty);
+        rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
         spin_unlock(&cli->cl_loi_list_lock);
         return rc;
 }
 
-int osc_rd_create_low_wm(char *page, char **start, off_t off, int count,
-                         int *eof, void *data)
-{
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        spin_unlock(&obd->obd_dev_lock);
-
-        return snprintf(page, count, "%d\n",
-                        exp->exp_osc_data.oed_oscc.oscc_kick_barrier);
-}
-
-int osc_wr_create_low_wm(struct file *file, const char *buffer,
-                         unsigned long count, void *data)
-{
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-        int val, rc;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
-
-        if (val < 0)
-                return -ERANGE;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        exp->exp_osc_data.oed_oscc.oscc_kick_barrier = val;
-        spin_unlock(&obd->obd_dev_lock);
-
-        return count;
-}
-
-int osc_rd_create_count(char *page, char **start, off_t off, int count,
-                        int *eof, void *data)
-{
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        spin_unlock(&obd->obd_dev_lock);
-
-        return snprintf(page, count, "%d\n",
-                        exp->exp_osc_data.oed_oscc.oscc_grow_count);
-}
-
-int osc_wr_create_count(struct file *file, const char *buffer,
-                        unsigned long count, void *data)
-{
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-        int val, rc;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
-
-        if (val < 0)
-                return -ERANGE;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        exp->exp_osc_data.oed_oscc.oscc_grow_count = val;
-        spin_unlock(&obd->obd_dev_lock);
-
-        return count;
-}
-
-int osc_rd_prealloc_next_id(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
-{
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        spin_unlock(&obd->obd_dev_lock);
-
-        return snprintf(page, count, LPU64"\n",
-                        exp->exp_osc_data.oed_oscc.oscc_next_id);
-}
-
-int osc_rd_prealloc_last_id(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
+int osc_rd_cur_grant_bytes(char *page, char **start, off_t off, int count,
+                           int *eof, void *data)
 {
-        struct obd_device *obd = data;
-        struct obd_export *exp;
-
-        if (obd == NULL || list_empty(&obd->obd_exports))
-                return 0;
-
-        spin_lock(&obd->obd_dev_lock);
-        exp = list_entry(obd->obd_exports.next, struct obd_export,
-                         exp_obd_chain);
-        spin_unlock(&obd->obd_dev_lock);
+        struct obd_device *dev = data;
+        struct client_obd *cli = &dev->u.cli;
+        int rc;
 
-        return snprintf(page, count, LPU64"\n",
-                        exp->exp_osc_data.oed_oscc.oscc_last_id);
+        spin_lock(&cli->cl_loi_list_lock);
+        rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
+        spin_unlock(&cli->cl_loi_list_lock);
+        return rc;
 }
 
 static struct lprocfs_vars lprocfs_obd_vars[] = {
@@ -285,21 +171,19 @@ static struct lprocfs_vars lprocfs_obd_vars[] = {
         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
+        { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
-        { "max_pages_per_rpc", osc_rd_max_pages_per_rpc, 
+        { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
                                osc_wr_max_pages_per_rpc, 0 },
-        { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight, 
+        { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
                                 osc_wr_max_rpcs_in_flight, 0 },
         { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
-        {"create_low_watermark", osc_rd_create_low_wm, osc_wr_create_low_wm, 0},
-        { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
-        { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
-        { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
+        { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
         { 0 }
 };
 
@@ -310,32 +194,50 @@ static struct lprocfs_vars lprocfs_module_vars[] = {
 
 #define pct(a,b) (b ? a * 100 / b : 0)
 
+#define PRINTF_STIME(stime) (unsigned long)(stime)->st_num,     \
+        lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
+
 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 {
-        struct timeval now;
+        unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
         struct obd_device *dev = seq->private;
         struct client_obd *cli = &dev->u.cli;
+        unsigned long gap_av, wait_av;
         unsigned long flags;
-        unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
-        int i, rpcs, r, w;
+        struct timeval now;
+        int i;
 
         do_gettimeofday(&now);
 
         spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
 
-        rpcs = cli->cl_brw_in_flight;
-        r = cli->cl_pending_r_pages;
-        w = cli->cl_pending_w_pages;
-                                                                                
-        seq_printf(seq, "snapshot_time:         %lu:%lu (secs:usecs)\n",
+        wait_av = cli->cl_cache_wait_num ?
+                cli->cl_cache_wait_sum / cli->cl_cache_wait_num : 0;
+        
+        gap_av = cli->cl_write_gaps ?
+                cli->cl_write_gap_sum / cli->cl_write_gaps : 0;
+
+        seq_printf(seq, "snapshot_time:        %lu.%lu (secs.usecs)\n",
                    now.tv_sec, now.tv_usec);
-        seq_printf(seq, "RPCs in flight:        %d\n", rpcs);
-        seq_printf(seq, "pending write pages:   %d\n", w);
-        seq_printf(seq, "pending read pages:   %d\n", r);
+
+        seq_printf(seq, "read RPCs in flight:  %d\n",
+                   cli->cl_r_in_flight);
+        seq_printf(seq, "write RPCs in flight: %d\n",
+                   cli->cl_w_in_flight);
+        seq_printf(seq, "pending write pages:  %d\n",
+                   cli->cl_pending_w_pages);
+        seq_printf(seq, "pending read pages:   %d\n",
+                   cli->cl_pending_r_pages);
+
+        /* cache or grant waiting stats */
+        seq_printf(seq, "write waits num:      %lu\n",
+                   cli->cl_cache_wait_num);
+        seq_printf(seq, "av. wait time:        %lu (usec)\n",
+                   wait_av);
 
         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
-        seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
-        seq_printf(seq, "       rpcs   %% cum %%\n");
+        seq_printf(seq, "pages per RPC         RPCs   %% cum %% |");
+        seq_printf(seq, "       RPCs   %% cum %%\n");
 
         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
@@ -347,18 +249,24 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
                 read_cum += r;
                 write_cum += w;
-                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n", 
-                                 1 << i, r, pct(r, read_tot), 
-                                 pct(read_cum, read_tot), w, 
+                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
+                                 1 << i, r, pct(r, read_tot),
+                                 pct(read_cum, read_tot), w,
                                  pct(w, write_tot),
                                  pct(write_cum, write_tot));
                 if (read_cum == read_tot && write_cum == write_tot)
                         break;
         }
 
+        /* different RPC related stats like av gap time between two write RPCs,
+         * number of sync RPCs, etc. */
+        seq_printf(seq, "\nsync RPCs:            %lu\n", cli->cl_sync_rpcs);
+        seq_printf(seq, "write gaps:           %lu\n", cli->cl_write_gaps);
+        seq_printf(seq, "av. gap time:         %lu (usec)\n", gap_av);
+        
         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
-        seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
-        seq_printf(seq, "       rpcs   %% cum %%\n");
+        seq_printf(seq, "RPCs in flight        RPCs   %% cum %% |");
+        seq_printf(seq, "       RPCs   %% cum %%\n");
 
         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
@@ -370,20 +278,29 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
                 read_cum += r;
                 write_cum += w;
-                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n", 
-                                 i, r, pct(r, read_tot), 
-                                 pct(read_cum, read_tot), w, 
+                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
+                                 i, r, pct(r, read_tot),
+                                 pct(read_cum, read_tot), w,
                                  pct(w, write_tot),
                                  pct(write_cum, write_tot));
                 if (read_cum == read_tot && write_cum == write_tot)
                         break;
         }
 
+        seq_printf(seq, "\nRPC service time: (RPCs, average ms)\n");
+        seq_printf(seq, "\tread\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&cli->cl_read_stime));
+        seq_printf(seq, "\twrite\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&cli->cl_write_stime));
+
+        seq_printf(seq, "app waiting: (num, average ms)\n");
+        seq_printf(seq, "\tenter cache\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&cli->cl_enter_stime));
+
         spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
 
         return 0;
 }
-#undef pct
 
 static void *osc_rpc_stats_seq_start(struct seq_file *p, loff_t *pos)
 {
@@ -399,6 +316,7 @@ static void *osc_rpc_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
 static void osc_rpc_stats_seq_stop(struct seq_file *p, void *v)
 {
 }
+
 struct seq_operations osc_rpc_stats_seq_sops = {
         .start = osc_rpc_stats_seq_start,
         .stop = osc_rpc_stats_seq_stop,
@@ -408,10 +326,10 @@ struct seq_operations osc_rpc_stats_seq_sops = {
 
 static int osc_rpc_stats_seq_open(struct inode *inode, struct file *file)
 {
-        struct proc_dir_entry *dp = inode->u.generic_ip;
+        struct proc_dir_entry *dp = PDE(inode);
         struct seq_file *seq;
         int rc;
+
         rc = seq_open(file, &osc_rpc_stats_seq_sops);
         if (rc)
                 return rc;
@@ -432,10 +350,22 @@ static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
         lprocfs_oh_clear(&cli->cl_read_page_hist);
         lprocfs_oh_clear(&cli->cl_write_page_hist);
 
+        memset(&cli->cl_read_stime, 0, sizeof(cli->cl_read_stime));
+        memset(&cli->cl_write_stime, 0, sizeof(cli->cl_write_stime));
+        memset(&cli->cl_enter_stime, 0, sizeof(cli->cl_enter_stime));
+
+        cli->cl_cache_wait_num = 0;
+        cli->cl_cache_wait_sum = 0;
+        cli->cl_write_gap_sum = 0;
+        cli->cl_write_gaps = 0;
+        cli->cl_write_num = 0;
+        cli->cl_read_num = 0;
+
         return len;
 }
 
 struct file_operations osc_rpc_stats_fops = {
+        .owner   = THIS_MODULE,
         .open    = osc_rpc_stats_seq_open,
         .read    = seq_read,
         .write   = osc_rpc_stats_seq_write,
@@ -443,12 +373,116 @@ struct file_operations osc_rpc_stats_fops = {
         .release = seq_release,
 };
 
-int lproc_osc_attach_seqstat(struct obd_device *dev)
+/* cache stats */
+static int osc_cache_stats_seq_show(struct seq_file *seq, void *v)
+{
+        struct obd_device *dev = seq->private;
+        struct client_obd *cli = &dev->u.cli;
+        unsigned long flags;
+        struct timeval now;
+
+        do_gettimeofday(&now);
+
+        spin_lock_irqsave(&cli->cl_loi_list_lock, flags);
+
+        seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
+                   now.tv_sec, now.tv_usec);
+
+        seq_printf(seq, "cache size:            %lu (b)\n", cli->cl_dirty_max);
+        seq_printf(seq, "max loading:           %lu (b)\n", cli->cl_dirty_dmax);
+        seq_printf(seq, "min loading:           %lu (b)\n", cli->cl_dirty_dmin);
+        seq_printf(seq, "av. cache loading:     %lu (b)\n", cli->cl_dirty_av);
+
+        seq_printf(seq, "\nav. loading ratio:     %lu%%\n",
+                   pct(cli->cl_dirty_av, cli->cl_dirty_max));
+        seq_printf(seq, "max loading ratio:     %lu%%\n",
+                   pct(cli->cl_dirty_dmax, cli->cl_dirty_max));
+
+        spin_unlock_irqrestore(&cli->cl_loi_list_lock, flags);
+        
+        return 0;
+}
+#undef pct
+
+static void *osc_cache_stats_seq_start(struct seq_file *p, loff_t *pos)
+{
+        if (*pos == 0)
+                return (void *)1;
+        return NULL;
+}
+static void *osc_cache_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
+{
+        ++*pos;
+        return NULL;
+}
+static void osc_cache_stats_seq_stop(struct seq_file *p, void *v)
+{
+}
+
+struct seq_operations osc_cache_stats_seq_sops = {
+        .start = osc_cache_stats_seq_start,
+        .stop = osc_cache_stats_seq_stop,
+        .next = osc_cache_stats_seq_next,
+        .show = osc_cache_stats_seq_show,
+};
+
+static int osc_cache_stats_seq_open(struct inode *inode, struct file *file)
 {
-        return lprocfs_obd_seq_create(dev, "rpc_stats", 0444, 
-                                      &osc_rpc_stats_fops, dev);
+        struct proc_dir_entry *dp = PDE(inode);
+        struct seq_file *seq;
+        int rc;
+
+        rc = seq_open(file, &osc_cache_stats_seq_sops);
+        if (rc)
+                return rc;
+        seq = file->private_data;
+        seq->private = dp->data;
+        return 0;
 }
 
+static ssize_t osc_cache_stats_seq_write(struct file *file, const char *buf,
+                                         size_t len, loff_t *off)
+{
+        struct seq_file *seq = file->private_data;
+        struct obd_device *dev = seq->private;
+        struct client_obd *cli = &dev->u.cli;
+
+        cli->cl_dirty_num = 0;
+        cli->cl_dirty_sum = 0;
+        cli->cl_dirty_av = 0;
+        cli->cl_dirty_dmax = 0;
+        cli->cl_dirty_dmin = 0;
+
+        return len;
+}
+
+struct file_operations osc_cache_stats_fops = {
+        .owner   = THIS_MODULE,
+        .open    = osc_cache_stats_seq_open,
+        .read    = seq_read,
+        .write   = osc_cache_stats_seq_write,
+        .llseek  = seq_lseek,
+        .release = seq_release,
+};
+
+int lproc_osc_attach_seqstat(struct obd_device *dev)
+{
+        int rc;
+        
+        rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
+                                    &osc_rpc_stats_fops, dev);
+        if (rc) {
+                CERROR("can't init \"rpc_stats\", err %d\n", rc);
+                return rc;
+        }
+
+        rc = lprocfs_obd_seq_create(dev, "cache_stats", 0444,
+                                    &osc_cache_stats_fops, dev);
+        if (rc)
+                CERROR("can't init \"cache_stats\", err %d\n", rc);
+
+        return rc;
+}
 
 #endif /* LPROCFS */
-LPROCFS_INIT_VARS(osc,lprocfs_module_vars, lprocfs_obd_vars)
+LPROCFS_INIT_VARS(osc, lprocfs_module_vars, lprocfs_obd_vars)