Commit d5108e69 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe
Browse files

IB/rxe: Make counters thread safe



Current rxe device counters are not thread safe.
When multiple QPs are used, they can be racy.
Make them thread safe by making it atomic64.

Fixes: 0b1e5b99 ("IB/rxe: Add port protocol stats")
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 6e3722ba
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ int rxe_ib_get_hw_stats(struct ib_device *ibdev,
		return -EINVAL;
		return -EINVAL;


	for (cnt = 0; cnt  < ARRAY_SIZE(rxe_counter_name); cnt++)
	for (cnt = 0; cnt  < ARRAY_SIZE(rxe_counter_name); cnt++)
		stats->value[cnt] = dev->stats_counters[cnt];
		stats->value[cnt] = atomic64_read(&dev->stats_counters[cnt]);


	return ARRAY_SIZE(rxe_counter_name);
	return ARRAY_SIZE(rxe_counter_name);
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -409,16 +409,16 @@ struct rxe_dev {
	spinlock_t		mmap_offset_lock; /* guard mmap_offset */
	spinlock_t		mmap_offset_lock; /* guard mmap_offset */
	int			mmap_offset;
	int			mmap_offset;


	u64			stats_counters[RXE_NUM_OF_COUNTERS];
	atomic64_t		stats_counters[RXE_NUM_OF_COUNTERS];


	struct rxe_port		port;
	struct rxe_port		port;
	struct list_head	list;
	struct list_head	list;
	struct crypto_shash	*tfm;
	struct crypto_shash	*tfm;
};
};


static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters cnt)
static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters index)
{
{
	rxe->stats_counters[cnt]++;
	atomic64_inc(&rxe->stats_counters[index]);
}
}


static inline struct rxe_dev *to_rdev(struct ib_device *dev)
static inline struct rxe_dev *to_rdev(struct ib_device *dev)