Re: [PATCH v2 0/6] perf: Introduce extended syscall error reporting

From: Alexander Shishkin
Date: Wed Aug 26 2015 - 12:59:05 EST


Ingo Molnar <mingo@xxxxxxxxxx> writes:

> * Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>
>> ... but back then I didn't feel like complicating an error recovery ABI for the
>> needs of the 1%, robust error handling is all about simplicity: if it's not
>> simple, tools won't use it.
>
> And note that it needs to be 'simple' in two places for usage to grow naturally:
>
> - the usage site in the kernel
> - the tooling side that recovers the information.
>
> That's why I think that such a form:
>
> return err_str(-EINVAL, "x86/perf: CPU does not support precise sampling");
>
> is obviously simple on the kernel side as it returns -EINVAL, and is very simple
> on the tooling side as well, if we are allowed to extend prctl().

So I hacked stuff a bit [1] to accomodate some of the above
ideas. The below diff shows how these ideas integrate with perf. The
rest is in my github tree.

- this exterr implementation allows its users to add arbitrary
information to the call site structures and also pretty print them on
the way out; in the example, perf stores perf_event_attr field name
that is the source of trouble; it's a string rather than offsetof(),
because half of our event attribute is a bit field;
- the "way out" doesn't have to be syscall return path (although in the
example it is);
- userspace can fetch the extended error reports via prctl() like you
suggested above;
- error codes are still passed around in the [-EXT_ERRNO..-MAX_ERRNO]
range until they are passed to userspace (which is where ext_err_code()
converts them back to traditional errno.h values).

# perf record -e branches -c1 ls
kernel says (0/95): {
"file": "/home/ash/work/linux/arch/x86/kernel/cpu/perf_event.c",
"line": 432,
"code": -95,
"module": "perf/x86",
"message": "BTS sampling not allowed for kernel space"
, "attr_field": "exclude_kernel"
}

Error:
No hardware sampling interrupt available.
No APIC? If so then you can boot the kernel with the "lapic" boot parameter to force-enable it.
#

[1] https://github.com/virtuoso/linux-perf/commits/exterr