aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2009-03-30 13:07:08 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-06 03:30:40 -0400
commitd5d2bc0dd0379deddb9ede66fec90a3083eaec57 (patch)
treede84b06f86ebab60c11ba231b9f68bfe8887ee79 /arch
parent7595d63b3a9ce65d14c4fbd0e7de448a343d7215 (diff)
perf_counter: make it possible for hw_perf_counter_init to return error codes
Impact: better error reporting At present, if hw_perf_counter_init encounters an error, all it can do is return NULL, which causes sys_perf_counter_open to return an EINVAL error to userspace. This isn't very informative for userspace; it means that userspace can't tell the difference between "sorry, oprofile is already using the PMU" and "we don't support this CPU" and "this CPU doesn't support the requested generic hardware event". This commit uses the PTR_ERR/ERR_PTR/IS_ERR set of macros to let hw_perf_counter_init return an error code on error rather than just NULL if it wishes. If it does so, that error code will be returned from sys_perf_counter_open to userspace. If it returns NULL, an EINVAL error will be returned to userspace, as before. This also adapts the powerpc hw_perf_counter_init to make use of this to return ENXIO, EINVAL, EBUSY, or EOPNOTSUPP as appropriate. It would be good to add extra error numbers in future to allow userspace to distinguish the various errors that are currently reported as EINVAL, i.e. irq_period < 0, too many events in a group, conflict between exclude_* settings in a group, and PMU resource conflict in a group. [ v2: fix a bug pointed out by Corey Ashford where error returns from hw_perf_counter_init were not handled correctly in the case of raw hardware events.] Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Orig-LKML-Reference: <20090330171023.682428180@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/kernel/perf_counter.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/arch/powerpc/kernel/perf_counter.c b/arch/powerpc/kernel/perf_counter.c
index 560dd1e7b524..0a4d14f279ae 100644
--- a/arch/powerpc/kernel/perf_counter.c
+++ b/arch/powerpc/kernel/perf_counter.c
@@ -624,13 +624,13 @@ hw_perf_counter_init(struct perf_counter *counter)
624 int err; 624 int err;
625 625
626 if (!ppmu) 626 if (!ppmu)
627 return NULL; 627 return ERR_PTR(-ENXIO);
628 if ((s64)counter->hw_event.irq_period < 0) 628 if ((s64)counter->hw_event.irq_period < 0)
629 return NULL; 629 return ERR_PTR(-EINVAL);
630 if (!perf_event_raw(&counter->hw_event)) { 630 if (!perf_event_raw(&counter->hw_event)) {
631 ev = perf_event_id(&counter->hw_event); 631 ev = perf_event_id(&counter->hw_event);
632 if (ev >= ppmu->n_generic || ppmu->generic_events[ev] == 0) 632 if (ev >= ppmu->n_generic || ppmu->generic_events[ev] == 0)
633 return NULL; 633 return ERR_PTR(-EOPNOTSUPP);
634 ev = ppmu->generic_events[ev]; 634 ev = ppmu->generic_events[ev];
635 } else { 635 } else {
636 ev = perf_event_config(&counter->hw_event); 636 ev = perf_event_config(&counter->hw_event);
@@ -656,14 +656,14 @@ hw_perf_counter_init(struct perf_counter *counter)
656 n = collect_events(counter->group_leader, ppmu->n_counter - 1, 656 n = collect_events(counter->group_leader, ppmu->n_counter - 1,
657 ctrs, events); 657 ctrs, events);
658 if (n < 0) 658 if (n < 0)
659 return NULL; 659 return ERR_PTR(-EINVAL);
660 } 660 }
661 events[n] = ev; 661 events[n] = ev;
662 ctrs[n] = counter; 662 ctrs[n] = counter;
663 if (check_excludes(ctrs, n, 1)) 663 if (check_excludes(ctrs, n, 1))
664 return NULL; 664 return ERR_PTR(-EINVAL);
665 if (power_check_constraints(events, n + 1)) 665 if (power_check_constraints(events, n + 1))
666 return NULL; 666 return ERR_PTR(-EINVAL);
667 667
668 counter->hw.config = events[n]; 668 counter->hw.config = events[n];
669 atomic64_set(&counter->hw.period_left, counter->hw_event.irq_period); 669 atomic64_set(&counter->hw.period_left, counter->hw_event.irq_period);
@@ -687,7 +687,7 @@ hw_perf_counter_init(struct perf_counter *counter)
687 counter->destroy = hw_perf_counter_destroy; 687 counter->destroy = hw_perf_counter_destroy;
688 688
689 if (err) 689 if (err)
690 return NULL; 690 return ERR_PTR(err);
691 return &power_perf_ops; 691 return &power_perf_ops;
692} 692}
693 693