[RFC] perf: perf_event_attr anon unions and static initializer issue

From: Stephane Eranian
Date: Fri Oct 05 2012 - 06:36:04 EST


Hi,

I am writing a little test program for the perf_event API which is using
hardcoded events. Some of those events (SNBEP uncore events) require
a value for config1. I was naively assuming, one could simply do:

struct perf_event_attr attr = { .config = 0x1234, .config1 = 0x456 };

However this does not work with gcc version < 4.6 apparently. Don't
know how this even works with other compilers. I looked online and
I could not really find a good way of solving this that would be portable
across compiler versions.

If we name those unions, then this will break lots of existing programs.
We'd have to create a "named" version of perf_event_attr and then
memcpy() at runtime. Or simply initialize the .config1 and such fields at
runtime from a separate table.

Does anyone have a better solution to propose?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/