Skip to content

Commit 804c189

Browse files
author
Mete Durlu
committed
net/smc: introduce statistics for ringbufs usage of net namespace
JIRA: https://issues.redhat.com/browse/RHEL-99989 commit e0d1035 Author: Wen Gu <guwen@linux.alibaba.com> Date: Wed Aug 14 21:08:27 2024 +0800 net/smc: introduce statistics for ringbufs usage of net namespace The buffer size histograms in smc_stats, namely rx/tx_rmbsize, record the sizes of ringbufs for all connections that have ever appeared in the net namespace. They are incremental and we cannot know the actual ringbufs usage from these. So here introduces statistics for current ringbufs usage of existing smc connections in the net namespace into smc_stats, it will be incremented when new connection uses a ringbuf and decremented when the ringbuf is unused. Signed-off-by: Wen Gu <guwen@linux.alibaba.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com> Signed-off-by: Mete Durlu <mdurlu@redhat.com>
1 parent 6ccdef3 commit 804c189

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

include/uapi/linux/smc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ enum {
253253
SMC_NLA_STATS_T_TX_BYTES, /* u64 */
254254
SMC_NLA_STATS_T_RX_CNT, /* u64 */
255255
SMC_NLA_STATS_T_TX_CNT, /* u64 */
256+
SMC_NLA_STATS_T_RX_RMB_USAGE, /* uint */
257+
SMC_NLA_STATS_T_TX_RMB_USAGE, /* uint */
256258
__SMC_NLA_STATS_T_MAX,
257259
SMC_NLA_STATS_T_MAX = __SMC_NLA_STATS_T_MAX - 1
258260
};

net/smc/smc_core.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,22 +1203,30 @@ static void smcd_buf_detach(struct smc_connection *conn)
12031203
static void smc_buf_unuse(struct smc_connection *conn,
12041204
struct smc_link_group *lgr)
12051205
{
1206+
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
1207+
bool is_smcd = lgr->is_smcd;
1208+
int bufsize;
1209+
12061210
if (conn->sndbuf_desc) {
1207-
if (!lgr->is_smcd && conn->sndbuf_desc->is_vm) {
1211+
bufsize = conn->sndbuf_desc->len;
1212+
if (!is_smcd && conn->sndbuf_desc->is_vm) {
12081213
smcr_buf_unuse(conn->sndbuf_desc, false, lgr);
12091214
} else {
1210-
memzero_explicit(conn->sndbuf_desc->cpu_addr, conn->sndbuf_desc->len);
1215+
memzero_explicit(conn->sndbuf_desc->cpu_addr, bufsize);
12111216
WRITE_ONCE(conn->sndbuf_desc->used, 0);
12121217
}
1218+
SMC_STAT_RMB_SIZE(smc, is_smcd, false, false, bufsize);
12131219
}
12141220
if (conn->rmb_desc) {
1215-
if (!lgr->is_smcd) {
1221+
bufsize = conn->rmb_desc->len;
1222+
if (!is_smcd) {
12161223
smcr_buf_unuse(conn->rmb_desc, true, lgr);
12171224
} else {
1218-
memzero_explicit(conn->rmb_desc->cpu_addr,
1219-
conn->rmb_desc->len + sizeof(struct smcd_cdc_msg));
1225+
bufsize += sizeof(struct smcd_cdc_msg);
1226+
memzero_explicit(conn->rmb_desc->cpu_addr, bufsize);
12201227
WRITE_ONCE(conn->rmb_desc->used, 0);
12211228
}
1229+
SMC_STAT_RMB_SIZE(smc, is_smcd, true, false, bufsize);
12221230
}
12231231
}
12241232

@@ -2433,7 +2441,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
24332441
buf_desc = smc_buf_get_slot(bufsize_short, lock, buf_list);
24342442
if (buf_desc) {
24352443
buf_desc->is_dma_need_sync = 0;
2436-
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize);
2444+
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize);
24372445
SMC_STAT_BUF_REUSE(smc, is_smcd, is_rmb);
24382446
break; /* found reusable slot */
24392447
}
@@ -2454,7 +2462,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
24542462
}
24552463

