Skip to content

Commit fb586f2

Browse files
marceloleitnerdavem330
authored andcommitted
sctp: delay calls to sk_data_ready() as much as possible
Currently processing of multiple chunks in a single SCTP packet leads to multiple calls to sk_data_ready, causing multiple wake up signals which are costy and doesn't make it wake up any faster. With this patch it will note that the wake up is pending and will do it before leaving the state machine interpreter, latest place possible to do it realiably and cleanly. Note that sk_data_ready events are not dependent on asocs, unlike waking up writers. v2: series re-checked v3: use local vars to cleanup the code, suggested by Jakub Sitnicki Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 250eb1f commit fb586f2

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ struct sctp_sock {
217217
v4mapped:1,
218218
frag_interleave:1,
219219
recvrcvinfo:1,
220-
recvnxtinfo:1;
220+
recvnxtinfo:1,
221+
pending_data_ready:1;
221222

222223
atomic_t pd_mode;
223224
/* Receive to here while partial delivery is in effect. */

‎net/sctp/sm_sideeffect.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,8 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
12221222
sctp_cmd_seq_t *commands,
12231223
gfp_t gfp)
12241224
{
1225+
struct sock *sk = ep->base.sk;
1226+
struct sctp_sock *sp = sctp_sk(sk);
12251227
int error = 0;
12261228
int force;
12271229
sctp_cmd_t *cmd;
@@ -1742,6 +1744,11 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
17421744
error = sctp_outq_uncork(&asoc->outqueue, gfp);
17431745
} else if (local_cork)
17441746
error = sctp_outq_uncork(&asoc->outqueue, gfp);
1747+
1748+
if (sp->pending_data_ready) {
1749+
sk->sk_data_ready(sk);
1750+
sp->pending_data_ready = 0;
1751+
}
17451752
return error;
17461753
nomem:
17471754
error = -ENOMEM;

‎net/sctp/ulpqueue.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ int sctp_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
264264
sctp_ulpq_clear_pd(ulpq);
265265

266266
if (queue == &sk->sk_receive_queue)
267-
sk->sk_data_ready(sk);
267+
sctp_sk(sk)->pending_data_ready = 1;
268268
return 1;
269269

270270
out_free:
@@ -1140,5 +1140,5 @@ void sctp_ulpq_abort_pd(struct sctp_ulpq *ulpq, gfp_t gfp)
11401140

11411141
/* If there is data waiting, send it up the socket now. */
11421142
if (sctp_ulpq_clear_pd(ulpq) || ev)
1143-
sk->sk_data_ready(sk);
1143+
sctp_sk(sk)->pending_data_ready = 1;
11441144
}

0 commit comments

Comments
 (0)