source: trunk/kernel/libk/xbarrier.c @ 636

Last change on this file since 636 was 563, checked in by alain, 6 years ago

Complete restructuration of kernel spinlocks.

File size: 1.9 KB
RevLine 
[563]1/*
2 * xbarrier.c -  Busy-waiting, trans-clusters, kernel barrier implementation.
3 *
4 * Author   Alain Greiner (2016,2017,2018)
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_kernel_types.h>
25#include <hal_remote.h>
26#include <hal_atomic.h>
27#include <xbarrier.h>
28
29
30/////////////////////////////////////////////////
31inline void xbarrier_wait( xptr_t    barrier_xp,
32                           uint32_t  count )
33{
34    uint32_t  expected;
35
36    xbarrier_t * ptr = GET_PTR( barrier_xp );
37    cxy_t        cxy = GET_CXY( barrier_xp );
38
39    // get barrier sense value
40    uint32_t sense = hal_remote_l32( XPTR( cxy , &ptr->sense ) );
41
42    // compute expected value
43    if ( sense == 0 ) expected = 1;
44    else              expected = 0;
45
46    // atomically increment current
47    uint32_t current = hal_remote_atomic_add( XPTR( cxy , &ptr->current ) , 1 );
48
49    // last task reset current and toggle sense
50    if( current == (count-1) )
51    {
52        hal_remote_s32( XPTR( cxy , &ptr->current) , 0 );
53        hal_remote_s32( XPTR( cxy , &ptr->sense  ) , expected );
54    }
55    else   // other tasks poll the sense
56    {
57        while( hal_remote_l32( XPTR( cxy , &ptr->sense ) ) != expected ) asm volatile ("nop");
58    }
59}
60
Note: See TracBrowser for help on using the repository browser.