Skip to content

Commit 0b207a6

Browse files
cpusensor: Search in peci-0 directory
The code was searching /sys/bus/peci/devices for PECI sensors. This results in below directories to be searched on typical 2 socket x86 systems. * peci-0 * 0-30 * 0-31 Where 0-30 and 0-31 exist in peci-0 as well. It is unnecessary, and the files in 0-30 and 0-31 will be searched twice because they exist in peci-0. Change the code to search in /sys/bus/peci/devices/peci-0 to make sure it only search the files within the expected directory. Note that the current peci driver only create peci-0, this code could be easily extended to support peci-1/2/3 in the future. Tested: The time for cpusensor to search the peci sensors reduces from 0.5s to about 0.3s. Signed-off-by: Lei YU <[email protected]> Change-Id: I7b0f3ad7bea7a3dced13a985f0ad19ffda33f6d2
1 parent afd55b9 commit 0b207a6

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: src/CPUSensorMain.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ bool createSensors(boost::asio::io_service& io,
168168
}
169169

170170
std::vector<fs::path> hwmonNamePaths;
171-
if (!findFiles(fs::path(R"(/sys/bus/peci/devices)"),
172-
R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
173-
hwmonNamePaths, 6))
171+
if (!findFiles(fs::path(R"(/sys/bus/peci/devices/peci-0)"),
172+
R"(\d+-.+/peci-.+/hwmon/hwmon\d+/name$)", hwmonNamePaths, 5))
174173
{
175174
std::cerr << "No CPU sensors in system\n";
176175
return true;

Diff for: tests/test_Utils.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,21 @@ TEST_F(TestUtils, findFiles_peciPath_end_with_slash)
145145
EXPECT_TRUE(ret);
146146
EXPECT_EQ(foundPaths.size(), 3u);
147147
}
148+
149+
TEST_F(TestUtils, findFiles_in_sub_peci_match)
150+
{
151+
std::vector<fs::path> foundPaths;
152+
auto ret =
153+
findFiles(peciDir / "peci-0", R"(\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
154+
foundPaths, 5);
155+
EXPECT_TRUE(ret);
156+
EXPECT_EQ(foundPaths.size(), 1u);
157+
158+
foundPaths.clear();
159+
160+
ret = findFiles(peciDir / "peci-0",
161+
R"(\d+-.+/peci-.+/hwmon/hwmon\d+/temp\d+_input)",
162+
foundPaths, 5);
163+
EXPECT_TRUE(ret);
164+
EXPECT_EQ(foundPaths.size(), 3u);
165+
}

0 commit comments

Comments
 (0)