Skip to content

Commit 0dc8968

Browse files
aharonl-nvidiajgunthorpe
authored andcommitted
RDMA/counter: Add an is_disabled field in struct rdma_hw_stats
Add a bitmap in rdma_hw_stat structure, with each bit indicates whether the corresponding counter is currently disabled or not. By default hwcounters are enabled. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Aharon Landau <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Mark Zhang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 0a0800c commit 0dc8968

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,15 +968,21 @@ static int fill_stat_counter_hwcounters(struct sk_buff *msg,
968968
if (!table_attr)
969969
return -EMSGSIZE;
970970

971-
for (i = 0; i < st->num_counters; i++)
971+
mutex_lock(&st->lock);
972+
for (i = 0; i < st->num_counters; i++) {
973+
if (test_bit(i, st->is_disabled))
974+
continue;
972975
if (rdma_nl_stat_hwcounter_entry(msg, st->descs[i].name,
973976
st->value[i]))
974977
goto err;
978+
}
979+
mutex_unlock(&st->lock);
975980

976981
nla_nest_end(msg, table_attr);
977982
return 0;
978983

979984
err:
985+
mutex_unlock(&st->lock);
980986
nla_nest_cancel(msg, table_attr);
981987
return -EMSGSIZE;
982988
}
@@ -2104,6 +2110,9 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
21042110
goto err_stats;
21052111
}
21062112
for (i = 0; i < num_cnts; i++) {
2113+
if (test_bit(i, stats->is_disabled))
2114+
continue;
2115+
21072116
v = stats->value[i] +
21082117
rdma_counter_get_hwstat_value(device, port, i);
21092118
if (rdma_nl_stat_hwcounter_entry(msg,

drivers/infiniband/core/verbs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,11 +2994,20 @@ struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
29942994
if (!stats)
29952995
return NULL;
29962996

2997+
stats->is_disabled = kcalloc(BITS_TO_LONGS(num_counters),
2998+
sizeof(*stats->is_disabled), GFP_KERNEL);
2999+
if (!stats->is_disabled)
3000+
goto err;
3001+
29973002
stats->descs = descs;
29983003
stats->num_counters = num_counters;
29993004
stats->lifespan = msecs_to_jiffies(lifespan);
30003005

30013006
return stats;
3007+
3008+
err:
3009+
kfree(stats);
3010+
return NULL;
30023011
}
30033012
EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
30043013

@@ -3008,6 +3017,10 @@ EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
30083017
*/
30093018
void rdma_free_hw_stats_struct(struct rdma_hw_stats *stats)
30103019
{
3020+
if (!stats)
3021+
return;
3022+
3023+
kfree(stats->is_disabled);
30113024
kfree(stats);
30123025
}
30133026
EXPORT_SYMBOL(rdma_free_hw_stats_struct);

include/rdma/ib_verbs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ struct rdma_stat_desc {
565565
* their own value during their allocation routine.
566566
* @descs - Array of pointers to static descriptors used for the counters
567567
* in directory.
568+
* @is_disabled - A bitmap to indicate each counter is currently disabled
569+
* or not.
568570
* @num_counters - How many hardware counters there are. If name is
569571
* shorter than this number, a kernel oops will result. Driver authors
570572
* are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
@@ -577,6 +579,7 @@ struct rdma_hw_stats {
577579
unsigned long timestamp;
578580
unsigned long lifespan;
579581
const struct rdma_stat_desc *descs;
582+
unsigned long *is_disabled;
580583
int num_counters;
581584
u64 value[];
582585
};

0 commit comments

Comments
 (0)