[Devel] [PATCH RHEL7 COMMIT] fuse/kio_pcs: adapt prometheus statistics to current vstorage state

Konstantin Khorenko khorenko at virtuozzo.com
Fri Apr 27 12:07:53 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.47.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.46.7
------>
commit 36b1455dfe00c44327fd78a4850cb627586f96b8
Author: Alexey Kuznetsov <kuznet at virtuozzo.com>
Date:   Fri Apr 27 12:07:53 2018 +0300

    fuse/kio_pcs: adapt prometheus statistics to current vstorage state
    
    Signed-off-by: Alexey Kuznetsov <kuznet at virtuozzo.com>
    Signed-off-by: Dmitry Monakhov <dmonakhov at openvz.org>
---
 fs/fuse/kio/pcs/fuse_prometheus_prot.h | 25 ++++++++++++++++---------
 fs/fuse/kio/pcs/pcs_cs.c               | 14 ++++----------
 fs/fuse/kio/pcs/pcs_fuse_kdirect.c     | 34 ++++++++++++++++------------------
 3 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/fs/fuse/kio/pcs/fuse_prometheus_prot.h b/fs/fuse/kio/pcs/fuse_prometheus_prot.h
index 254fae3ad1eb..e39f2337268f 100644
--- a/fs/fuse/kio/pcs/fuse_prometheus_prot.h
+++ b/fs/fuse/kio/pcs/fuse_prometheus_prot.h
@@ -1,23 +1,30 @@
 #ifndef __FUSE_PROMETHEUS_PROT__
 #define __FUSE_PROMETHEUS_PROT__ 1
 
-#define KFUSE_OP_READ		0
-#define KFUSE_OP_WRITE		1
-#define KFUSE_OP_FSYNC		2
-#define KFUSE_OP_FALLOCATE	3
-#define KFUSE_OP_MAX		4
+#define KFUSE_OP_CS_READ	0
+#define KFUSE_OP_CS_WRITE	1
+#define KFUSE_OP_CS_SYNC	2
+#define KFUSE_OP_CS_WRITE_HOLE	3
+#define KFUSE_OP_CS_WRITE_ZERO	4
+#define KFUSE_OP_CS_FIEMAP	5
 
-#define KFUSE_PROM_MAX		(9*5 + 1)
+#define KFUSE_OP_READ		6
+#define KFUSE_OP_WRITE		7
+#define KFUSE_OP_FSYNC		8
+#define KFUSE_OP_FALLOCATE	9
+#define KFUSE_OP_MAX		10
+
+#define KFUSE_PROM_MAX		(9*5 + 2)
 
 struct kfuse_stat_rec
 {
-	u64	value;
-	u64	count;
+	u64	buckets[KFUSE_PROM_MAX];
+	u64	sum;
 };
 
 struct kfuse_histogram
 {
-	struct kfuse_stat_rec	buckets[KFUSE_OP_MAX][KFUSE_PROM_MAX+1];
+	struct kfuse_stat_rec	metrics[KFUSE_OP_MAX];
 };
 
 #endif /* __FUSE_PROMETHEUS_PROT__ */
diff --git a/fs/fuse/kio/pcs/pcs_cs.c b/fs/fuse/kio/pcs/pcs_cs.c
index d6324d9a90f4..2752658bedab 100644
--- a/fs/fuse/kio/pcs/pcs_cs.c
+++ b/fs/fuse/kio/pcs/pcs_cs.c
@@ -234,21 +234,15 @@ struct pcs_cs *pcs_cs_find_create(struct pcs_cs_set *csset, PCS_NODE_ID_T *id, P
 	return cs;
 }
 
