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

Add output of cbrtrace.c to support branch entropy calculation. #6278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fzhang1991
Copy link

Add the output of CBR instruction number, taken number, and not taken number on the console before the information of "Client 'cbrtrace' exiting,", like this:
CBR instruction number: 826871, taken: 432406, not taken: 394465
Client 'cbrtrace' exiting

Instead of printing all the branch information, a commonly used metric to evaluate branch behavior is branch entropy. Branch entropy is calculated based on the taken ratio of CBR instructions

Copy link
Contributor

@derekbruening derekbruening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting a contribution. Please see the review comments.

/* Clean call for the cbr */
static void
at_cbr(app_pc inst_addr, app_pc targ_addr, app_pc fall_addr, int taken, void *bb_addr)
{
cbrn += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This global variable increment is racy and will be inaccurate for many-threaded apps. Best to use thread-local counters and aggregate at thread exit time under a lock (see e.g. instrace_simple num_refs).


static client_id_t client_id;

static int tls_idx;

static long cbrn = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never seen "n" as a suffix -- best to use a clearer name like "cbr_count".

@@ -93,6 +98,8 @@ event_thread_exit(void *drcontext)
static void
event_exit(void)
{
dr_fprintf(STDERR, "CBR instruction number: %ld, taken: %ld, not taken: %ld\n", cbrn,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be inside SHOW_RESULTS to allow a build with no output.

@@ -75,10 +80,10 @@ event_thread_init(void *drcontext)
{
file_t log;
log =
log_file_open(client_id, drcontext, NULL /* using client lib path */, "cbrtrace",
log_file_open(client_id, drcontext, NULL /* using client lib path */, "cbrtrace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please maintain the clang-format style. This is likely why all the tests are failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants