Skip to content

Commit 7808df2

Browse files
florincorasDave Barach
authored andcommitted
session: allow small pacer bursts
Instead of enforcing a "strict" release of data, which relies on frequent rescheduling of sessions, allow some pacer coalescing, i.e., short bursts, that can minimize load on scheduler/session layer and potentially leverage tso. Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I67e38e5b8dc335bd214113b70c68c27ae92bd6da
1 parent de22111 commit 7808df2

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

src/vnet/session/session_node.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ session_tx_fifo_read_and_snd_i (session_worker_t * wrk,
10371037
return SESSION_TX_NO_BUFFERS;
10381038
}
10391039

1040-
transport_connection_update_tx_bytes (ctx->tc, ctx->max_len_to_snd);
1040+
if (transport_connection_is_tx_paced (ctx->tc))
1041+
transport_connection_tx_pacer_update_bytes (ctx->tc, ctx->max_len_to_snd);
10411042

10421043
ctx->left_to_snd = ctx->max_len_to_snd;
10431044
n_left = ctx->n_segs_per_evt;

src/vnet/session/transport.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ format_transport_pacer (u8 * s, va_list * args)
632632

633633
now = transport_us_time_now (thread_index);
634634
diff = now - pacer->last_update;
635-
s = format (s, "rate %lu bucket %lu t/p %.3f last_update %U idle %u",
635+
s = format (s, "rate %lu bucket %lu t/p %.3f last_update %U burst %u",
636636
pacer->bytes_per_sec, pacer->bucket, pacer->tokens_per_period,
637-
format_clib_us_time, diff, pacer->idle_timeout_us);
637+
format_clib_us_time, diff, pacer->max_burst);
638638
return s;
639639
}
640640

@@ -644,38 +644,45 @@ spacer_max_burst (spacer_t * pacer, clib_us_time_t time_now)
644644
u64 n_periods = (time_now - pacer->last_update);
645645
u64 inc;
646646

647-
if (PREDICT_FALSE (n_periods > pacer->idle_timeout_us))
648-
{
649-
pacer->last_update = time_now;
650-
pacer->bucket = TRANSPORT_PACER_MIN_BURST;
651-
return TRANSPORT_PACER_MIN_BURST;
652-
}
653-
654647
if ((inc = (f32) n_periods * pacer->tokens_per_period) > 10)
655648
{
656649
pacer->last_update = time_now;
657-
pacer->bucket = clib_min (pacer->bucket + inc, pacer->bytes_per_sec);
650+
pacer->bucket = clib_min (pacer->bucket + inc, pacer->max_burst);
658651
}
659652

660-
return clib_min (pacer->bucket, TRANSPORT_PACER_MAX_BURST);
653+
return pacer->bucket > 0 ? pacer->max_burst : 0;
661654
}
662655

663656
static inline void
664657
spacer_update_bucket (spacer_t * pacer, u32 bytes)
665658
{
666-
ASSERT (pacer->bucket >= bytes);
667659
pacer->bucket -= bytes;
668660
}
669661

670662
static inline void
671663
spacer_set_pace_rate (spacer_t * pacer, u64 rate_bytes_per_sec,
672664
clib_us_time_t rtt)
673665
{
666+
clib_us_time_t max_time;
667+
674668
ASSERT (rate_bytes_per_sec != 0);
675669
pacer->bytes_per_sec = rate_bytes_per_sec;
676670
pacer->tokens_per_period = rate_bytes_per_sec * CLIB_US_TIME_PERIOD;
677-
pacer->idle_timeout_us = clib_max (rtt * TRANSPORT_PACER_IDLE_FACTOR,
678-
TRANSPORT_PACER_MIN_IDLE);
671+
672+
/* Allow a min number of bursts per rtt, if their size is acceptable. Goal
673+
* is to spread the sending of data over the rtt but to also allow for some
674+
* coalescing that can potentially
675+
* 1) reduce load on session layer by reducing scheduling frequency for a
676+
* session and
677+
* 2) optimize sending when tso if available
678+
*
679+
* Max "time-length" of a burst cannot be less than 1us or more than 1ms.
680+
*/
681+
max_time = rtt / TRANSPORT_PACER_BURSTS_PER_RTT;
682+
max_time = clib_clamp (max_time, 1 /* 1us */ , 1000 /* 1ms */ );
683+
pacer->max_burst = (rate_bytes_per_sec * max_time) * CLIB_US_TIME_PERIOD;
684+
pacer->max_burst = clib_clamp (pacer->max_burst, TRANSPORT_PACER_MIN_BURST,
685+
TRANSPORT_PACER_MAX_BURST);
679686
}
680687

681688
static inline u64

src/vnet/session/transport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define TRANSPORT_PACER_MIN_BURST TRANSPORT_PACER_MIN_MSS
2424
#define TRANSPORT_PACER_MAX_BURST (43 * TRANSPORT_PACER_MIN_MSS)
2525
#define TRANSPORT_PACER_MAX_BURST_PKTS 43
26+
#define TRANSPORT_PACER_BURSTS_PER_RTT 20
2627
#define TRANSPORT_PACER_MIN_IDLE 100
2728
#define TRANSPORT_PACER_IDLE_FACTOR 0.05
2829

src/vnet/session/transport_types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ typedef enum transport_connection_flags_
6565
typedef struct _spacer
6666
{
6767
u64 bytes_per_sec;
68-
u64 bucket;
68+
i64 bucket;
6969
clib_us_time_t last_update;
7070
f32 tokens_per_period;
71-
u32 idle_timeout_us;
71+
u32 max_burst;
7272
} spacer_t;
7373

7474
#define TRANSPORT_CONN_ID_LEN 44
@@ -146,8 +146,8 @@ typedef struct _transport_connection
146146
#define c_stats connection.stats
147147
#define c_pacer connection.pacer
148148
#define c_flags connection.flags
149-
#define s_ho_handle pacer.bucket
150-
#define c_s_ho_handle connection.pacer.bucket
149+
#define s_ho_handle pacer.bytes_per_sec
150+
#define c_s_ho_handle connection.pacer.bytes_per_sec
151151
} transport_connection_t;
152152

153153
STATIC_ASSERT (STRUCT_OFFSET_OF (transport_connection_t, s_index)

src/vppinfra/clib.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ extract_bits (uword x, int start, int count)
332332
_x < _y ? _x : _y; \
333333
})
334334

335+
#define clib_clamp(x,lo,hi) \
336+
({ \
337+
__typeof__ (x) _x = (x); \
338+
__typeof__ (lo) _lo = (lo); \
339+
__typeof__ (hi) _hi = (hi); \
340+
_x < _lo ? _lo : (_x > _hi ? _hi : _x); \
341+
})
342+
335343
#define clib_abs(x) \
336344
({ \
337345
__typeof__ (x) _x = (x); \

0 commit comments

Comments
 (0)