Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Ignore specified signal when using perf#12436

Merged
janvorli merged 3 commits into
dotnet:masterfrom
sdmaclea:PR-PAL_IgnoreProfileSignal
Jul 25, 2017
Merged

Ignore specified signal when using perf#12436
janvorli merged 3 commits into
dotnet:masterfrom
sdmaclea:PR-PAL_IgnoreProfileSignal

Conversation

@sdmaclea
Copy link
Copy Markdown

Add a do nothing signal handler to SIGRTMAX for profiling purposes. Allows synchronization point injection into the profile

Add a do nothing signal handler to SIGRTMAX
for profiling purposes.  Allows synchronization
point in injection into the profile
@sdmaclea
Copy link
Copy Markdown
Author

@janvorli PTAL I found this necessary/helpful for profiling more complicated benchmarks.

Comment thread src/pal/src/exception/signal.cpp Outdated
}


void PAL_IgnoreProfileSignal(void)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sdmaclea, could you please explain how the SIGRTMAX is used as a marker?

Copy link
Copy Markdown
Author

@sdmaclea sdmaclea Jun 26, 2017

Choose a reason for hiding this comment

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

@janvorli perf record -g -e cycles:ppp -e signal:* will record instructions samples as the cycle counter expires as well as signals. If I want to inject a marker into a benchmark, I can use something like pkill -64 corerun. When I am profiling a server application, this allows me to sweep through various client configurations and add a marker when the stimulus changes. When I analyze the profile, I can use perf script | <filterscript> to analyze only the events between a specific set of marker. This can be fed into other flows i.e. perf script | <filterscript> | <flamegraph flatten script> | <flamegraph svg script>

For the filter script, I used an awk script like below to only print cycle events after the first SIGRTMAX event:

/.*signal:signal_deliver: sig=.*/ { 
    trace = /=64/;
} 

/sched:/ || /signal:/ { 
    suppress=1 
} 

/cycles:ppp/ { 
    suppress=0 
} 

{ 
    if(trace && !suppress) print 
}

That awk script was designed to work with perf record -g -e cycles:ppp -e sched:* -e signal:signal_deliver --filter "sig==64 || sig==2" It turns tracing on when it receives SIGRTMAX (64) and off when it receives SIGINT (2).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if rather than having the SIGRTMAX hardcoded in the code, we would add a new config option (COMPlus_XXXXX) that would contain the number of signal that we want to ignore? There are no realtime signals on FreeBSD (yet?) or OSX and it seems that the signal used for this purpose doesn't necessarily have to be a realtime one. So such solution would be more universal and also explicit about whether to ignore the signal or not, which seems useful. I could also imagine apps that actually use the SIGRTMAX and host coreclr. Again, the explicit selection of the signal would be helpful in such case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@janvorli Configurable would be good. It may be nice to allowCOMPlus_PerfSignalIgnoreMask could allow multiple bits to be set, but it would probably be limited to 64 bits (0-63). Or a comment describing recommended signals.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that sticking to one signal would be fine. Or can you already see a use case where multiple signals would be useful?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@janvorli I could only speculate that multiple signal might be useful.

Pushed implementation with only single signal.

@sdmaclea sdmaclea changed the title Ignore SIGRTMAX when using perf Ignore specified signal when using perf Jun 28, 2017
Comment thread src/inc/clrconfigvalues.h

#ifdef FEATURE_PERFMAP
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux to enable writing /tmp/perf-$pid.map. It is disabled by default", CLRConfig::REGUTIL_default)
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepeted and ignored as a marker in the perf logs. It is disabled by default", CLRConfig::REGUTIL_default)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A nit - spelling: accepeted -> accepted. LGTM otherwise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@janvorli Done++

Comment thread src/inc/clrconfigvalues.h Outdated

#ifdef FEATURE_PERFMAP
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapEnabled, W("PerfMapEnabled"), 0, "This flag is used on Linux to enable writing /tmp/perf-$pid.map. It is disabled by default", CLRConfig::REGUTIL_default)
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_PerfMapIgnoreSignal, W("PerfMapIgnoreSignal"), 0, "When perf map is enabled, this option will configure the specified signal to be accepted and ignored. This allows it to be used as a marker in the perf logs. It is disabled by default", CLRConfig::REGUTIL_default)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have a strong object to this, but I'm wondering if this should be associated with the perf map stuff (as opposed to not being under FEATURE_PERFMAP and just being called COMPlus_IgnoreSignal or something). I understand that your use case is profiling-associated, but perhaps we can make this a more general concept.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm..
I can leave it dependent on FEATURE_PERFMAP. I can enable it independent to the PerfMapEnabled, if t is is generally useful.

Perf has unique requirement on how the signal should be ignored. Normally, you would tell the kernel to ignore the signal by not delivering it. I had assumed this meant the config should be unique to perf, only needed to handle one signal, and was not generally useful..

Most common orthogonal use cases would be prefer the kernel ignoring a signal. This is significantly faster for the kernel as it doesn't need to do anything.

@adityamandaleeka @janvorli What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sdmaclea I would prefer keeping it as you have it now.

void PAL_IgnoreProfileSignal(int signalNum)
{
#if !HAVE_MACH_EXCEPTIONS
// Add a signal handler which will ignore signals
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: synchronize

Comment thread src/vm/perfmap.cpp Outdated

int signalNum = (int) CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PerfMapIgnoreSignal);

if(signalNum > 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor style nit: space after if

@sdmaclea sdmaclea force-pushed the PR-PAL_IgnoreProfileSignal branch from 00607bd to c0c2b55 Compare July 5, 2017 14:55
@sdmaclea
Copy link
Copy Markdown
Author

sdmaclea commented Jul 5, 2017

@dotnet-bot test Windows_NT arm64 Cross Checked Build and Test

@sdmaclea
Copy link
Copy Markdown
Author

sdmaclea commented Jul 5, 2017

@dotnet-bot test Windows_NT arm64 Checked

@adityamandaleeka
Copy link
Copy Markdown
Member

@dotnet-bot test Ubuntu arm64 Cross Debug Build

1 similar comment
@janvorli
Copy link
Copy Markdown
Member

@dotnet-bot test Ubuntu arm64 Cross Debug Build

@sdmaclea
Copy link
Copy Markdown
Author

sdmaclea commented Jul 19, 2017

@janvorli Ubuntu arm64 CI is broken per @jashook . @jashook @RussKeldorph Is there an ETA for fixing this? Should it be disabled/ignored?

@sdmaclea
Copy link
Copy Markdown
Author

Please ignore the Ubuntu arm64 build error. This is a CI issue. It build locally. I have been using it without an issue for weeks.

Please merge

@janvorli janvorli merged commit 5d105ad into dotnet:master Jul 25, 2017
@sdmaclea sdmaclea deleted the PR-PAL_IgnoreProfileSignal branch August 1, 2017 17:51
@karelz karelz modified the milestone: 2.1.0 Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants