mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 02:50:43 +00:00
perf tools: Add time out to force stop proc map processing
System wide sampling like 'perf top' or 'perf record -a' read all threads /proc/xxx/maps before sampling. If there are any threads which generating a keeping growing huge maps, perf will do infinite loop during synthesizing. Nothing will be sampled. This patch fixes this issue by adding per-thread timeout to force stop this kind of endless proc map processing. PERF_RECORD_MISC_PROC_MAP_PARSE_TIME_OUT is introduced to indicate that the mmap record are truncated by time out. User will get warning notification when truncated mmap records are detected. Reported-by: Ying Huang <ying.huang@intel.com> Signed-off-by: Kan Liang <kan.liang@intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Ying Huang <ying.huang@intel.com> Link: http://lkml.kernel.org/r/1434549071-25611-1-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
c05676c062
commit
930e6fcd2b
4 changed files with 34 additions and 0 deletions
|
@ -565,6 +565,10 @@ struct perf_event_mmap_page {
|
||||||
#define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
|
#define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
|
||||||
#define PERF_RECORD_MISC_GUEST_USER (5 << 0)
|
#define PERF_RECORD_MISC_GUEST_USER (5 << 0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Indicates that /proc/PID/maps parsing are truncated by time out.
|
||||||
|
*/
|
||||||
|
#define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT (1 << 12)
|
||||||
/*
|
/*
|
||||||
* PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
|
* PERF_RECORD_MISC_MMAP_DATA and PERF_RECORD_MISC_COMM_EXEC are used on
|
||||||
* different events so can reuse the same bit position.
|
* different events so can reuse the same bit position.
|
||||||
|
|
|
@ -213,6 +213,8 @@ static int perf_event__synthesize_fork(struct perf_tool *tool,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PROC_MAP_PARSE_TIMEOUT (500 * 1000000ULL)
|
||||||
|
|
||||||
int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
union perf_event *event,
|
union perf_event *event,
|
||||||
pid_t pid, pid_t tgid,
|
pid_t pid, pid_t tgid,
|
||||||
|
@ -222,6 +224,8 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
{
|
{
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
unsigned long long t;
|
||||||
|
bool truncation = false;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (machine__is_default_guest(machine))
|
if (machine__is_default_guest(machine))
|
||||||
|
@ -240,6 +244,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
}
|
}
|
||||||
|
|
||||||
event->header.type = PERF_RECORD_MMAP2;
|
event->header.type = PERF_RECORD_MMAP2;
|
||||||
|
t = rdclock();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
char bf[BUFSIZ];
|
char bf[BUFSIZ];
|
||||||
|
@ -253,6 +258,12 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
if (fgets(bf, sizeof(bf), fp) == NULL)
|
if (fgets(bf, sizeof(bf), fp) == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if ((rdclock() - t) > PROC_MAP_PARSE_TIMEOUT) {
|
||||||
|
pr_warning("Reading %s time out.\n", filename);
|
||||||
|
truncation = true;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* ensure null termination since stack will be reused. */
|
/* ensure null termination since stack will be reused. */
|
||||||
strcpy(execname, "");
|
strcpy(execname, "");
|
||||||
|
|
||||||
|
@ -301,6 +312,10 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
event->header.misc |= PERF_RECORD_MISC_MMAP_DATA;
|
event->header.misc |= PERF_RECORD_MISC_MMAP_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (truncation)
|
||||||
|
event->header.misc |= PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT;
|
||||||
|
|
||||||
if (!strcmp(execname, ""))
|
if (!strcmp(execname, ""))
|
||||||
strcpy(execname, anonstr);
|
strcpy(execname, anonstr);
|
||||||
|
|
||||||
|
@ -319,6 +334,9 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (truncation)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
|
@ -265,6 +265,7 @@ struct events_stats {
|
||||||
u32 nr_unknown_id;
|
u32 nr_unknown_id;
|
||||||
u32 nr_unprocessable_samples;
|
u32 nr_unprocessable_samples;
|
||||||
u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
|
u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
|
||||||
|
u32 nr_proc_map_timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct attr_event {
|
struct attr_event {
|
||||||
|
|
|
@ -1064,6 +1064,8 @@ static int machines__deliver_event(struct machines *machines,
|
||||||
case PERF_RECORD_MMAP:
|
case PERF_RECORD_MMAP:
|
||||||
return tool->mmap(tool, event, sample, machine);
|
return tool->mmap(tool, event, sample, machine);
|
||||||
case PERF_RECORD_MMAP2:
|
case PERF_RECORD_MMAP2:
|
||||||
|
if (event->header.misc & PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT)
|
||||||
|
++evlist->stats.nr_proc_map_timeout;
|
||||||
return tool->mmap2(tool, event, sample, machine);
|
return tool->mmap2(tool, event, sample, machine);
|
||||||
case PERF_RECORD_COMM:
|
case PERF_RECORD_COMM:
|
||||||
return tool->comm(tool, event, sample, machine);
|
return tool->comm(tool, event, sample, machine);
|
||||||
|
@ -1360,6 +1362,15 @@ static void perf_session__warn_about_errors(const struct perf_session *session)
|
||||||
ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
|
ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
|
||||||
|
|
||||||
events_stats__auxtrace_error_warn(stats);
|
events_stats__auxtrace_error_warn(stats);
|
||||||
|
|
||||||
|
if (stats->nr_proc_map_timeout != 0) {
|
||||||
|
ui__warning("%d map information files for pre-existing threads were\n"
|
||||||
|
"not processed, if there are samples for addresses they\n"
|
||||||
|
"will not be resolved, you may find out which are these\n"
|
||||||
|
"threads by running with -v and redirecting the output\n"
|
||||||
|
"to a file.\n",
|
||||||
|
stats->nr_proc_map_timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int perf_session__flush_thread_stack(struct thread *thread,
|
static int perf_session__flush_thread_stack(struct thread *thread,
|
||||||
|
|
Loading…
Reference in a new issue