Index: trunk/kernel/libk/remote_barrier.c
===================================================================
--- trunk/kernel/libk/remote_barrier.c	(revision 671)
+++ trunk/kernel/libk/remote_barrier.c	(revision 683)
@@ -2,5 +2,5 @@
  * remote_barrier.c -  POSIX barrier implementation.
  *
- * Author   Alain Greiner (2016,2017,2018,2019)
+ * Author   Alain Greiner    (2016,2017,2018,2019,2020)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -84,6 +84,5 @@
 {
     generic_barrier_t * gen_barrier_ptr;  // local pointer on generic barrier descriptor
-    void              * barrier;          // local pointer on implementation barrier descriptor      
-    kmem_req_t          req;              // kmem request
+    void              * barrier;          // local pointer on impl barrier descriptor      
 
     // get pointer on local process_descriptor
@@ -96,9 +95,7 @@
 
     // allocate memory for generic barrier descriptor
-    req.type   = KMEM_KCM;
-    req.order  = bits_log2( sizeof(generic_barrier_t) );
-    req.flags  = AF_ZERO | AF_KERNEL;
-    gen_barrier_ptr = kmem_remote_alloc( ref_cxy , &req );
-
+    gen_barrier_ptr = kmem_remote_alloc( ref_cxy, 
+                                         bits_log2(sizeof(generic_barrier_t)),
+                                         AF_KERNEL );
     if( gen_barrier_ptr == NULL )
     {
@@ -108,12 +105,10 @@
 
     // create implementation specific barrier descriptor
-    if( attr == NULL )                                    // simple barrier implementation
+    if( attr == NULL )                                    // simple barrier
     {
         // create simple barrier descriptor
          barrier = simple_barrier_create( count );
-
-        if( barrier == NULL ) return -1;
-    }
-    else                                                  // QDT barrier implementation
+    }
+    else                                                  // QDT barrier
     {
         uint32_t x_size   = attr->x_size;
@@ -126,4 +121,7 @@
             printk("\n[ERROR] in %s : count(%d) != x_size(%d) * y_size(%d) * nthreads(%d)\n",
             __FUNCTION__, count, x_size, y_size, nthreads );
+            kmem_remote_free( ref_cxy, 
+                              gen_barrier_ptr,
+                              bits_log2(sizeof(generic_barrier_t)) );
             return -1;
         }
@@ -131,6 +129,13 @@
         // create DQT barrier descriptor
         barrier = dqt_barrier_create( x_size , y_size , nthreads );
-
-        if( barrier == NULL ) return -1;
+    }
+
+    if( barrier == NULL ) 
+    {
+        printk("\n[ERROR] in %s : cannot create impl barrier\n", __FUNCTION__ );
+        kmem_remote_free( ref_cxy, 
+                          gen_barrier_ptr,
+                          bits_log2(sizeof(generic_barrier_t)) );
+        return -1;
     }
 
@@ -157,6 +162,4 @@
 void generic_barrier_destroy( xptr_t gen_barrier_xp )
 {
-    kmem_req_t  req;              // kmem request
-
     // get pointer on local process_descriptor
     process_t * process = CURRENT_THREAD->process;
@@ -191,8 +194,8 @@
     remote_busylock_release( lock_xp );
 
-    // release memory allocated to barrier descriptor
-    req.type          = KMEM_KCM;
-    req.ptr           = gen_barrier_ptr;
-    kmem_remote_free( ref_cxy , &req );
+    // release memory allocated to generic barrier descriptor
+    kmem_remote_free( gen_barrier_cxy,
+                      gen_barrier_ptr,
+                      bits_log2(sizeof(generic_barrier_t)) );
 
 }  // end generic_barrier_destroy()
