Skip to content

Commit e0d1035

Browse files
Wen GuPaolo Abeni
authored andcommitted
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>
1 parent d386d59 commit e0d1035

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

@@ -2427,7 +2435,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
24272435
buf_desc = smc_buf_get_slot(bufsize_comp, lock, buf_list);
24282436
if (buf_desc) {
24292437
buf_desc->is_dma_need_sync = 0;
2430-
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize);
2438+
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize);
24312439
SMC_STAT_BUF_REUSE(smc, is_smcd, is_rmb);
24322440
break; /* found reusable slot */
24332441
}
@@ -2448,7 +2456,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
24482456
}
24492457

24502458
SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rmb);
2451-
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize);
2459+
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, true, bufsize);
24522460
buf_desc->used = 1;
24532461
down_write(lock);
24542462
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
@@ -79,6 +79,8 @@ struct smc_stats_tech {
7979
u64 tx_bytes;
8080
u64 rx_cnt;
8181
u64 tx_cnt;
82+
u64 rx_rmbuse;
83+
u64 tx_rmbuse;
8284
};
8385

8486
struct smc_stats {
@@ -135,38 +137,46 @@ do { \
135137
} \
136138
while (0)
137139

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

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

155-
#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \
164+
#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _is_add, _len) \
156165
do { \
157166
struct net *_net = sock_net(&(_smc)->sk); \
158167
struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
168+
typeof(_is_add) is_add = (_is_add); \
159169
typeof(_is_smcd) is_d = (_is_smcd); \
160170
typeof(_is_rx) is_r = (_is_rx); \
161171
typeof(_len) l = (_len); \
162172
if ((is_d) && (is_r)) \
163-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \
173+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, is_add, l); \
164174
if ((is_d) && !(is_r)) \
165-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \
175+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, is_add, l); \
166176
if (!(is_d) && (is_r)) \
167-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \
177+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, is_add, l); \
168178
if (!(is_d) && !(is_r)) \
169-
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \
179+
SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, is_add, l); \
170180
} \
171181
while (0)
172182

0 commit comments

Comments
 (0)