Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use an automatic table of contents instead of a manual one
[simgrid.git] / doc / doxygen / inside_extending.doc
1 /*!
2 \page inside_extending Extending SimGrid
3
4 \tableofcontents
5
6 \section simgrid_dev_guide_api How to add a new MSG function?
7 Search for expression \"TUTORIAL: New API\".
8 \verbatim
9 user@caraja:~/workspace/simgrid/src$ cg "TUTORIAL: New API"
10  0 msg/msg_new_api.c             15 /* TUTORIAL: New API*/
11  1 simix/smx_smurf.c            582 /* TUTORIAL: New API*/
12  2 simix/smx_smurf.c            616 /* TUTORIAL: New API*/
13  3 simix/smx_smurf_private.h    102 /* TUTORIAL: New API*/
14  4 simix/smx_smurf_private.h    629 /* TUTORIAL: New API*/
15  5 simix/smx_private.h           28 /* TUTORIAL: New API*/
16  6 simix/smx_private.h          101 /* TUTORIAL: New API*/
17  7 simix/smx_private.h          182 /* TUTORIAL: New API*/
18  8 simix/smx_global.c           454 /* TUTORIAL: New API*/
19  9 simix/smx_new_api.c            8 /* TUTORIAL: New API*/
20 10 simix/smx_user.c            1684 /* TUTORIAL: New API*/
21 11 simix/smx_new_api_private.h    8 /* TUTORIAL: New API*/
22 12 simix/smx_process.c          338 /* TUTORIAL: New API*/
23 \endverbatim
24
25 \section simgrid_dev_guide_model How to add a new model in surf?
26 The figure below show the architecture of the SURF layer. This layer is composed
27 of different kind of models representing the differents systems we want to
28 modelize (i.e.cpu, network, storage, workstation, virtual machine).
29
30 A model in simgrid is composed of three classes: Model, Resource and Action
31 (surf_interface.hpp).
32
33 \image html surf++.png
34 \image latex surf++.pdf "surf++" width=\textwidth
35
36 Actually there are five kind of models: CpuModel, NetworkModel, WorkstationModel,
37 WorkstationVMModel and StorageModel. For each kind of model, there is an
38 interface (e.g.: cpu_interface.hpp) and some implementations (e.g.: cpu_cas01.hpp,
39 cpu_ti.hpp).
40
41 init function:
42 void surf_cpu_model_init_Cas01()
43 s_surf_model_description_t surf_network_model_description[] = {
44
45 \subsection simgrid_dev_guide_model_implem How to add a new model implementation in surf?
46
47 If you want to create a new implementation of a kind of model you must extend
48 the classes of the corresponding interfaces.
49
50 For instance, if you want to add a new cup model called `Plop`, create two files
51 cpu_plop.hpp and cpu_plop_cpp which contains classes CpuPlopModel, CpuPlop and
52 CpuPlopAction implementating respectively the interfaces CpuModel, Cpu and
53 CpuAction. You also need to define a initializing function like this:
54
55 ~~~~
56 void surf_cpu_model_init_plop()
57 {
58   xbt_assert(!surf_cpu_model_pm);
59
60   surf_cpu_model_pm = new CpuPlopModel();
61
62   sg_platf_host_add_cb(cpu_parse_init);
63   sg_platf_postparse_add_cb(cpu_add_traces);
64
65   xbt_dynar_push(model_list, &surf_cpu_model_pm);
66 }
67 ~~~~
68
69 and add an entry in the corresponding array in surf_interface.cpp
70
71 ~~~~
72 s_surf_model_description_t surf_cpu_model_description[] = {
73   {"Cas01",
74    "Simplistic CPU model (time=size/power).",
75    surf_cpu_model_init_Cas01},
76   {"Plop",
77    "The new plop CPU model.",
78    surf_cpu_model_init_plop},
79   {NULL, NULL, NULL}      // this array must be NULL terminated
80 };
81 ~~~~
82
83 \subsection simgrid_dev_guide_model_kind How to add a new kind of model in surf?
84
85 If you want to create a new kind of model, you must create a new interface
86 where you extend the classes Model, Resource and Action, and then create an
87 implementation of this interface.
88
89
90 \section simgrid_dev_guide_surf_callbacks How to use surf callbacks?
91
92 Adding features to surf could also be handle by using surf callbacks (instead
93 of adding new implementation model). The list of available callbacks is
94 accessible there \ref SURF_callbacks. An example of using surf callbacks is the
95 energy plugin. If you want to add a plugin you need to define callback function
96 and to connect them to callbacks handler in an initialization function.
97
98 ~~~~
99 static void MyNetworkLinkCreatedCallback(NetworkLinkPtr cpu){
100   // your code
101 }
102
103 static void MyNetworkLinkDestructedCallback(NetworkLinkPtr cpu){
104   // your code
105 }
106
107 static void MyNetworkCommunicationCallback(NetworkActionPtr cpu,
108                                            RoutingEdgePtr src,
109                                            RoutingEdgePtr dst){
110   // your code
111 }
112
113 void sg_my_network_plugin_init() {
114   surf_callback_connect(networkLinkCreatedCallbacks,
115                         MyNetworkLinkCreatedCallback);
116   surf_callback_connect(networkLinkDestructedCallbacks,
117                         MyNetworkLinkDestructedCallback);
118   surf_callback_connect(networkCommunicationCallbacks,
119                         MyNetworkCommunicationCallback);
120 }
121 ~~~~
122
123 Then you need to add an entry in surf_interface.cpp refering to your
124 initialization function.
125
126 ~~~~
127 s_surf_model_description_t surf_plugin_description[] = {
128                   {"Energy",
129                    "Cpu energy consumption.",
130                    sg_energy_plugin_init},
131                   {"MyNetworkPlugin",
132                    "My network plugin.",
133                    sg_my_network_plugin_init},
134                   {NULL, NULL, NULL}      // this array must be NULL terminated
135 };
136 ~~~~
137
138 \section simgrid_dev_guide_simcall How to add a new simcall?
139 A simcall is used to go from user mode to kernel mode. The workflow of
140 a simcall is the following:
141
142 - `<ret> simcall_<name>(<args>)`
143  - `simcall_BODY_<name>(<args>)`
144   - create the simcall
145   - `SIMIX_process_yield` if not maestro
146   - ========== KERNEL MODE ==========
147   - `SIMIX_simcall_pre`
148    - `SIMIX_pre_<name>(simcall, <args>)`
149    - `SIMIX_simcall_answer(simcall)`
150
151 To simplify the simcall creation, we have made a python script that
152 generate most of the code and give helpers for the remaining stuff.
153 The script generating the simcalls (src/simix/simcalls.in) take in input
154 the src/simix/simcalls.in file where the simcalls are defined and generate
155 the following files:
156
157 - simcall_generated_args_getter_setter.h:
158   functions to get and set simcall arguments
159 - simcall_generated_res_getter_setter.h:
160   functions to get and set simcall result
161 - simcall_generated_body.c:
162   the BODY function of the simcall
163 - simcall_generated_case.c:
164   the case of the SIMIX_simcall_pre function
165 - simcall_generated_enum.h:
166   the enum of simcalls
167 - simcall_generated_string.c:
168   string corresponding to the enum to debug
169
170 Furthermode if the simcall_<name> or the SIMIX_pre_<name> function are missing,
171 a warning will show up with a prototype of the corresponding fonction to fill.
172
173 The simcall.in file list all the simcalls in sections. A line starting by "##"
174 define a new section which will be replace by a "ifdef" in the generated code.
175 There is a simcall by line which follow this format:
176
177 ~~~~
178 Simcall -> Name HasAnswer Res Args
179 Name -> [a-z0-9_]+
180 Has_Answer -> "True" | "False"
181 Res -> "(" Type MaybeCast ")"
182 Args -> Args Arg | Arg
183 Arg -> "(" Name "," Type MaybeCast ")"
184 Type -> "char" | "const char*" | "int" | "long" | "unsigned char" | "unsigned short" | "unsigned int" | "unsigned long" | "float" | "double" | "void*" | "FPtr" | "const void*" | "size_t" | "sg_size_t" | "void" | "void*"
185 MaybeCast -> "," Cast | ""
186 Cast -> [a-z0-9_* ]+
187 ~~~~
188
189 \section simgrid_dev_guide_tag What is How to add a new tag for xml files?
190 Search for expression \"TUTORIAL: New TAG\".
191 \verbatim
192 user@caraja:~/workspace/simgrid/src$ cg "TUTORIAL: New TAG"
193 0 surf/sg_platf.c                    43 /* TUTORIAL: New TAG*/
194 1 surf/sg_platf.c                    89 /* TUTORIAL: New TAG*/
195 2 surf/sg_platf.c                   124 /* TUTORIAL: New TAG*/
196 3 surf/sg_platf.c                   337 /* TUTORIAL: New TAG*/
197 4 surf/surfxml_parse.c              769 /* TUTORIAL: New TAG*/
198 5 surf/surf_private.h               205 /* TUTORIAL: New TAG*/
199 6 surf/surfxml_parseplatf.c          64 /* TUTORIAL: New TAG*/
200 7 surf/surfxml_parseplatf.c          85 /* TUTORIAL: New TAG*/
201 8 include/simgrid/platf_interface.h  42 /* TUTORIAL: New TAG*/
202 \endverbatim
203 */