Skip to content

Commit

Permalink
Stop reading devices that don't like it
Browse files Browse the repository at this point in the history
Attempting to read devices that don't respond well
to reading causes the fru device scan time to go up,
stop doing that.

Tested: Scan time went down, less messages like
failed to read bus X address XX

Change-Id: I56847f957b7c6bf88ad158ecb4c6a621599c11ab
Signed-off-by: James Feist <james.feist@linux.intel.com>
  • Loading branch information
feistjj committed Nov 18, 2019
1 parent 733f765 commit 7972bb9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/FruDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ static boost::container::flat_map<
std::pair<size_t, size_t>, std::shared_ptr<sdbusplus::asio::dbus_interface>>
foundDevices;

static boost::container::flat_map<size_t, std::set<size_t>> failedAddresses;

boost::asio::io_service io;
auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
auto objServer = sdbusplus::asio::object_server(systemBus);
Expand Down Expand Up @@ -248,6 +250,27 @@ static int64_t readFromEeprom(int flag __attribute__((unused)), int fd,
return read(fd, buf, len);
}

static int getRootBus(size_t bus)
{
auto ec = std::error_code();
auto path = std::filesystem::read_symlink(
std::filesystem::path("/sys/bus/i2c/devices/i2c-" +
std::to_string(bus) + "/mux_device"),
ec);
if (ec)
{
return -1;
}

std::string filename = path.filename();
auto findBus = filename.find("-");
if (findBus == std::string::npos)
{
return -1;
}
return std::stoi(filename.substr(0, findBus));
}

static bool isMuxBus(size_t bus)
{
return is_symlink(std::filesystem::path(
Expand Down Expand Up @@ -467,6 +490,15 @@ int getBusFrus(int file, int first, int last, int bus,

// Scan for i2c eeproms loaded on this bus.
std::set<int> skipList = findI2CEeproms(bus, devices);
std::set<size_t>& failedItems = failedAddresses[bus];

std::set<size_t>* rootFailures = nullptr;
int rootBus = getRootBus(bus);

if (rootBus >= 0)
{
rootFailures = &(failedAddresses[rootBus]);
}

for (int ii = first; ii <= last; ii++)
{
Expand Down Expand Up @@ -496,12 +528,27 @@ int getBusFrus(int file, int first, int last, int bus,

makeProbeInterface(bus, ii);

if (failedItems.find(ii) != failedItems.end())
{
// if we failed to read it once, unlikely we can read it later
continue;
}

if (rootFailures != nullptr)
{
if (rootFailures->find(ii) != rootFailures->end())
{
continue;
}
}

/* Check for Device type if it is 8 bit or 16 bit */
int flag = isDevice16Bit(file);
if (flag < 0)
{
std::cerr << "failed to read bus " << bus << " address " << ii
<< "\n";
failedItems.insert(ii);
continue;
}

Expand Down

0 comments on commit 7972bb9

Please sign in to comment.