-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.coding
207 lines (158 loc) · 7.98 KB
/
README.coding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
**
** Source tree organization
**
******************************************************
There is at least 4 sub-projects in the tree:
- XBT: eXtended Bundle of Tools (low-level toolbox: logging, datatypes).
- SURF: a SimUlation aRtiFact. This is the simulation kernel.
- MSG: originally MetaSimGrid, MSG is a simple distributed application
simulator.
- SMPI: Simulated MPI, to run MPI application using emulation technics.
They are all in the same tree because they are complementary tools and
having all of them in the same package makes the installation easier
for end-users. Moreover, it enables to share the compilation chain and
eases the development.
The tree is not split on projects, but on file finality:
include/ -> all *public* headers
include/xbt/*.h -> one file per module
src/include -> another location for protected headers. Used by SURF, and
other should be converted, since this is the Right Thing.
examples/ -> Supposed to be copy/pastable by the user, so keep it clear and
avoid any kind of trick. In particular, do only include the
public headers here.
teshsuite/ -> The more test the better. Put in there any strange test
doing things that the users are not supposed to do,
just to see if our framework is robust to incorrect and
unusual behaviors. All tests written in this section
should leverage our tesh(1) utility.
**
** Indentation standard
**
*****************************************************
Most files use the Kernighan & Ritchie coding style with 2 spaces of
indentation. The indent program can help you to stick to it:
indent -kr -l80 -nut -i2 -lps -npcs -br -brs -ce -cdw -bbo -npsl <myfile>
The script ./tools/indent runs indent with the appropriate options.
FIXME: this list of arguments is still to be discussed, maybe
**
** Type naming standard
**
*****************************************************
It may sound strange, but the type naming convention was source of intense
discussion between da SimGrid posse members. The convention we came to may not
be the best solution, but it has the merit to exist and leave everyone work.
So please stick to it.
- ???_t is a valid type (built with typedef)
- s_toto_t is a structure (access to fields with .)
- s_toto is a structure needing 'struct' keyword to be used
- e_toto_t is an enum
- u_toto_t is an union
- u_toto is an union needing 'union' keyword to be used
- toto_t is an 'object' (struct*)
Please to not call toto_t something else than an 'object' (ie, something you
have to call _new and _free on it).
Example:
typedef struct s_toto {} s_toto_t, *toto_t;
typedef enum {} e_toto_t;
Moreover, only toto_t (and e_toto_t) are public. The rest (mainly s_toto_t)
is private.
If you see any part of the code not following this convention, this is a
bug. Please report it (or fix it yourself if you can).
**
** Random bits about coding standards and portability
**
*****************************************************
MALLOC
Don't use it, or you'll have to check the result (and do some dirty stuff
on AIX). Use xbt_malloc (or even better, xbt_new) instead.
SIZE_T (FIXME: obsolete?)
If possible, avoid size_t and use unsigned long instead. If not,
#include <sys/types.h> in all files manipulating size_t
do cast it to unsigned long before printing (and use %lu),
or use %zu.
INTEGERS
Please avoid to use long ints. This is the source of many compatibility
problems between 32 bits and 64 bits archs. Either use plain ints (generally
32 bits wide) or long long ints (64 bits wide, at least). At last resort
consider using integer types defined in C99 by <stdint.h>.
PRINTF pointer difference (FIXME: advertise %td instead?)
printf ("diff = %ld\n", (long) (pointer2 - pointer1));
INLINE functions
The definition of a inline function must be visible when it is used.
As such, an inline function should be defined (an not only declared)
in header file (.h) with attributes 'static XBT_INLINE'. It should
not be defined in source file (.c).
**
** Commenting the source: doxygen
**
****************************************************
The global structure of the documentation is in doc/modules.doc
The structure of each module (xbt, msg, etc) is in doc/module-<module>.doc
The structure of a module is in its public header. This way, you're sure to
see all the public interface (and only it). The different parts of the
interface are grouped using the @name construct, even if it's buggy. Since
parts often get reordered, it's better to add numbers to the parts (so that
users can see the intended order).
The documentation of each type and macro are also in the public header since
this is were they live.
The documentation of each function must be in the C file were it lives.
Any public element (function, type and macro) must have a @brief part.
**
** XBT virtualization mechanism (FIXME: this section is deprecated)
**
****************************************************
There is some functionalities that we want to virtualize in XBT. We
want xbt_time to give the simulated clock when running on top of the
simulator, and the host clock when running on a real system. This
could be placed in GRAS (and was, historically), but there is some
reason to lower it down to XBT.
Here is the used naming scheme:
- xbt_<module>_<func>(): functions working both in SG and RL
- xbt_os_<module>_<func>(): RL functions usable even in simulator
That way, in libsimgrid, we still can use native functions if we
want to. It may for example be useful to get the real time when
implementing the simulator. Think of the SIGINT handler, which
wants to see if the user pressed the key twice in a 5 seconds
interval. This is of little use to check the simulated time here.
Here is the file layout:
- xbt_rl_<module>.c: native implementation (xbt_<module>_<func>()).
Simply call the corresponding xbt_os_<module>_<func>.
Part only of libgras.so
- xbt_sg_<module>.c: SIMIX implementation xbt_<module>_<func>()).
Simply call the corresponding SIMIX implementation.
Part only of libsimgrid.so
- xbt_os_<module>.c: body of the functions implementing natively the
stuff (xbt_os_<module>_<func>()).
Part of both libgras.so and libsimgrid.so
Since there is almost nothing in xbt_rl_module.c and xbt_sg_module.c,
it'd be better to use symbol aliasing here (to declare in the object
code that the same function have two names), but I'm still
investigating the portability of the thing to windows.
*
* SimGrid Hacker Survival Guide (FIXME: should be betterly placed)
********************************
* Before pushing any change, don't forget to check if the compilation
passes with compiler optimizations and warnings turned on:
cmake -Denable_compile_optimizations=ON \
-Denable_compile_warnings=ON
* Your commit message should follow the git habits, explained eg here:
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
* When you add/remove files, and/or make changes in the lists of files to build,
please check that "make distcheck" still succeeds. This is needed to ensure
that the generated archive is consistent.
* If you want to debug memory allocation problems, here are a few hints:
- disable compiler optimizations, to have better backtraces;
- disable the mallocators, or it will be hard to match malloc's with
free's;
- disable model checking, unless your problem lies in the model
checker part of SimGrid (MC brings its own malloc implementation,
which valgrind doesn't understand).
All this is configured with:
cmake -Denable_model-checking=OFF \
-Denable_mallocators=OFF \
-Denable_compile_optimizations=OFF
* If you break the logs (for example while hacking in the dynars), you
want to define XBT_LOG_MAYDAY at the beginning of log.h. It will
deactivate the whole logging mechanism, switching to printfs
instead. SimGrid becomes incredibly verbose when doing so, but it
you let you fixing the dynars.