Logo AND Algorithmique Numérique Distribuée

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