| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | /* tracepoint-sample.c
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  |  * Executes a tracepoint when /proc/tracepoint-sample is opened. | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is released under the GPLv2. | 
					
						
							|  |  |  |  * See the file COPYING for more details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/sched.h>
 | 
					
						
							|  |  |  | #include <linux/proc_fs.h>
 | 
					
						
							|  |  |  | #include "tp-samples-trace.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-14 17:47:47 -05:00
										 |  |  | DEFINE_TRACE(subsys_event); | 
					
						
							|  |  |  | DEFINE_TRACE(subsys_eventb); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | struct proc_dir_entry *pentry_sample; | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int my_open(struct inode *inode, struct file *file) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	trace_subsys_event(inode, file); | 
					
						
							|  |  |  | 	for (i = 0; i < 10; i++) | 
					
						
							|  |  |  | 		trace_subsys_eventb(); | 
					
						
							|  |  |  | 	return -EPERM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 15:43:56 -07:00
										 |  |  | static const struct file_operations mark_ops = { | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | 	.open = my_open, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | static int __init sample_init(void) | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | 	printk(KERN_ALERT "sample init\n"); | 
					
						
							|  |  |  | 	pentry_sample = proc_create("tracepoint-sample", 0444, NULL, | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | 		&mark_ops); | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | 	if (!pentry_sample) | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | 		return -EPERM; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | static void __exit sample_exit(void) | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | 	printk(KERN_ALERT "sample exit\n"); | 
					
						
							|  |  |  | 	remove_proc_entry("tracepoint-sample", NULL); | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | module_init(sample_init) | 
					
						
							|  |  |  | module_exit(sample_exit) | 
					
						
							| 
									
										
										
										
											2008-07-18 12:16:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Mathieu Desnoyers"); | 
					
						
							| 
									
										
										
										
											2009-03-24 16:00:28 -04:00
										 |  |  | MODULE_DESCRIPTION("Tracepoint sample"); |