~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/verification/rv/src/trace.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * trace helpers.
  4  *
  5  * Copyright (C) 2022 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
  6  */
  7 
  8 #include <sys/sendfile.h>
  9 #include <tracefs.h>
 10 #include <signal.h>
 11 #include <stdlib.h>
 12 #include <unistd.h>
 13 #include <errno.h>
 14 
 15 #include <rv.h>
 16 #include <trace.h>
 17 #include <utils.h>
 18 
 19 /*
 20  * create_instance - create a trace instance with *instance_name
 21  */
 22 static struct tracefs_instance *create_instance(char *instance_name)
 23 {
 24         return tracefs_instance_create(instance_name);
 25 }
 26 
 27 /*
 28  * destroy_instance - remove a trace instance and free the data
 29  */
 30 static void destroy_instance(struct tracefs_instance *inst)
 31 {
 32         tracefs_instance_destroy(inst);
 33         tracefs_instance_free(inst);
 34 }
 35 
 36 /**
 37  * collect_registered_events - call the existing callback function for the event
 38  *
 39  * If an event has a registered callback function, call it.
 40  * Otherwise, ignore the event.
 41  *
 42  * Returns 0 if the event was collected, 1 if the tool should stop collecting trace.
 43  */
 44 int
 45 collect_registered_events(struct tep_event *event, struct tep_record *record,
 46                           int cpu, void *context)
 47 {
 48         struct trace_instance *trace = context;
 49         struct trace_seq *s = trace->seq;
 50 
 51         if (should_stop())
 52                 return 1;
 53 
 54         if (!event->handler)
 55                 return 0;
 56 
 57         event->handler(s, record, event, context);
 58 
 59         return 0;
 60 }
 61 
 62 /**
 63  * trace_instance_destroy - destroy and free a rv trace instance
 64  */
 65 void trace_instance_destroy(struct trace_instance *trace)
 66 {
 67         if (trace->inst) {
 68                 destroy_instance(trace->inst);
 69                 trace->inst = NULL;
 70         }
 71 
 72         if (trace->seq) {
 73                 free(trace->seq);
 74                 trace->seq = NULL;
 75         }
 76 
 77         if (trace->tep) {
 78                 tep_free(trace->tep);
 79                 trace->tep = NULL;
 80         }
 81 }
 82 
 83 /**
 84  * trace_instance_init - create an trace instance
 85  *
 86  * It is more than the tracefs instance, as it contains other
 87  * things required for the tracing, such as the local events and
 88  * a seq file.
 89  *
 90  * Note that the trace instance is returned disabled. This allows
 91  * the tool to apply some other configs, like setting priority
 92  * to the kernel threads, before starting generating trace entries.
 93  *
 94  * Returns 0 on success, non-zero otherwise.
 95  */
 96 int trace_instance_init(struct trace_instance *trace, char *name)
 97 {
 98         trace->seq = calloc(1, sizeof(*trace->seq));
 99         if (!trace->seq)
100                 goto out_err;
101 
102         trace_seq_init(trace->seq);
103 
104         trace->inst = create_instance(name);
105         if (!trace->inst)
106                 goto out_err;
107 
108         trace->tep = tracefs_local_events(NULL);
109         if (!trace->tep)
110                 goto out_err;
111 
112         /*
113          * Let the main enable the record after setting some other
114          * things such as the priority of the tracer's threads.
115          */
116         tracefs_trace_off(trace->inst);
117 
118         return 0;
119 
120 out_err:
121         trace_instance_destroy(trace);
122         return 1;
123 }
124 
125 /**
126  * trace_instance_start - start tracing a given rv instance
127  *
128  * Returns 0 on success, -1 otherwise.
129  */
130 int trace_instance_start(struct trace_instance *trace)
131 {
132         return tracefs_trace_on(trace->inst);
133 }
134 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php