Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MALP_Blackboard.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #ifndef MALP_BB_H
20 #define MALP_BB_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <unistd.h>
29 
30 #include "Hash_Table.h"
31 #include "Chained_List.h"
32 #include "Spinlock.h"
33 
34 #include "Knowledge_System.h"
35 #include "Data_Entry.h"
36 #include "Key_Entry.h"
37 #include "Pbb_Workers.h"
38 
39 #include "MALP_Blackboard_Level.h"
40 
45 #define KS_COLL_AVOID 5
46 
52 struct Ks_cell
53 {
56 };
57 
62 #define KEY_COLL_AVOID 5
63 
68 struct Key_cell
69 {
72 };
73 
78 #define NAME_COLL_AVOID 5
79 
84 struct Name_cell
85 {
88 };
89 
95 {
102  void (*default_handler)( struct MALP_blackboard *, uint64_t KS_id, struct Data_entry **, uint32_t, void *arg);
104  void *context;
106  volatile uint64_t pending_datas;
107  uint32_t cpu_count;
110 };
111 
112 
120 void MALP_blackboard_init( struct MALP_blackboard *bb, uint32_t workers_count, void *context );
121 
128 static inline void MALP_blackboard_set_default_KS_handler( struct MALP_blackboard *bb, void (*default_handler)( struct MALP_blackboard *, uint64_t KS_id, struct Data_entry **, uint32_t, void * ) )
129 {
130  bb->default_handler = default_handler;
131 }
132 
133 
140 void MALP_blackboard_wait( struct MALP_blackboard *bb );
141 
147 void MALP_blackboard_release( struct MALP_blackboard *bb );
148 
149 
156 static inline uint32_t MALP_blackboard_cpu_count(struct MALP_blackboard *bb)
157 {
158  return bb->cpu_count;
159 }
160 
161 
170 int MALP_Blackboard_ks_present( struct MALP_blackboard *bb, uint64_t type );
171 
182 struct Knowledge_system * MALP_Blackboard_new_ks( struct MALP_blackboard *bb, uint64_t type, uint64_t *sensivities,
183  uint32_t sensivities_count, void (*process)( struct MALP_blackboard *bb, struct Data_entry **de, uint32_t entry_count, void *arg ), void *arg );
184 
191 void MALP_Blackboard_delete_ks( struct MALP_blackboard *bb, uint64_t type );
192 
202 int MALP_Blackboard_submit_data( struct MALP_blackboard *bb, uint64_t key, void *payload, size_t payload_size );
203 
211 int MALP_Blackboard_submit_data_entry( struct MALP_blackboard *bb, struct Data_entry *de );
212 
220 
221 
228 static inline int MALP_Blackboard_writable_data( struct Data_entry *de )
229 {
230 
231  if( Data_entry_get_ref_count( de ) == 0 )
232  {
233  return 1;
234  }
235  else
236  {
237  return 0;
238  }
239 }
240 
248 static inline uint64_t MALP_Blackboard_pending( struct MALP_blackboard *bb )
249 {
250  uint64_t ret = 0;
251 
252  MALP_Spinlock_lock( &bb->lock );
253  ret = bb->pending_datas;
254  MALP_Spinlock_unlock( &bb->lock );
255 
256  return ret;
257 }
258 
259 
266 static inline void MALP_Blackboard_wait_pending( struct MALP_blackboard *bb, uint64_t value )
267 {
268  int got_val = 0;
269 
270  while( !got_val )
271  {
272  if( MALP_Blackboard_pending( bb ) == 0 )
273  got_val = 1;
274 
275  usleep( 1024 );
276  }
277 }
278 
279 
286 static inline uint64_t MALP_Blackboard_type_hash(uint64_t type)
287 {
288  return MALP_Trace_crc64( (char *)&type, sizeof( uint64_t ) );
289 }
290 
298 static inline uint64_t MALP_Blackboard_type_state_hash(uint64_t type, uint64_t state)
299 {
300  uint64_t a[2] = {type, state};
301  return MALP_Trace_crc64( (char *)a, sizeof( uint64_t ) * 2 );
302 }
303 
304 
311 static inline void MALP_Blackboard_add_pending( struct MALP_blackboard *bb)
312 {
313  MALP_Spinlock_lock( &bb->lock );
314  bb->pending_datas++;
315  MALP_Spinlock_unlock( &bb->lock );
316 }
317 
318 
325 static inline void MALP_Blackboard_remove_pending( struct MALP_blackboard *bb)
326 {
327  MALP_Spinlock_lock( &bb->lock );
328  bb->pending_datas--;
329  MALP_Spinlock_unlock( &bb->lock );
330 }
331 
332 
333 
334 /* Export test funcs for tests */
343 int knowledge_system_test_func(void *pks, uint64_t key, void *arg);
344 
353 int empty_knowledge_system_test_func(void *pks, uint64_t key, void *arg);
354 
363 int key_entry_test_func(void *pke, uint64_t key, void *arg);
364 
373 int empty_key_entry_test_func(void *pke, uint64_t key, void *arg);
374 
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 
380 
381 #endif
int knowledge_system_test_func(void *pks, uint64_t key, void *arg)
knowledge_system_test_func
void MALP_blackboard_init(struct MALP_blackboard *bb, uint32_t workers_count, void *context)
MALP_blackboard initialisation.
static void MALP_Blackboard_remove_pending(struct MALP_blackboard *bb)
Decrements the number of pending data block counter.
int MALP_Blackboard_submit_data_entry(struct MALP_blackboard *bb, struct Data_entry *de)
MALP_Blackboard_submit_data_entry.
#define KS_COLL_AVOID
Number of KS cells (Number of elements)
static uint64_t MALP_Trace_crc64(char *source, uint64_t size)
Computes the hash of a given data.
Definition: CRC64.h:54
void MALP_Blackboard_delete_ks(struct MALP_blackboard *bb, uint64_t type)
MALP_Blackboard_delete_ks.
static void MALP_blackboard_set_default_KS_handler(struct MALP_blackboard *bb, void(*default_handler)(struct MALP_blackboard *, uint64_t KS_id, struct Data_entry **, uint32_t, void *))
sets MALP_blackboard's default Knowledge system handler
This is the structure used to store the clusters (items that have the same hash)
Definition: Hash_Table.h:44
struct Hash_Table_Internal ___
The Knowledge_system structure.
struct Hash_Table ks_table
The Knowledge system cell structure Structure containing an internal hash table and table of knowledg...
struct Hash_Table de_name_table
static uint64_t MALP_Blackboard_type_state_hash(uint64_t type, uint64_t state)
MALP_Blackboard_type_state_hash.
struct Hash_Table_Internal ___
int MALP_Blackboard_ks_present(struct MALP_blackboard *bb, uint64_t type)
test if a knowledge system is available in a MALP_Blackboard Test if a knowledge system of a specific...
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
void MALP_blackboard_release(struct MALP_blackboard *bb)
MALP_blackboard release.
void(* default_handler)(struct MALP_blackboard *, uint64_t KS_id, struct Data_entry **, uint32_t, void *arg)
The MALP_blackboard structure.
static int MALP_Blackboard_writable_data(struct Data_entry *de)
MALP_Blackboard_writable_data.
struct Hash_Table key_table
struct Knowledge_system * MALP_Blackboard_new_ks(struct MALP_blackboard *bb, uint64_t type, uint64_t *sensivities, uint32_t sensivities_count, void(*process)(struct MALP_blackboard *bb, struct Data_entry **de, uint32_t entry_count, void *arg), void *arg)
Create a new Knowledge system while associating a key (used as an id and a type) and a handler (proce...
void(* process)(struct MALP_blackboard *bb, struct Data_entry **de, uint32_t entry_count, void *arg)
static uint64_t MALP_Blackboard_pending(struct MALP_blackboard *bb)
Returns the number of pebnding data block counter.
static uint32_t MALP_blackboard_cpu_count(struct MALP_blackboard *bb)
Return the number of currently online processors for a MALP_blackboard.
void * name[NAME_COLL_AVOID]
struct Knowledge_system ks[KS_COLL_AVOID]
static uint64_t MALP_Blackboard_type_hash(uint64_t type)
MALP_Blackboard_type_hash.
This is the main hask table structure.
Definition: Hash_Table.h:53
void MALP_blackboard_wait(struct MALP_blackboard *bb)
MALP_blackboard_wait Function to call the wait function for the Pbb workers of a MALP blackboard...
int MALP_Blackboard_submit_data(struct MALP_blackboard *bb, uint64_t key, void *payload, size_t payload_size)
MALP_Blackboard_submit_data.
Structure defining a parallel blackboard worker set.
Definition: Pbb_Workers.h:52
MALP_Spinlock lock
static void MALP_Blackboard_add_pending(struct MALP_blackboard *bb)
Increments the number of pending data block counter.
static uint64_t Data_entry_get_ref_count(struct Data_entry *de)
Getter on the ref_count of a Data_entry.
Definition: Data_Entry.h:94
The Name_cell structure Structure containing an internal hash table and table of cell names...
int MALP_Blackboard_resubmit_data_entry(struct MALP_blackboard *bb, struct Data_entry *de)
MALP_Blackboard_resubmit_data_entry.
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
int empty_key_entry_test_func(void *pke, uint64_t key, void *arg)
empty_key_entry_test_func
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
int key_entry_test_func(void *pke, uint64_t key, void *arg)
key_entry_test_func
int empty_knowledge_system_test_func(void *pks, uint64_t key, void *arg)
empty_knowledge_system_test_func
struct Hash_Table_Internal ___
struct Key_entry ke[KEY_COLL_AVOID]
Struct defining a piece of data that can exist on the blackboard.
Definition: Data_Entry.h:37
The Key_cell structure Structure containing an internal hash table and table of key entries ( Key ent...
The Key_entry struct.
Definition: Key_Entry.h:35
#define KEY_COLL_AVOID
Number of column keys (Number of elements)
struct Pbb_workers workers
#define NAME_COLL_AVOID
Number of column names (Number of elements)
static void MALP_Blackboard_wait_pending(struct MALP_blackboard *bb, uint64_t value)
MALP_Blackboard_wait_pending.
volatile uint64_t pending_datas