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

dynamic: Fix -U for -fpatchable-function-entry #1799

Merged

Conversation

honggyukim
Copy link
Collaborator

@honggyukim honggyukim commented Aug 6, 2023

We have missed handling -U option to functions compiled with -fpatchable-function-entry.

This patch fixes the problem as follows.

Before:

  $ ./runtest.py "265|266"
  Start 2 tests with 2 worker

  Compiler                  gcc                                           clang
  Runtime test case         pg             finstrument-fu fpatchable-fun  pg             finstrument-fu fpatchable-fun
  ------------------------: O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os  O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os
  265 patchable_dynamic3  : NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG  NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG
  266 patchable_dynamic4  : NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG  NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG

After:

  $ ./runtest.py "265|266"
  Start 2 tests with 2 worker

  Compiler                  gcc                                           clang
  Runtime test case         pg             finstrument-fu fpatchable-fun  pg             finstrument-fu fpatchable-fun
  ------------------------: O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os  O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os
  265 patchable_dynamic3  : OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK  OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK
  266 patchable_dynamic4  : OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK  OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK

This is verified in both x86_64 and aarch64.

Fixes: 151fb61 ("dynamic: Refactor 'match_pattern_list'")

@@ -623,6 +623,7 @@ int mcount_unpatch_func(struct mcount_dynamic_info *mdi, struct uftrace_symbol *

switch (mdi->type) {
case DYNAMIC_FENTRY:
case DYNAMIC_PATCHABLE:
Copy link
Owner

Choose a reason for hiding this comment

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

But there's nothing to unpatch for -fpatchable-function-entry as they are already NOPs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does its job in the following example.

$ g++ -fpatchable-function-entry=5 example.cpp

$ uftrace record -P. -U ^std:: a.out

Since -P. asks patching all the available functions, we need a way to suppress the previous patching request.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, multiple updates also make it useful.

else if (match == 1)
mcount_patch_func_with_stats(mdi, sym);
else
mcount_unpatch_func(mdi, sym, NULL);
Copy link
Owner

Choose a reason for hiding this comment

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

IIRC I saw this change in the Ciena's work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, it looks 151fb61 missed fixing patch_patchable_func_matched along with patch_normal_func_matched.

Copy link
Owner

Choose a reason for hiding this comment

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

As it has other problems, I think I can merge this one first.

We have missed handling -U option to functions compiled with
-fpatchable-function-entry.

This patch fixes the problem as follows.

Before:
  $ ./runtest.py "265|266"
  Start 2 tests with 2 worker

  Compiler                  gcc                                           clang
  Runtime test case         pg             finstrument-fu fpatchable-fun  pg             finstrument-fu fpatchable-fun
  ------------------------: O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os  O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os
  265 patchable_dynamic3  : NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG  NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG
  266 patchable_dynamic4  : NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG  NG NG NG NG NG NG NG NG NG NG NG NG NG NG NG

After:
  $ ./runtest.py "265|266"
  Start 2 tests with 2 worker

  Compiler                  gcc                                           clang
  Runtime test case         pg             finstrument-fu fpatchable-fun  pg             finstrument-fu fpatchable-fun
  ------------------------: O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os  O0 O1 O2 O3 Os O0 O1 O2 O3 Os O0 O1 O2 O3 Os
  265 patchable_dynamic3  : OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK  OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK
  266 patchable_dynamic4  : OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK  OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK

This is verified in both x86_64 and aarch64.

Fixes: 151fb61 ("dynamic: Refactor 'match_pattern_list'")
Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
@honggyukim honggyukim force-pushed the check/unpatch-for-patchable-func branch from f1150cf to 782e0bc Compare September 3, 2023 14:50
@honggyukim
Copy link
Collaborator Author

I just added the following line at the commit message.

Fixes: 151fb611 ("dynamic: Refactor 'match_pattern_list'")

Copy link
Owner

@namhyung namhyung left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -623,6 +623,7 @@ int mcount_unpatch_func(struct mcount_dynamic_info *mdi, struct uftrace_symbol *

switch (mdi->type) {
case DYNAMIC_FENTRY:
case DYNAMIC_PATCHABLE:
Copy link
Owner

Choose a reason for hiding this comment

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

Ok, multiple updates also make it useful.

else if (match == 1)
mcount_patch_func_with_stats(mdi, sym);
else
mcount_unpatch_func(mdi, sym, NULL);
Copy link
Owner

Choose a reason for hiding this comment

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

As it has other problems, I think I can merge this one first.

@namhyung namhyung merged commit 58e7307 into namhyung:master Sep 12, 2023
3 checks passed
@honggyukim honggyukim deleted the check/unpatch-for-patchable-func branch September 12, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants