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

I/O statistics counters for Tap/RawSocket apps #947

Merged
merged 43 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b34c3ee
engine: Set shm path to "app/$name"
lukego Feb 22, 2016
94ff234
Amendments to #766:
eugeneia Apr 12, 2016
aac0c8c
Merge PR #766 (engine: Set shm path to "app/$name") into yang
eugeneia Apr 12, 2016
fad0f43
core.counter: Qualify counter names using `shm.resolve'.
eugeneia Apr 13, 2016
7ed4ed0
snabb top: add `--app' option to print app counters.
eugeneia Apr 12, 2016
eb9005b
snabb top: unlink own shm tree to avoid clutter.
eugeneia Apr 13, 2016
5fbe0d6
vhost_user: Add RFC 7223 app counters.
eugeneia Apr 14, 2016
8bb3215
Intel_app: Add RFC 7223 app counters.
eugeneia Apr 14, 2016
7a55478
snabb top: Add --link parameter to list link counters.
eugeneia Apr 14, 2016
dde5da2
core.app: Put app counters under "counters/<app>", update snabb top.
eugeneia Apr 14, 2016
924ff4e
lib.json: Import JSON4Lua 1.0.0, include encode functionality.
eugeneia Apr 18, 2016
8e34093
lib.macaddress: Support numeric initialization; add method to get num…
eugeneia Apr 18, 2016
5f9efd2
core.link: Create “discontinuity-time” counters.
eugeneia Apr 18, 2016
7b39148
snabb top: add `--yang' option to print YANG model as JSON.
eugeneia Apr 19, 2016
8984741
snabb top --yang: Represent uint64_t as decimal string.
eugeneia Apr 20, 2016
ee00d16
[core.lib] Generalize `timer' to optionally accept 'repeating'
eugeneia Apr 28, 2016
45490b8
Revert "Intel_app: Add RFC 7223 app counters."
eugeneia Apr 28, 2016
f0ed10b
intel_app: expose per-pciaddress statistics in `counters/<pciaddress>'.
eugeneia Apr 28, 2016
aca8064
Merge branch 'master' into yang-local
eugeneia May 13, 2016
c186591
lib.protocol.ethernet: Add n_mcast, branch-free Multicast predicate.
eugeneia Apr 25, 2016
b09e843
Fix for f0ed10b: require macaddress module.
eugeneia May 27, 2016
62e2fbf
Revert "lib.json: Import JSON4Lua 1.0.0, include encode functionality."
eugeneia Jun 1, 2016
f4834a5
snabb top: revert --yang dump.
eugeneia Jun 1, 2016
793c394
snabbify statistics model.
eugeneia Jun 2, 2016
2b9ef2c
intel_app: add ifTable MIB related counters.
eugeneia Jun 2, 2016
e9f5dda
lib.macaddress: add bytes method.
eugeneia Jun 2, 2016
6b12e9c
spin out SNMP code from apps.intel.intel10 to lib.ipc.shmem.iftable_mib.
eugeneia Jun 2, 2016
1c9f585
Move model.txt to src/doc/statistics.md.
eugeneia Jun 7, 2016
339f8f1
apps.intel_app: Revert rxerrors calculation, remove broken txerrors.
eugeneia Jun 7, 2016
7ec7f80
Revert "lib.macaddress: add bytes method." and remove int method.
eugeneia Jun 7, 2016
327804f
doc/statistics.md: remove duplicates.
eugeneia Jun 9, 2016
30fcbcb
Merge branch 'master' into statistics-superset
eugeneia Jun 9, 2016
90fc893
core.app: fix bug in #766 introduced while merging 6cac870a.
eugeneia Jun 10, 2016
ceb080f
core.app: fix bug in #766, use app.shmpath during reconfig.
eugeneia Jun 10, 2016
d82729a
core.app: fix typo in previous commit.
eugeneia Jun 10, 2016
5488c68
lib.protocol.ethernet: add is_bcast and n_bcast.
eugeneia Jun 8, 2016
9044c6f
apps.vhost.vhost_user: count rxbcast/txbcast.
eugeneia Jun 8, 2016
5a01612
apps.tap.tap: add statistics counters.
eugeneia Jun 8, 2016
6233d15
core.packet: make max_payload public.
eugeneia Jun 13, 2016
788438e
apps.socket.raw: add statistics counters.
eugeneia Jun 8, 2016
e3fcbbf
Revert "lib.protocol.ethernet: Add n_mcast, branch-free Multicast pre…
eugeneia Jul 4, 2016
b3abaa0
Merge branch 'statistics-superset' into io-stats-1
eugeneia Jul 4, 2016
b418f8f
intel_app: fix wrong “speed” counter value.
eugeneia Jul 4, 2016
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
18 changes: 15 additions & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ not been transmitted or freed. The number of allocatable packets is
limited by the size of the underlying "freelist", e.g. a pool of unused
packet objects from and to which packets are allocated and freed.

— Variable **packet.max_payload**

Maximum payload length for packets. Read-only.

— Function **packet.allocate**

Returns a new empty packet. An an error is raised if there are no packets
Expand Down Expand Up @@ -549,10 +553,18 @@ Returns a table that acts as a bounds checked wrapper around a C array of
ctype and the caller must ensure that the allocated memory region at
*base*/*offset* is at least `sizeof(type)*size` bytes long.

— Function **lib.timer** *s*
— Function **lib.timer** *duration*, *mode*, *timefun*

Returns a closure that will return `false` until *duration* has elapsed. If
*mode* is `'repeating'` the timer will reset itself after returning `true`,
thus implementing an interval timer. *Timefun* is used to get a monotonic time.
*Timefun* defaults to `C.get_time_ns`.

The “deadline” for a given *duration* is computed by adding *duration* to the
result of calling *timefun*, and is saved in the resulting closure. A
*duration* has elapsed when its deadline is less than or equal the value
obtained using *timefun* when calling the closure.

Returns a function that accepts no parameters and acts as a predicate to
test if *ns* nanoseconds have elapsed.

— Function **lib.waitfor** *condition*

Expand Down
188 changes: 6 additions & 182 deletions src/apps/intel/intel10g.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
--- affordable (~$400) network cards made by Intel and others.
---
--- You will need to familiarize yourself with the excellent [data
--- sheet]() to understand this module.
--- sheet](http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82599-10-gbe-controller-datasheet.pdf)
--- to understand this module.

module(...,package.seeall)

Expand All @@ -17,7 +18,6 @@ local pci = require("lib.hardware.pci")
local register = require("lib.hardware.register")
local index_set = require("lib.index_set")
local macaddress = require("lib.macaddress")
local mib = require("lib.ipc.shmem.mib")
local timer = require("core.timer")

local bits, bitset = lib.bits, lib.bitset
Expand Down Expand Up @@ -49,10 +49,6 @@ local default = {
-- The default MTU allows for an IP packet of a total size of 9000
-- bytes without VLAN tagging.
mtu = 9014,

snmp = {
status_timer = 5, -- Interval for IF status check and MIB update
}
}

local function pass (...) return ... end
Expand All @@ -79,7 +75,6 @@ function new_sf (conf)
rdh = 0, -- Cache of receive head (RDH) register
rdt = 0, -- Cache of receive tail (RDT) register
rxnext = 0, -- Index of next buffer to receive
snmp = conf.snmp,
}
return setmetatable(dev, M_sf)
end
Expand Down Expand Up @@ -118,9 +113,6 @@ end
--- See data sheet section 4.6.3 "Initialization Sequence."

function M_sf:init ()
if self.snmp then
self:init_snmp()
end
self:init_dma_memory()

self.redos = 0
Expand Down Expand Up @@ -190,156 +182,6 @@ function M_sf:ingress_packet_drops ()
return self.qs.QPRDC[0]()
end

function M_sf:init_snmp ()
-- Rudimentary population of a row in the ifTable MIB. Allocation
-- of the ifIndex is delegated to the SNMP agent via the name of
-- the interface in ifDescr (currently the PCI address).
local ifTable = mib:new({ directory = self.snmp.directory or nil,
filename = self.pciaddress })
self.snmp.ifTable = ifTable
-- ifTable
ifTable:register('ifDescr', 'OctetStr', self.pciaddress)
ifTable:register('ifType', 'Integer32', 6) -- ethernetCsmacd
ifTable:register('ifMtu', 'Integer32', self.mtu)
ifTable:register('ifSpeed', 'Gauge32', 10000000)

-- After a reset of the NIC, the "native" MAC address is copied to
-- the receive address register #0 from the EEPROM
local ral, rah = self.r.RAL[0](), self.r.RAH[0]()
assert(bit.band(rah, bits({ AV = 31 })) == bits({ AV = 31 }),
"MAC address on "..self.pciaddress.." is not valid ")
local mac = ffi.new("struct { uint32_t lo; uint16_t hi; }")
mac.lo = ral
mac.hi = bit.band(rah, 0xFFFF)
ifTable:register('ifPhysAddress', { type = 'OctetStr', length = 6 },
ffi.string(mac, 6))
ifTable:register('ifAdminStatus', 'Integer32', 1) -- up
ifTable:register('ifOperStatus', 'Integer32', 2) -- down
ifTable:register('ifLastChange', 'TimeTicks', 0)
ifTable:register('_X_ifLastChange_TicksBase', 'Counter64', C.get_unix_time())
ifTable:register('ifInOctets', 'Counter32', 0)
ifTable:register('ifInUcastPkts', 'Counter32', 0)
ifTable:register('ifInDiscards', 'Counter32', 0)
ifTable:register('ifInErrors', 'Counter32', 0) -- TBD
ifTable:register('ifInUnknownProtos', 'Counter32', 0) -- TBD
ifTable:register('ifOutOctets', 'Counter32', 0)
ifTable:register('ifOutUcastPkts', 'Counter32', 0)
ifTable:register('ifOutDiscards', 'Counter32', 0)
ifTable:register('ifOutErrors', 'Counter32', 0) -- TBD
-- ifXTable
ifTable:register('ifName', { type = 'OctetStr', length = 255 },
self.pciaddress)
ifTable:register('ifInMulticastPkts', 'Counter32', 0)
ifTable:register('ifInBroadcastPkts', 'Counter32', 0)
ifTable:register('ifOutMulticastPkts', 'Counter32', 0)
ifTable:register('ifOutBroadcastPkts', 'Counter32', 0)
ifTable:register('ifHCInOctets', 'Counter64', 0)
ifTable:register('ifHCInUcastPkts', 'Counter64', 0)
ifTable:register('ifHCInMulticastPkts', 'Counter64', 0)
ifTable:register('ifHCInBroadcastPkts', 'Counter64', 0)
ifTable:register('ifHCOutOctets', 'Counter64', 0)
ifTable:register('ifHCOutUcastPkts', 'Counter64', 0)
ifTable:register('ifHCOutMulticastPkts', 'Counter64', 0)
ifTable:register('ifHCOutBroadcastPkts', 'Counter64', 0)
ifTable:register('ifLinkUpDownTrapEnable', 'Integer32', 2) -- disabled
ifTable:register('ifHighSpeed', 'Gauge32', 10000)
ifTable:register('ifPromiscuousMode', 'Integer32', 2) -- false
ifTable:register('ifConnectorPresent', 'Integer32', 1) -- true
ifTable:register('ifAlias', { type = 'OctetStr', length = 64 },
self.pciaddress) -- TBD add description
ifTable:register('ifCounterDiscontinuityTime', 'TimeTicks', 0) -- TBD
ifTable:register('_X_ifCounterDiscontinuityTime', 'Counter64', 0) -- TBD

--- Create a timer to periodically check the interface status.
--- Static variables are used in the timer function to avoid
--- garbage.
local status = { [1] = 'up', [2] = 'down' }
local mask = bits{Link_up=30}
local promisc = bits({UPE = 9})
-- Pre-allocate storage for the results of register-reads
local r = {
in_mcast_pkts = { r = self.s.MPRC },
in_bcast_pkts = { r = self.s.BPRC },
in_pkts = { r = self.s.GPRC },
in_octets64 = { r = self.s.GORC64 },

out_mcast_pkts = { r = self.s.MPTC },
out_bcast_pkts = { r = self.s.BPTC },
out_pkts = { r = self.s.GPTC },
out_octets64 = { r = self.s.GOTC64 },
}
local r_keys = {}
for k, _ in pairs(r) do
table.insert(r_keys, k)
r[k].v = ffi.new("uint64_t [1]")
end
local function read_registers()
for _, k in ipairs(r_keys) do
r[k].v[0] = r[k].r()
end
end
self.logger = lib.logger_new({ module = 'intel10g' })
local t = timer.new("Interface "..self.pciaddress.." status checker",
function(t)
local old = ifTable:get('ifOperStatus')
local new = 1
if band(self.r.LINKS(), mask) ~= mask then
new = 2
end
if old ~= new then
self.logger:log("Interface "..self.pciaddress..
" status change: "..status[old]..
" => "..status[new])
ifTable:set('ifOperStatus', new)
ifTable:set('ifLastChange', 0)
ifTable:set('_X_ifLastChange_TicksBase',
C.get_unix_time())
end

ifTable:set('ifPromiscuousMode',
(bit.band(self.r.FCTRL(), promisc) ~= 0ULL
and 1) or 2)
-- Update counters
read_registers()
ifTable:set('ifHCInMulticastPkts', r.in_mcast_pkts.v[0])
ifTable:set('ifInMulticastPkts', r.in_mcast_pkts.v[0])
ifTable:set('ifHCInBroadcastPkts', r.in_bcast_pkts.v[0])
ifTable:set('ifInBroadcastPkts', r.in_bcast_pkts.v[0])
local in_ucast_pkts = r.in_pkts.v[0] - r.in_bcast_pkts.v[0]
- r.in_mcast_pkts.v[0]
ifTable:set('ifHCInUcastPkts', in_ucast_pkts)
ifTable:set('ifInUcastPkts', in_ucast_pkts)
ifTable:set('ifHCInOctets', r.in_octets64.v[0])
ifTable:set('ifInOctets', r.in_octets64.v[0])

ifTable:set('ifHCOutMulticastPkts', r.out_mcast_pkts.v[0])
ifTable:set('ifOutMulticastPkts', r.out_mcast_pkts.v[0])
ifTable:set('ifHCOutBroadcastPkts', r.out_bcast_pkts.v[0])
ifTable:set('ifOutBroadcastPkts', r.out_bcast_pkts.v[0])
local out_ucast_pkts = r.out_pkts.v[0] - r.out_bcast_pkts.v[0]
- r.out_mcast_pkts.v[0]
ifTable:set('ifHCOutUcastPkts', out_ucast_pkts)
ifTable:set('ifOutUcastPkts', out_ucast_pkts)
ifTable:set('ifHCOutOctets', r.out_octets64.v[0])
ifTable:set('ifOutOctets', r.out_octets64.v[0])

-- The RX receive drop counts are only
-- available through the RX stats register.
-- We only read stats register #0 here. See comment
-- in init_statistics()
ifTable:set('ifInDiscards', self.qs.QPRDC[0]())

ifTable:set('ifInErrors', self.s.CRCERRS() +
self.s.ILLERRC() + self.s.ERRBC() +
self.s.RUC() + self.s.RFC() +
self.s.ROC() + self.s.RJC())
end,
1e9 * (self.snmp.status_timer or
default.snmp.status_timer), 'repeating')
timer.activate(t)
return self
end

function M_sf:global_reset ()
local reset = bits{LinkReset=3, DeviceReset=26}
self.r.CTRL(reset)
Expand Down Expand Up @@ -452,22 +294,10 @@ end
local txdesc_flags = bits{ifcs=25, dext=29, dtyp0=20, dtyp1=21, eop=24}

function M_sf:transmit (p)
-- We must not send packets that are bigger than the MTU. This
-- check is currently disabled to satisfy some selftests until
-- agreement on this strategy is reached.
-- if p.length > self.mtu then
-- if self.snmp then
-- local errors = self.snmp.ifTable:ptr('ifOutDiscards')
-- errors[0] = errors[0] + 1
-- end
-- packet.free(p)
-- else
do
self.txdesc[self.tdt].address = memory.virtual_to_physical(p.data)
self.txdesc[self.tdt].options = bor(p.length, txdesc_flags, lshift(p.length+0ULL, 46))
self.txpackets[self.tdt] = p
self.tdt = band(self.tdt + 1, num_descriptors - 1)
end
self.txdesc[self.tdt].address = memory.virtual_to_physical(p.data)
self.txdesc[self.tdt].options = bor(p.length, txdesc_flags, lshift(p.length+0ULL, 46))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future patches, I'd like comments or defined constants explaining numbers like that 46.

self.txpackets[self.tdt] = p
self.tdt = band(self.tdt + 1, num_descriptors - 1)
end

function M_sf:sync_transmit ()
Expand Down Expand Up @@ -653,7 +483,6 @@ function new_pf (conf)
mac_set = index_set:new(127, "MAC address table"),
vlan_set = index_set:new(64, "VLAN Filter table"),
mirror_set = index_set:new(4, "Mirror pool table"),
snmp = conf.snmp,
}
return setmetatable(dev, M_pf)
end
Expand All @@ -679,9 +508,6 @@ function M_pf:close()
end

function M_pf:init ()
if self.snmp then
self:init_snmp()
end
self.redos = 0
local mask = bits{Link_up=30}
for i = 1, 100 do
Expand All @@ -707,7 +533,6 @@ function M_pf:init ()
return self
end

M_pf.init_snmp = M_sf.init_snmp
M_pf.global_reset = M_sf.global_reset
M_pf.disable_interrupts = M_sf.disable_interrupts
M_pf.set_receive_descriptors = pass
Expand Down Expand Up @@ -788,7 +613,6 @@ function M_pf:new_vf (poolnum)
base = self.base, -- mmap()ed register file
s = self.s, -- Statistics registers
mtu = self.mtu,
snmp = self.snmp,
-- and others are our own
r = {}, -- Configuration registers
poolnum = poolnum,
Expand Down
Loading