Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCM::checkStatus() implemented #814

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions src/cpucounters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <condition_variable>
#include <mutex>
#include <atomic>
#include <system_error>

#ifdef __APPLE__
#include <sys/types.h>
Expand Down Expand Up @@ -3834,30 +3835,54 @@ PCM::ErrorCode PCM::program(const PCM::ProgramMode mode_, const void * parameter
return PCM::Success;
}

void PCM::checkStatus(const PCM::ErrorCode status)
{
switch (status)
{
case pcm::PCM::Success:
{
break;
}
case pcm::PCM::MSRAccessDenied:
throw std::system_error(pcm::PCM::MSRAccessDenied, std::generic_category(),
"Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access).");
case pcm::PCM::PMUBusy:
throw std::system_error(pcm::PCM::PMUBusy, std::generic_category(),
"Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit"
" is occupied by other application). Try to stop the application that uses PMU,"
" or reset PMU configuration from PCM application itself");
default:
throw std::system_error(pcm::PCM::UnknownError, std::generic_category(),
"Access to Intel(r) Performance Counter Monitor has denied (Unknown error).");
}
}

void PCM::checkError(const PCM::ErrorCode code)
{
switch (code)
try
{
case PCM::Success:
break;
case PCM::MSRAccessDenied:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (no MSR or PCI CFG space access).\n";
exit(EXIT_FAILURE);
case PCM::PMUBusy:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (Performance Monitoring Unit is occupied by other application)\n";
std::cerr << "Try to stop the application that uses PMU, or reset PMU configuration from PCM application itself\n";
std::cerr << "You can try to reset PMU configuration now. Try to reset? (y/n)\n";
char yn;
std::cin >> yn;
if ('y' == yn)
{
resetPMU();
std::cerr << "PMU configuration has been reset. Try to rerun the program again.\n";
}
exit(EXIT_FAILURE);
default:
std::cerr << "Access to Intel(r) Performance Counter Monitor has denied (Unknown error).\n";
exit(EXIT_FAILURE);
checkStatus(code);
}
catch (const std::system_error &e)
{
switch (e.code().value())
{
case PCM::PMUBusy:
std::cerr << e.what() << "\n"
<< "You can try to reset PMU configuration now. Try to reset? (y/n)" << std::endl;
char yn;
std::cin >> yn;
if ('y' == yn)
{
resetPMU();
std::cerr << "PMU configuration has been reset. Try to rerun the program again." << std::endl;
}
exit(EXIT_FAILURE);
case PCM::MSRAccessDenied:
default:
std::cerr << e.what() << std::endl;
exit(EXIT_FAILURE);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/cpucounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,12 @@ class PCM_API PCM
*/
ErrorCode program(const ProgramMode mode_ = DEFAULT_EVENTS, const void * parameter_ = NULL, const bool silent = false, const int pid = -1); // program counters and start counting

/*! \brief checks the error without side effects.
\throw std::system_error generic_category exception with PCM error code.
\param code error code from the 'program' call
*/
void checkStatus(const ErrorCode status);

/*! \brief checks the error and suggests solution and/or exits the process
\param code error code from the 'program' call
*/
Expand Down