Skip to content

Commit 5702977

Browse files
authored
Merge pull request #211 from kad/opae-multiple-devices
Fix OPAE library to work with multiple cards
2 parents 9d585ea + 37fe284 commit 5702977

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
From f36acdab907e4f97f6f273ef1e81bbdc7e504dfe Mon Sep 17 00:00:00 2001
2+
From: Alexander Kanevskiy <kad@linux.intel.com>
3+
Date: Mon, 26 Aug 2019 17:21:38 +0300
4+
Subject: [PATCH] OPAE in containers: don't enumerate missing device
5+
6+
In case of container usages with FPGA, sysfs entries might have
7+
more information than actually available to the container.
8+
Ignore devices during enumeration that don't have valid /dev
9+
nodes.
10+
---
11+
libopae/plugins/xfpga/enum.c | 18 ++++++++++++++++++
12+
tools/extra/fpgadiag/diag_utils.cpp | 13 ++++++++-----
13+
tools/extra/fpgadiag/perf_counters.cpp | 2 ++
14+
3 files changed, 28 insertions(+), 5 deletions(-)
15+
16+
diff --git a/libopae/plugins/xfpga/enum.c b/libopae/plugins/xfpga/enum.c
17+
index 9ae72629..117fdfd0 100644
18+
--- a/libopae/plugins/xfpga/enum.c
19+
+++ b/libopae/plugins/xfpga/enum.c
20+
@@ -343,6 +343,15 @@ STATIC fpga_result enum_fme(const char *sysfspath, const char *name,
21+
22+
snprintf_s_s(dpath, sizeof(dpath), FPGA_DEV_PATH "/%s", name);
23+
24+
+ // Make device node exists
25+
+ if (stat(dpath, &stats) != 0) {
26+
+ FPGA_MSG("stat failed: %s", strerror(errno));
27+
+ return FPGA_OK;
28+
+ }
29+
+
30+
+ if (!S_ISCHR(stats.st_mode))
31+
+ return FPGA_OK;
32+
+
33+
pdev = add_dev(sysfspath, dpath, parent);
34+
if (!pdev) {
35+
FPGA_MSG("Failed to allocate device");
36+
@@ -421,6 +430,15 @@ STATIC fpga_result enum_afu(const char *sysfspath, const char *name,
37+
38+
snprintf_s_s(dpath, sizeof(dpath), FPGA_DEV_PATH "/%s", name);
39+
40+
+ // Make device node exists
41+
+ if (stat(dpath, &stats) != 0) {
42+
+ FPGA_MSG("stat failed: %s", strerror(errno));
43+
+ return FPGA_OK;
44+
+ }
45+
+
46+
+ if (!S_ISCHR(stats.st_mode))
47+
+ return FPGA_OK;
48+
+
49+
pdev = add_dev(sysfspath, dpath, parent);
50+
if (!pdev) {
51+
FPGA_ERR("Failed to allocate device");
52+
diff --git a/tools/extra/fpgadiag/diag_utils.cpp b/tools/extra/fpgadiag/diag_utils.cpp
53+
index 2c98eb66..f661adc4 100644
54+
--- a/tools/extra/fpgadiag/diag_utils.cpp
55+
+++ b/tools/extra/fpgadiag/diag_utils.cpp
56+
@@ -68,11 +68,14 @@ properties::ptr_t get_properties(intel::utils::option_map::ptr_t opts, fpga_objt
57+
token::ptr_t get_parent_token(handle::ptr_t h)
58+
{
59+
auto props = properties::get(h);
60+
-
61+
- auto tokens = token::enumerate({properties::get(props->parent)});
62+
- if (!tokens.empty())
63+
- {
64+
- return tokens[0];
65+
+ try {
66+
+ auto tokens = token::enumerate({properties::get(props->parent)});
67+
+ if (!tokens.empty())
68+
+ {
69+
+ return tokens[0];
70+
+ }
71+
+ }catch(not_found &) {
72+
+ // Ignore FPGA_NOT_FOUND if process has access only to port and FME is not visible
73+
}
74+
return token::ptr_t();
75+
}
76+
diff --git a/tools/extra/fpgadiag/perf_counters.cpp b/tools/extra/fpgadiag/perf_counters.cpp
77+
index de918dcb..c6af30ac 100644
78+
--- a/tools/extra/fpgadiag/perf_counters.cpp
79+
+++ b/tools/extra/fpgadiag/perf_counters.cpp
80+
@@ -48,6 +48,7 @@ fpga_cache_counters::fpga_cache_counters(token::ptr_t fme)
81+
: fme_(fme)
82+
, perf_feature_rev_(-1)
83+
{
84+
+ if (!fme) return;
85+
auto rev = sysobject::get(fme_, "*perf/revision", FPGA_OBJECT_GLOB);
86+
if (rev) {
87+
perf_feature_rev_ = rev->read64();
88+
@@ -218,6 +219,7 @@ fpga_fabric_counters::fpga_fabric_counters(token::ptr_t fme)
89+
: fme_(fme)
90+
, perf_feature_rev_(-1)
91+
{
92+
+ if (!fme) return;
93+
auto rev = sysobject::get(fme_, "*perf/revision", FPGA_OBJECT_GLOB);
94+
if (rev) {
95+
perf_feature_rev_ = rev->read64();
96+
--
97+
2.16.4
98+

demo/clearlinux-demo-opae/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ RUN swupd update --no-boot-update ${CLEAR_LINUX_VERSION}
1717
# Fetch dependencies and source code
1818
ARG OPAE_RElEASE=1.3.2-1
1919

20-
RUN swupd bundle-add wget c-basic devpkg-json-c devpkg-util-linux devpkg-hwloc doxygen Sphinx && \
20+
RUN swupd bundle-add wget c-basic devpkg-json-c devpkg-util-linux devpkg-hwloc doxygen Sphinx patch && \
2121
mkdir -p /usr/src/opae && \
2222
cd /usr/src/opae && \
2323
wget https://github.com/OPAE/opae-sdk/archive/${OPAE_RElEASE}.tar.gz && \
2424
tar xf *.tar.gz
2525

2626
# Build OPAE
27+
ADD 0001-OPAE-in-containers-don-t-enumerate-missing-device.patch /usr/src/opae/opae-sdk-${OPAE_RElEASE}
2728
RUN cd /usr/src/opae/opae-sdk-${OPAE_RElEASE} && \
29+
patch -p1 < 0001-OPAE-in-containers-don-t-enumerate-missing-device.patch && \
2830
mkdir build && \
2931
cd build && \
3032
cmake .. -DBUILD_ASE=0 -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_SKIP_RPATH=true && \

0 commit comments

Comments
 (0)