source: trunk/kernel/libk/remote_barrier.c @ 7

Last change on this file since 7 was 1, checked in by alain, 8 years ago

First import

File size: 1.8 KB
Line 
1/*
2 * remote_barrier.c - distributed kernel barrier implementaion
3 *
4 * Author   Alain Greiner (2016)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_remote.h>
26#include <remote_barrier.h>
27
28/////////////////////////////////////////
29inline void remote_barrier( xptr_t    xp,
30                            uint32_t  count ) 
31{
32    uint32_t  expected;
33
34    remote_barrier_t * ptr = (remote_barrier_t *)GET_PTR( xp );
35    cxy_t              cxy = GET_CXY( xp );
36
37    // get barrier sense value
38    uint32_t sense = hal_remote_lw( XPTR( cxy , &ptr->sense ) );
39
40        // compute expected value
41    if ( sense == 0 ) expected = 1;
42    else              expected = 0;
43
44    // increment count
45    uint32_t current = hal_remote_atomic_add( XPTR( cxy , &ptr->current ) , 1 );
46
47    // last task reset current and toggle sense
48    if( current == (count-1) ) 
49    {
50        hal_remote_sw( XPTR( cxy , &ptr->current) , 0 ); 
51        hal_remote_sw( XPTR( cxy , &ptr->sense  ) , expected ); 
52    }
53    else   // other tasks poll the sense
54    {
55        while( hal_remote_lw( XPTR( cxy , &ptr->sense ) ) != expected ) asm volatile ("nop");
56    }
57}
58
59
Note: See TracBrowser for help on using the repository browser.