Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpdk: replace TSC clock with GetTime (gettimeofday) function v1 #11389

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/runmode-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ static void InitEal(void)
if (retval < 0) { // retval bound to the result of rte_eal_init
FatalError("DPDK EAL initialization error: %s", rte_strerror(-retval));
}
DPDKSetTimevalOfMachineStart();
}

static void DPDKDerefConfig(void *conf)
Expand Down
66 changes: 5 additions & 61 deletions src/source-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ TmEcode NoDPDKSupportExit(ThreadVars *tv, const void *initdata, void **data)
#include <numa.h>

#define BURST_SIZE 32
static struct timeval machine_start_time = { 0, 0 };
// interrupt mode constants
#define MIN_ZERO_POLL_COUNT 10U
#define MIN_ZERO_POLL_COUNT_TO_SLEEP 10U
Expand Down Expand Up @@ -146,11 +145,7 @@ static TmEcode DecodeDPDKThreadInit(ThreadVars *, const void *, void **);
static TmEcode DecodeDPDKThreadDeinit(ThreadVars *tv, void *data);
static TmEcode DecodeDPDK(ThreadVars *, Packet *, void *);

static uint64_t CyclesToMicroseconds(uint64_t cycles);
static uint64_t CyclesToSeconds(uint64_t cycles);
static void DPDKFreeMbufArray(struct rte_mbuf **mbuf_array, uint16_t mbuf_cnt, uint16_t offset);
static uint64_t DPDKGetSeconds(void);

static bool InterruptsRXEnable(uint16_t port_id, uint16_t queue_id)
{
uint32_t event_data = port_id << UINT16_WIDTH | queue_id;
Expand Down Expand Up @@ -193,57 +188,6 @@ static inline void DPDKFreeMbufArray(
}
}

static uint64_t CyclesToMicroseconds(const uint64_t cycles)
{
const uint64_t ticks_per_us = rte_get_tsc_hz() / 1000000;
if (ticks_per_us == 0) {
return 0;
}
return cycles / ticks_per_us;
}

static uint64_t CyclesToSeconds(const uint64_t cycles)
{
const uint64_t ticks_per_s = rte_get_tsc_hz();
if (ticks_per_s == 0) {
return 0;
}
return cycles / ticks_per_s;
}

static void CyclesAddToTimeval(
const uint64_t cycles, struct timeval *orig_tv, struct timeval *new_tv)
{
uint64_t usec = CyclesToMicroseconds(cycles) + orig_tv->tv_usec;
new_tv->tv_sec = orig_tv->tv_sec + usec / 1000000;
new_tv->tv_usec = (usec % 1000000);
}

void DPDKSetTimevalOfMachineStart(void)
{
gettimeofday(&machine_start_time, NULL);
machine_start_time.tv_sec -= DPDKGetSeconds();
}

/**
* Initializes real_tv to the correct real time. Adds TSC counter value to the timeval of
* the machine start
* @param machine_start_tv - timestamp when the machine was started
* @param real_tv
*/
static SCTime_t DPDKSetTimevalReal(struct timeval *machine_start_tv)
{
struct timeval real_tv;
CyclesAddToTimeval(rte_get_tsc_cycles(), machine_start_tv, &real_tv);
return SCTIME_FROM_TIMEVAL(&real_tv);
}

/* get number of seconds from the reset of TSC counter (typically from the machine start) */
static uint64_t DPDKGetSeconds(void)
{
return CyclesToSeconds(rte_get_tsc_cycles());
}

static void DevicePostStartPMDSpecificActions(DPDKThreadVars *ptv, const char *driver_name)
{
if (strcmp(driver_name, "net_bonding") == 0) {
Expand Down Expand Up @@ -415,7 +359,7 @@ static TmEcode ReceiveDPDKLoopInit(ThreadVars *tv, DPDKThreadVars *ptv)
static inline void LoopHandleTimeoutOnIdle(ThreadVars *tv)
{
static thread_local uint64_t last_timeout_msec = 0;
SCTime_t t = DPDKSetTimevalReal(&machine_start_time);
SCTime_t t = TimeGet();
uint64_t msecs = SCTIME_MSECS(t);
if (msecs > last_timeout_msec + 100) {
TmThreadsCaptureHandleTimeout(tv, NULL);
Expand Down Expand Up @@ -474,7 +418,7 @@ static inline Packet *PacketInitFromMbuf(DPDKThreadVars *ptv, struct rte_mbuf *m
p->flags |= PKT_IGNORE_CHECKSUM;
}

p->ts = DPDKSetTimevalReal(&machine_start_time);
p->ts = TimeGet();
p->dpdk_v.mbuf = mbuf;
p->ReleasePacket = DPDKReleasePacket;
p->dpdk_v.copy_mode = ptv->copy_mode;
Expand Down Expand Up @@ -554,10 +498,10 @@ static void HandleShutdown(DPDKThreadVars *ptv)

static void PeriodicDPDKDumpCounters(DPDKThreadVars *ptv)
{
static thread_local time_t last_dump = 0;
time_t current_time = DPDKGetSeconds();
static thread_local SCTime_t last_dump = { 0 };
SCTime_t current_time = TimeGet();
/* Trigger one dump of stats every second */
if (current_time != last_dump) {
if (current_time.secs != last_dump.secs) {
DPDKDumpCounters(ptv);
last_dump = current_time;
}
Expand Down
Loading