| 1 | = MutekH tutorial for SoCLib platform = |
| 2 | |
| 3 | This guide explain how to run MutekH on a [wiki:Arch/Soclib SoCLib] hardware simulator. |
| 4 | This is allow easy experimentation with advanced multi-processor programming. |
| 5 | |
| 6 | You are '''highly encouraged''' to first follow the [wiki:QuickStartUnix MutekH as Unix process quick start guide] |
| 7 | which introduces more basic concepts. |
| 8 | |
| 9 | MutekH for SoCLib can be compiled for Mips, Arm, PowerPC processors. |
| 10 | Other processors are available with different platforms. |
| 11 | |
| 12 | == The SoCLib platform == |
| 13 | |
| 14 | The MutekH kernel source code is fully configurable and can be tweaked to adapt hardware platform |
| 15 | and application needs. Configuration is handled by a dedicated tool which check dependencies and |
| 16 | other relationships between the large set of available configuration tokens. |
| 17 | |
| 18 | The example below explains how to setup a SoCLib hardware simulator with 4 RISC processor (Mips, Arm or PowerPC). |
| 19 | |
| 20 | [[BR]][[BR]][[Image(arch.png,nolink)]][[BR]][[BR]] |
| 21 | |
| 22 | === Getting SoCLib === |
| 23 | |
| 24 | We now need to have a working SoCLib install. SoCLib installation is explained here: https://www.soclib.fr/trac/dev/wiki/InstallationNotes |
| 25 | |
| 26 | === SoCLib platform description === |
| 27 | |
| 28 | The SoCLib source tree contains a platform dedicated to this tutorial: |
| 29 | {{{soclib/soclib/platform/topcells/caba-vgmn-mutekh_soclib_tutorial/}}} |
| 30 | |
| 31 | === Getting the cross-compilers === |
| 32 | |
| 33 | SoCLib installation nodes already provides a way to get cross-compiler, if you don't already have them, MutekH holds a tool |
| 34 | to build a complete cross-compilation toolchain: |
| 35 | |
| 36 | The script is in [source:trunk/mutekh/tools/crossgen.mk@1183 tools/crossgen.mk]: |
| 37 | {{{ |
| 38 | $ tools/crossgen.mk |
| 39 | [prints some help] |
| 40 | $ tools/crossgen.mk all TARGET=mipsel-unknown-elf |
| 41 | }}} |
| 42 | |
| 43 | == The MutekH part == |
| 44 | |
| 45 | === Getting the sources === |
| 46 | |
| 47 | {{{ |
| 48 | svn co -r 1183 https://www-asim.lip6.fr/svn/mutekh/trunk/mutekh |
| 49 | }}} |
| 50 | |
| 51 | === Writing the example source code === |
| 52 | |
| 53 | Note: This example is available directly from [source:trunk/mutekh/examples/hello@1183 examples/hello] directory in source tree. |
| 54 | |
| 55 | * Writing the source code in `hello.c` |
| 56 | {{{ |
| 57 | #include <pthread.h> |
| 58 | |
| 59 | pthread_mutex_t m; |
| 60 | pthread_t a, b; |
| 61 | |
| 62 | void *f(void *param) |
| 63 | { |
| 64 | while (1) |
| 65 | { |
| 66 | pthread_mutex_lock(&m); |
| 67 | printf("(%i) %s", cpu_id(), param); |
| 68 | pthread_mutex_unlock(&m); |
| 69 | pthread_yield(); |
| 70 | } |
| 71 | } |
| 72 | int main() |
| 73 | { |
| 74 | pthread_mutex_init(&m, NULL); |
| 75 | pthread_create(&a, NULL, f, "Hello "); |
| 76 | pthread_create(&b, NULL, f, "World\n"); |
| 77 | } |
| 78 | }}} |
| 79 | |
| 80 | * Writing the `Makefile` |
| 81 | {{{ |
| 82 | objs = hello.o |
| 83 | }}} |
| 84 | |
| 85 | |
| 86 | === Writing the MutekH configuration === |
| 87 | |
| 88 | The MutekH configuration for the 4 Mips processors platform is in the [source:trunk/mutekh/examples/hello/config examples/hello/config] file. |
| 89 | |
| 90 | This file only holds information about the application (here a simple pthread application) and relies upon files in the [source:trunk/mutekh/examples/common@1183 examples/common] directory for the platform definitions. |
| 91 | |
| 92 | Have a look to the BuildSystem page for more information about configuration system and configuration file format. |
| 93 | |
| 94 | The [http://www.mutek.fr/www/mutekh_api/ MutekH API reference manual] describes all available configuration tokens. |
| 95 | |
| 96 | === Platform description === |
| 97 | |
| 98 | The MutekH software uses hardware enumeration to get details about available hardware in the platform, so the `CONFIG_ARCH_DEVICE_TREE` token is defined in the [source:trunk/mutekh/examples/common/platforms-soclib.conf@1183 examples/common/platforms-soclib.conf] configuration file. It will let the kernel get the platform layout description from a FlattenedDeviceTree which will be built into the kernel. |
| 99 | |
| 100 | Therefore, the build also compiles the correct FlattenedDeviceTree from the platform name. |
| 101 | |
| 102 | The current FlattenedDeviceTree source file is |
| 103 | [source:trunk/mutekh/examples/common/pf_soclib_tutorial_ppc.dts examples/common/pf_soclib_tutorial_ppc.dts], |
| 104 | [source:trunk/mutekh/examples/common/pf_soclib_tutorial_arm.dts (for arm)], |
| 105 | [source:trunk/mutekh/examples/common/pf_soclib_tutorial_mips.dts (for mips)]. |
| 106 | |
| 107 | === Compiling the application along with MutekH === |
| 108 | |
| 109 | The MutekH kernel and the application may be built out of the source tree. |
| 110 | |
| 111 | Change to the SoCLib platform directory and apply the following steps to experiment |
| 112 | with out of tree compilation. You have to setup the following variables: |
| 113 | |
| 114 | `MUTEKH_DIR`:: |
| 115 | Path to MutekH source tree |
| 116 | `APP`:: |
| 117 | Path to application source |
| 118 | `CONFIG`:: |
| 119 | MutekH configuration file name |
| 120 | `BUILD`:: |
| 121 | MutekH build option list (target architecture, cpu type, …) |
| 122 | |
| 123 | See the `config.mk` file in the tutorial platform directory for more information. |
| 124 | |
| 125 | {{{ |
| 126 | $ cd soclib/soclib/platform/topcells/caba-vgmn-mutekh_soclib_tutorial |
| 127 | $ make MUTEKH_DIR=/path/to/mutekh |
| 128 | }}} |
| 129 | |
| 130 | This will build the MutekH kernel along with the application. |
| 131 | You can still build MutekH separately as explained in the first part. The simulator can then be built using: |
| 132 | |
| 133 | {{{ |
| 134 | $ cd soclib/soclib/platform/topcells/caba-vgmn-mutekh_tutorial |
| 135 | $ make system.x |
| 136 | }}} |
| 137 | |
| 138 | == Execution == |
| 139 | |
| 140 | You can optionally pass an alternative kernel to the simulator, but this defaults to the correct kernel name if you followed the tutorial until here. |
| 141 | {{{ |
| 142 | $ ./system.x mutekh/kernel-soclib-ppc.out |
| 143 | }}} |
| 144 | |
| 145 | You may want to refer to other articles and documents available from the main page to go further with MutekH. |
| 146 | |
| 147 | The [soclib:wiki: SoCLib] home page provides a livecd image with more advanced examples ready to compile and run. These examples are using older MutekH revisions though. |
| 148 | |
| 149 | Other more advanced topics and guides are available from the [wiki: Main page]. |