Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/apps/rss/metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ local magic_number = 0x5ABB
pkt_meta_data_t = ffi.typeof([[
struct {
uint16_t magic;
/* Unix timestamp in nanoseconds */
uint64_t timestamp;
/* Actual ethertype for single-tagged frames */
uint16_t ethertype;
/* vlan == 0 if untagged frame */
Expand Down Expand Up @@ -272,6 +274,7 @@ function add (pkt, rm_ext_headers, vlan_override)

local md = md_ptr(pkt)
md.magic = magic_number
md.timestamp = ffi.C.get_unix_time_ns()
md.ref = 0
md.ethertype = ethertype
md.vlan = vlan_override or vlan
Expand Down
10 changes: 9 additions & 1 deletion src/core/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <sys/time.h>
#include <unistd.h>

/* Return the current wall-clock time in nanoseconds. */
/* Return the monotonic time in nanoseconds. */
uint64_t get_time_ns()
{
/* XXX Consider using RDTSC. */
Expand All @@ -15,6 +15,14 @@ uint64_t get_time_ns()
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
}

/* Return the current wall-clock time in nanoseconds. */
uint64_t get_unix_time_ns()
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
}

static double get_time(int clock)
{
struct timespec ts;
Expand Down
1 change: 1 addition & 0 deletions src/core/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
uint64_t get_time_ns();
double get_monotonic_time();
double get_unix_time();
uint64_t get_unix_time_ns();
void sleep_ns(int nanoseconds);
void full_memory_barrier();
void prefetch_for_read(const void *address);
Expand Down