* [RFC] perf: perf_event_attr anon unions and static initializer issue
@ 2012-10-05 10:36 Stephane Eranian
2012-10-05 11:01 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Stephane Eranian @ 2012-10-05 10:36 UTC (permalink / raw)
To: LKML
Cc: Peter Zijlstra, mingo, David Ahern, Arnaldo Carvalho de Melo,
Namhyung Kim
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?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] perf: perf_event_attr anon unions and static initializer issue
2012-10-05 10:36 [RFC] perf: perf_event_attr anon unions and static initializer issue Stephane Eranian
@ 2012-10-05 11:01 ` Peter Zijlstra
2012-10-05 11:49 ` Stephane Eranian
0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2012-10-05 11:01 UTC (permalink / raw)
To: Stephane Eranian
Cc: LKML, mingo, David Ahern, Arnaldo Carvalho de Melo, Namhyung Kim
On Fri, 2012-10-05 at 12:36 +0200, Stephane Eranian wrote:
> struct perf_event_attr attr = { .config = 0x1234, .config1 = 0x456 };
> Does anyone have a better solution to propose?
struct perf_event_attr attr = {
.config = 0x1234,
{ .config1 = 0x5678 },
};
sometimes works, but apparently not in this case.. its a bit unfortunate
indeed. EDG based compilers and the latest C std use your version --
hence also 4.6 supporting it.
Yeah, I'm afraid we're stuck with this until a future where modern C
isn't modern anymore.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] perf: perf_event_attr anon unions and static initializer issue
2012-10-05 11:01 ` Peter Zijlstra
@ 2012-10-05 11:49 ` Stephane Eranian
2012-10-05 12:43 ` Borislav Petkov
0 siblings, 1 reply; 4+ messages in thread
From: Stephane Eranian @ 2012-10-05 11:49 UTC (permalink / raw)
To: Peter Zijlstra
Cc: LKML, mingo, David Ahern, Arnaldo Carvalho de Melo, Namhyung Kim
On Fri, Oct 5, 2012 at 1:01 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Fri, 2012-10-05 at 12:36 +0200, Stephane Eranian wrote:
>
>> struct perf_event_attr attr = { .config = 0x1234, .config1 = 0x456 };
>
>> Does anyone have a better solution to propose?
>
>
> struct perf_event_attr attr = {
> .config = 0x1234,
> { .config1 = 0x5678 },
> };
>
> sometimes works, but apparently not in this case.. its a bit unfortunate
> indeed. EDG based compilers and the latest C std use your version --
> hence also 4.6 supporting it.
>
> Yeah, I'm afraid we're stuck with this until a future where modern C
> isn't modern anymore.
Yeah, unfortunately.
I ended up creating a separate table for config1 and initializing attr.config1
at runtime. That way it works regardless of the compiler....
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] perf: perf_event_attr anon unions and static initializer issue
2012-10-05 11:49 ` Stephane Eranian
@ 2012-10-05 12:43 ` Borislav Petkov
0 siblings, 0 replies; 4+ messages in thread
From: Borislav Petkov @ 2012-10-05 12:43 UTC (permalink / raw)
To: Stephane Eranian
Cc: Peter Zijlstra, LKML, mingo, David Ahern,
Arnaldo Carvalho de Melo, Namhyung Kim
On Fri, Oct 05, 2012 at 01:49:44PM +0200, Stephane Eranian wrote:
> Yeah, unfortunately. I ended up creating a separate table for config1
> and initializing attr.config1 at runtime. That way it works regardless
> of the compiler....
Did the same thing in the persistent events patches recently:
http://marc.info/?l=linux-kernel&m=134513917126309
--
Regards/Gruss,
Boris.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-05 12:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-05 10:36 [RFC] perf: perf_event_attr anon unions and static initializer issue Stephane Eranian
2012-10-05 11:01 ` Peter Zijlstra
2012-10-05 11:49 ` Stephane Eranian
2012-10-05 12:43 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).