Skip to content

Commit

Permalink
Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/tip/linux-2.6-tip

* 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  perf tools: Fix time function double declaration with glibc
  perf tools: Fix build by checking if extra warnings are supported
  perf tools: Fix build when using gcc 3.4.6
  perf tools: Add missing header, fixes build
  perf tools: Fix 64 bit integer format strings
  perf test: Fix build on older glibcs
  perf: perf_event_exit_task_context: s/rcu_dereference/rcu_dereference_raw/
  perf test: Use cpu_map->[cpu] when setting affinity
  perf symbols: Fix annotation of thumb code
  perf: Annotate cpuctx->ctx.mutex to avoid a lockdep splat
  powerpc, perf: Fix frequency calculation for overflowing counters (FSL version)
  perf: Fix perf_event_init_task()/perf_event_free_task() interaction
  perf: Fix find_get_context() vs perf_event_exit_task() race
  • Loading branch information
Linus Torvalds committed Jan 24, 2011
2 parents ce84d53 + 00e99a4 commit 500d85c
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 121 deletions.
1 change: 1 addition & 0 deletions arch/powerpc/kernel/perf_event_fsl_emb.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,
if (left <= 0)
left = period;
record = 1;
event->hw.last_period = event->hw.sample_period;
}
if (left < 0x80000000LL)
val = 0x80000000LL - left;
Expand Down
46 changes: 27 additions & 19 deletions kernel/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -2201,13 +2201,6 @@ find_lively_task_by_vpid(pid_t vpid)
if (!task)
return ERR_PTR(-ESRCH);

/*
* Can't attach events to a dying task.
*/
err = -ESRCH;
if (task->flags & PF_EXITING)
goto errout;

/* Reuse ptrace permission checks for now. */
err = -EACCES;
if (!ptrace_may_access(task, PTRACE_MODE_READ))
Expand Down Expand Up @@ -2268,14 +2261,27 @@ find_get_context(struct pmu *pmu, struct task_struct *task, int cpu)

get_ctx(ctx);

if (cmpxchg(&task->perf_event_ctxp[ctxn], NULL, ctx)) {
/*
* We raced with some other task; use
* the context they set.
*/
err = 0;
mutex_lock(&task->perf_event_mutex);
/*
* If it has already passed perf_event_exit_task().
* we must see PF_EXITING, it takes this mutex too.
*/
if (task->flags & PF_EXITING)
err = -ESRCH;
else if (task->perf_event_ctxp[ctxn])
err = -EAGAIN;
else
rcu_assign_pointer(task->perf_event_ctxp[ctxn], ctx);
mutex_unlock(&task->perf_event_mutex);

if (unlikely(err)) {
put_task_struct(task);
kfree(ctx);
goto retry;

if (err == -EAGAIN)
goto retry;
goto errout;
}
}

Expand Down Expand Up @@ -5374,6 +5380,8 @@ static int pmu_dev_alloc(struct pmu *pmu)
goto out;
}

static struct lock_class_key cpuctx_mutex;

