Change parser strings to include length.
[bertos.git] / bertos / benchmark / kernel_footprint.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Luca Ottaviano <lottaviano@develer.com>
34  * \author Andrea Righi <arighi@develer.com>
35  * \author Daniele Basile <asterix@develer.com>
36  *
37  * \brief Kernel footprint benchmark.
38  */
39
40 #include "kernel_footprint.h"
41
42 #include <cpu/irq.h>
43
44 #include <kern/proc.h>
45 #include <kern/signal.h>
46 #include <kern/msg.h>
47 #include <kern/sem.h>
48
49 MsgPort in_port;
50
51 static void init(void)
52 {
53     IRQ_ENABLE;
54     proc_init();
55 }
56
57 static PROC_DEFINE_STACK(proc1_stack, KERN_MINSTACKSIZE);
58
59 static NORETURN void proc1_main(void)
60 {
61         int i;
62         for(;;)
63         {
64                 i++;
65         }
66 }
67
68 void kernel_footprint(void)
69 {
70         init();
71
72         // generate code for process
73         struct Process *p =
74                 proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack);
75         proc_setPri(p, 5);
76         proc_yield();
77
78         // generate code for msg
79         Msg msg;
80         msg_initPort(&in_port, event_createSignal(p, SIG_USER1));
81         msg_put(&in_port, &msg);
82         msg_peek(&in_port);
83         Msg *msg_re = msg_get(&in_port);
84         msg_reply(msg_re);
85
86         // generate code for signals
87         sig_send(p, SIG_USER0);
88
89         // generate code for msg
90         Semaphore sem;
91         sem_init(&sem);
92         sem_obtain(&sem);
93         sem_release(&sem);
94
95         sig_wait(SIG_USER0);
96 }