RDMA/mlx5: Extend ODP statistics with operation count
authorChiara Meiohas <cmeiohas@nvidia.com>
Tue, 3 Dec 2024 13:57:11 +0000 (15:57 +0200)
committerLeon Romanovsky <leon@kernel.org>
Tue, 10 Dec 2024 09:09:09 +0000 (04:09 -0500)
The current ODP counters represent the total number of pages
handled, but it is not enough to understand the effectiveness
of these operations.

Extend the ODP counters to include the number of times page fault
and invalidation events were handled.

Example for a single page fault handling 512 pages:
- page_fault: incremented by 512 (total pages)
- page_fault_handled: incremented by 1 (operation count)

The same example is applicable for page invalidation too.

Previous output:
$ rdma stat mr
dev rocep8s0f0 mrn 8 page_faults 27 page_invalidations 0 page_prefetch 29

New output:
$ rdma stat mr
dev rocep8s0f0 mrn 21 page_faults 512 page_faults_handled 1
page_invalidations 0 page_invalidations_handled 0 page_prefetch 51200

Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com>
Reviewed-by: Michael Guralnik <michaelgur@nvidia.com>
Link: https://patch.msgid.link/b18f29ed1392996ade66e9e6c45f018925253f6a.1733234165.git.leonro@nvidia.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/odp.c
drivers/infiniband/hw/mlx5/restrack.c
include/rdma/ib_verbs.h

index a01b592aa7168dc99d0eca781958bf689ca2e700..974a45c92fbb0d7008bbaa75b7d3921478a7a4c3 100644 (file)
@@ -669,6 +669,12 @@ struct mlx5_ib_mkey {
 #define mlx5_update_odp_stats(mr, counter_name, value)         \
        atomic64_add(value, &((mr)->odp_stats.counter_name))
 
+#define mlx5_update_odp_stats_with_handled(mr, counter_name, value)         \
+       do {                                                                \
+               mlx5_update_odp_stats(mr, counter_name, value);             \
+               atomic64_add(1, &((mr)->odp_stats.counter_name##_handled)); \
+       } while (0)
+
 struct mlx5_ib_mr {
        struct ib_mr ibmr;
        struct mlx5_ib_mkey mmkey;
index 4b37446758fd4efe5c776eef211038ee1abc4780..4eb03fc0d302284dd9df98cea038c3e1e835445b 100644 (file)
@@ -313,7 +313,7 @@ static bool mlx5_ib_invalidate_range(struct mmu_interval_notifier *mni,
                                     MLX5_IB_UPD_XLT_ZAP |
                                     MLX5_IB_UPD_XLT_ATOMIC);
 
-       mlx5_update_odp_stats(mr, invalidations, invalidations);
+       mlx5_update_odp_stats_with_handled(mr, invalidations, invalidations);
 
        /*
         * We are now sure that the device will not access the
@@ -997,7 +997,7 @@ next_mr:
                if (ret < 0)
                        goto end;
 
-               mlx5_update_odp_stats(mr, faults, ret);
+               mlx5_update_odp_stats_with_handled(mr, faults, ret);
 
                npages += ret;
                ret = 0;
@@ -1529,7 +1529,7 @@ static void mlx5_ib_mr_memory_pfault_handler(struct mlx5_ib_dev *dev,
                        goto err;
        }
 
-       mlx5_update_odp_stats(mr, faults, ret);
+       mlx5_update_odp_stats_with_handled(mr, faults, ret);
        mlx5r_deref_odp_mkey(mmkey);
 
        if (pfault->memory.flags & MLX5_MEMORY_PAGE_FAULT_FLAGS_LAST)
index affcf8fe943c1d3ada09ea4fae0b559d16b20fe2..67841922c7b8770c86fb5a47588e09560d0004f5 100644 (file)
@@ -95,10 +95,19 @@ static int fill_stat_mr_entry(struct sk_buff *msg, struct ib_mr *ibmr)
        if (rdma_nl_stat_hwcounter_entry(msg, "page_faults",
                                         atomic64_read(&mr->odp_stats.faults)))
                goto err_table;
+       if (rdma_nl_stat_hwcounter_entry(
+                   msg, "page_faults_handled",
+                   atomic64_read(&mr->odp_stats.faults_handled)))
+               goto err_table;
        if (rdma_nl_stat_hwcounter_entry(
                    msg, "page_invalidations",
                    atomic64_read(&mr->odp_stats.invalidations)))
                goto err_table;
+       if (rdma_nl_stat_hwcounter_entry(
+                   msg, "page_invalidations_handled",
+                   atomic64_read(&mr->odp_stats.invalidations_handled)))
+               goto err_table;
+
        if (rdma_nl_stat_hwcounter_entry(msg, "page_prefetch",
                                         atomic64_read(&mr->odp_stats.prefetch)))
                goto err_table;
index 3417636da960226c989864c677224a015c053539..6ddd5e3bb884e59f2637674e7b6dfe2fd4e5c4d3 100644 (file)
@@ -2256,7 +2256,9 @@ struct rdma_netdev_alloc_params {
 
 struct ib_odp_counters {
        atomic64_t faults;
+       atomic64_t faults_handled;
        atomic64_t invalidations;
+       atomic64_t invalidations_handled;
        atomic64_t prefetch;
 };