Skip to content

Commit

Permalink
sctp: introduce priority based stream scheduler
Browse files Browse the repository at this point in the history
This patch introduces RFC Draft ndata section 3.4 Priority Based
Scheduler (SCTP_SS_PRIO).

It works by having a struct sctp_stream_priority for each priority
configured. This struct is then enlisted on a queue ordered per priority
if, and only if, there is a stream with data queued, so that dequeueing
is very straightforward: either finish current datamsg or simply dequeue
from the highest priority queued, which is the next stream pointed, and
that's it.

If there are multiple streams assigned with the same priority and with
data queued, it will do round robin amongst them while respecting
datamsgs boundaries (when not using idata chunks), to be reasonably
fair.

We intentionally don't maintain a list of priorities nor a list of all
streams with the same priority to save memory. The first would mean at
least 2 other pointers per priority (which, for 1000 priorities, that
can mean 16kB) and the second would also mean 2 other pointers but per
stream. As SCTP supports up to 65535 streams on a given asoc, that's
1MB. This impacts when giving a priority to some stream, as we have to
find out if the new priority is already being used and if we can free
the old one, and also when tearing down.

The new fields in struct sctp_stream_out_ext and sctp_stream are added
under a union because that memory is to be shared with other schedulers.

See-also: https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-ndata-13
Tested-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Marcelo Ricardo Leitner authored and David S. Miller committed Oct 3, 2017
1 parent 0ccdf3c commit 637784a
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 2 deletions.
24 changes: 24 additions & 0 deletions include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,27 @@ struct sctp_inithdr_host {
__u32 initial_tsn;
};

struct sctp_stream_priorities {
/* List of priorities scheduled */
struct list_head prio_sched;
/* List of streams scheduled */
struct list_head active;
/* The next stream stream in line */
struct sctp_stream_out_ext *next;
__u16 prio;
};

struct sctp_stream_out_ext {
__u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
__u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
struct list_head outq; /* chunks enqueued by this stream */
union {
struct {
/* Scheduled streams list */
struct list_head prio_list;
struct sctp_stream_priorities *prio_head;
};
};
};

struct sctp_stream_out {
Expand All @@ -1351,6 +1368,13 @@ struct sctp_stream {
__u16 incnt;
/* Current stream being sent, if any */
struct sctp_stream_out *out_curr;
union {
/* Fields used by priority scheduler */
struct {
/* List of priorities scheduled */
struct list_head prio_list;
};
};
};

#define SCTP_STREAM_CLOSED 0x00
Expand Down
3 changes: 2 additions & 1 deletion include/uapi/linux/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,8 @@ struct sctp_add_streams {
/* SCTP Stream schedulers */
enum sctp_sched_type {
SCTP_SS_FCFS,
SCTP_SS_MAX = SCTP_SS_FCFS
SCTP_SS_PRIO,
SCTP_SS_MAX = SCTP_SS_PRIO
};

#endif /* _UAPI_SCTP_H */
2 changes: 1 addition & 1 deletion net/sctp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sctp-y := sm_statetable.o sm_statefuns.o sm_sideeffect.o \
inqueue.o outqueue.o ulpqueue.o \
tsnmap.o bind_addr.o socket.o primitive.o \
output.o input.o debug.o stream.o auth.o \
offload.o stream_sched.o
offload.o stream_sched.o stream_sched_prio.o

sctp_probe-y := probe.o

Expand Down
3 changes: 3 additions & 0 deletions net/sctp/stream_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ static struct sctp_sched_ops sctp_sched_fcfs = {

/* API to other parts of the stack */

extern struct sctp_sched_ops sctp_sched_prio;

struct sctp_sched_ops *sctp_sched_ops[] = {
&sctp_sched_fcfs,
&sctp_sched_prio,
};

int sctp_sched_set_sched(struct sctp_association *asoc,
Expand Down
Loading

0 comments on commit 637784a

Please sign in to comment.