Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * @file oprof.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * @remark Copyright 2002 OProfile authors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * @remark Read the file COPYING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * @author John Levon <levon@movementarian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/oprofile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "oprof.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "event_buffer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "cpu_buffer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "buffer_sync.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "oprofile_stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct oprofile_operations oprofile_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) unsigned long oprofile_started;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) unsigned long oprofile_backtrace_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static unsigned long is_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static DEFINE_MUTEX(start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)    0 - use performance monitoring hardware if available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)    1 - use the timer int mechanism regardless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) int oprofile_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if ((err = alloc_cpu_buffers()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if ((err = alloc_event_buffer()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (oprofile_ops.setup && (err = oprofile_ops.setup()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* Note even though this starts part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * profiling overhead, it's necessary to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 * us missing task deaths and eventually oopsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * when trying to process the event buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (oprofile_ops.sync_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		int sync_ret = oprofile_ops.sync_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		switch (sync_ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			goto post_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			goto do_generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		case -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) do_generic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if ((err = sync_start()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) post_sync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	is_setup = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) out3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (oprofile_ops.shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		oprofile_ops.shutdown();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	free_event_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	free_cpu_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static void switch_worker(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static DECLARE_DELAYED_WORK(switch_work, switch_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void start_switch_worker(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (oprofile_ops.switch_events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		schedule_delayed_work(&switch_work, oprofile_time_slice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void stop_switch_worker(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	cancel_delayed_work_sync(&switch_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void switch_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (oprofile_ops.switch_events())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	atomic_inc(&oprofile_stats.multiplex_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	start_switch_worker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* User inputs in ms, converts to jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int oprofile_set_timeout(unsigned long val_msec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	unsigned long time_slice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (oprofile_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!oprofile_ops.switch_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	time_slice = msecs_to_jiffies(val_msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (time_slice == MAX_JIFFY_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	oprofile_time_slice = time_slice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static inline void start_switch_worker(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static inline void stop_switch_worker(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Actually start profiling (echo 1>/dev/oprofile/enable) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int oprofile_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (!is_setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (oprofile_started)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	oprofile_reset_stats();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if ((err = oprofile_ops.start()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	start_switch_worker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	oprofile_started = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* echo 0>/dev/oprofile/enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void oprofile_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (!oprofile_started)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	oprofile_ops.stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	oprofile_started = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	stop_switch_worker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/* wake up the daemon to read what remains */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	wake_up_buffer_waiter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void oprofile_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (oprofile_ops.sync_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		int sync_ret = oprofile_ops.sync_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		switch (sync_ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			goto post_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			goto do_generic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			goto post_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) do_generic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	sync_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) post_sync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (oprofile_ops.shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		oprofile_ops.shutdown();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	is_setup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	free_event_buffer();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	free_cpu_buffers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int oprofile_set_ulong(unsigned long *addr, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	mutex_lock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!oprofile_started) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		*addr = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	mutex_unlock(&start_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int timer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int __init oprofile_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/* always init architecture to setup backtrace support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	timer_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	err = oprofile_arch_init(&oprofile_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (!timer && !oprofilefs_register())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		oprofile_arch_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* setup timer mode: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	timer_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* no nmi timer mode if oprofile.timer is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (timer || op_nmi_timer_init(&oprofile_ops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		err = oprofile_timer_init(&oprofile_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return oprofilefs_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void __exit oprofile_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	oprofilefs_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (!timer_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		oprofile_arch_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) module_init(oprofile_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) module_exit(oprofile_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) module_param_named(timer, timer, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_PARM_DESC(timer, "force use of timer interrupt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_AUTHOR("John Levon <levon@movementarian.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("OProfile system profiler");