Backport DIM insterface
authorVladimir Sokolovsky <vlad@mellanox.com>
Wed, 4 Sep 2019 23:22:22 +0000 (18:22 -0500)
committerVladimir Sokolovsky <vlad@mellanox.com>
Wed, 4 Sep 2019 23:22:22 +0000 (18:22 -0500)
Signed-off-by: Vladimir Sokolovsky <vlad@mellanox.com>
compat/Makefile
compat/dim.c [new file with mode: 0644]
include/linux/compat-2.6.h
include/linux/compat-4.14.h [new file with mode: 0644]
include/linux/dim.h
include/linux/gfp.h [new file with mode: 0644]

index 5b35cf0..2f55924 100644 (file)
@@ -15,6 +15,7 @@ compat-$(CONFIG_COMPAT_KERNEL_4_16) += compat-4.16.o
 compat-$(CONFIG_COMPAT_KERNEL_5_2) += compat-5.2.o
 
 compat-$(CONFIG_COMPAT_KERNEL_5_2) += xarray.o
+compat-$(CONFIG_COMPAT_KERNEL_5_2) += dim.o
 compat-$(CONFIG_COMPAT_KERNEL_5_2) += rdma_dim.o
 compat-y += uuid.o
 compat-y += rhashtable.o
diff --git a/compat/dim.c b/compat/dim.c
new file mode 100644 (file)
index 0000000..ddad4a3
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * Copyright (c) 2019, Mellanox Technologies inc.  All rights reserved.
+ */
+
+#include <linux/dim.h>
+
+void dim_turn(struct dim *dim)
+{
+       switch (dim->tune_state) {
+       case DIM_PARKING_ON_TOP:
+       case DIM_PARKING_TIRED:
+               break;
+       case DIM_GOING_RIGHT:
+               dim->tune_state = DIM_GOING_LEFT;
+               dim->steps_left = 0;
+               break;
+       case DIM_GOING_LEFT:
+               dim->tune_state = DIM_GOING_RIGHT;
+               dim->steps_right = 0;
+               break;
+       }
+}
+EXPORT_SYMBOL(dim_turn);
+
+void dim_calc_stats(struct dim_sample *start, struct dim_sample *end,
+                   struct dim_stats *curr_stats)
+{
+       /* u32 holds up to 71 minutes, should be enough */
+       u32 delta_us = ktime_us_delta(end->time, start->time);
+       u32 npkts = BIT_GAP(BITS_PER_TYPE(u32), end->pkt_ctr, start->pkt_ctr);
+       u32 nbytes = BIT_GAP(BITS_PER_TYPE(u32), end->byte_ctr,
+                            start->byte_ctr);
+       u32 ncomps = BIT_GAP(BITS_PER_TYPE(u32), end->comp_ctr,
+                            start->comp_ctr);
+
+       if (!delta_us)
+               return;
+
+       curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
+       curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
+       curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
+                                       delta_us);
+       curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
+       if (curr_stats->epms != 0)
+               curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL(
+                       curr_stats->cpms * 100, curr_stats->epms);
+       else
+               curr_stats->cpe_ratio = 0;
+
+}
+EXPORT_SYMBOL(dim_calc_stats);
index 1a46957..f43fe71 100644 (file)
@@ -58,6 +58,7 @@ void backport_dependency_symbol(void);
 #include <linux/compat-4.5.h>
 #include <linux/compat-4.9.h>
 #include <linux/compat-4.11.h>
+#include <linux/compat-4.14.h>
 #include <linux/compat-4.16.h>
 #include <linux/compat-4.17.h>
 #include <linux/compat-5.1.h>
diff --git a/include/linux/compat-4.14.h b/include/linux/compat-4.14.h
new file mode 100644 (file)
index 0000000..d1ff44d
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef LINUX_4_14_COMPAT_H
+#define LINUX_4_14_COMPAT_H
+
+#include <linux/version.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0))
+#include <linux/kernel.h>
+
+#define DIV_ROUND_DOWN_ULL(ll, d) \
+       ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
+
+#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)) */
+
+#endif /* LINUX_4_14_COMPAT_H */
index 2f07555..4de1da5 100644 (file)
@@ -207,24 +207,6 @@ bool dim_on_top(struct dim *dim);
  */
 void dim_turn(struct dim *dim);
 
-/**
- *     dim_park_on_top - enter a parking state on a top location
- *     @dim: DIM context
- *
- * Enter parking state.
- * Clear all movement history.
- */
-void dim_park_on_top(struct dim *dim);
-
-/**
- *     dim_park_tired - enter a tired parking state
- *     @dim: DIM context
- *
- * Enter parking state.
- * Clear all movement history and cause DIM checks frequency to reduce.
- */
-void dim_park_tired(struct dim *dim);
-
 /**
  *     dim_calc_stats - calculate the difference between two samples
  *     @start: start sample
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
new file mode 100644 (file)
index 0000000..6453cf7
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef _COMPAT_LINUX_GFP_H
+#define _COMPAT_LINUX_GFP_H
+
+#include "../../compat/config.h"
+#include <linux/version.h>
+
+#include_next <linux/gfp.h>
+#ifndef __GFP_ACCOUNT
+#define ___GFP_ACCOUNT          0x100000u
+#define __GFP_ACCOUNT   ((__force gfp_t)___GFP_ACCOUNT)
+#endif
+#ifndef __GFP_MEMALLOC
+#define __GFP_MEMALLOC 0
+#endif
+
+
+#ifndef HAVE_GFP_DIRECT_RECLAIM
+#define ___GFP_DIRECT_RECLAIM  0x400u
+#define __GFP_DIRECT_RECLAIM   ((__force gfp_t)___GFP_DIRECT_RECLAIM) /* Caller can reclaim */
+#endif
+#ifndef HAVE_GFPFLAGES_ALLOW_BLOCKING
+static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
+{
+       return !!(gfp_flags & __GFP_DIRECT_RECLAIM);
+}
+#endif
+#endif /* _COMPAT_LINUX_GFP_H */