-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Timer based profiler #6642
Merged
Merged
Timer based profiler #6642
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a583779
Add support for timer interrupt based profiling, which is useful for …
8e7e85f
Update runtime_api file with new routines.
28c649b
Turn locking back on in timer based profiling case as it can be used
0423ec9
Formatting.
dfc84a3
Formatting.
94dd632
Add target flag for timer profiling and extend performance_profiler
ad9da86
Formatting.
95342b7
Update cover page on TPS report.
a414e12
Merge branch 'master' into timer_based_profiler
3ab0ad1
tickle buildbots
steven-johnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "HalideRuntime.h" | ||
#include "posix_timeval.h" | ||
|
||
struct itimerval { | ||
struct timeval it_interval; | ||
struct timeval it_value; | ||
}; | ||
|
||
typedef void (*sighandler_t)(int); | ||
extern "C" sighandler_t signal(int signum, sighandler_t handler); | ||
extern "C" int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value); | ||
|
||
typedef unsigned long sigset_t; | ||
extern "C" int sigprocmask(int how, const sigset_t *set, sigset_t *oldset); | ||
|
||
#ifndef SIG_BLOCK | ||
#define SIG_BLOCK 0 | ||
#endif | ||
#ifndef SIG_UNBLOCK | ||
#define SIG_UNBLOCK 1 | ||
#endif | ||
|
||
#ifndef SIGPROF | ||
#define SIGPROF 27 | ||
#endif | ||
|
||
namespace { | ||
|
||
bool inited = false; | ||
|
||
void profiler_handler(int sig) { | ||
halide_profiler_state *s = halide_profiler_get_state(); | ||
static uint64_t prev_time = 0; | ||
int sleep = halide_profiler_sample(s, &prev_time); | ||
if (sleep == -1) { | ||
itimerval timer_state; | ||
timer_state.it_interval.tv_sec = 0; | ||
timer_state.it_interval.tv_usec = 0; | ||
|
||
setitimer(2 /* ITIMER_PROF */, &timer_state, nullptr); | ||
signal(SIGPROF, nullptr); | ||
inited = false; | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
WEAK extern "C" void halide_start_timer_chain() { | ||
if (!inited) { | ||
halide_profiler_state *s = halide_profiler_get_state(); | ||
itimerval timer_state; | ||
timer_state.it_interval.tv_sec = 0; | ||
timer_state.it_interval.tv_usec = s->sleep_time * 1000.0; | ||
timer_state.it_value = timer_state.it_interval; | ||
|
||
signal(SIGPROF, &profiler_handler); | ||
setitimer(2 /*ITIMER_PROF*/, &timer_state, nullptr); | ||
halide_enable_timer_interrupt(); | ||
inited = true; | ||
} | ||
} | ||
|
||
WEAK extern "C" void halide_disable_timer_interrupt() { | ||
sigset_t mask = 1 << SIGPROF; | ||
sigprocmask(SIG_BLOCK, &mask, nullptr); | ||
} | ||
|
||
WEAK extern "C" void halide_enable_timer_interrupt() { | ||
sigset_t mask = 1 << SIGPROF; | ||
sigprocmask(SIG_UNBLOCK, &mask, nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef _STRUCT_TIMEVAL | ||
#define _STRUCT_TIMEVAL | ||
|
||
#ifdef BITS_64 | ||
struct timeval { | ||
int64_t tv_sec, tv_usec; | ||
}; | ||
#else | ||
struct timeval { | ||
int32_t tv_sec, tv_usec; | ||
}; | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you call this (and other new calls) from thread-based profiling? Even if it's just UB maybe worth calling out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In thread based profiling, Halide fires up a thread to call
halide_profiler_sample
. It can be called directly as well, though I can't think of a reason to do so. It would simply result in profile samples being collected more often than otherwise I believe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other calls probably result in undefined references as they are only provided for a timer profiling based runtime.