Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | #include <ll/sys/types.h> |
||
20 | #include <ll/stdlib.h> |
||
21 | |||
22 | #include <kernel/func.h> |
||
23 | #include <kernel/mem.h> |
||
24 | #include <kernel/log.h> |
||
25 | |||
26 | #include <trace/types.h> |
||
27 | #include <trace/trace.h> |
||
28 | #include <trace/queues.h> |
||
29 | |||
30 | #include <fs/fs.h> |
||
31 | |||
32 | #include <unistd.h> |
||
33 | #include <fcntl.h> |
||
34 | #include <limits.h> |
||
35 | |||
36 | typedef struct TAGfixed_queue_t { |
||
37 | int size; |
||
38 | int index; |
||
39 | char *filename; |
||
40 | int uniq; |
||
41 | |||
42 | trc_event_t table[0]; |
||
43 | } fixed_queue_t; |
||
44 | |||
45 | static trc_event_t *fixed_get(fixed_queue_t *queue) |
||
46 | { |
||
47 | if (queue->index>=queue->size) return NULL; |
||
48 | return &queue->table[queue->index++]; |
||
49 | } |
||
50 | |||
51 | static int fixed_post(fixed_queue_t *queue) |
||
52 | { |
||
53 | return 0; |
||
54 | } |
||
55 | |||
56 | static TRC_FIXED_PARMS defaultargs; |
||
57 | static int once=0; |
||
58 | |||
59 | static int fixed_create(trc_queue_t *queue, TRC_FIXED_PARMS *args) |
||
60 | { |
||
61 | fixed_queue_t *ptr; |
||
62 | |||
63 | if (!once) { |
||
64 | /* well... this func is called when the system is not running! */ |
||
65 | once=1; |
||
66 | trc_fixed_default_parms(defaultargs); |
||
67 | } |
||
68 | if (args==NULL) args=&defaultargs; |
||
69 | |||
70 | ptr=(fixed_queue_t*)kern_alloc(sizeof(fixed_queue_t)+ |
||
71 | sizeof(trc_event_t)*(args->size+1)); |
||
72 | if (ptr==NULL) return -1; |
||
73 | |||
74 | |||
75 | queue->get=(trc_event_t*(*)(void*))fixed_get; |
||
76 | queue->post=(int(*)(void*))fixed_post; |
||
77 | queue->data=ptr; |
||
78 | |||
79 | ptr->size=args->size; |
||
80 | ptr->index=0; |
||
81 | ptr->filename=args->filename; |
||
82 | return 0; |
||
83 | } |
||
84 | |||
85 | static TASK fixed_shutdown(fixed_queue_t *queue) |
||
86 | { |
||
87 | char pathname[PATH_MAX]; |
||
88 | int h; |
||
89 | |||
90 | printk(KERN_DEBUG "<fixed queuesize:%i>",queue->index); |
||
91 | |||
92 | if (queue->filename==NULL) trc_create_name("fix",queue->uniq,pathname); |
||
93 | else trc_create_name(queue->filename,0,pathname); |
||
94 | |||
95 | //sys_status(SCHED_STATUS); |
||
96 | //task_delay(250000); |
||
97 | |||
98 | h=open("/TEMP/FIX1",O_CREAT|O_TRUNC|O_WRONLY); |
||
99 | if (h!=-1) { |
||
100 | write(h,queue->table,queue->index*sizeof(trc_event_t)); |
||
101 | close(h); |
||
102 | printk(KERN_NOTICE "tracer file %s created!",pathname); |
||
103 | } else { |
||
104 | printk(KERN_NOTICE "tracer file %s not created!",pathname); |
||
105 | } |
||
106 | |||
107 | resume_fs_shutdown(); |
||
108 | return NULL; |
||
109 | } |
||
110 | |||
111 | static int fixed_activate(fixed_queue_t *queue, int uniq) |
||
112 | { |
||
113 | queue->uniq=uniq; |
||
114 | return 0; |
||
115 | } |
||
116 | |||
117 | static int fixed_terminate(fixed_queue_t *queue) |
||
118 | { |
||
119 | SOFT_TASK_MODEL model; |
||
120 | PID pid; |
||
121 | |||
122 | suspend_fs_shutdown(); |
||
123 | |||
124 | //nrt_task_default_model(model); |
||
125 | //nrt_task_def_system(model); |
||
126 | //nrt_task_def_arg(model,queue); |
||
127 | |||
128 | soft_task_default_model(model); |
||
129 | soft_task_def_system(model); |
||
130 | soft_task_def_notrace(model); |
||
131 | soft_task_def_periodic(model); |
||
132 | soft_task_def_period(model,50000); |
||
133 | soft_task_def_met(model,10000); |
||
134 | soft_task_def_wcet(model,10000); |
||
135 | soft_task_def_arg(model,queue); |
||
136 | |||
137 | pid=task_create("ShutTrcFix",fixed_shutdown,&model,NULL); |
||
138 | if (pid==-1) { |
||
139 | printk(KERN_ERR "can't start tracer shutdown task (fixed)"); |
||
140 | return -1; |
||
141 | } else |
||
142 | task_activate(pid); |
||
143 | |||
144 | return 0; |
||
145 | } |
||
146 | |||
147 | int trc_register_fixed_queue(void) |
||
148 | { |
||
149 | int res; |
||
150 | |||
151 | res=trc_register_queuetype(TRC_FIXED_QUEUE, |
||
152 | (int(*)(trc_queue_t*,void*))fixed_create, |
||
153 | (int(*)(void*,int))fixed_activate, |
||
154 | (int(*)(void*))fixed_terminate |
||
155 | ); |
||
156 | |||
157 | if (res!=0) printk(KERN_WARNING "can't register tracer fixed queue"); |
||
158 | return res; |
||
159 | } |