Skip to content

Commit 6701b86

Browse files
authored
Merge pull request #224 from intel-innersource/rdementi/ulimit-increase
automatic ulimit increase
2 parents a81806c + 3c2edde commit 6701b86

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/cpucounters.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#ifdef __linux__
5858
#include <sys/mman.h>
5959
#include <dirent.h>
60+
#include <sys/resource.h>
6061
#endif
6162
#endif
6263

@@ -2059,6 +2060,30 @@ std::ofstream* PCM::outfile = nullptr; // output file stream
20592060
std::streambuf* PCM::backup_ofile = nullptr; // backup of original output = cout
20602061
std::streambuf* PCM::backup_ofile_cerr = nullptr; // backup of original output = cerr
20612062

2063+
#ifdef __linux__
2064+
void increaseULimit()
2065+
{
2066+
rlimit lim{};
2067+
if (getrlimit(RLIMIT_NOFILE, &lim) == 0)
2068+
{
2069+
const rlim_t recommendedLimit = 1000000;
2070+
// std::cout << "file open limit: " << lim.rlim_cur << "," << lim.rlim_max << "\n";
2071+
if (lim.rlim_cur < recommendedLimit || lim.rlim_max < recommendedLimit)
2072+
{
2073+
lim.rlim_cur = lim.rlim_max = recommendedLimit;
2074+
if (setrlimit(RLIMIT_NOFILE, &lim) != 0)
2075+
{
2076+
std::cerr << "PCM Info: setrlimit for file limit " << recommendedLimit << " failed with error " << strerror(errno) << "\n";
2077+
}
2078+
}
2079+
}
2080+
else
2081+
{
2082+
std::cerr << "PCM Info: getrlimit for file limit failed with error " << strerror(errno) << "\n";
2083+
}
2084+
}
2085+
#endif
2086+
20622087
PCM::PCM() :
20632088
cpu_family(-1),
20642089
cpu_model(-1),
@@ -2115,6 +2140,9 @@ PCM::PCM() :
21152140
run_state(1),
21162141
needToRestoreNMIWatchdog(false)
21172142
{
2143+
#ifdef __linux__
2144+
increaseULimit();
2145+
#endif
21182146
#ifdef _MSC_VER
21192147
// WARNING: This driver code (msr.sys) is only for testing purposes, not for production use
21202148
Driver drv(Driver::msrLocalPath());

src/msr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ MsrHandle::MsrHandle(uint32 cpu) : fd(-1), cpu_id(cpu)
238238
delete[] path;
239239
if (handle < 0)
240240
{
241-
std::cerr << "PCM Error: can't open MSR handle for core " << cpu << "\n";
241+
std::cerr << "PCM Error: can't open MSR handle for core " << cpu << " (" << strerror(errno) << ")\n";
242242
std::cerr << "Try no-MSR mode by setting env variable PCM_NO_MSR=1\n";
243243
throw std::exception();
244244
}

0 commit comments

Comments
 (0)