int perf_pmu_register(struct pmu *pmu, char *name, int type)
{
int cpu, ret;
Expand Down Expand Up @@ -5422,6 +5430,7 @@ int perf_pmu_register(struct pmu *pmu, char *name, int type)

cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
__perf_event_init_context(&cpuctx->ctx);
lockdep_set_class(&cpuctx->ctx.mutex, &cpuctx_mutex);
cpuctx->ctx.type = cpu_context;
cpuctx->ctx.pmu = pmu;
cpuctx->jiffies_interval = 1;
Expand Down Expand Up @@ -6127,7 +6136,7 @@ static void perf_event_exit_task_context(struct task_struct *child, int ctxn)
* scheduled, so we are now safe from rescheduling changing
* our context.
*/
child_ctx = child->perf_event_ctxp[ctxn];
child_ctx = rcu_dereference_raw(child->perf_event_ctxp[ctxn]);
task_ctx_sched_out(child_ctx, EVENT_ALL);

/*
Expand Down Expand Up @@ -6440,11 +6449,6 @@ int perf_event_init_context(struct task_struct *child, int ctxn)
unsigned long flags;
int ret = 0;

child->perf_event_ctxp[ctxn] = NULL;

mutex_init(&child->perf_event_mutex);
INIT_LIST_HEAD(&child->perf_event_list);

if (likely(!parent->perf_event_ctxp[ctxn]))
return 0;

Expand Down Expand Up @@ -6533,6 +6537,10 @@ int perf_event_init_task(struct task_struct *child)
{
int ctxn, ret;

memset(child->perf_event_ctxp, 0, sizeof(child->perf_event_ctxp));
mutex_init(&child->perf_event_mutex);
INIT_LIST_HEAD(&child->perf_event_list);

for_each_task_context_nr(ctxn) {
ret = perf_event_init_context(child, ctxn);
if (ret)
Expand Down
9 changes: 7 additions & 2 deletions tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,11 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstack-protector
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wvolatile-register-var
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
Expand Down Expand Up @@ -294,6 +292,13 @@ ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y)
CFLAGS := $(CFLAGS) -fstack-protector-all
endif

ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wstack-protector),y)
CFLAGS := $(CFLAGS) -Wstack-protector
endif

ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wvolatile-register-var),y)
CFLAGS := $(CFLAGS) -Wvolatile-register-var
endif

### --- END CONFIGURATION SECTION ---

Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename)
continue;

offset = start + i;
sprintf(cmd, "addr2line -e %s %016llx", filename, offset);
sprintf(cmd, "addr2line -e %s %016" PRIx64, filename, offset);
fp = popen(cmd, "r");
if (!fp)
continue;
Expand Down Expand Up @@ -270,9 +270,9 @@ static void hist_entry__print_hits(struct hist_entry *self)

for (offset = 0; offset < len; ++offset)
if (h->ip[offset] != 0)
printf("%*Lx: %Lu\n", BITS_PER_LONG / 2,
printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2,
sym->start + offset, h->ip[offset]);
printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum);
printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
}

static int hist_entry__tty_annotate(struct hist_entry *he)
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
addr = data->ptr;

if (sym != NULL)
snprintf(buf, sizeof(buf), "%s+%Lx", sym->name,
snprintf(buf, sizeof(buf), "%s+%" PRIx64 "", sym->name,
addr - map->unmap_ip(map, sym->start));
else
snprintf(buf, sizeof(buf), "%#Lx", addr);
snprintf(buf, sizeof(buf), "%#" PRIx64 "", addr);
printf(" %-34s |", buf);

printf(" %9llu/%-5lu | %9llu/%-5lu | %8lu | %8lu | %6.3f%%\n",
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,9 @@ static void print_result(void)
pr_info("%10u ", st->nr_acquired);
pr_info("%10u ", st->nr_contended);

pr_info("%15llu ", st->wait_time_total);
pr_info("%15llu ", st->wait_time_max);
pr_info("%15llu ", st->wait_time_min == ULLONG_MAX ?
pr_info("%15" PRIu64 " ", st->wait_time_total);
pr_info("%15" PRIu64 " ", st->wait_time_max);
pr_info("%15" PRIu64 " ", st->wait_time_min == ULLONG_MAX ?
0 : st->wait_time_min);
pr_info("\n");
}
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ static int __cmd_record(int argc, const char **argv)
* Approximate RIP event size: 24 bytes.
*/
fprintf(stderr,
"[ perf record: Captured and wrote %.3f MB %s (~%lld samples) ]\n",
"[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n",
(double)bytes_written / 1024.0 / 1024.0,
output_name,
bytes_written / 24);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static int process_read_event(event_t *event, struct sample_data *sample __used,
event->read.value);
}

dump_printf(": %d %d %s %Lu\n", event->read.pid, event->read.tid,
dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
attr ? __event_name(attr->type, attr->config) : "FAIL",
event->read.value);

Expand Down
20 changes: 10 additions & 10 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static void calibrate_run_measurement_overhead(void)
}
run_measurement_overhead = min_delta;

printf("run measurement overhead: %Ld nsecs\n", min_delta);
printf("run measurement overhead: %" PRIu64 " nsecs\n", min_delta);
}

static void calibrate_sleep_measurement_overhead(void)
Expand All @@ -211,7 +211,7 @@ static void calibrate_sleep_measurement_overhead(void)
min_delta -= 10000;
sleep_measurement_overhead = min_delta;

