8000 core.link: Streamline counters [DRAFT] by lukego · Pull Request #570 · snabbco/snabb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

core.link: Streamline counters [DRAFT] #570

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

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
4 changes: 3 additions & 1 deletion src/core/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ struct link {
// Two cursors:
// read: the next element to be read
// write: the next element to be written
int read, write;
int64_t read, write;
// How many packets have been dropped due to ring overflow?
int64_t dropped;
// Index (into the Lua app.active_apps array) of the app that
// receives from this link.
int receiving_app;
Expand Down
23 changes: 8 additions & 15 deletions src/core/link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ end

function receive (r)
-- if debug then assert(not empty(r), "receive on empty link") end
local p = r.packets[r.read]
r.read = band(r.read + 1, size - 1)

r.stats.rxpackets = r.stats.rxpackets + 1
r.stats.rxbytes = r.stats.rxbytes + p.length
local p = r.packets[band(r.read, size-1)]
r.read = r.read + 1
return p
end

Expand All @@ -38,10 +35,8 @@ function transmit (r, p)
r.stats.txdrop = r.stats.txdrop + 1
packet.free(p)
else
r.packets[r.write] = p
r.write = band(r.write + 1, size - 1)
r.stats.txpackets = r.stats.txpackets + 1
r.stats.txbytes = r.stats.txbytes + p.length
r.packets[band(r.write, size-1)] = p
r.write = r.write + 1
r.has_new_data = true
end
end
Expand All @@ -58,19 +53,17 @@ end

-- Return the number of packets that are ready for read.
function nreadable (r)
if r.read > r.write then
return r.write + size - r.read
else
return r.write - r.read
end
return r.write - r.read
end

function nwritable (r)
return max - nreadable(r)
end

function stats (r)
return r.stats
return { rxpackets = tonumber(r.read),
txpackets = tonumber(r.write),
txdropped = tonumber(r.dropped) }
end

function selftest ()
Expand Down
0