Changes between Initial Version and Version 1 of Component/Virtual Coprocessor Wrapper


Ignore:
Timestamp:
Jan 14, 2013, 4:29:23 PM (11 years ago)
Author:
meunier
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Component/Virtual Coprocessor Wrapper

    v1 v1  
     1[wiki:Component SocLib Components General Index]
     2
     3
     4= Component description =
     5
     6== Objective ==
     7
     8This component aims at encapsulating some code written in C into a hardware component, called ''virtual coprocessor wrapper''. The objective targetted is to have an estimation of the performances when a task is executed in hardware, without having to write a real coprocessor.
     9
     10
     11== Modelisation ==
     12
     13The coprocessor is modeled by a hardware component, the ''wrapper'', which contains registers, a transition function and a Moore generation function. It can be interfaced with a `vci_mwmr_controller` that allows access to any number of MWMR channels in memory. The C function corresponding to the hardware task is associated to a posix thread, which is executed in parallel with the simulator for the architecture. This task thread is launched by the ''wrapper'' on reset.
     14
     15The task thread communicates with the ''wrapper'' with two fifo channels:
     16 * the `cmd` channel, which transmits to the ''wrapper'' the SRL commands:
     17   * `srl_mwmr_read(channel, buffer, size)`
     18   * `srl_mwmr_write(channel, buffer, size)`
     19   * `srl_busy_cycles(n_cycles)`
     20 * the `rsp` channel, which is used to transmit the response to the read requests
     21
     22[[Image(virtual_coprocessor_wrapper.svg)]]
     23
     24To avoid race conditions, a single lock is used for both fifos cmd and rsp.
     25
     26The ''wrapper'' is implemented as a four-state automaton, whose role is to execute the SRL commands transmitted by the hardware task.
     27
     28[[Image(coprocessor_wrapper_fsm.svg)]]
     29
     301. In IDLE state, the automaton tests if a command is available in the `cmd` fifo.
     31 * If yes, it gets the parameters and goes in a state corresponding to the type of the command to execute it.
     32 * If no, it waits until a command is available
     33
     342. In READ state, the automaton transfers data from the MWMR controller directly into the buffer of the task thread (1 word/cycle). When the last word has been transfered, the automatod signals the completion to wake up the task thread, and returns in IDLE state.
     35
     363. In WRITE state, the automaton makes the transfer from the task thread to the MWMR controller (1 word/cycle), and returns in idle when the transfer is complete.
     37
     384. In BUSY state, the automaton decreases a counter at each cycle until the counter reaches 0.
     39
     40
     41== Synchronization ==
     42
     43The ''wrapper'' behaves as if all the SRL commands were blocking for the task thread, which is well adapted to sequential coprocessors, which never execute several commands in parallel:
     44
     45[[Image(simple_copro.svg)]]
     46
     47However, to avoid potential useless switches between the threads, only the read commands really are blocking. Thus, if a task thread only makes writes, it will continue executing until the `cmd` fifo is considered full (the defaut value is 50 commands, but it could be anything).
     48
     49The two threads are synchronized with two `pthread_cond_t` conditions: `task_cond` and `wrapper_cond`.
     50Here is the simplified execution scheme on one (host) processor, for a task thread making only reads:
     51 * On creation, the task thread is executed
     52 * The task thread makes a read: it sends a command and then try to read a response; as there is none, it waits on `task_cond`
     53 * The wrapper thread is executed, receives the read request, and process it. When the response is ready, it signals `task_cond`
     54 * The wrapper thread tries to read another command. As there is none, it waits on `wrapper_cond`
     55 * The task thread is executed, and makes another read, etc.
     56
     57Here is the simplified execution scheme on one (host) processor, for a task thread making only writes:
     58 * On creation, the task thread is executed
     59 * The task thread makes a write: it sends a command and then continue its execution
     60 * After a certain number of writes, the command fifo reaches its maximum value. The task thread signals `wrapper_cond` and waits on `task_cond`
     61 * The wrapper thread is executed, and start processing all the writes commands.
     62 * When there is no more commands in the `cmd` fifo, the wrapper thread signals `task_cond` and waits on `wrapper_cond`
     63 * The task thread is executed, and makes another write, etc.
     64With several cores, the difference is that after the creation of the task thread, the wrapper thread can continue its execution, and theoritically consume the writes as they are produced, thus none of the threads never waits (though in practice the task thread will always be faster).
     65
     66
     67(A finir)
     68
     69= Component usage =
     70
     71== Object ==
     72
     73{{{
     74soclib::common::ProcessWrapper *process;
     75}}}
     76
     77== Instanciation ==
     78
     79
     80{{{
     81    soclib::common::ProcessWrapper(
     82        const std::string &cmd,
     83        const std::vector<std::string> &argv );
     84}}}
     85
     86 cmd::
     87   The command to launch, it will be looked for in $PATH
     88 argv::
     89   The argv in a standart unix style. argv[0] should look like cmd.
     90
     91== Usage ==
     92
     93{{{
     94    std::vector<std::string> argv;
     95    argv.push_back("date");
     96    argv.push_back("+%s");
     97    soclib::common::ProcessWrapper process("date", argv);
     98
     99    char buffer[128];
     100    process.read( buffer, 128 );
     101    std::cout << "Date is " << buffer << " seconds since EPOCH" << std::endl;
     102}}}
     103