perf evsel: Carve out event modifier formatting
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / evsel.c
1 /*
2  * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3  *
4  * Parts came from builtin-{top,stat,record}.c, see those files for further
5  * copyright notes.
6  *
7  * Released under the GPL v2. (and only v2, not any later version)
8  */
9
10 #include <byteswap.h>
11 #include "asm/bug.h"
12 #include "evsel.h"
13 #include "evlist.h"
14 #include "util.h"
15 #include "cpumap.h"
16 #include "thread_map.h"
17 #include "target.h"
18 #include "../../include/linux/perf_event.h"
19
20 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
21 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
22
23 int __perf_evsel__sample_size(u64 sample_type)
24 {
25         u64 mask = sample_type & PERF_SAMPLE_MASK;
26         int size = 0;
27         int i;
28
29         for (i = 0; i < 64; i++) {
30                 if (mask & (1ULL << i))
31                         size++;
32         }
33
34         size *= sizeof(u64);
35
36         return size;
37 }
38
39 void hists__init(struct hists *hists)
40 {
41         memset(hists, 0, sizeof(*hists));
42         hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
43         hists->entries_in = &hists->entries_in_array[0];
44         hists->entries_collapsed = RB_ROOT;
45         hists->entries = RB_ROOT;
46         pthread_mutex_init(&hists->lock, NULL);
47 }
48
49 void perf_evsel__init(struct perf_evsel *evsel,
50                       struct perf_event_attr *attr, int idx)
51 {
52         evsel->idx         = idx;
53         evsel->attr        = *attr;
54         INIT_LIST_HEAD(&evsel->node);
55         hists__init(&evsel->hists);
56 }
57
58 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
59 {
60         struct perf_evsel *evsel = zalloc(sizeof(*evsel));
61
62         if (evsel != NULL)
63                 perf_evsel__init(evsel, attr, idx);
64
65         return evsel;
66 }
67
68 static const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
69         "cycles",
70         "instructions",
71         "cache-references",
72         "cache-misses",
73         "branches",
74         "branch-misses",
75         "bus-cycles",
76         "stalled-cycles-frontend",
77         "stalled-cycles-backend",
78         "ref-cycles",
79 };
80
81 const char *__perf_evsel__hw_name(u64 config)
82 {
83         if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config])
84                 return perf_evsel__hw_names[config];
85
86         return "unknown-hardware";
87 }
88
89 static int perf_evsel__add_modifiers(struct perf_evsel *evsel, char *bf, size_t size)
90 {
91         int colon = 0, r = 0;
92         struct perf_event_attr *attr = &evsel->attr;
93         bool exclude_guest_default = false;
94
95 #define MOD_PRINT(context, mod) do {                                    \
96                 if (!attr->exclude_##context) {                         \
97                         if (!colon) colon = ++r;                        \
98                         r += scnprintf(bf + r, size - r, "%c", mod);    \
99                 } } while(0)
100
101         if (attr->exclude_kernel || attr->exclude_user || attr->exclude_hv) {
102                 MOD_PRINT(kernel, 'k');
103                 MOD_PRINT(user, 'u');
104                 MOD_PRINT(hv, 'h');
105                 exclude_guest_default = true;
106         }
107
108         if (attr->precise_ip) {
109                 if (!colon)
110                         colon = ++r;
111                 r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp");
112                 exclude_guest_default = true;
113         }
114
115         if (attr->exclude_host || attr->exclude_guest == exclude_guest_default) {
116                 MOD_PRINT(host, 'H');
117                 MOD_PRINT(guest, 'G');
118         }
119 #undef MOD_PRINT
120         if (colon)
121                 bf[colon - 1] = ':';
122         return r;
123 }
124
125 static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
126 {
127         int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(evsel->attr.config));
128         return r + perf_evsel__add_modifiers(evsel, bf + r, size - r);
129 }
130
131 int perf_evsel__name(struct perf_evsel *evsel, char *bf, size_t size)
132 {
133         int ret;
134
135         switch (evsel->attr.type) {
136         case PERF_TYPE_RAW:
137                 ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config);
138                 break;
139
140         case PERF_TYPE_HARDWARE:
141                 ret = perf_evsel__hw_name(evsel, bf, size);
142                 break;
143         default:
144                 /*
145                  * FIXME
146                  *
147                  * This is the minimal perf_evsel__name so that we can
148                  * reconstruct event names taking into account event modifiers.
149                  *
150                  * The old event_name uses it now for raw anr hw events, so that
151                  * we don't drag all the parsing stuff into the python binding.
152                  *
153                  * On the next devel cycle the rest of the event naming will be
154                  * brought here.
155                  */
156                 return 0;
157         }
158
159         return ret;
160 }
161
162 void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts,
163                         struct perf_evsel *first)
164 {
165         struct perf_event_attr *attr = &evsel->attr;
166         int track = !evsel->idx; /* only the first counter needs these */
167
168         attr->disabled = 1;
169         attr->sample_id_all = opts->sample_id_all_missing ? 0 : 1;
170         attr->inherit       = !opts->no_inherit;
171         attr->read_format   = PERF_FORMAT_TOTAL_TIME_ENABLED |
172                               PERF_FORMAT_TOTAL_TIME_RUNNING |
173                               PERF_FORMAT_ID;
174
175         attr->sample_type  |= PERF_SAMPLE_IP | PERF_SAMPLE_TID;
176
177         /*
178          * We default some events to a 1 default interval. But keep
179          * it a weak assumption overridable by the user.
180          */
181         if (!attr->sample_period || (opts->user_freq != UINT_MAX &&
182                                      opts->user_interval != ULLONG_MAX)) {
183                 if (opts->freq) {
184                         attr->sample_type       |= PERF_SAMPLE_PERIOD;
185                         attr->freq              = 1;
186                         attr->sample_freq       = opts->freq;
187                 } else {
188                         attr->sample_period = opts->default_interval;
189                 }
190         }
191
192         if (opts->no_samples)
193                 attr->sample_freq = 0;
194
195         if (opts->inherit_stat)
196                 attr->inherit_stat = 1;
197
198         if (opts->sample_address) {
199                 attr->sample_type       |= PERF_SAMPLE_ADDR;
200                 attr->mmap_data = track;
201         }
202
203         if (opts->call_graph)
204                 attr->sample_type       |= PERF_SAMPLE_CALLCHAIN;
205
206         if (perf_target__has_cpu(&opts->target))
207                 attr->sample_type       |= PERF_SAMPLE_CPU;
208
209         if (opts->period)
210                 attr->sample_type       |= PERF_SAMPLE_PERIOD;
211
212         if (!opts->sample_id_all_missing &&
213             (opts->sample_time || !opts->no_inherit ||
214              perf_target__has_cpu(&opts->target)))
215                 attr->sample_type       |= PERF_SAMPLE_TIME;
216
217         if (opts->raw_samples) {
218                 attr->sample_type       |= PERF_SAMPLE_TIME;
219                 attr->sample_type       |= PERF_SAMPLE_RAW;
220                 attr->sample_type       |= PERF_SAMPLE_CPU;
221         }
222
223         if (opts->no_delay) {
224                 attr->watermark = 0;
225                 attr->wakeup_events = 1;
226         }
227         if (opts->branch_stack) {
228                 attr->sample_type       |= PERF_SAMPLE_BRANCH_STACK;
229                 attr->branch_sample_type = opts->branch_stack;
230         }
231
232         attr->mmap = track;
233         attr->comm = track;
234
235         if (perf_target__none(&opts->target) &&
236             (!opts->group || evsel == first)) {
237                 attr->enable_on_exec = 1;
238         }
239 }
240
241 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
242 {
243         int cpu, thread;
244         evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
245
246         if (evsel->fd) {
247                 for (cpu = 0; cpu < ncpus; cpu++) {
248                         for (thread = 0; thread < nthreads; thread++) {
249                                 FD(evsel, cpu, thread) = -1;
250                         }
251                 }
252         }
253
254         return evsel->fd != NULL ? 0 : -ENOMEM;
255 }
256
257 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
258 {
259         evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
260         if (evsel->sample_id == NULL)
261                 return -ENOMEM;
262
263         evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
264         if (evsel->id == NULL) {
265                 xyarray__delete(evsel->sample_id);
266                 evsel->sample_id = NULL;
267                 return -ENOMEM;
268         }
269
270         return 0;
271 }
272
273 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus)
274 {
275         evsel->counts = zalloc((sizeof(*evsel->counts) +
276                                 (ncpus * sizeof(struct perf_counts_values))));
277         return evsel->counts != NULL ? 0 : -ENOMEM;
278 }
279
280 void perf_evsel__free_fd(struct perf_evsel *evsel)
281 {
282         xyarray__delete(evsel->fd);
283         evsel->fd = NULL;
284 }
285
286 void perf_evsel__free_id(struct perf_evsel *evsel)
287 {
288         xyarray__delete(evsel->sample_id);
289         evsel->sample_id = NULL;
290         free(evsel->id);
291         evsel->id = NULL;
292 }
293
294 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
295 {
296         int cpu, thread;
297
298         for (cpu = 0; cpu < ncpus; cpu++)
299                 for (thread = 0; thread < nthreads; ++thread) {
300                         close(FD(evsel, cpu, thread));
301                         FD(evsel, cpu, thread) = -1;
302                 }
303 }
304
305 void perf_evsel__exit(struct perf_evsel *evsel)
306 {
307         assert(list_empty(&evsel->node));
308         xyarray__delete(evsel->fd);
309         xyarray__delete(evsel->sample_id);
310         free(evsel->id);
311 }
312
313 void perf_evsel__delete(struct perf_evsel *evsel)
314 {
315         perf_evsel__exit(evsel);
316         close_cgroup(evsel->cgrp);
317         free(evsel->name);
318         free(evsel);
319 }
320
321 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
322                               int cpu, int thread, bool scale)
323 {
324         struct perf_counts_values count;
325         size_t nv = scale ? 3 : 1;
326
327         if (FD(evsel, cpu, thread) < 0)
328                 return -EINVAL;
329
330         if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1) < 0)
331                 return -ENOMEM;
332
333         if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
334                 return -errno;
335
336         if (scale) {
337                 if (count.run == 0)
338                         count.val = 0;
339                 else if (count.run < count.ena)
340                         count.val = (u64)((double)count.val * count.ena / count.run + 0.5);
341         } else
342                 count.ena = count.run = 0;
343
344         evsel->counts->cpu[cpu] = count;
345         return 0;
346 }
347
348 int __perf_evsel__read(struct perf_evsel *evsel,
349                        int ncpus, int nthreads, bool scale)
350 {
351         size_t nv = scale ? 3 : 1;
352         int cpu, thread;
353         struct perf_counts_values *aggr = &evsel->counts->aggr, count;
354
355         aggr->val = aggr->ena = aggr->run = 0;
356
357         for (cpu = 0; cpu < ncpus; cpu++) {
358                 for (thread = 0; thread < nthreads; thread++) {
359                         if (FD(evsel, cpu, thread) < 0)
360                                 continue;
361
362                         if (readn(FD(evsel, cpu, thread),
363                                   &count, nv * sizeof(u64)) < 0)
364                                 return -errno;
365
366                         aggr->val += count.val;
367                         if (scale) {
368                                 aggr->ena += count.ena;
369                                 aggr->run += count.run;
370                         }
371                 }
372         }
373
374         evsel->counts->scaled = 0;
375         if (scale) {
376                 if (aggr->run == 0) {
377                         evsel->counts->scaled = -1;
378                         aggr->val = 0;
379                         return 0;
380                 }
381
382                 if (aggr->run < aggr->ena) {
383                         evsel->counts->scaled = 1;
384                         aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5);
385                 }
386         } else
387                 aggr->ena = aggr->run = 0;
388
389         return 0;
390 }
391
392 static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
393                               struct thread_map *threads, bool group,
394                               struct xyarray *group_fds)
395 {
396         int cpu, thread;
397         unsigned long flags = 0;
398         int pid = -1, err;
399
400         if (evsel->fd == NULL &&
401             perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0)
402                 return -ENOMEM;
403
404         if (evsel->cgrp) {
405                 flags = PERF_FLAG_PID_CGROUP;
406                 pid = evsel->cgrp->fd;
407         }
408
409         for (cpu = 0; cpu < cpus->nr; cpu++) {
410                 int group_fd = group_fds ? GROUP_FD(group_fds, cpu) : -1;
411
412                 for (thread = 0; thread < threads->nr; thread++) {
413
414                         if (!evsel->cgrp)
415                                 pid = threads->map[thread];
416
417                         FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr,
418                                                                      pid,
419                                                                      cpus->map[cpu],
420                                                                      group_fd, flags);
421                         if (FD(evsel, cpu, thread) < 0) {
422                                 err = -errno;
423                                 goto out_close;
424                         }
425
426                         if (group && group_fd == -1)
427                                 group_fd = FD(evsel, cpu, thread);
428                 }
429         }
430
431         return 0;
432
433 out_close:
434         do {
435                 while (--thread >= 0) {
436                         close(FD(evsel, cpu, thread));
437                         FD(evsel, cpu, thread) = -1;
438                 }
439                 thread = threads->nr;
440         } while (--cpu >= 0);
441         return err;
442 }
443
444 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads)
445 {
446         if (evsel->fd == NULL)
447                 return;
448
449         perf_evsel__close_fd(evsel, ncpus, nthreads);
450         perf_evsel__free_fd(evsel);
451         evsel->fd = NULL;
452 }
453
454 static struct {
455         struct cpu_map map;
456         int cpus[1];
457 } empty_cpu_map = {
458         .map.nr = 1,
459         .cpus   = { -1, },
460 };
461
462 static struct {
463         struct thread_map map;
464         int threads[1];
465 } empty_thread_map = {
466         .map.nr  = 1,
467         .threads = { -1, },
468 };
469
470 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
471                      struct thread_map *threads, bool group,
472                      struct xyarray *group_fd)
473 {
474         if (cpus == NULL) {
475                 /* Work around old compiler warnings about strict aliasing */
476                 cpus = &empty_cpu_map.map;
477         }
478
479         if (threads == NULL)
480                 threads = &empty_thread_map.map;
481
482         return __perf_evsel__open(evsel, cpus, threads, group, group_fd);
483 }
484
485 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
486                              struct cpu_map *cpus, bool group,
487                              struct xyarray *group_fd)
488 {
489         return __perf_evsel__open(evsel, cpus, &empty_thread_map.map, group,
490                                   group_fd);
491 }
492
493 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
494                                 struct thread_map *threads, bool group,
495                                 struct xyarray *group_fd)
496 {
497         return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group,
498                                   group_fd);
499 }
500
501 static int perf_event__parse_id_sample(const union perf_event *event, u64 type,
502                                        struct perf_sample *sample,
503                                        bool swapped)
504 {
505         const u64 *array = event->sample.array;
506         union u64_swap u;
507
508         array += ((event->header.size -
509                    sizeof(event->header)) / sizeof(u64)) - 1;
510
511         if (type & PERF_SAMPLE_CPU) {
512                 u.val64 = *array;
513                 if (swapped) {
514                         /* undo swap of u64, then swap on individual u32s */
515                         u.val64 = bswap_64(u.val64);
516                         u.val32[0] = bswap_32(u.val32[0]);
517                 }
518
519                 sample->cpu = u.val32[0];
520                 array--;
521         }
522
523         if (type & PERF_SAMPLE_STREAM_ID) {
524                 sample->stream_id = *array;
525                 array--;
526         }
527
528         if (type & PERF_SAMPLE_ID) {
529                 sample->id = *array;
530                 array--;
531         }
532
533         if (type & PERF_SAMPLE_TIME) {
534                 sample->time = *array;
535                 array--;
536         }
537
538         if (type & PERF_SAMPLE_TID) {
539                 u.val64 = *array;
540                 if (swapped) {
541                         /* undo swap of u64, then swap on individual u32s */
542                         u.val64 = bswap_64(u.val64);
543                         u.val32[0] = bswap_32(u.val32[0]);
544                         u.val32[1] = bswap_32(u.val32[1]);
545                 }
546
547                 sample->pid = u.val32[0];
548                 sample->tid = u.val32[1];
549         }
550
551         return 0;
552 }
553
554 static bool sample_overlap(const union perf_event *event,
555                            const void *offset, u64 size)
556 {
557         const void *base = event;
558
559         if (offset + size > base + event->header.size)
560                 return true;
561
562         return false;
563 }
564
565 int perf_event__parse_sample(const union perf_event *event, u64 type,
566                              int sample_size, bool sample_id_all,
567                              struct perf_sample *data, bool swapped)
568 {
569         const u64 *array;
570
571         /*
572          * used for cross-endian analysis. See git commit 65014ab3
573          * for why this goofiness is needed.
574          */
575         union u64_swap u;
576
577         memset(data, 0, sizeof(*data));
578         data->cpu = data->pid = data->tid = -1;
579         data->stream_id = data->id = data->time = -1ULL;
580         data->period = 1;
581
582         if (event->header.type != PERF_RECORD_SAMPLE) {
583                 if (!sample_id_all)
584                         return 0;
585                 return perf_event__parse_id_sample(event, type, data, swapped);
586         }
587
588         array = event->sample.array;
589
590         if (sample_size + sizeof(event->header) > event->header.size)
591                 return -EFAULT;
592
593         if (type & PERF_SAMPLE_IP) {
594                 data->ip = event->ip.ip;
595                 array++;
596         }
597
598         if (type & PERF_SAMPLE_TID) {
599                 u.val64 = *array;
600                 if (swapped) {
601                         /* undo swap of u64, then swap on individual u32s */
602                         u.val64 = bswap_64(u.val64);
603                         u.val32[0] = bswap_32(u.val32[0]);
604                         u.val32[1] = bswap_32(u.val32[1]);
605                 }
606
607                 data->pid = u.val32[0];
608                 data->tid = u.val32[1];
609                 array++;
610         }
611
612         if (type & PERF_SAMPLE_TIME) {
613                 data->time = *array;
614                 array++;
615         }
616
617         data->addr = 0;
618         if (type & PERF_SAMPLE_ADDR) {
619                 data->addr = *array;
620                 array++;
621         }
622
623         data->id = -1ULL;
624         if (type & PERF_SAMPLE_ID) {
625                 data->id = *array;
626                 array++;
627         }
628
629         if (type & PERF_SAMPLE_STREAM_ID) {
630                 data->stream_id = *array;
631                 array++;
632         }
633
634         if (type & PERF_SAMPLE_CPU) {
635
636                 u.val64 = *array;
637                 if (swapped) {
638                         /* undo swap of u64, then swap on individual u32s */
639                         u.val64 = bswap_64(u.val64);
640                         u.val32[0] = bswap_32(u.val32[0]);
641                 }
642
643                 data->cpu = u.val32[0];
644                 array++;
645         }
646
647         if (type & PERF_SAMPLE_PERIOD) {
648                 data->period = *array;
649                 array++;
650         }
651
652         if (type & PERF_SAMPLE_READ) {
653                 fprintf(stderr, "PERF_SAMPLE_READ is unsupported for now\n");
654                 return -1;
655         }
656
657         if (type & PERF_SAMPLE_CALLCHAIN) {
658                 if (sample_overlap(event, array, sizeof(data->callchain->nr)))
659                         return -EFAULT;
660
661                 data->callchain = (struct ip_callchain *)array;
662
663                 if (sample_overlap(event, array, data->callchain->nr))
664                         return -EFAULT;
665
666                 array += 1 + data->callchain->nr;
667         }
668
669         if (type & PERF_SAMPLE_RAW) {
670                 const u64 *pdata;
671
672                 u.val64 = *array;
673                 if (WARN_ONCE(swapped,
674                               "Endianness of raw data not corrected!\n")) {
675                         /* undo swap of u64, then swap on individual u32s */
676                         u.val64 = bswap_64(u.val64);
677                         u.val32[0] = bswap_32(u.val32[0]);
678                         u.val32[1] = bswap_32(u.val32[1]);
679                 }
680
681                 if (sample_overlap(event, array, sizeof(u32)))
682                         return -EFAULT;
683
684                 data->raw_size = u.val32[0];
685                 pdata = (void *) array + sizeof(u32);
686
687                 if (sample_overlap(event, pdata, data->raw_size))
688                         return -EFAULT;
689
690                 data->raw_data = (void *) pdata;
691
692                 array = (void *)array + data->raw_size + sizeof(u32);
693         }
694
695         if (type & PERF_SAMPLE_BRANCH_STACK) {
696                 u64 sz;
697
698                 data->branch_stack = (struct branch_stack *)array;
699                 array++; /* nr */
700
701                 sz = data->branch_stack->nr * sizeof(struct branch_entry);
702                 sz /= sizeof(u64);
703                 array += sz;
704         }
705         return 0;
706 }
707
708 int perf_event__synthesize_sample(union perf_event *event, u64 type,
709                                   const struct perf_sample *sample,
710                                   bool swapped)
711 {
712         u64 *array;
713
714         /*
715          * used for cross-endian analysis. See git commit 65014ab3
716          * for why this goofiness is needed.
717          */
718         union u64_swap u;
719
720         array = event->sample.array;
721
722         if (type & PERF_SAMPLE_IP) {
723                 event->ip.ip = sample->ip;
724                 array++;
725         }
726
727         if (type & PERF_SAMPLE_TID) {
728                 u.val32[0] = sample->pid;
729                 u.val32[1] = sample->tid;
730                 if (swapped) {
731                         /*
732                          * Inverse of what is done in perf_event__parse_sample
733                          */
734                         u.val32[0] = bswap_32(u.val32[0]);
735                         u.val32[1] = bswap_32(u.val32[1]);
736                         u.val64 = bswap_64(u.val64);
737                 }
738
739                 *array = u.val64;
740                 array++;
741         }
742
743         if (type & PERF_SAMPLE_TIME) {
744                 *array = sample->time;
745                 array++;
746         }
747
748         if (type & PERF_SAMPLE_ADDR) {
749                 *array = sample->addr;
750                 array++;
751         }
752
753         if (type & PERF_SAMPLE_ID) {
754                 *array = sample->id;
755                 array++;
756         }
757
758         if (type & PERF_SAMPLE_STREAM_ID) {
759                 *array = sample->stream_id;
760                 array++;
761         }
762
763         if (type & PERF_SAMPLE_CPU) {
764                 u.val32[0] = sample->cpu;
765                 if (swapped) {
766                         /*
767                          * Inverse of what is done in perf_event__parse_sample
768                          */
769                         u.val32[0] = bswap_32(u.val32[0]);
770                         u.val64 = bswap_64(u.val64);
771                 }
772                 *array = u.val64;
773                 array++;
774         }
775
776         if (type & PERF_SAMPLE_PERIOD) {
777                 *array = sample->period;
778                 array++;
779         }
780
781         return 0;
782 }