cregit-Linux how code gets into the kernel

Release 4.11 drivers/oprofile/nmi_timer_int.c

Directory: drivers/oprofile
/**
 * @file nmi_timer_int.c
 *
 * @remark Copyright 2011 Advanced Micro Devices, Inc.
 *
 * @author Robert Richter <robert.richter@amd.com>
 */

#include <linux/init.h>
#include <linux/smp.h>
#include <linux/errno.h>
#include <linux/oprofile.h>
#include <linux/perf_event.h>

#ifdef CONFIG_OPROFILE_NMI_TIMER

static DEFINE_PER_CPU(struct perf_event *, nmi_timer_events);

static int ctr_running;


static struct perf_event_attr nmi_timer_attr = {
	.type           = PERF_TYPE_HARDWARE,
	.config         = PERF_COUNT_HW_CPU_CYCLES,
	.size           = sizeof(struct perf_event_attr),
	.pinned         = 1,
	.disabled       = 1,
};


static void nmi_timer_callback(struct perf_event *event, struct perf_sample_data *data, struct pt_regs *regs) { event->hw.interrupts = 0; /* don't throttle interrupts */ oprofile_add_sample(regs, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter37100.00%1100.00%
Total37100.00%1100.00%


static int nmi_timer_start_cpu(int cpu) { struct perf_event *event = per_cpu(nmi_timer_events, cpu); if (!event) { event = perf_event_create_kernel_counter(&nmi_timer_attr, cpu, NULL, nmi_timer_callback, NULL); if (IS_ERR(event)) return PTR_ERR(event); per_cpu(nmi_timer_events, cpu) = event; } if (event && ctr_running) perf_event_enable(event); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter80100.00%1100.00%
Total80100.00%1100.00%


static void nmi_timer_stop_cpu(int cpu) { struct perf_event *event = per_cpu(nmi_timer_events, cpu); if (event && ctr_running) perf_event_disable(event); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter32100.00%1100.00%
Total32100.00%1100.00%


static int nmi_timer_cpu_online(unsigned int cpu) { nmi_timer_start_cpu(cpu); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter1266.67%150.00%
Sebastian Andrzej Siewior633.33%150.00%
Total18100.00%2100.00%


static int nmi_timer_cpu_predown(unsigned int cpu) { nmi_timer_stop_cpu(cpu); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Sebastian Andrzej Siewior1055.56%150.00%
Robert Richter844.44%150.00%
Total18100.00%2100.00%


static int nmi_timer_start(void) { int cpu; get_online_cpus(); ctr_running = 1; for_each_online_cpu(cpu) nmi_timer_start_cpu(cpu); put_online_cpus(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter33100.00%1100.00%
Total33100.00%1100.00%


static void nmi_timer_stop(void) { int cpu; get_online_cpus(); for_each_online_cpu(cpu) nmi_timer_stop_cpu(cpu); ctr_running = 0; put_online_cpus(); }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter30100.00%1100.00%
Total30100.00%1100.00%

static enum cpuhp_state hp_online;
static void nmi_timer_shutdown(void) { struct perf_event *event; int cpu; cpuhp_remove_state(hp_online); for_each_possible_cpu(cpu) { event = per_cpu(nmi_timer_events, cpu); if (!event) continue; perf_event_disable(event); per_cpu(nmi_timer_events, cpu) = NULL; perf_event_release_kernel(event); } }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter5996.72%150.00%
Sebastian Andrzej Siewior23.28%150.00%
Total61100.00%2100.00%


static int nmi_timer_setup(void) { int err; u64 period; /* clock cycles per tick: */ period = (u64)cpu_khz * 1000; do_div(period, HZ); nmi_timer_attr.sample_period = period; err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "oprofile/nmi:online", nmi_timer_cpu_online, nmi_timer_cpu_predown); if (err < 0) { nmi_timer_shutdown(); return err; } hp_online = err; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter5273.24%133.33%
Sebastian Andrzej Siewior1419.72%133.33%
Srivatsa S. Bhat57.04%133.33%
Total71100.00%3100.00%


int __init op_nmi_timer_init(struct oprofile_operations *ops) { int err = 0; err = nmi_timer_setup(); if (err) return err; nmi_timer_shutdown(); /* only check, don't alloc */ ops->create_files = NULL; ops->setup = nmi_timer_setup; ops->shutdown = nmi_timer_shutdown; ops->start = nmi_timer_start; ops->stop = nmi_timer_stop; ops->cpu_type = "timer"; printk(KERN_INFO "oprofile: using NMI timer interrupt.\n"); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Robert Richter77100.00%1100.00%
Total77100.00%1100.00%

#endif

Overall Contributors

PersonTokensPropCommitsCommitProp
Robert Richter49192.12%133.33%
Sebastian Andrzej Siewior376.94%133.33%
Srivatsa S. Bhat50.94%133.33%
Total533100.00%3100.00%
Directory: drivers/oprofile
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.