Skip to content

Commit

Permalink
core.packet: record packet allocation events to timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Nov 2, 2018
1 parent 0e52b24 commit e834845
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ function breathe ()
-- Commit counters and rebalance freelists at a reasonable frequency
if counter.read(breaths) % 100 == 0 then
counter.commit()
packet.rebalance_freelists()
events.commited_counters()
packet.rebalance_freelists()
end
-- Randomize the log level. Enable each level in 5x more breaths
-- than the level below by randomly picking from log5() distribution.
Expand Down
31 changes: 31 additions & 0 deletions src/core/packet.events
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
2|packet_allocated:
A packet has been allocated from the packet freelist.

2|packet_freed: length
A packet has been freed to the packet freelist.

'length' is the byte size of the packet.

6|packets_preallocated: packets
DMA memory for packets had been preallocated from the operating system.

'packets' is the number of packets for which space has been reserved.

4|group_freelist_wait:
The process is waiting to acquire the group freelist’s lock.

4|group_freelist_locked:
The process has acquired the group freelist’s lock.

4|group_freelist_unlocked:
The process has released the group freelist’s lock.

4|group_freelist_released: packets
The packet freelist was rebalanced with the group freelist.

'packets' is the number of packets released to the group freelist.

4|group_freelist_reclaimed: packets
The packet freelist was refilled from the group freelist.

'packets' is the number of packets reclaimed from the group freelist.
17 changes: 16 additions & 1 deletion src/core/packet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ local memory = require("core.memory")
local shm = require("core.shm")
local counter = require("core.counter")
local sync = require("core.sync")
local timeline = require("core.timeline")

local events = timeline.load_events(timeline.log(), "core.packet")

require("core.packet_h")

Expand Down Expand Up @@ -107,31 +110,41 @@ end

-- Return borrowed packets to group freelist.
function rebalance_freelists ()
if group_fl and freelist_nfree(packets_fl) > packets_allocated then
local free_packets = freelist_nfree(packets_fl)
if group_fl and free_packets > packets_allocated then
events.group_freelist_wait()
freelist_lock(group_fl)
events.group_freelist_locked()
while freelist_nfree(packets_fl) > packets_allocated
and not freelist_full(group_fl) do
freelist_add(group_fl, freelist_remove(packets_fl))
end
freelist_unlock(group_fl)
events.group_freelist_unlocked()
events.group_freelist_released(free_packets - freelist_nfree(packets_fl))
end
end

-- Return an empty packet.
function allocate ()
if freelist_nfree(packets_fl) == 0 then
if group_fl then
events.group_freelist_wait()
freelist_lock(group_fl)
events.group_freelist_locked()
while freelist_nfree(group_fl) > 0
and freelist_nfree(packets_fl) < packets_allocated do
freelist_add(packets_fl, freelist_remove(group_fl))
end
freelist_unlock(group_fl)
events.group_freelist_unlocked()
events.group_freelist_reclaimed(freelist_nfree(packets_fl))
end
if freelist_nfree(packets_fl) == 0 then
preallocate_step()
end
end
events.packet_allocated()
return freelist_remove(packets_fl)
end

Expand Down Expand Up @@ -229,6 +242,7 @@ function account_free (p)
end

function free (p)
events.packet_freed(p.length)
account_free(p)
free_internal(p)
end
Expand All @@ -250,6 +264,7 @@ function preallocate_step()
end
packets_allocated = packets_allocated + packet_allocation_step
packet_allocation_step = 2 * packet_allocation_step
events.packets_preallocated(packet_allocation_step)
end

function selftest ()
Expand Down

0 comments on commit e834845

Please sign in to comment.