-static void (*io_times_logger_cb)(struct pcs_int_request *ireq, struct pcs_msg *resp, u32 max_iolat, void *ctx) = NULL;
-static void *io_times_logger_ctx = NULL;
-
-void cs_set_io_times_logger(void (*logger)(struct pcs_int_request *ireq, struct pcs_msg *resp, u32 max_iolat, void *ctx), void *ctx)
-{
-	io_times_logger_cb = logger;
-	io_times_logger_ctx = ctx;
-}
-
 void cs_log_io_times(struct pcs_int_request * ireq, struct pcs_msg * resp, unsigned int max_iolat)
 {
 	/* Ugly. Need to move fc ref to get rid of pcs_cluster_core */
 	struct fuse_conn * fc = container_of(ireq->cc, struct pcs_fuse_cluster, cc)->fc;
+	struct pcs_cs_iohdr * h = (struct pcs_cs_iohdr *)msg_inline_head(resp);
+	int reqt = h->hdr.type != PCS_CS_SYNC_RESP ? ireq->iochunk.direction : PCS_REQ_T_SYNC;
+
+	fuse_stat_account(fc, reqt, ktime_sub(ktime_get(), ireq->ts_sent));
 	if (fc->ktrace && fc->ktrace_level >= LOG_TRACE) {
-		struct pcs_cs_iohdr * h = (struct pcs_cs_iohdr *)msg_inline_head(resp);
 		int n = 1;
 		struct fuse_trace_hdr * t;
 
diff --git a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
index f35b8975a19b..bae89deffde2 100644
--- a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
+++ b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
@@ -1033,27 +1033,25 @@ void fuse_stat_account(struct fuse_conn * fc, int op, ktime_t val)
 		cpu = get_cpu();
 		histp = per_cpu_ptr(tr->prometheus_hist, cpu);
 		if (histp && *histp) {
-			struct kfuse_stat_rec * buckets = (*histp)->buckets[op];
-			struct kfuse_stat_rec * bucket;
+			struct kfuse_stat_rec * rec = (*histp)->metrics + op;
+			int bucket;
 			unsigned long long lat = ktime_to_ns(val)/1000;
 
 			if (lat < 1000)
-				bucket = buckets + (lat/100);
+				bucket = (lat/100);
 			else if (lat < 10000)
-				bucket = buckets + 9*1 + (lat/1000);
+				bucket = 9*1 + (lat/1000);
 			else if (lat < 100000)
-				bucket = buckets + 9*2 + (lat/10000);
+				bucket = 9*2 + (lat/10000);
 			else if (lat < 1000000)
-				bucket = buckets + 9*3 + (lat/100000);
+				bucket = 9*3 + (lat/100000);
 			else if (lat < 10000000)
-				bucket = buckets + 9*4 + (lat/1000000);
+				bucket = 9*4 + (lat/1000000);
 			else
-				bucket = buckets + 9*5;
+				bucket = 9*5 + 1;
 
-			bucket->value += lat;
-			bucket->count++;
-			buckets[KFUSE_PROM_MAX].value += lat;
-			buckets[KFUSE_PROM_MAX].count++;
+			rec->buckets[bucket]++;
+			rec->sum += lat;
 		}
 		put_cpu();
 	}
@@ -1088,10 +1086,10 @@ static ssize_t prometheus_file_read(struct file *filp,
 	struct kfuse_histogram * hist;
 	int cpu;
 
-	if (*ppos >= KFUSE_PROM_MAX*KFUSE_OP_MAX*sizeof(struct kfuse_stat_rec))
+	if (*ppos >= sizeof(struct kfuse_histogram))
 		return 0;
-	if (*ppos + count > KFUSE_PROM_MAX*KFUSE_OP_MAX*sizeof(struct kfuse_stat_rec))
-		count = KFUSE_PROM_MAX*KFUSE_OP_MAX*sizeof(struct kfuse_stat_rec) - *ppos;
+	if (*ppos + count > sizeof(struct kfuse_histogram))
+		count = sizeof(struct kfuse_histogram) - *ppos;
 
 	hist = (void*)get_zeroed_page(GFP_KERNEL);
 	if (!hist)
@@ -1107,10 +1105,10 @@ static ssize_t prometheus_file_read(struct file *filp,
 		if (histp && *histp) {
 			int i, k;
 			for (i = 0; i < KFUSE_OP_MAX; i++) {
-				for (k = 0; k < KFUSE_PROM_MAX + 1; k++) {
-					hist->buckets[i][k].value += (*histp)->buckets[i][k].value;
-					hist->buckets[i][k].count += (*histp)->buckets[i][k].count;
+				for (k = 0; k < KFUSE_PROM_MAX; k++) {
+					hist->metrics[i].buckets[k] += (*histp)->metrics[i].buckets[k];
 				}
+				hist->metrics[i].sum += (*histp)->metrics[i].sum;
 			}
 		}
 	}


More information about the Devel mailing list