@@ -246,5 +249,4 @@
 simple_barrier_t * simple_barrier_create( uint32_t  count )
 {
-    kmem_req_t         req;
     simple_barrier_t * barrier;
 
@@ -258,9 +260,7 @@
 
     // allocate memory for simple barrier descriptor
-    req.type   = KMEM_KCM;
-    req.order  = bits_log2( sizeof(simple_barrier_t) );
-    req.flags  = AF_ZERO | AF_KERNEL;
-    barrier    = kmem_remote_alloc( ref_cxy , &req );
-
+    barrier  = kmem_remote_alloc( ref_cxy,
+                                  bits_log2(sizeof(simple_barrier_t)),
+                                  AF_ZERO );
     if( barrier == NULL )
     {
@@ -291,6 +291,4 @@
 void simple_barrier_destroy( xptr_t barrier_xp )
 {
-    kmem_req_t  req;
-
     // get barrier cluster and local pointer
     cxy_t              barrier_cxy = GET_CXY( barrier_xp );
@@ -298,7 +296,7 @@
 
     // release memory allocated for barrier descriptor
-    req.type = KMEM_KCM;
-    req.ptr  = barrier_ptr;
-    kmem_remote_free( barrier_cxy , &req );
+    kmem_remote_free( barrier_cxy,
+                      barrier_ptr,
+                      bits_log2(sizeof(simple_barrier_t)) );
 
 #if DEBUG_BARRIER_DESTROY
@@ -471,5 +469,4 @@
     uint32_t        y;             // Y coordinate in QDT mesh
     uint32_t        l;             // level coordinate
-    kmem_req_t      req;           // kmem request
 
     // compute number of DQT levels, depending on the mesh size
@@ -478,11 +475,14 @@
 
 // check x_size and y_size arguments
-assert( __FUNCTION__, (z <= 16) , "DQT mesh size larger than (16*16)\n");
+assert( __FUNCTION__, (z <= 16),
+"DQT mesh size larger than (16*16)\n");
 
 // check size of an array of 5 DQT nodes
-assert( __FUNCTION__, (sizeof(dqt_node_t) * 5 <= 512 ), "array of DQT nodes larger than 512 bytes\n");
+assert( __FUNCTION__, (sizeof(dqt_node_t) * 5 <= 512 ),
+"array of DQT nodes larger than 512 bytes\n");
 
 // check size of DQT barrier descriptor
-assert( __FUNCTION__, (sizeof(dqt_barrier_t) <= 0x4000 ), "DQT barrier descriptor larger than 4 pages\n");
+assert( __FUNCTION__, (sizeof(dqt_barrier_t) <= 0x4000 ),
+"DQT barrier descriptor larger than 4 pages\n");
 
     // get pointer on client thread and process descriptors
@@ -502,9 +502,7 @@
 
     // 1. allocate 4 small pages for the DQT barrier descriptor in reference cluster
-    req.type   = KMEM_PPM;
-    req.order  = 2;                     // 4 small pages == 16 Kbytes                     
-    req.flags  = AF_ZERO | AF_KERNEL;
-    barrier    = kmem_remote_alloc( ref_cxy , &req );
-
+    barrier    = kmem_remote_alloc( ref_cxy,
+                                    CONFIG_PPM_PAGE_ORDER + 2,   // 4 small pages
+                                    AF_ZERO );      
     if( barrier == NULL )
     {
@@ -536,14 +534,10 @@
         {
             cxy_t  cxy = HAL_CXY_FROM_XY( x , y );   // target cluster identifier
-            xptr_t local_array_xp;                   // xptr of nodes array in cluster cxy
+            xptr_t local_array_xp;                   // xptr on nodes array in cluster cxy
 
             // allocate memory in existing clusters only
             if( LOCAL_CLUSTER->cluster_info[x][y] )
             {
-                req.type  = KMEM_KCM;
-                req.order = 9;                    // 512 bytes
-                req.flags = AF_ZERO | AF_KERNEL;
-
-                void * ptr = kmem_remote_alloc( cxy , &req );
+                void * ptr = kmem_remote_alloc( cxy , 9 , AF_ZERO );  // 512 bytes
 
                 if( ptr == NULL )
@@ -729,8 +723,6 @@
 void dqt_barrier_destroy( xptr_t   barrier_xp )
 {
-    kmem_req_t   req;                      // kmem request
     uint32_t     x;
     uint32_t     y;
-
 
     // get DQT barrier descriptor cluster and local pointer
@@ -767,9 +759,5 @@
                 void  * buf       = GET_PTR( buf_xp );
 
-assert( __FUNCTION__, (cxy == GET_CXY(buf_xp)) , "bad extended pointer on dqt_nodes array\n" );
-
-                req.type  = KMEM_KCM;
-                req.ptr   = buf;
-                kmem_remote_free( cxy , &req );
+                kmem_remote_free( cxy , buf , 9 );    // 512 bytes
 
 #if DEBUG_BARRIER_DESTROY
@@ -785,7 +773,7 @@
 
     // 2. release memory allocated for barrier descriptor in ref cluster
-    req.type = KMEM_PPM;
-    req.ptr  = barrier_ptr;
-    kmem_remote_free( barrier_cxy , &req );
+    kmem_remote_free( barrier_cxy,
+                      barrier_ptr,
+                      CONFIG_PPM_PAGE_ORDER + 2 );   // 4 small pages
 
 #if DEBUG_BARRIER_DESTROY