24562464
SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rmb);
2457-
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize);
2465+
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize);
24582466
buf_desc->used = 1;
24592467
down_write(lock);
24602468
smc_lgr_buf_list_add(lgr, is_rmb, buf_list, buf_desc);

net/smc/smc_stats.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ static int smc_nl_fill_stats_tech_data(struct sk_buff *skb,
218218
smc_tech->tx_bytes,
219219
SMC_NLA_STATS_PAD))
220220
goto errattr;
221+
if (nla_put_uint(skb, SMC_NLA_STATS_T_RX_RMB_USAGE,
222+
smc_tech->rx_rmbuse))
223+
goto errattr;
224+
if (nla_put_uint(skb, SMC_NLA_STATS_T_TX_RMB_USAGE,
225+
smc_tech->tx_rmbuse))
226+
goto errattr;
221227
if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_RX_CNT,
222228
smc_tech->rx_cnt,
223229
SMC_NLA_STATS_PAD))

net/smc/smc_stats.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ struct smc_stats_tech {
8080
u64 tx_bytes;
8181
u64 rx_cnt;
8282
u64 tx_cnt;
83+
u64 rx_rmbuse;
84+
u64 tx_rmbuse;
8385
};
8486

8587
struct smc_stats {
@@ -136,38 +138,46 @@ do { \
136138
} \
137139
while (0)
138140

139-
#define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _len) \
141+
#define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _is_add, _len) \
140142
do { \
143+
typeof(_smc_stats) stats = (_smc_stats); \
144+
typeof(_is_add) is_a = (_is_add); \
141145
typeof(_len) _l = (_len); \
142146
typeof(_tech) t = (_tech); \
143147
int _pos; \
144148
int m = SMC_BUF_MAX - 1; \
145149
if (_l <= 0) \
146150
break; \
147-
_pos = fls((_l - 1) >> 13); \
148-
_pos = (_pos <= m) ? _pos : m; \
149-
this_cpu_inc((*(_smc_stats)).smc[t].k ## _rmbsize.buf[_pos]); \
151+
if (is_a) { \
152+
_pos = fls((_l - 1) >> 13); \
153+
_pos = (_pos <= m) ? _pos : m; \
154+
this_cpu_inc((*stats).smc[t].k ## _rmbsize.buf[_pos]); \
155+
this_cpu_add((*stats).smc[t].k ## _rmbuse, _l); \
156+
} else { \
157+
this_cpu_sub((*stats).smc[t].k ## _rmbuse, _l); \
158+
} \
150159
} \
151160
while (0)
152161

153162
#define SMC_STAT_RMB_SUB(_smc_stats, type, t, key) \
154163
this_cpu_inc((*(_smc_stats)).smc[t].rmb ## _ ## key.type ## _cnt)
155164

156-
#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \
165+
#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _is_add, _len) \
157166
do { \
158167
struct net *_net = sock_net(&(_smc)->sk); \
159168
struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
169+
typeof(_is_add) is_add = (_is_add); \
160170
typeof(_is_smcd) is_d = (_is_smcd); \
161171
typeof(_is_rx) is_r = (_is_rx); \
162172
typeof(_len) l = (_len); \
163173
if ((is_d) && (is_r)) \
164-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \
174+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, is_add, l); \
165175
if ((is_d) && !(is_r)) \
166-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \
176+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, is_add, l); \
167177
if (!(is_d) && (is_r)) \
168-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \
178+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, is_add, l); \
169179
if (!(is_d) && !(is_r)) \
170-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \
180+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, is_add, l); \
171181
} \
172182
while (0)
173183

0 commit comments

Comments
 (0)