printf("sleep measurement overhead: %Ld nsecs\n", min_delta);
printf("sleep measurement overhead: %" PRIu64 " nsecs\n", min_delta);
}

static struct sched_atom *
Expand Down Expand Up @@ -617,13 +617,13 @@ static void test_calibrations(void)
burn_nsecs(1e6);
T1 = get_nsecs();

printf("the run test took %Ld nsecs\n", T1-T0);
printf("the run test took %" PRIu64 " nsecs\n", T1 - T0);

T0 = get_nsecs();
sleep_nsecs(1e6);
T1 = get_nsecs();

printf("the sleep test took %Ld nsecs\n", T1-T0);
printf("the sleep test took %" PRIu64 " nsecs\n", T1 - T0);
}

#define FILL_FIELD(ptr, field, event, data) \
Expand Down Expand Up @@ -816,10 +816,10 @@ replay_switch_event(struct trace_switch_event *switch_event,
delta = 0;

if (delta < 0)
die("hm, delta: %Ld < 0 ?\n", delta);
die("hm, delta: %" PRIu64 " < 0 ?\n", delta);

if (verbose) {
printf(" ... switch from %s/%d to %s/%d [ran %Ld nsecs]\n",
printf(" ... switch from %s/%d to %s/%d [ran %" PRIu64 " nsecs]\n",
switch_event->prev_comm, switch_event->prev_pid,
switch_event->next_comm, switch_event->next_pid,
delta);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ latency_switch_event(struct trace_switch_event *switch_event,
delta = 0;

if (delta < 0)
die("hm, delta: %Ld < 0 ?\n", delta);
die("hm, delta: %" PRIu64 " < 0 ?\n", delta);


sched_out = perf_session__findnew(session, switch_event->prev_pid);
Expand Down Expand Up @@ -1221,7 +1221,7 @@ static void output_lat_thread(struct work_atoms *work_list)

avg = work_list->total_lat / work_list->nb_atoms;

printf("|%11.3f ms |%9llu | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n",
printf("|%11.3f ms |%9" PRIu64 " | avg:%9.3f ms | max:%9.3f ms | max at: %9.6f s\n",
(double)work_list->total_runtime / 1e6,
work_list->nb_atoms, (double)avg / 1e6,
(double)work_list->max_lat / 1e6,
Expand Down Expand Up @@ -1423,7 +1423,7 @@ map_switch_event(struct trace_switch_event *switch_event,
delta = 0;

if (delta < 0)
die("hm, delta: %Ld < 0 ?\n", delta);
die("hm, delta: %" PRIu64 " < 0 ?\n", delta);


sched_out = perf_session__findnew(session, switch_event->prev_pid);
Expand Down Expand Up @@ -1713,7 +1713,7 @@ static void __cmd_lat(void)
}

printf(" -----------------------------------------------------------------------------------------\n");
printf(" TOTAL: |%11.3f ms |%9Ld |\n",
printf(" TOTAL: |%11.3f ms |%9" PRIu64 " |\n",
(double)all_runtime/1e6, all_count);

printf(" ---------------------------------------------------\n");
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static int process_sample_event(event_t *event, struct sample_data *sample,
if (session->sample_type & PERF_SAMPLE_RAW) {
if (debug_mode) {
if (sample->time < last_timestamp) {
pr_err("Samples misordered, previous: %llu "
"this: %llu\n", last_timestamp,
pr_err("Samples misordered, previous: %" PRIu64
" this: %" PRIu64 "\n", last_timestamp,
sample->time);
nr_unordered++;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ static int __cmd_script(struct perf_session *session)
ret = perf_session__process_events(session, &event_ops);

if (debug_mode)
pr_err("Misordered timestamps: %llu\n", nr_unordered);
pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ static int read_counter_aggr(struct perf_evsel *counter)
update_stats(&ps->res_stats[i], count[i]);

if (verbose) {
fprintf(stderr, "%s: %Ld %Ld %Ld\n", event_name(counter),
count[0], count[1], count[2]);
fprintf(stderr, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
event_name(counter), count[0], count[1], count[2]);
}

/*
Expand Down
Loading

0 comments on commit 500d85c

Please sign in to comment.