Skip to content

Commit b152828

Browse files
authored
Merge pull request #965 from intel/push-2025-07-21
Push 2025 07 21
2 parents b07bac0 + 367aed5 commit b152828

File tree

4 files changed

+65
-27
lines changed

4 files changed

+65
-27
lines changed

Intel-PMT

src/cpucounters.cpp

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,8 @@ void enableNMIWatchdog(const bool silent)
30333033
}
30343034
#endif
30353035

3036+
constexpr const char* threadCreateErrorMessage = "This might be due to a too low limit for the number of threads per process. Try to increase it\n";
3037+
30363038
class CoreTaskQueue
30373039
{
30383040
std::queue<std::packaged_task<void()> > wQueue;
@@ -3043,28 +3045,38 @@ class CoreTaskQueue
30433045
CoreTaskQueue(CoreTaskQueue &) = delete;
30443046
CoreTaskQueue & operator = (CoreTaskQueue &) = delete;
30453047
public:
3046-
CoreTaskQueue(int32 core) :
3047-
worker([=]() {
3048+
CoreTaskQueue(int32 core)
3049+
{
30483050
try {
3049-
TemporalThreadAffinity tempThreadAffinity(core, false);
3050-
std::unique_lock<std::mutex> lock(m);
3051-
while (1) {
3052-
while (wQueue.empty()) {
3053-
condVar.wait(lock);
3051+
worker = std::thread([=]() {
3052+
try {
3053+
TemporalThreadAffinity tempThreadAffinity(core, false);
3054+
std::unique_lock<std::mutex> lock(m);
3055+
while (1) {
3056+
while (wQueue.empty()) {
3057+
condVar.wait(lock);
3058+
}
3059+
while (!wQueue.empty()) {
3060+
wQueue.front()();
3061+
wQueue.pop();
3062+
}
3063+
}
30543064
}
3055-
while (!wQueue.empty()) {
3056-
wQueue.front()();
3057-
wQueue.pop();
3065+
catch (const std::exception& e)
3066+
{
3067+
std::cerr << "PCM Error. Exception in CoreTaskQueue worker function: " << e.what() << "\n";
30583068
}
3059-
}
3069+
3070+
});
30603071
}
3061-
catch (const std::exception & e)
3072+
catch (const std::exception& e)
30623073
{
3063-
std::cerr << "PCM Error. Exception in CoreTaskQueue worker function: " << e.what() << "\n";
3074+
std::cerr << "PCM Error: caught exception " << e.what() << " while creating thread for core task queue " << core << "\n" <<
3075+
threadCreateErrorMessage;
3076+
throw; // re-throw
30643077
}
30653078

3066-
})
3067-
{}
3079+
}
30683080
void push(std::packaged_task<void()> & task)
30693081
{
30703082
std::unique_lock<std::mutex> lock(m);
@@ -10939,15 +10951,23 @@ CounterWidthExtender::CounterWidthExtender(AbstractRawCounter * raw_counter_, ui
1093910951
last_raw_value = (*raw_counter)();
1094010952
extended_value = last_raw_value;
1094110953
DBG(3, "Initial Value " , extended_value);
10942-
UpdateThread = new std::thread(
10943-
[&]() {
10944-
while (1)
10945-
{
10946-
MySleepMs(static_cast<int>(this->watchdog_delay_ms));
10947-
/* uint64 dummy = */ this->read();
10954+
try {
10955+
UpdateThread = new std::thread(
10956+
[&]() {
10957+
while (1)
10958+
{
10959+
MySleepMs(static_cast<int>(this->watchdog_delay_ms));
10960+
/* uint64 dummy = */ this->read();
10961+
}
1094810962
}
10963+
);
10964+
}
10965+
catch (const std::exception& e)
10966+
{
10967+
std::cerr << "PCM Error: caught exception " << e.what() << " while creating thread for a CounterWidthExtender\n" <<
10968+
threadCreateErrorMessage;
10969+
throw; // re-throw
1094910970
}
10950-
);
1095110971
}
1095210972
CounterWidthExtender::~CounterWidthExtender()
1095310973
{

src/pcm-raw.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ AddEventStatus addEvent(PCM::RawPMUConfigs & curPMUConfigs, string eventStr)
10741074
const auto configArray = split(configStr, ',');
10751075
bool fixed = false;
10761076
std::string lookup;
1077-
auto pmtAddRecord = [&lookup, &pmuName, &config](const std::vector<TelemetryDB::PMTRecord> & records) -> AddEventStatus
1077+
auto pmtAddRecord = [&lookup, &pmuName, &config](const std::vector<TelemetryDB::PMTRecord> & records, const bool first = false) -> AddEventStatus
10781078
{
10791079
if (pmuName == "pmt")
10801080
{
@@ -1083,7 +1083,7 @@ AddEventStatus addEvent(PCM::RawPMUConfigs & curPMUConfigs, string eventStr)
10831083
cerr << "ERROR: lookup \"" << lookup << "\" not found in PMT telemetry database\n";
10841084
return AddEventStatus::Failed;
10851085
}
1086-
if (records.size() > 1)
1086+
if (records.size() > 1 && first == false)
10871087
{
10881088
cerr << "ERROR: lookup \"" << lookup << "\" is ambiguous in PMT telemetry database\n\n";
10891089
for (const auto & record : records)
@@ -1092,10 +1092,11 @@ AddEventStatus addEvent(PCM::RawPMUConfigs & curPMUConfigs, string eventStr)
10921092
record.print(cerr);
10931093
cerr << "\n";
10941094
}
1095+
cerr << "Alternatively use lookupf or ilookupf to select the first record in the list.\n";
10951096
return AddEventStatus::Failed;
10961097
}
10971098
config.second = records[0].fullName;
1098-
assert(records.size() == 1);
1099+
assert(records.size() >= 1);
10991100
config.first[PCM::PMTEventPosition::UID] = records[0].uid;
11001101
config.first[PCM::PMTEventPosition::offset] = records[0].qWordOffset;
11011102
config.first[PCM::PMTEventPosition::type] = (records[0].sampleType == "Snapshot") ? PCM::MSRType::Static : PCM::MSRType::Freerun;
@@ -1150,6 +1151,16 @@ AddEventStatus addEvent(PCM::RawPMUConfigs & curPMUConfigs, string eventStr)
11501151
if (pmtAddRecord(telemDB.ilookup(lookup)) != AddEventStatus::OK)
11511152
return AddEventStatus::Failed;
11521153
}
1154+
else if (pcm_sscanf(item) >> s_expect("lookupf=") >> setw(255) >> lookup)
1155+
{
1156+
if (pmtAddRecord(telemDB.lookup(lookup), true) != AddEventStatus::OK)
1157+
return AddEventStatus::Failed;
1158+
}
1159+
else if (pcm_sscanf(item) >> s_expect("ilookupf=") >> setw(255) >> lookup)
1160+
{
1161+
if (pmtAddRecord(telemDB.ilookup(lookup), true) != AddEventStatus::OK)
1162+
return AddEventStatus::Failed;
1163+
}
11531164
else if (item == "fixed")
11541165
{
11551166
fixed = true;

src/threadpool.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ class ThreadPool {
102102

103103
private:
104104
void addThread() {
105-
threads_.push_back( std::thread( std::bind( &this->execute, this ) ) );
105+
try {
106+
threads_.push_back( std::thread( std::bind( &this->execute, this ) ) );
107+
} catch (const std::exception& e) {
108+
std::cerr << "PCM Error. Exception in ThreadPool::addThread: " << e.what()
109+
<< ". Possible causes: insufficient system resources, thread limit reached, or invalid thread function."
110+
<< " Suggested actions: check system resource availability, verify thread pool configuration, and ensure the thread function is valid.\n";
111+
throw;
112+
}
106113
}
107114

108115
// Executes work items from a std::thread, do not call manually

0 commit comments

Comments
 (0)