<commit_before>module(...,package.seeall)

local ffi = require("ffi")
local C = ffi.C

local lib      = require("core.lib")
local freelist = require("core.freelist")
local buffer   = require("core.buffer")
local packet   = require("core.packet")
                 require("apps.solarflare.ef_vi_h")

local EVENTS_PER_POLL = 256
local RECEIVE_BUFFER_COUNT = 256
local FLUSH_RECEIVE_QUEUE_THRESHOLD = 32
local TX_BUFFER_COUNT = 256

local ciul = ffi.load("ciul")

local ef_vi_version = ffi.string(ciul.ef_vi_version_str())
print("ef_vi loaded, version " .. ef_vi_version)

-- common utility functions

ffi.cdef[[
char *strerror(int errnum);
]]

local function try (rc, message)
   if rc < 0 then
      error(string.format("%s failed: %s", message,
                          ffi.string(C.strerror(ffi.errno()))))
   end
   return rc
end

events = ffi.new("ef_event[" .. EVENTS_PER_POLL .. "]")
tx_request_ids = ffi.new("ef_request_id[" .. C.EF_VI_TRANSMIT_BATCH .. "]")

SolarFlareNic = {}
SolarFlareNic.__index = SolarFlareNic
SolarFlareNic.version = ef_vi_version

function SolarFlareNic:new(args)
   assert(args.ifname, "missing ifname argument")
   args.receives_enqueued = 0
   local dev = setmetatable(args, { __index = SolarFlareNic })
   return dev:open()
end

function SolarFlareNic:enqueue_receive(id)
   self.rxbuffers[id] = buffer.allocate()<commit_msg>add set_rx_buffer_freelist method and allocation code<commit_after>module(...,package.seeall)

local ffi = require("ffi")
local C = ffi.C

local lib      = require("core.lib")
local freelist = require("core.freelist")
local buffer   = require("core.buffer")
local packet   = require("core.packet")
                 require("apps.solarflare.ef_vi_h")

local EVENTS_PER_POLL = 256
local RECEIVE_BUFFER_COUNT = 256
local FLUSH_RECEIVE_QUEUE_THRESHOLD = 32
local TX_BUFFER_COUNT = 256

local ciul = ffi.load("ciul")

local ef_vi_version = ffi.string(ciul.ef_vi_version_str())
print("ef_vi loaded, version " .. ef_vi_version)

-- common utility functions

ffi.cdef[[
char *strerror(int errnum);
]]

local function try (rc, message)
   if rc < 0 then
      error(string.format("%s failed: %s", message,
                          ffi.string(C.strerror(ffi.errno()))))
   end
   return rc
end

events = ffi.new("ef_event[" .. EVENTS_PER_POLL .. "]")
tx_request_ids = ffi.new("ef_request_id[" .. C.EF_VI_TRANSMIT_BATCH .. "]")

SolarFlareNic = {}
SolarFlareNic.__index = SolarFlareNic
SolarFlareNic.version = ef_vi_version

function SolarFlareNic:new(args)
   assert(args.ifname, "missing ifname argument")
   args.receives_enqueued = 0
   local dev = setmetatable(args, { __index = SolarFlareNic })
   return dev:open()
end

-- Allocate receive buffers from the given freelist.
function SolarFlareNic:set_rx_buffer_freelist (fl)
   assert(fl)
   self.rx_buffer_freelist = fl
end

function SolarFlareNic:enqueue_receive(id)
   local fl = self.rx_buffer_freelist
   if fl then
      if freelist.nfree(fl) > 0 then
         self.rxbuffers[id] = freelist.remove(fl)
      else
         return
      end
   else
      self.rxbuffers[id] = buffer.allocate()
   end
{'fraction_non_alphanumeric': 0.11925425908068145, 'fraction_numerical': 0.008678881388621022, 'mean_word_length': 3.8625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3610158', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1101, 'n_words': 231}