From a11da340ecbbfa5f6258234b30699a856ba3ad0d Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:25:34 +0400 Subject: [PATCH 01/18] src/lib/hardware/vfio: get path to driver from environment variables --- src/lib/hardware/vfio.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/hardware/vfio.lua b/src/lib/hardware/vfio.lua index 7254efbc56..7bdff0d02d 100644 --- a/src/lib/hardware/vfio.lua +++ b/src/lib/hardware/vfio.lua @@ -11,6 +11,9 @@ require("lib.hardware.vfio_h") -- Is VFIO initialized yet? initialized = false +-- This path is used if the "SNABB_VFIO_DRIVER" environment variable is not defined +VFIO_DEFAULT_DRIVER_PATH = "/sys/bus/pci/drivers/vfio-pci" + -- Array of mappings that were requested before vfio was initialized. -- -- These must then be mapped at initialization time. @@ -77,9 +80,13 @@ end --- ### Device manipulation. +function get_driver_path () + return os.getenv("SNABB_VFIO_DRIVER") or VFIO_DEFAULT_DRIVER_PATH +end + --- add a device to the vfio-pci driver function bind_device_to_vfio (pciaddress) - lib.writefile("/sys/bus/pci/drivers/vfio-pci/bind", pciaddress) + lib.writefile(get_driver_path() .. "/bind", pciaddress) end function setup_vfio(pciaddress, do_group) From aa795655d048169a34f6fc931d29f6eb8cff02e2 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:25:59 +0400 Subject: [PATCH 02/18] src/lib/hardware/vfio: get path to iommu_groups from environment variables --- src/lib/hardware/vfio.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/hardware/vfio.lua b/src/lib/hardware/vfio.lua index 7bdff0d02d..42cb08af64 100644 --- a/src/lib/hardware/vfio.lua +++ b/src/lib/hardware/vfio.lua @@ -13,6 +13,8 @@ initialized = false -- This path is used if the "SNABB_VFIO_DRIVER" environment variable is not defined VFIO_DEFAULT_DRIVER_PATH = "/sys/bus/pci/drivers/vfio-pci" +-- This path is used if the "SNABB_VFIO_IOMMU_GROUPS" environment variable is not defined +VFIO_DEFAULT_IOMMU_GROUP_PATH = "/sys/kernel/iommu_groups" -- Array of mappings that were requested before vfio was initialized. -- @@ -72,10 +74,16 @@ function device_group(pciaddress) return lib.basename(lib.readlink(pci.path(pciaddress)..'/iommu_group')) end +function get_iommu_groups_path() + return os.getenv("SNABB_VFIO_IOMMU_GROUPS") or VFIO_DEFAULT_IOMMU_GROUP_PATH +end + -- Return all the devices that belong to the same group function group_devices(group) - if not group then return {} end - return lib.files_in_directory('/sys/kernel/iommu_groups/'..group..'/devices/') + if not group then return {} end + return lib.files_in_directory( + get_iommu_groups_path() .. '/' .. group .. '/devices/' + ) end --- ### Device manipulation. From 7df2ce06f5706f1fdd581518acaf9972dff6e169 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Thu, 27 Mar 2014 16:35:55 +0400 Subject: [PATCH 03/18] src/lib/hardware/vfio: function to check vfio availability --- src/lib/hardware/vfio.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/hardware/vfio.lua b/src/lib/hardware/vfio.lua index 42cb08af64..791367359c 100644 --- a/src/lib/hardware/vfio.lua +++ b/src/lib/hardware/vfio.lua @@ -97,6 +97,10 @@ function bind_device_to_vfio (pciaddress) lib.writefile(get_driver_path() .. "/bind", pciaddress) end +function is_vfio_available() + return lib.can_write(get_driver_path() .. "/bind") +end + function setup_vfio(pciaddress, do_group) if do_group then for _,f in ipairs(group_devices(device_group(pciaddress))) do From 56e397e4f1eda02b2d8fd647b8e027a7b23d6c84 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:26:45 +0400 Subject: [PATCH 04/18] src/lib/hardware/pci: get path to pci devices from environment variables --- src/lib/hardware/pci.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/hardware/pci.lua b/src/lib/hardware/pci.lua index 8b5cc5f79c..be84fd0fd8 100644 --- a/src/lib/hardware/pci.lua +++ b/src/lib/hardware/pci.lua @@ -7,6 +7,9 @@ local lib = require("core.lib") require("lib.hardware.pci_h") +-- This path is used if the "SNABB_PCI_DEVICE" environment variable is not defined +PCI_DEFAULT_DEVICE_PATH = "/sys/bus/pci/devices" + --- ### Hardware device information devices = {} @@ -25,7 +28,7 @@ devices = {} --- Initialize (or re-initialize) the `devices` table. function scan_devices () - for _,device in ipairs(lib.files_in_directory("/sys/bus/pci/devices")) do + for _,device in ipairs(lib.files_in_directory(get_pci_device_path())) do local info = device_info(device) if info.driver then table.insert(devices, info) end end @@ -46,8 +49,14 @@ function device_info (pciaddress) return info end +function get_pci_device_path() + return os.getenv("SNABB_PCI_DEVICE") or PCI_DEFAULT_DEVICE_PATH +end + --- Return the path to the sysfs directory for `pcidev`. -function path(pcidev) return "/sys/bus/pci/devices/"..pcidev end +function path(pcidev) + return get_pci_device_path() .. "/" .. pcidev +end -- Return the name of the Lua module that implements support for this device. function which_driver (vendor, device) From f48c60a142d02257b29e8745d444366398120094 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Tue, 25 Mar 2014 22:49:34 +0400 Subject: [PATCH 05/18] src/lib/hardware/bus: use new functions to get path --- src/lib/hardware/bus.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/hardware/bus.lua b/src/lib/hardware/bus.lua index 9dbe1c1846..452302d649 100644 --- a/src/lib/hardware/bus.lua +++ b/src/lib/hardware/bus.lua @@ -16,7 +16,7 @@ devices = {} map_devices = {} function scan_devices () - for _,device in ipairs(lib.files_in_directory("/sys/bus/pci/devices")) do + for _,device in ipairs(lib.files_in_directory(pci.get_pci_device_path())) do local info = device_info(device) if info.driver and not map_devices[device] then table.insert(devices, info) @@ -26,7 +26,7 @@ function scan_devices () end function host_has_vfio() - local files = lib.files_in_directory('/sys/kernel/iommu_groups/') + local files = lib.files_in_directory(vfio.get_iommu_groups_path()) return files and #files > 0 end From 9586972e1bf7130621ad5507ce441f499036d035 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Thu, 27 Mar 2014 16:08:17 +0400 Subject: [PATCH 06/18] src/apps/intel/intel_app: check vfio before test execution --- src/apps/intel/intel_app.lua | 5 +++++ src/core/app.lua | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/apps/intel/intel_app.lua b/src/apps/intel/intel_app.lua index 18213b9e2d..5bf4602328 100644 --- a/src/apps/intel/intel_app.lua +++ b/src/apps/intel/intel_app.lua @@ -73,6 +73,11 @@ function Intel82599:report () end function selftest () + print("selftest: intel_app") + if not vfio.is_vfio_available() then + print("VFIO not available\nTest skipped") + os.exit(app.TEST_SKIPPED_CODE) + end -- Create a pieline: -- Source --> Intel82599(loopback) --> Sink -- and push packets through it. diff --git a/src/core/app.lua b/src/core/app.lua index 4c950a2421..1dc0b20724 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -8,6 +8,8 @@ local config = require("core.config") local timer = require("core.timer") require("core.packet_h") +TEST_SKIPPED_CODE = 43 + -- The set of all active apps and links in the system. -- Indexed both by name (in a table) and by number (in an array). app_table, app_array = {}, {} From e67fa5493e9ba629a816629adcb770975e3f0b5b Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Thu, 27 Mar 2014 16:08:57 +0400 Subject: [PATCH 07/18] src/apps/vhost/vhost_user: check vfio before test execution --- src/apps/vhost/vhost_user.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/apps/vhost/vhost_user.lua b/src/apps/vhost/vhost_user.lua index d5517d301e..887ae090d5 100644 --- a/src/apps/vhost/vhost_user.lua +++ b/src/apps/vhost/vhost_user.lua @@ -418,6 +418,10 @@ end function selftest () print("selftest: vhost_user") + if not vfio.is_vfio_available() then + print("VFIO not available\nTest skipped") + os.exit(app.TEST_SKIPPED_CODE) + end -- Create an app network that proxies packets between a vhost_user -- port (qemu) and an Intel port (in loopback mode). Create -- separate pcap traces for packets received from vhost and intel. From 5c156cdab8de09a26712df4c8596e29971efdf2f Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:28:06 +0400 Subject: [PATCH 08/18] src/apps/intel/intel_app: get pci id for test from environment variables --- src/apps/intel/intel_app.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/apps/intel/intel_app.lua b/src/apps/intel/intel_app.lua index 5bf4602328..76c0057596 100644 --- a/src/apps/intel/intel_app.lua +++ b/src/apps/intel/intel_app.lua @@ -12,6 +12,10 @@ local intel10g = require("apps.intel.intel10g") local vfio = require("lib.hardware.vfio") local config = require("core.config") +-- default id of pci device used in test +-- This ID is used if the "SNABB_TEST_PCI_ID" environment variable is not defined +DEFAULT_TEST_PCI_ID = "0000:01:00.0" + Intel82599 = {} -- Create an Intel82599 App for the device with 'pciaddress'. @@ -72,25 +76,30 @@ function Intel82599:report () register.dump(self.dev.s, true) end +function getTestPCIID() + return os.getenv("SNABB_TEST_PCI_ID") or DEFAULT_TEST_PCI_ID +end + function selftest () print("selftest: intel_app") if not vfio.is_vfio_available() then print("VFIO not available\nTest skipped") os.exit(app.TEST_SKIPPED_CODE) end + local pciid = getTestPCIID() -- Create a pieline: -- Source --> Intel82599(loopback) --> Sink -- and push packets through it. - vfio.bind_device_to_vfio("0000:01:00.0") + vfio.bind_device_to_vfio(pciid) local c = config.new() - config.app(c, "intel10g", Intel82599, "0000:01:00.0") + config.app(c, "intel10g", Intel82599, pciid) config.app(c, "source", basic_apps.Source) config.app(c, "sink", basic_apps.Sink) config.link(c, "source.out -> intel10g.rx") config.link(c, "intel10g.tx -> sink.in") app.configure(c) --[[ - app.apps.intel10g = Intel82599:new("0000:01:00.0") + app.apps.intel10g = Intel82599:new(pciid) app.apps.source = app.new(basic_apps.Source) app.apps.sink = app.new(basic_apps.Sink) app.connect("source", "out", "intel10g", "rx") From fe273365ea508de2b3c506ecc3148971bd4f7487 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:28:37 +0400 Subject: [PATCH 09/18] src/apps/vhost/vhost_user: get pci id for test from environment variables --- src/apps/vhost/vhost_user.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/apps/vhost/vhost_user.lua b/src/apps/vhost/vhost_user.lua index 887ae090d5..f7429d3b97 100644 --- a/src/apps/vhost/vhost_user.lua +++ b/src/apps/vhost/vhost_user.lua @@ -28,6 +28,10 @@ require("apps.vhost.vhost_user_h") assert(ffi.sizeof("struct vhost_user_msg") == 212, "ABI error") +-- default id of pci device used in test +-- This ID is used if the "SNABB_TEST_PCI_ID" environment variable is not defined +DEFAULT_TEST_PCI_ID = "0000:01:00.0" + VhostUser = {} function VhostUser:new (socket_path) @@ -416,6 +420,10 @@ function map_from_qemu (addr, mem_table) error("mapping to host address failed" .. tostring(ffi.cast("void*",addr))) end +function getTestPCIID() + return os.getenv("SNABB_TEST_PCI_ID") or DEFAULT_TEST_PCI_ID +end + function selftest () print("selftest: vhost_user") if not vfio.is_vfio_available() then @@ -439,14 +447,16 @@ function selftest () -- v -- intel pcap -- - pci.unbind_device_from_linux('0000:01:00.0') - vfio.setup_vfio('0000:01:00.0') - vfio.bind_device_to_vfio("0000:01:00.0") + local pciid = getTestPCIID() + + pci.unbind_device_from_linux(pciid) + vfio.setup_vfio(pciid) + vfio.bind_device_to_vfio(pciid) local c = config.new() config.app(c, "vhost_user", VhostUser, "vhost_user_test.sock") config.app(c, "vhost_dump", pcap.PcapWriter, "vhost_vm_dump.cap") config.app(c, "vhost_tee", basic_apps.Tee) - config.app(c, "intel", intel_app.Intel82599, "0000:01:00.0") + config.app(c, "intel", intel_app.Intel82599, pciid) config.app(c, "intel_dump", pcap.PcapWriter, "vhost_nic_dump.cap") config.app(c, "intel_tee", basic_apps.Tee) config.link(c, "vhost_user.tx -> vhost_tee.input") From b64caea988d63866410b2008018c01cb253ad2ee Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:30:16 +0400 Subject: [PATCH 10/18] src/core/memory: calculate size in bytes only if varialble is not null --- src/core/memory.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/memory.lua b/src/core/memory.lua index f6fb5da7b4..7a17eeeb39 100644 --- a/src/core/memory.lua +++ b/src/core/memory.lua @@ -70,7 +70,9 @@ end function get_huge_page_size () local meminfo = lib.readfile("/proc/meminfo", "*a") local _,_,hugesize = meminfo:find("Hugepagesize: +([0-9]+) kB") - return tonumber(hugesize) * 1024 + return hugesize + and tonumber(hugesize) * 1024 + or 2048 -- A typical x86 system will have a Huge Page Size of 2048 kBytes end base_page_size = 4096 From 5e59668ca6d6a91b6b8470aedcde9aa5ff5d9a23 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:31:04 +0400 Subject: [PATCH 11/18] src/core/memory: get path to hugepages files from environment variables --- src/core/memory.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/memory.lua b/src/core/memory.lua index 7a17eeeb39..4faf853f23 100644 --- a/src/core/memory.lua +++ b/src/core/memory.lua @@ -6,6 +6,8 @@ local C = ffi.C local lib = require("core.lib") require("core.memory_h") +-- This path is used if the "SNABB_HUGEPAGES" environment variable is not defined +DEFAULT_HUGEPAGES_PATH = "/proc/sys/vm/nr_hugepages" -- hook variables @@ -59,12 +61,16 @@ function reserve_new_page () set_hugepages(get_hugepages() + 1) end +function get_hugepages_path() + return os.getenv("SNABB_HUGEPAGES") or DEFAULT_HUGEPAGES_PATH +end + function get_hugepages () - return lib.readfile("/proc/sys/vm/nr_hugepages", "*n") + return lib.readfile(get_hugepages_path(), "*n") end function set_hugepages (n) - lib.writefile("/proc/sys/vm/nr_hugepages", tostring(n)) + lib.writefile(get_hugepages_path(), tostring(n)) end function get_huge_page_size () @@ -97,7 +103,7 @@ end function selftest (options) print("selftest: memory") require("lib.hardware.bus") - print("HugeTLB pages (/proc/sys/vm/nr_hugepages): " .. get_hugepages()) + print("HugeTLB pages (" .. get_hugepages_path() .. "): " .. get_hugepages()) for i = 1, 4 do io.write(" Allocating a "..(huge_page_size/1024/1024).."MB HugeTLB: ") io.flush() @@ -107,7 +113,7 @@ function selftest (options) ffi.cast("uint32_t*", dmaptr)[0] = 0xdeadbeef -- try a write assert(dmaptr ~= nil and dmalen == huge_page_size) end - print("HugeTLB pages (/proc/sys/vm/nr_hugepages): " .. get_hugepages()) + print("HugeTLB pages (" .. get_hugepages_path() .. "): " .. get_hugepages()) print("HugeTLB page allocation OK.") end From 1bc33ab3d29cece8dd612fabb9dcfe4b7d17db57 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sat, 29 Mar 2014 15:31:36 +0400 Subject: [PATCH 12/18] src/core/memory: get path to meminfo file from environment variable --- src/core/memory.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/memory.lua b/src/core/memory.lua index 4faf853f23..e790637814 100644 --- a/src/core/memory.lua +++ b/src/core/memory.lua @@ -8,6 +8,8 @@ require("core.memory_h") -- This path is used if the "SNABB_HUGEPAGES" environment variable is not defined DEFAULT_HUGEPAGES_PATH = "/proc/sys/vm/nr_hugepages" +-- This path is used if the "SNABB_MEMINFO" environment variable is not defined +DEFAULT_MEMINFO_PATH = "/proc/meminfo" -- hook variables @@ -65,6 +67,10 @@ function get_hugepages_path() return os.getenv("SNABB_HUGEPAGES") or DEFAULT_HUGEPAGES_PATH end +function get_meminfo_path() + return os.getenv("SNABB_MEMINFO") or DEFAULT_MEMINFO_PATH +end + function get_hugepages () return lib.readfile(get_hugepages_path(), "*n") end @@ -74,7 +80,7 @@ function set_hugepages (n) end function get_huge_page_size () - local meminfo = lib.readfile("/proc/meminfo", "*a") + local meminfo = lib.readfile(get_meminfo_path(), "*a") local _,_,hugesize = meminfo:find("Hugepagesize: +([0-9]+) kB") return hugesize and tonumber(hugesize) * 1024 From 022895cdf737f3c5f4d9210ab4e7c2318371c2e8 Mon Sep 17 00:00:00 2001 From: Mikhail Nazarov Date: Sun, 30 Mar 2014 20:53:12 +0400 Subject: [PATCH 13/18] src/Makefile: check exitcode of test --- src/Makefile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index c8d9c93288..de52a2181a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,6 +4,8 @@ E= @echo #Q= #E= @: +TEST_SKIPPED="43" + SRCDIR = $(shell find . -type d -not -regex './obj.*' -printf '%P ') OBJDIR = $(patsubst %,obj/%,$(SRCDIR)) @@ -47,7 +49,18 @@ test: $(TESTMODS) $(TESTMODS): testlog snabbswitch $(E) "TEST $@" - $(Q) ./snabbswitch -t $@ > testlog/$@ || (echo "*** EXIT CODE: $?" >> testlog/$@; echo "ERROR testlog/$@") + $(Q) ./snabbswitch -t $@ > testlog/$@ || ( \ + EXITCODE="$$?"; \ + [ "$$EXITCODE" -eq $(TEST_SKIPPED) ] \ + && ( \ + echo "SKIPPED testlog/$@"; \ + echo "EXITCODE: $$EXITCODE" >> testlog/$@; \ + ) \ + || ( \ + echo "ERROR testlog/$@"; \ + echo "EXITCODE: $$EXITCODE" >> testlog/$@; \ + ) \ + ) $(OBJDIR) testlog: $(E) "DIR $@" From 9a08c5b77eab3690a50d83160ece9fdfa6100b65 Mon Sep 17 00:00:00 2001 From: Vladimir Fedin Date: Mon, 31 Mar 2014 05:41:14 -0700 Subject: [PATCH 14/18] src/doc/hacking.md: environment variables info added --- src/doc/hacking.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/doc/hacking.md diff --git a/src/doc/hacking.md b/src/doc/hacking.md new file mode 100644 index 0000000000..ca3e3176ae --- /dev/null +++ b/src/doc/hacking.md @@ -0,0 +1,32 @@ +Several environment variables can be set for snabbswitch code: + +* SNABB_VFIO_DRIVER + Default value "/sys/bus/pci/drivers/vfio-pci" + +* SNABB_VFIO_IOMMU_GROUPS + Default value "/sys/kernel/iommu_groups" + +* SNABB_PCI_DEVICE + Default value "/sys/bus/pci/devices" + +* SNABB_TEST_PCI_ID + Default value "0000:01:00.0" + +* SNABB_HUGEPAGES + Default value "/proc/sys/vm/nr_hugepages" + +* SNABB_MEMINFO + Default value "/proc/meminfo" + +You can run tests defining some of the variables: + + cd src; sudo SNABB_MEMINFO=/proc/meminfo make test; + +if a test can't find resource needed it will usually skip and return code 43 +(TEST_SKIPPED_CODE). + +Also separate commands can utilize environment virables changes: + + sudo SNABB_HUGEPAGES=/proc/sys/vm/nr_hugepages snabbswitch -l designs.basic.basic + +FIXME: add some sane examples and explanatory notes to variables. From 5fb707915b0267f36733780b0b00ba6d2b013238 Mon Sep 17 00:00:00 2001 From: Vladimir Fedin Date: Tue, 1 Apr 2014 02:27:42 +0400 Subject: [PATCH 15/18] core/app.lua, lib/hardware/pci.lua, vfio.lua: variable naming style fixes --- src/core/app.lua | 2 +- src/lib/hardware/pci.lua | 4 ++-- src/lib/hardware/vfio.lua | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/app.lua b/src/core/app.lua index 1dc0b20724..0612abe255 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -8,7 +8,7 @@ local config = require("core.config") local timer = require("core.timer") require("core.packet_h") -TEST_SKIPPED_CODE = 43 +test_skipped_code = 43 -- The set of all active apps and links in the system. -- Indexed both by name (in a table) and by number (in an array). diff --git a/src/lib/hardware/pci.lua b/src/lib/hardware/pci.lua index be84fd0fd8..a4fe0d3804 100644 --- a/src/lib/hardware/pci.lua +++ b/src/lib/hardware/pci.lua @@ -8,7 +8,7 @@ local lib = require("core.lib") require("lib.hardware.pci_h") -- This path is used if the "SNABB_PCI_DEVICE" environment variable is not defined -PCI_DEFAULT_DEVICE_PATH = "/sys/bus/pci/devices" +pci_default_device_path = "/sys/bus/pci/devices" --- ### Hardware device information @@ -50,7 +50,7 @@ function device_info (pciaddress) end function get_pci_device_path() - return os.getenv("SNABB_PCI_DEVICE") or PCI_DEFAULT_DEVICE_PATH + return os.getenv("SNABB_PCI_DEVICE") or pci_default_device_path end --- Return the path to the sysfs directory for `pcidev`. diff --git a/src/lib/hardware/vfio.lua b/src/lib/hardware/vfio.lua index 791367359c..2d6179e592 100644 --- a/src/lib/hardware/vfio.lua +++ b/src/lib/hardware/vfio.lua @@ -12,9 +12,9 @@ require("lib.hardware.vfio_h") initialized = false -- This path is used if the "SNABB_VFIO_DRIVER" environment variable is not defined -VFIO_DEFAULT_DRIVER_PATH = "/sys/bus/pci/drivers/vfio-pci" +vfio_default_driver_path = "/sys/bus/pci/drivers/vfio-pci" -- This path is used if the "SNABB_VFIO_IOMMU_GROUPS" environment variable is not defined -VFIO_DEFAULT_IOMMU_GROUP_PATH = "/sys/kernel/iommu_groups" +vfio_default_iommu_group_path = "/sys/kernel/iommu_groups" -- Array of mappings that were requested before vfio was initialized. -- @@ -75,7 +75,7 @@ function device_group(pciaddress) end function get_iommu_groups_path() - return os.getenv("SNABB_VFIO_IOMMU_GROUPS") or VFIO_DEFAULT_IOMMU_GROUP_PATH + return os.getenv("SNABB_VFIO_IOMMU_GROUPS") or vfio_default_iommu_group_path end -- Return all the devices that belong to the same group @@ -89,7 +89,7 @@ end --- ### Device manipulation. function get_driver_path () - return os.getenv("SNABB_VFIO_DRIVER") or VFIO_DEFAULT_DRIVER_PATH + return os.getenv("SNABB_VFIO_DRIVER") or vfio_default_driver_path end --- add a device to the vfio-pci driver From 424d1df12b5e07af8599f6e5910347514f7069dd Mon Sep 17 00:00:00 2001 From: Vladimir Fedin Date: Tue, 1 Apr 2014 02:28:27 +0400 Subject: [PATCH 16/18] src/apps/intel/intel_app.lua: pci id default removed, check added --- src/apps/intel/intel_app.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/apps/intel/intel_app.lua b/src/apps/intel/intel_app.lua index 76c0057596..21b93c2abe 100644 --- a/src/apps/intel/intel_app.lua +++ b/src/apps/intel/intel_app.lua @@ -12,10 +12,6 @@ local intel10g = require("apps.intel.intel10g") local vfio = require("lib.hardware.vfio") local config = require("core.config") --- default id of pci device used in test --- This ID is used if the "SNABB_TEST_PCI_ID" environment variable is not defined -DEFAULT_TEST_PCI_ID = "0000:01:00.0" - Intel82599 = {} -- Create an Intel82599 App for the device with 'pciaddress'. @@ -77,16 +73,21 @@ function Intel82599:report () end function getTestPCIID() - return os.getenv("SNABB_TEST_PCI_ID") or DEFAULT_TEST_PCI_ID + return os.getenv("SNABB_TEST_PCI_ID") end function selftest () print("selftest: intel_app") if not vfio.is_vfio_available() then print("VFIO not available\nTest skipped") - os.exit(app.TEST_SKIPPED_CODE) + os.exit(app.test_skipped_code) end + local pciid = getTestPCIID() + if not pciid then + print("SNABB_sPCI_ID was not set\nTest skipped") + os.exit(app.test_skipped_code) + end -- Create a pieline: -- Source --> Intel82599(loopback) --> Sink -- and push packets through it. From 22588ca5a6eceaaa95cacfa7808019605d31a848 Mon Sep 17 00:00:00 2001 From: Vladimir Fedin Date: Tue, 1 Apr 2014 02:28:52 +0400 Subject: [PATCH 17/18] src/apps/vhost/vhost_user.lua: pci id default remived, checks added --- src/apps/vhost/vhost_user.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/apps/vhost/vhost_user.lua b/src/apps/vhost/vhost_user.lua index f7429d3b97..18d5a86b4c 100644 --- a/src/apps/vhost/vhost_user.lua +++ b/src/apps/vhost/vhost_user.lua @@ -28,10 +28,6 @@ require("apps.vhost.vhost_user_h") assert(ffi.sizeof("struct vhost_user_msg") == 212, "ABI error") --- default id of pci device used in test --- This ID is used if the "SNABB_TEST_PCI_ID" environment variable is not defined -DEFAULT_TEST_PCI_ID = "0000:01:00.0" - VhostUser = {} function VhostUser:new (socket_path) @@ -421,14 +417,18 @@ function map_from_qemu (addr, mem_table) end function getTestPCIID() - return os.getenv("SNABB_TEST_PCI_ID") or DEFAULT_TEST_PCI_ID + return os.getenv("SNABB_TEST_PCI_ID") +end + +function getVhostUserSocketFile() + return os.getenv("SNABB_VHOST_USER_SOCKET_FILE") end function selftest () print("selftest: vhost_user") if not vfio.is_vfio_available() then print("VFIO not available\nTest skipped") - os.exit(app.TEST_SKIPPED_CODE) + os.exit(app.test_skipped_code) end -- Create an app network that proxies packets between a vhost_user -- port (qemu) and an Intel port (in loopback mode). Create @@ -448,12 +448,22 @@ function selftest () -- intel pcap -- local pciid = getTestPCIID() + if not pciid then + print("SNABB_TEST_PCI_ID was not set\nTest skipped") + os.exit(app.test_skipped_code) + end + + local vhost_user_sock = getVhostUserSocketFile() + if not vhost_user_sock then + print("SNABB_VHOST_USER_SOCKET_FILE was not set\nTest skipped") + os.exit(app.test_skipped_code) + end pci.unbind_device_from_linux(pciid) vfio.setup_vfio(pciid) vfio.bind_device_to_vfio(pciid) local c = config.new() - config.app(c, "vhost_user", VhostUser, "vhost_user_test.sock") + config.app(c, "vhost_user", VhostUser, vhost_user_sock) config.app(c, "vhost_dump", pcap.PcapWriter, "vhost_vm_dump.cap") config.app(c, "vhost_tee", basic_apps.Tee) config.app(c, "intel", intel_app.Intel82599, pciid) From e33c4cd42b46fc42561f88a51ab44dcd787ff3f6 Mon Sep 17 00:00:00 2001 From: Vladimir Fedin Date: Tue, 1 Apr 2014 02:29:24 +0400 Subject: [PATCH 18/18] src/doc/hacking.md: no defaults update, new variable added --- src/doc/hacking.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/doc/hacking.md b/src/doc/hacking.md index ca3e3176ae..4923cd0045 100644 --- a/src/doc/hacking.md +++ b/src/doc/hacking.md @@ -9,18 +9,22 @@ Several environment variables can be set for snabbswitch code: * SNABB_PCI_DEVICE Default value "/sys/bus/pci/devices" -* SNABB_TEST_PCI_ID - Default value "0000:01:00.0" - * SNABB_HUGEPAGES Default value "/proc/sys/vm/nr_hugepages" * SNABB_MEMINFO Default value "/proc/meminfo" +* SNABB_VHOST_USER_SOCKET_FILE + No default value + +* SNABB_TEST_PCI_ID + No default value + You can run tests defining some of the variables: - cd src; sudo SNABB_MEMINFO=/proc/meminfo make test; + cd src; sudo SNABB_TEST_PCI_ID="0000:01:00.0" \ + SNABB_VHOST_USER_SOCKET_FILE="vhost_user_test.sock" make test; if a test can't find resource needed it will usually skip and return code 43 (TEST_SKIPPED_CODE).