Skip to content

Commit 6b7f5a2

Browse files
committedApr 17, 2020
tas,libtas: use cycles for poll cycle delays
This should guarantee that both sides are measuring the same way
1 parent 7738edd commit 6b7f5a2

File tree

12 files changed

+55
-46
lines changed

12 files changed

+55
-46
lines changed
 

‎include/tas_memif.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ struct flexnic_info {
6363
/** export mac address */
6464
uint64_t mac_address;
6565
/** Cycles to poll before blocking for application */
66-
uint32_t poll_cycle_app;
66+
uint64_t poll_cycle_app;
6767
/** Cycles to poll before blocking for TAS */
68-
uint32_t poll_cycle_tas;
68+
uint64_t poll_cycle_tas;
6969
/** Number of queues in queue manager */
7070
uint32_t qmq_num;
7171
/** Number of cores in flexnic emulator */
@@ -212,9 +212,9 @@ struct flextcp_pl_appctx {
212212

213213
/********************************************************/
214214
/* read-write fields */
215+
uint64_t last_ts;
215216
uint32_t rx_head;
216217
uint32_t tx_head;
217-
uint32_t last_ts;
218218
uint32_t rx_avail;
219219
} __attribute__((packed));
220220

‎lib/tas/include/tas_ll.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ struct flextcp_context {
6464
uint32_t rxq_head;
6565
uint32_t txq_tail;
6666
uint32_t txq_avail;
67-
uint32_t last_ts;
67+
uint32_t _pad;
68+
uint64_t last_ts;
6869
} queues[FLEXTCP_MAX_FTCPCORES];
6970

7071
/* list of connections with pending updates for NIC */
@@ -80,7 +81,7 @@ struct flextcp_context {
8081
uint16_t next_queue;
8182

8283
/* waiting */
83-
uint32_t last_inev_ts;
84+
uint64_t last_inev_ts;
8485
int evfd;
8586
};
8687

‎lib/tas/init.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ int flextcp_context_tx_alloc(struct flextcp_context *ctx,
495495

496496
static void flextcp_flexnic_kick(struct flextcp_context *ctx, int core)
497497
{
498-
uint32_t now = util_timeout_time_us();
498+
uint64_t now = util_rdtsc();
499499

500500
if(now - ctx->queues[core].last_ts > flexnic_info->poll_cycle_tas) {
501501
// Kick
@@ -941,9 +941,7 @@ int flextcp_context_canwait(struct flextcp_context *ctx)
941941

942942
if ((ctx->flags & CTX_FLAG_WANTWAIT) != 0) {
943943
/* in want wait state: just wait for grace period to be over */
944-
if ((util_timeout_time_us() - ctx->last_inev_ts) >
945-
flexnic_info->poll_cycle_app)
946-
{
944+
if ((util_rdtsc() - ctx->last_inev_ts) > flexnic_info->poll_cycle_app) {
947945
/* past grace period, move on to lastwait. clear polled flag, to make sure
948946
* it gets polled again before we clear lastwait. */
949947
ctx->flags &= ~(CTX_FLAG_POLL_CALLED | CTX_FLAG_WANTWAIT);
@@ -958,7 +956,7 @@ int flextcp_context_canwait(struct flextcp_context *ctx)
958956
}
959957
} else {
960958
/* not currently getting ready to wait, so start */
961-
ctx->last_inev_ts = util_timeout_time_us();
959+
ctx->last_inev_ts = util_rdtsc();
962960
ctx->flags |= CTX_FLAG_WANTWAIT;
963961
}
964962

‎lib/tas/kernel.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ static int kernel_evfd = 0;
4141

4242
void flextcp_kernel_kick(void)
4343
{
44-
static uint32_t __thread last_ts = 0;
45-
uint32_t now = util_timeout_time_us();
44+
static uint64_t __thread last_ts = 0;
45+
uint64_t now = util_rdtsc();
4646

4747
/* fprintf(stderr, "kicking kernel?\n"); */
4848

‎tas/blocking.c

+15-16
Original file line numberDiff line numberDiff line change
@@ -28,62 +28,61 @@
2828
#include <unistd.h>
2929

3030
#include <tas.h>
31-
#include <utils_timeout.h>
3231

3332
extern int kernel_notifyfd;
3433

35-
static void notify_core(int cfd, uint32_t *last_ts, uint32_t ts_us,
36-
uint32_t delta)
34+
static void notify_core(int cfd, uint64_t *last_ts, uint64_t tsc,
35+
uint64_t delta)
3736
{
3837
uint64_t val;
3938

40-
if(ts_us - *last_ts > delta) {
39+
if(tsc - *last_ts > delta) {
4140
val = 1;
4241
if (write(cfd, &val, sizeof(uint64_t)) != sizeof(uint64_t)) {
4342
perror("notify_core: write failed");
4443
abort();
4544
}
4645
}
4746

48-
*last_ts = ts_us;
47+
*last_ts = tsc;
4948
}
5049

5150
void notify_fastpath_core(unsigned core)
5251
{
5352
notify_core(fp_state->kctx[core].evfd, &fp_state->kctx[core].last_ts,
54-
util_timeout_time_us(), tas_info->poll_cycle_tas);
53+
util_rdtsc(), tas_info->poll_cycle_tas);
5554
}
5655

57-
void notify_app_core(int appfd, uint32_t *last_ts)
56+
void notify_app_core(int appfd, uint64_t *last_ts)
5857
{
59-
notify_core(appfd, last_ts, util_timeout_time_us(), tas_info->poll_cycle_app);
58+
notify_core(appfd, last_ts, util_rdtsc(), tas_info->poll_cycle_app);
6059
}
6160

62-
void notify_appctx(struct flextcp_pl_appctx *ctx, uint32_t ts_us)
61+
void notify_appctx(struct flextcp_pl_appctx *ctx, uint64_t tsc)
6362
{
64-
notify_core(ctx->evfd, &ctx->last_ts, ts_us, tas_info->poll_cycle_app);
63+
notify_core(ctx->evfd, &ctx->last_ts, tsc, tas_info->poll_cycle_app);
6564
}
6665

6766
void notify_slowpath_core(void)
6867
{
69-
static uint32_t __thread last_ts = 0;
70-
notify_core(kernel_notifyfd, &last_ts, util_timeout_time_us(),
68+
static uint64_t __thread last_ts = 0;
69+
notify_core(kernel_notifyfd, &last_ts, util_rdtsc(),
7170
tas_info->poll_cycle_tas);
7271
}
7372

74-
int notify_canblock(struct notify_blockstate *nbs, int had_data, uint32_t ts)
73+
int notify_canblock(struct notify_blockstate *nbs, int had_data, uint64_t tsc)
7574
{
7675
if (had_data) {
7776
/* not idle this round, reset everything */
7877
nbs->can_block = nbs->second_bar = 0;
79-
nbs->last_active_ts = ts;
78+
nbs->last_active_ts = tsc;
8079
} else if (nbs->second_bar) {
8180
/* we can block now, reset afterwards */
8281
nbs->can_block = nbs->second_bar = 0;
83-
nbs->last_active_ts = ts;
82+
nbs->last_active_ts = tsc;
8483
return 1;
8584
} else if (nbs->can_block &&
86-
ts - nbs->last_active_ts > tas_info->poll_cycle_tas)
85+
tsc - nbs->last_active_ts > tas_info->poll_cycle_tas)
8786
{
8887
/* we've reached the poll cycle interval, so just poll once more */
8988
nbs->second_bar = 1;

‎tas/fast/fastemu.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555

5656

5757
static void dataplane_block(struct dataplane_context *ctx, uint32_t ts);
58-
static unsigned poll_rx(struct dataplane_context *ctx, uint32_t ts) __attribute__((noinline));
58+
static unsigned poll_rx(struct dataplane_context *ctx, uint32_t ts,
59+
uint64_t tsc) __attribute__((noinline));
5960
static unsigned poll_queues(struct dataplane_context *ctx, uint32_t ts) __attribute__((noinline));
6061
static unsigned poll_kernel(struct dataplane_context *ctx, uint32_t ts) __attribute__((noinline));
6162
static unsigned poll_qman(struct dataplane_context *ctx, uint32_t ts) __attribute__((noinline));
@@ -72,7 +73,7 @@ static inline void tx_flush(struct dataplane_context *ctx);
7273
static inline void tx_send(struct dataplane_context *ctx,
7374
struct network_buf_handle *nbh, uint16_t off, uint16_t len);
7475

75-
static void arx_cache_flush(struct dataplane_context *ctx, uint32_t ts) __attribute__((noinline));
76+
static void arx_cache_flush(struct dataplane_context *ctx, uint64_t tsc) __attribute__((noinline));
7677

7778
int dataplane_init(void)
7879
{
@@ -159,7 +160,7 @@ void dataplane_loop(struct dataplane_context *ctx)
159160
ts = qman_timestamp(cyc);
160161

161162
STATS_TS(start);
162-
n += poll_rx(ctx, ts);
163+
n += poll_rx(ctx, ts, cyc);
163164
STATS_TS(rx);
164165
tx_flush(ctx);
165166

@@ -181,7 +182,7 @@ void dataplane_loop(struct dataplane_context *ctx)
181182
poll_scale(ctx);
182183

183184
was_idle = (n == 0);
184-
if (config.fp_interrupts && notify_canblock(&nbs, !was_idle, ts)) {
185+
if (config.fp_interrupts && notify_canblock(&nbs, !was_idle, cyc)) {
185186
dataplane_block(ctx, ts);
186187
notify_canblock_reset(&nbs);
187188
}
@@ -252,7 +253,8 @@ void dataplane_dump_stats(void)
252253
}
253254
#endif
254255

255-
static unsigned poll_rx(struct dataplane_context *ctx, uint32_t ts)
256+
static unsigned poll_rx(struct dataplane_context *ctx, uint32_t ts,
257+
uint64_t tsc)
256258
{
257259
int ret;
258260
unsigned i, n;
@@ -307,7 +309,7 @@ static unsigned poll_rx(struct dataplane_context *ctx, uint32_t ts)
307309
}
308310
}
309311

310-
arx_cache_flush(ctx, ts);
312+
arx_cache_flush(ctx, tsc);
311313

312314
/* free received buffers */
313315
for (i = 0; i < n; i++) {
@@ -589,7 +591,7 @@ static void poll_scale(struct dataplane_context *ctx)
589591
fp_scale_to = 0;
590592
}
591593

592-
static void arx_cache_flush(struct dataplane_context *ctx, uint32_t ts)
594+
static void arx_cache_flush(struct dataplane_context *ctx, uint64_t tsc)
593595
{
594596
uint16_t i;
595597
struct flextcp_pl_appctx *actx;
@@ -614,7 +616,7 @@ static void arx_cache_flush(struct dataplane_context *ctx, uint32_t ts)
614616

615617
for (i = 0; i < ctx->arx_num; i++) {
616618
actx = &fp_state->appctx[ctx->id][ctx->arx_ctx[i]];
617-
notify_appctx(actx, ts);
619+
notify_appctx(actx, tsc);
618620
}
619621

620622
ctx->arx_num = 0;

‎tas/include/tas.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ void network_cleanup(void);
6060
void *util_create_shmsiszed(const char *name, size_t size, void *addr);
6161

6262
struct notify_blockstate {
63-
uint32_t last_active_ts;
63+
uint64_t last_active_ts;
6464
int can_block;
6565
int second_bar;
6666
};
6767

6868
void notify_fastpath_core(unsigned core);
69-
void notify_appctx(struct flextcp_pl_appctx *ctx, uint32_t ts_us);
70-
void notify_app_core(int appfd, uint32_t *last_ts);
69+
void notify_appctx(struct flextcp_pl_appctx *ctx, uint64_t tsc);
70+
void notify_app_core(int appfd, uint64_t *last_tsc);
7171
void notify_slowpath_core(void);
72-
int notify_canblock(struct notify_blockstate *nbs, int had_data, uint32_t ts);
72+
int notify_canblock(struct notify_blockstate *nbs, int had_data, uint64_t tsc);
7373
void notify_canblock_reset(struct notify_blockstate *nbs);
7474

7575
/* should become config options */

‎tas/shm.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <utils.h>
3838
#include <rte_config.h>
3939
#include <rte_malloc.h>
40+
#include <rte_cycles.h>
4041

4142
#include <tas.h>
4243
#include <tas_memif.h>
@@ -53,6 +54,8 @@ static void *util_create_shmsiszed_huge(const char *name, size_t size,
5354
/* destroy shared huge page memory region */
5455
static void destroy_shm_huge(const char *name, size_t size, void *addr)
5556
__attribute__((used));
57+
/* convert microseconds to cycles */
58+
static uint64_t us_to_cycles(uint32_t us);
5659

5760
/* Allocate DMA memory before DPDK grabs all huge pages */
5861
int shm_preinit(void)
@@ -104,8 +107,8 @@ int shm_init(unsigned num)
104107
tas_info->qmq_num = FLEXNIC_NUM_QMQUEUES;
105108
tas_info->cores_num = num;
106109
tas_info->mac_address = 0;
107-
tas_info->poll_cycle_app = config.fp_poll_interval_app;
108-
tas_info->poll_cycle_tas = config.fp_poll_interval_tas;
110+
tas_info->poll_cycle_app = us_to_cycles(config.fp_poll_interval_app);
111+
tas_info->poll_cycle_tas = us_to_cycles(config.fp_poll_interval_tas);
109112

110113
if (config.fp_hugepages)
111114
tas_info->flags |= FLEXNIC_FLAG_HUGEPAGES;
@@ -237,3 +240,9 @@ static void destroy_shm_huge(const char *name, size_t size, void *addr)
237240
}
238241
unlink(path);
239242
}
243+
244+
static uint64_t us_to_cycles(uint32_t us)
245+
{
246+
return (rte_get_tsc_hz() * us) / 1000000;
247+
}
248+

‎tas/slow/appif.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct app_context {
5252
struct app_doorbell *doorbell;
5353

5454
int ready, evfd;
55-
uint32_t last_ts;
55+
uint64_t last_ts;
5656
struct app_context *next;
5757

5858
struct {

‎tas/slow/kernel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int slowpath_main(void)
132132
loadmon_ts = cur_ts;
133133
}
134134

135-
if (notify_canblock(&nbs, n != 0, cur_ts)) {
135+
if (notify_canblock(&nbs, n != 0, util_rdtsc())) {
136136
slowpath_block(cur_ts);
137137
notify_canblock_reset(&nbs);
138138
}

‎tests/tas_unit/fastpath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int qman_set(struct qman_thread *t, uint32_t id, uint32_t rate, uint32_t avail,
5959
return 0;
6060
}
6161

62-
void notify_fastpath_core(unsigned core, uint32_t ts_us)
62+
void notify_fastpath_core(unsigned core)
6363
{
6464
printf("notify_fastpath_core(%u)\n", core);
6565
}

‎tests/testutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int test_subcase(const char *name, void (*run)(void *), void *param)
6464
printf(" [passed]\n");
6565
return 0;
6666
} else {
67-
printf(" [failed]\n");
67+
printf(" [failed] %d %d\n", WIFEXITED(status), WEXITSTATUS(status));
6868
return -1;
6969
}
7070
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.