Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1217701 > unrolled thread

perf: possible bug in perf_event__read_size

Started byVince Weaver <vincent.weaver@maine.edu>
First post2015-09-02 17:30 +0200
Last post2015-09-02 17:40 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  perf: possible bug in perf_event__read_size Vince Weaver <vincent.weaver@maine.edu> - 2015-09-02 17:30 +0200
    Re: perf: possible bug in perf_event__read_size Vince Weaver <vincent.weaver@maine.edu> - 2015-09-02 17:40 +0200

#1217701 — perf: possible bug in perf_event__read_size

FromVince Weaver <vincent.weaver@maine.edu>
Date2015-09-02 17:30 +0200
Subjectperf: possible bug in perf_event__read_size
Message-ID<q4i96-yB-69@gated-at.bofh.it>
so I'm trying to track down a weird bug where opening a massive amount of 
events (10000) in one group and then trying to read the values causes 
memory corruption.

But in any case I ran across this code in kernel/events/core.c

+static void perf_event__read_size(struct perf_event *event)
+{
+       int entry = sizeof(u64); /* value */
+       int size = 0;
+       int nr = 1;
+
+       if (event->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+               size += sizeof(u64);
+
+       if (event->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
+               size += sizeof(u64);
+
+       if (event->attr.read_format & PERF_FORMAT_ID)
+               entry += sizeof(u64);
                ^^^^^
+
+       if (event->attr.read_format & PERF_FORMAT_GROUP) {
+               nr += event->group_leader->nr_siblings;
+               size += sizeof(u64);
+       }
+
+       size += entry * nr;
+       event->read_size = size;
+}

Shouldn't that be

       if (event->attr.read_format & PERF_FORMAT_ID)
               size += sizeof(u64);

otherwise we are allocating 16-bytes for each entry rather than 8-bytes
if PERF_FORMAT_ID is specified?  or am I missing something?

I tried to track down where this change originated but my git powers are 
not enough to get a git blame to work past a file rename.

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

[toc] | [next] | [standalone]


#1217703

FromVince Weaver <vincent.weaver@maine.edu>
Date2015-09-02 17:40 +0200
Message-ID<q4iiK-JG-3@gated-at.bofh.it>
In reply to#1217701
On Wed, 2 Sep 2015, Vince Weaver wrote:
> Shouldn't that be
> 
>        if (event->attr.read_format & PERF_FORMAT_ID)
>                size += sizeof(u64);

never mind, after a lot of further thought I can see this is a "clever" 
hack to allow group events to have an ID for each value.

It's a shame the perf_event code doesn't more comments in the code, 
especially when the code is being clever like this.

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web