cregit-Linux how code gets into the kernel

Release 4.10 tools/perf/tests/dwarf-unwind.c

Directory: tools/perf/tests
#include <linux/compiler.h>
#include <linux/types.h>
#include <unistd.h>
#include "tests.h"
#include "debug.h"
#include "machine.h"
#include "event.h"
#include "unwind.h"
#include "perf_regs.h"
#include "map.h"
#include "thread.h"
#include "callchain.h"

#if defined (__x86_64__) || defined (__i386__) || defined (__powerpc__)
#include "arch-tests.h"
#endif

/* For bsearch. We try to unwind functions in shared object. */
#include <stdlib.h>


static int mmap_handler(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct machine *machine) { return machine__process_mmap2_event(machine, event, sample); }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa3594.59%133.33%
don zickusdon zickus12.70%133.33%
arnaldo carvalho de meloarnaldo carvalho de melo12.70%133.33%
Total37100.00%3100.00%


static int init_live_machine(struct machine *machine) { union perf_event event; pid_t pid = getpid(); return perf_event__synthesize_mmap_events(NULL, &event, pid, pid, mmap_handler, machine, true, 500); }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa4095.24%150.00%
kan liangkan liang24.76%150.00%
Total42100.00%2100.00%

#define MAX_STACK 8
static int unwind_entry(struct unwind_entry *entry, void *arg) { unsigned long *cnt = (unsigned long *) arg; char *symbol = entry->sym ? entry->sym->name : NULL; static const char *funcs[MAX_STACK] = { "test__arch_unwind_sample", "unwind_thread", "compare", "bsearch", "krava_3", "krava_2", "krava_1", "test__dwarf_unwind" }; /* * The funcs[MAX_STACK] array index, based on the * callchain order setup. */ int idx = callchain_param.order == ORDER_CALLER ? MAX_STACK - *cnt - 1 : *cnt; if (*cnt >= MAX_STACK) { pr_debug("failed: crossed the max stack value %d\n", MAX_STACK); return -1; } if (!symbol) { pr_debug("failed: got unresolved address 0x%" PRIx64 "\n", entry->ip); return -1; } (*cnt)++; pr_debug("got: %s 0x%" PRIx64 ", expecting %s\n", symbol, entry->ip, funcs[idx]); return strcmp((const char *) symbol, funcs[idx]); }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa16897.67%266.67%
wang nanwang nan42.33%133.33%
Total172100.00%3100.00%

__attribute__ ((noinline))
static int unwind_thread(struct thread *thread) { struct perf_sample sample; unsigned long cnt = 0; int err = -1; memset(&sample, 0, sizeof(sample)); if (test__arch_unwind_sample(&sample, thread)) { pr_debug("failed to get unwind sample\n"); goto out; } err = unwind__get_entries(unwind_entry, &cnt, thread, &sample, MAX_STACK); if (err) pr_debug("unwind failed\n"); else if (cnt != MAX_STACK) { pr_debug("got wrong number of stack entries %lu != %d\n", cnt, MAX_STACK); err = -1; } out: free(sample.user_stack.data); free(sample.user_regs.regs); return err; }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa132100.00%1100.00%
Total132100.00%1100.00%

static int global_unwind_retval = -INT_MAX; __attribute__ ((noinline))
static int compare(void *p1, void *p2) { /* Any possible value should be 'thread' */ struct thread *thread = *(struct thread **)p1; if (global_unwind_retval == -INT_MAX) { /* Call unwinder twice for both callchain orders. */ callchain_param.order = ORDER_CALLER; global_unwind_retval = unwind_thread(thread); if (!global_unwind_retval) { callchain_param.order = ORDER_CALLEE; global_unwind_retval = unwind_thread(thread); } } return p1 - p2; }

Contributors

PersonTokensPropCommitsCommitProp
wang nanwang nan4862.34%150.00%
jiri olsajiri olsa2937.66%150.00%
Total77100.00%2100.00%

__attribute__ ((noinline))
static int krava_3(struct thread *thread) { struct thread *array[2] = {thread, thread}; void *fp = &bsearch; /* * make _bsearch a volatile function pointer to * prevent potential optimization, which may expand * bsearch and call compare directly from this function, * instead of libc shared object. */ void *(*volatile _bsearch)(void *, void *, size_t, size_t, int (*)(void *, void *)); _bsearch = fp; _bsearch(array, &thread, 2, sizeof(struct thread **), compare); return global_unwind_retval; }

Contributors

PersonTokensPropCommitsCommitProp
wang nanwang nan7684.44%150.00%
jiri olsajiri olsa1415.56%150.00%
Total90100.00%2100.00%

__attribute__ ((noinline))
static int krava_2(struct thread *thread) { return krava_3(thread); }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa17100.00%1100.00%
Total17100.00%1100.00%

__attribute__ ((noinline))
static int krava_1(struct thread *thread) { return krava_2(thread); }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa17100.00%1100.00%
Total17100.00%1100.00%


int test__dwarf_unwind(int subtest __maybe_unused) { struct machine *machine; struct thread *thread; int err = -1; machine = machine__new_host(); if (!machine) { pr_err("Could not get machine\n"); return -1; } if (machine__create_kernel_maps(machine)) { pr_err("Failed to create kernel maps\n"); return -1; } callchain_param.record_mode = CALLCHAIN_DWARF; if (init_live_machine(machine)) { pr_err("Could not init machine\n"); goto out; } if (verbose > 1) machine__fprintf(machine, stderr); thread = machine__find_thread(machine, getpid(), getpid()); if (!thread) { pr_err("Could not get thread\n"); goto out; } err = krava_1(thread); thread__put(thread); out: machine__delete_threads(machine); machine__delete(machine); return err; }

Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa14190.97%457.14%
arnaldo carvalho de meloarnaldo carvalho de melo85.16%228.57%
namhyung kimnamhyung kim63.87%114.29%
Total155100.00%7100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
jiri olsajiri olsa64477.50%533.33%
wang nanwang nan14417.33%16.67%
matt flemingmatt fleming161.93%16.67%
namhyung kimnamhyung kim91.08%16.67%
arnaldo carvalho de meloarnaldo carvalho de melo91.08%320.00%
ravi bangoriaravi bangoria50.60%16.67%
kan liangkan liang20.24%16.67%
don zickusdon zickus10.12%16.67%
borislav petkovborislav petkov10.12%16.67%
Total831100.00%15100.00%
Directory: tools/perf/tests
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.