Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/types.h>
0003 #include <linux/string.h>
0004 #include <linux/zalloc.h>
0005 
0006 #include "../../../util/event.h"
0007 #include "../../../util/synthetic-events.h"
0008 #include "../../../util/machine.h"
0009 #include "../../../util/tool.h"
0010 #include "../../../util/map.h"
0011 #include "../../../util/debug.h"
0012 
0013 #if defined(__x86_64__)
0014 
0015 int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
0016                        perf_event__handler_t process,
0017                        struct machine *machine)
0018 {
0019     int rc = 0;
0020     struct map *pos;
0021     struct maps *kmaps = machine__kernel_maps(machine);
0022     union perf_event *event = zalloc(sizeof(event->mmap) +
0023                      machine->id_hdr_size);
0024 
0025     if (!event) {
0026         pr_debug("Not enough memory synthesizing mmap event "
0027              "for extra kernel maps\n");
0028         return -1;
0029     }
0030 
0031     maps__for_each_entry(kmaps, pos) {
0032         struct kmap *kmap;
0033         size_t size;
0034 
0035         if (!__map__is_extra_kernel_map(pos))
0036             continue;
0037 
0038         kmap = map__kmap(pos);
0039 
0040         size = sizeof(event->mmap) - sizeof(event->mmap.filename) +
0041                PERF_ALIGN(strlen(kmap->name) + 1, sizeof(u64)) +
0042                machine->id_hdr_size;
0043 
0044         memset(event, 0, size);
0045 
0046         event->mmap.header.type = PERF_RECORD_MMAP;
0047 
0048         /*
0049          * kernel uses 0 for user space maps, see kernel/perf_event.c
0050          * __perf_event_mmap
0051          */
0052         if (machine__is_host(machine))
0053             event->header.misc = PERF_RECORD_MISC_KERNEL;
0054         else
0055             event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
0056 
0057         event->mmap.header.size = size;
0058 
0059         event->mmap.start = pos->start;
0060         event->mmap.len   = pos->end - pos->start;
0061         event->mmap.pgoff = pos->pgoff;
0062         event->mmap.pid   = machine->pid;
0063 
0064         strlcpy(event->mmap.filename, kmap->name, PATH_MAX);
0065 
0066         if (perf_tool__process_synth_event(tool, event, machine,
0067                            process) != 0) {
0068             rc = -1;
0069             break;
0070         }
0071     }
0072 
0073     free(event);
0074     return rc;
0075 }
0076 
0077 #endif
0078 
0079 void arch_perf_parse_sample_weight(struct perf_sample *data,
0080                    const __u64 *array, u64 type)
0081 {
0082     union perf_sample_weight weight;
0083 
0084     weight.full = *array;
0085     if (type & PERF_SAMPLE_WEIGHT)
0086         data->weight = weight.full;
0087     else {
0088         data->weight = weight.var1_dw;
0089         data->ins_lat = weight.var2_w;
0090     }
0091 }
0092 
0093 void arch_perf_synthesize_sample_weight(const struct perf_sample *data,
0094                     __u64 *array, u64 type)
0095 {
0096     *array = data->weight;
0097 
0098     if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
0099         *array &= 0xffffffff;
0100         *array |= ((u64)data->ins_lat << 32);
0101     }
0102 }