Logo AND Algorithmique Numérique Distribuée

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