source: trunk/libs/libalmosmkh/almosmkh.h @ 665

Last change on this file since 665 was 661, checked in by alain, 4 years ago

Introduce the non-standatd display_socket() syscall.
Improve the non-standard get_string() syscall.

File size: 40.5 KB
Line 
1/*
2 * almosmkh.h - User level ALMOS-MKH specific library definition.
3 *
4 * Author     Alain Greiner (2016,2017,2018,2019,2020)
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#ifndef _LIBALMOSMKH_H_
25#define _LIBALMOSMKH_H_
26
27/***************************************************************************************
28 * This file defines an user level, ALMOS-MKH specific library, containing:
29 * - non standard system calls.
30 * - debug functions.
31 * - remote malloc extensions.
32 * - a parallel_pthread_create function.
33 * - Frame Buffer access syscalls.
34 **************************************************************************************/
35
36#include <pthread.h>
37#include <shared_almos.h>
38
39
40/****************** Non standard (ALMOS_MKH specific) system calls ********************/
41
42
43/***************************************************************************************
44 * This syscall gives the process identified by the <pid> argument the exclusive
45 * ownership of its TXT terminal.
46 ***************************************************************************************
47 * @ pid        : process identifier.
48 * @ returns O if success / returns -1 if process not found.
49 **************************************************************************************/
50int fg( unsigned int pid );
51
52/***************************************************************************************
53 * This syscall stores in the buffer identified by the <owner> argument a non zero
54 * value when the process identified by the <pid> argument is currently the exclusive
55 * owner of its TXT terminal.
56 ***************************************************************************************
57 * @ pid        : [in]  process identifier.
58 * @ owner      : [out] pointer on buffer to store the
59 * @ returns O if success / returns -1 if process not found.
60 **************************************************************************************/
61int is_fg( unsigned int pid,
62           unsigned int * owner );
63
64/***************************************************************************************
65 * This syscall returns the hardware platform parameters in the hard_config_t pointed
66 * by the <config> argument. This structure is defined in the shared_almos.h file.
67 * The available configuration parameters are :
68 * - cores       : x_size / y_size / ncores
69 * - peripherals : nb_txt_channels / nb_nic_channels / nb_ioc_channels / nb_fbf_channels
70 ***************************************************************************************
71 * @ config   : [out] pointer on hard_config_t structure in user space.
72 * @ return 0 if success / return -1 if illegal argument.
73 **************************************************************************************/
74int get_config( struct hard_config_s * config );
75
76/***************************************************************************************
77 * This syscall returns the cluster identifier and the local index
78 * for the calling core.
79 ***************************************************************************************
80 * @ cxy      : [out] cluster identifier.
81 * @ lid      : [out] core local index in cluster.
82 * @ return always 0.
83 **************************************************************************************/
84int get_core_id( unsigned int * cxy,
85                 unsigned int * lid );
86
87/***************************************************************************************
88 * This syscall returns the number of cores in a given cluster.
89 ***************************************************************************************
90 * @ cxy      : [in]  target cluster identifier.
91 * @ ncores   : [out] number of cores in target cluster.
92 * @ return always 0.
93 **************************************************************************************/
94int get_nb_cores( unsigned int   cxy,
95                  unsigned int * ncores );
96
97/***************************************************************************************
98 * This syscall uses the DQDT to search, in a macro-cluster specified by the
99 * <cxy_base> and <level> arguments arguments, the core with the lowest load.
100 * it writes in the <cxy> and <lid> buffers the selected core cluster identifier
101 * and the local core index.
102 ***************************************************************************************
103 * @ cxy_base : [in]  any cluster identifier in macro-cluster.in clusters array.
104 * @ level    : [in]  macro-cluster level in [1,2,3,4,5].
105 * @ cxy      : [out] selected core cluster identifier.
106 * @ lid      : [out] selected core local index.
107 * @ return 0 if success / 1 if no core in macro-cluster / -1 if illegal arguments.
108 **************************************************************************************/
109int get_best_core( unsigned int   cxy_base,
110                   unsigned int   level,
111                   unsigned int * cxy,
112                   unsigned int * lid );
113
114/***************************************************************************************
115 * This function returns the value contained in the calling core cycles counter,
116 * taking into account a possible overflow on 32 bits architectures.
117 ***************************************************************************************
118 * @ cycle    : [out] current cycle value.
119 * @ return always 0.
120 **************************************************************************************/
121int get_cycle( unsigned long long * cycle );
122
123/***************************************************************************************
124 * This syscall allows the calling thread to specify the target cluster for
125 * a subsequent fork(). It must be called for each fork().
126 ***************************************************************************************
127 * @ cxy      : [in] target cluster identifier.
128 * @ return 0 if success / returns -1 if illegal cxy argument.
129 **************************************************************************************/
130int place_fork( unsigned int cxy );
131
132/***************************************************************************************
133 * This syscall implements the operations related to User Thread Local Storage.
134 ***************************************************************************************
135 * @ operation  : UTLS operation type as defined in "shared_sycalls.h" file.
136 * @ value      : argument value for the UTLS_SET operation.
137 * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure.
138 **************************************************************************************/
139int utls( unsigned int operation,
140          unsigned int value );
141
142/***************************************************************************************
143 * This syscall returns an 32 bits integer from the standard "stdin" stream.
144 * The value is copied in buffer pointed by the <buf> argument
145 * Both decimal numbers and hexadecimal numbers (prefixed by 0x) are supported.
146 ***************************************************************************************
147 * @ buffer    : pointer on buffer.
148 * @ returns 0 if success / returns -1 if failure.
149 **************************************************************************************/
150int get_uint32( unsigned int * buffer );
151
152/***************************************************************************************
153 * This syscall returns a character string from the standard "stdin" stream.
154 * The string is copied in buffer pointed by the <string> argument.
155 * If the number of characters exceed the buffer length, all character are canceled
156 * in both the buffer & the echoed string, and a new string capture start.
157 * - Only printable characters c such as (0x20 <= c) and (c < 0x7f) are echoed
158 *   and copied in the target buffer.
159 * - The LF (0x0A) character signaling the end of string is replaced by an extra
160 *   NUL (0x00) character in the target buffer.
161 * - the DEL (0x7F), BS (0x08) control characters are taken into account, and can be
162 *   used to correct both the buffer content and the echoed string.
163 ***************************************************************************************
164 * @ string   : pointer on the string buffer.
165 * @ maxlen   : max number of bytes in string buffer, including the terminating NUL.
166 * @ returns string length (including NUL) if success / returns -1 if failure.
167 **************************************************************************************/
168int get_string( char * string,
169                int    maxlen );
170
171
172/***************** Non standard (ALMOS-MKH specific) debug functions ******************/
173
174/***************************************************************************************
175 * This syscall copies in the user structure defined by the <info> argument the values
176 * registered in the calling thread "thread_info_t" kernel structure.
177 ******************************************************************************************
178 * @ info    : [out] pointer on thread_info_t structure in user space.
179 * @ return 0 if success / return -1 if illegal argument.
180 *****************************************************************************************/
181int get_thread_info( thread_info_t * info );
182
183/***************************************************************************************
184 * This debug syscall displays on the kernel terminal TXT0
185 * the thread / process / core identifiers, the current cycle, plus a user defined
186 * message as specified by the <string> argument.
187 ***************************************************************************************
188 * @ string    : [in] user defined message.
189 **************************************************************************************/
190void display_string( char * string );
191
192/***************************************************************************************
193 * This debug function displays on the kernel terminal TXT0
194 * the state of the  VMM for the process <pid> in cluster <cxy>.
195 * It can be called by any thread running in any cluster.
196 ***************************************************************************************
197 * @ cxy      : [in] target cluster identifier.
198 * @ pid      : [in] process identifier.
199 * @ mapping  : [in] detailed mapping if non zero.
200 * @ return 0 if success / return -1 if illegal argument.
201 **************************************************************************************/
202int display_vmm( unsigned int cxy,
203                 unsigned int pid,
204                 unsigned int mapping );
205
206/***************************************************************************************
207 * This debug syscall displays on the kernel terminal TXT0
208 * the state of the core scheduler identified by the <cxy> and <lid> arguments.
209 * It can be called by any thread running in any cluster.
210 ***************************************************************************************
211 * @ cxy      : [in] target cluster identifier.
212 * @ lid      : [in] target core local index.
213 * @ return 0 if success / return -1 if illegal arguments.
214 **************************************************************************************/
215int display_sched( unsigned int  cxy,
216                   unsigned int  lid );
217
218/***************************************************************************************
219 * This debug syscall displays on the kernel terminal TXT0
220 * the list of process registered in a given cluster identified by the <cxy> argument.
221 * Only the owned processes are displayed when the <owned> argument is non zero.
222 * It can be called by any thread running in any cluster.
223 ***************************************************************************************
224 * @ cxy      : [in] target cluster identifier.
225 * @ owned    : [in] only owned processes if non zero.
226 * @ return 0 if success / return -1 if illegal argument.
227 **************************************************************************************/
228int display_cluster_processes( unsigned int  cxy,
229                               unsigned int  owned );
230
231/***************************************************************************************
232 * This debug syscall displays on the kernel terminal TXT0
233 * the list of processes attached to a given TXT channel.
234 * It can be called by any thread running in any cluster.
235 ***************************************************************************************
236 * @ txt_id   : [in] TXT terminal indes.
237 * @ return 0 if success / return -1 if illegal argument.
238 **************************************************************************************/
239int display_txt_processes( unsigned int txt_id );
240
241/***************************************************************************************
242 * This debug syscall displays on the kernel terminal TXT0
243 * the set of busylocks hold by a thread identified by the <pid> and <trdid> arguments.
244 * It can be called by any thread running in any cluster.
245 ***************************************************************************************
246 * @ pid      : [in] process identifier.
247 * @ trdid    : [in] thread identifier.
248 * @ return 0 if success / return -1 if illegal arguments.
249 **************************************************************************************/
250int display_busylocks( unsigned int pid,
251                       unsigned int trdid );
252
253/***************************************************************************************
254 * This debug syscall displays on the kernel terminal TXT0
255 * the list of channel devices available in the architecture.
256 * It can be called by any thread running in any cluster.
257 ***************************************************************************************
258 * @ return always 0.
259 **************************************************************************************/
260int display_chdev( void );
261
262/***************************************************************************************
263 * This debug syscall displays on the kernel terminal TXT0
264 * the list of channel device or pseudo-files registered in the VFS cache.
265 * It can be called by any thread running in any cluster.
266 ***************************************************************************************
267 * @ return always 0.
268 **************************************************************************************/
269int display_vfs( void );
270
271/***************************************************************************************
272 * This debug syscall displays on the kernel terminal TXT0 the current DQDT state.
273 * It can be called by any thread running in any cluster.
274 ***************************************************************************************
275 * @ return always 0.
276 **************************************************************************************/
277int display_dqdt( void );
278
279/***************************************************************************************
280 * This debug syscall displays on the kernel terminal TXT0 the content of a given
281 * page of a given VFS mapper.
282 * It can be called by any thread running in any cluster.
283 ***************************************************************************************
284 * @ path      : pathname identifying the file/directory in VFS.
285 * @ page_id   : page index in file.
286 * @ nbytes    : number of bytes to display.
287 * @ return 0 if success / return -1 if file or page not found.
288 **************************************************************************************/
289int display_mapper( char        * path,
290                    unsigned int  page_id,
291                    unsigned int  nbytes);
292
293/***************************************************************************************
294 * This debug syscall displays on the kernel terminal TXT0
295 * the state of the barrier used by the process identified by the <pid> argument.
296 * It can be called by any thread running in any cluster.
297 ***************************************************************************************
298 * @ pid      : [in] process identifier.
299 * @ return 0 if success / return -1 if illegal arguments.
300 **************************************************************************************/
301int display_barrier( unsigned int pid );
302
303/***************************************************************************************
304 * This debug syscall displays on the kernel terminal TXT0 the content of <nb_slots>
305 * of the FAT mapper, starting from <min_slot>.
306 * If <nb_slots> is zero, it displays the state of the FATFS context in cluster
307 * defined by the <min_slot> argument interpreted as a cluster identifier.
308 * It can be called by any thread running in any cluster.
309 ***************************************************************************************
310 * @ min_slot   : first slot in page
311 * @ nb_slots   : number of slots to display.
312 * @ return 0 if success / return -1 if page not found.
313 **************************************************************************************/
314int display_fat( unsigned int min_slot,
315                 unsigned int nb_slots );
316
317/***************************************************************************************
318 * This debug syscall displays on the kernel terminal the current state of
319 * a socket identified by the <pid> and <fdid> arguments.
320 * It can be called by any thread running in any cluster.
321 ***************************************************************************************
322 * @ pid        : target process identifier.
323 * @ fdid       : file descriptor identifying the target socket.
324 * @ return 0 if success / return -1 if socket not found.
325 **************************************************************************************/
326int display_socket( unsigned int pid,
327                    unsigned int fdid );
328
329/*****************************************************************************************
330* This debug syscall is used to activate / desactivate the context switches trace
331* for a core identified by the <cxy> and <lid> arguments.
332* It can be called by any thread running in any cluster.
333*****************************************************************************************
334* @ active     : activate trace if non zero / desactivate if zero.
335* @ cxy        : cluster identifier.
336* @ lid        : core local index.
337* @ returns O if success / returns -1 if illegal arguments.
338****************************************************************************************/
339int trace( unsigned int active,
340           unsigned int cxy, 
341           unsigned int lid );
342
343/****************************************************************************************
344 * This syscall implements an user-level interactive debugger that can be
345 * introduced in any user application to display various kernel distributed structures.
346 ***************************************************************************************/
347void idbg( void );
348
349
350/****************** Non standard (ALMOS-MKH specific) malloc operations  ***************/
351
352/////////////////////////////////////////////////////////////////////////////////////////
353// General principles:
354// - In user space the HEAP zone spread between the ELF zone and the STACK zone,
355//   as defined in the kernel_config.h file.
356// - The malloc library uses the mmap() syscall to create - on demand -
357//   one vseg in a given cluster. The size of this vseg is defined below
358//   by the MALLOC_LOCAL_STORE_SIZE parameter.
359// - For a standard malloc(), the target cluster is the cluster containing
360//   the core running the client thread.
361// - For a remote_malloc(), the target cluster is explicitely defined
362//   by the argument.
363// - In each cluster, the available storage in virtual space is handled by a
364//   local allocator using the buddy algorithm.
365//
366// TODO : In this first implementation one single - fixed size - vseg
367//        is allocated on demand in each cluster.
368//        We should introduce the possibility to dynamically allocate
369//        several vsegs in each cluster, using several mmap when required.
370/////////////////////////////////////////////////////////////////////////////////////////
371// Free blocks organisation in each cluster :
372// - All free blocks have a size that is a power of 2, larger or equal
373//   to MALLOC_MIN_BLOCK_SIZE (typically 64 bytes).
374// - All free blocks are aligned.
375// - They are pre-classed in an array of linked lists, where all blocks in a
376//   given list have the same size.
377// - The NEXT pointer implementing those linked lists is written
378//   in the first bytes of the block itself, using the unsigned int type.
379// - The pointers on the first free block for each size are stored in an
380//   array of pointers free[32] in the storage(x,y) descriptor.
381/////////////////////////////////////////////////////////////////////////////////////////
382// Allocation policy:
383// - The block size required by the user can be any value, but the allocated
384//   block size can be larger than the requested size:
385// - The allocator computes actual_size, that is the smallest power of 2
386//   value larger or equal to the requested size AND larger or equal to
387//   MALLOC_MIN_BLOCK_SIZE.
388// - It pop the linked list of free blocks corresponding to actual_size,
389//   and returns the block B if the list[actual_size] is not empty.
390// - If the list[actual_size] is empty, it pop the list[actual_size * 2].
391//   If a block B' is found, it breaks this block in 2 B/2 blocks, returns
392//   the first B/2 block and push the other B/2 block into list[actual_size].
393// - If the list[actual_size * 2] is empty, it pop the list[actual_size * 4].
394//   If a block B is found, it break this block in 3 blocks B/4, B/4 and B/2,
395//   returns the first B/4 block, push the other blocks B/4 and B/2 into
396//   the proper lists. etc...
397// - If no block satisfying the request is available it returns a failure
398//   (NULL pointer).
399// - This allocation policy has the nice following property:
400//   If the vseg is aligned (the vseg base is a multiple of the
401//   vseg size), all allocated blocks are aligned on the actual_size.
402/////////////////////////////////////////////////////////////////////////////////////////
403// Free policy:
404// - Each allocated block is registered in an alloc[] array of unsigned char.
405// - This registration is required by the free() operation, because the size
406//   of the allocated block must be obtained from the base address of the block. 
407// - The number of entries in this array is equal to the max number
408//   of allocated block : MALLOC_LOCAL_STORE_SIZE / MALLOC_MIN_BLOCK_SIZE.
409// - For each allocated block, the value registered in the alloc[] array
410//   is log2( size_of_allocated_block ).
411// - The index in this array is computed from the allocated block base address:
412//      index = (block_base - vseg_base) / MALLOC_MIN_BLOCK_SIZE
413// - The alloc[] array is stored at the end of heap segment. This consume
414//   (1 / MALLOC_MIN_BLOCK_SIZE) of the total storage capacity.
415/////////////////////////////////////////////////////////////////////////////////////////
416
417
418#define MALLOC_INITIALIZED         0xBABEF00D   // magic number when initialised
419#define MALLOC_MIN_BLOCK_SIZE      0x40         // 64 bytes
420#define MALLOC_LOCAL_STORE_SIZE    0x2000000    // 32 Mbytes     
421#define MALLOC_MAX_CLUSTERS        0x100        // 256 clusters
422
423/////////////////////////////////////////////////////////////////////////////////////////
424//               store(x,y) descriptor (one per cluster)
425/////////////////////////////////////////////////////////////////////////////////////////
426
427typedef struct malloc_store_s
428{
429    pthread_mutex_t mutex;           // lock protecting exclusive access to local heap
430    unsigned int    initialized;     // initialised when value == MALLOC_INITIALIZED
431    unsigned int    cxy;             // cluster identifier 
432    unsigned int    store_base;      // store base address
433    unsigned int    store_size;      // store size (bytes)
434    unsigned int    alloc_base;      // alloc[] array base address
435    unsigned int    alloc_size;      // alloc[] array size (bytes)
436    unsigned int    free[32];        // array of addresses of first free block
437} 
438malloc_store_t;
439
440/*****************************************************************************************
441 * This function allocates <size> bytes of memory in user space, and returns a pointer
442 * to the allocated buffer. The pysical memory is allocated from store located in
443 * cluster identified by the <cxy> argument.
444 *****************************************************************************************
445 * @ size    : number of requested bytes.
446 * @ cxy     : target cluster identifier.
447 * @ returns a pointer on the allocated buffer if success / returns NULL if failure
448 ****************************************************************************************/
449void * remote_malloc( unsigned int size, 
450                      unsigned int cxy );
451
452/*****************************************************************************************
453 * This function releases the memory buffer identified by the <ptr> argument,
454 * to the store identified by the <cxy> argument.
455 * It  does nothing, but displays an error message, if the ptr is illegal.
456 *****************************************************************************************
457 * @ ptr   : pointer on the released buffer.
458 * @ cxy   : target cluster identifier.
459 ****************************************************************************************/
460void remote_free( void        * ptr,
461                  unsigned int  cxy );
462
463/*****************************************************************************************
464 * This function releases the memory buffer identified by the <ptr> argument,
465 * to the store located in cluster identified by the <cxy> argument, and allocates
466 * a new buffer containing <size> bytes from this store.
467 * The content of the old buffer is copied to the new buffer, up to <size> bytes.
468 * It displays an error message, but does nothing if the ptr is illegal.
469 *****************************************************************************************
470 * @ ptr     : pointer on the released buffer.
471 * @ size    : new buffer requested size (bytes).
472 * @ cxy     : target cluster identifier.
473 * @ return a pointer on allocated buffer if success / return NULL if failure
474 ****************************************************************************************/
475void * remote_realloc( void        * ptr,
476                       unsigned int  size,
477                       unsigned int  cxy );
478
479/*****************************************************************************************
480 * This function allocates enough space for <count> objects that are <size> bytes
481 * of memory each from the store located in cluster identied by the <cxy> argument.
482 * The allocated memory is filled with bytes of value zero.
483 *****************************************************************************************
484 * @ count   : number of requested objects.
485 * @ size    : number of bytes per object.
486 * @ cxy     : target cluster identifier.
487 * @ returns a pointer on allocated buffer if success / returns NULL if failure
488 ****************************************************************************************/
489void * remote_calloc( unsigned int count,
490                      unsigned int size,
491                      unsigned int cxy );
492
493/********* Non standard (ALMOS-MKH specific) pthread_parallel_create() syscall  *********/
494
495//////////////////////////////////////////////////////////////////////////////////////////
496// This syscall can be used to parallelize the creation, and the termination
497// of a parallel multi-threaded application.
498// It removes in the main thread the sequencial loop that creates the N working threads
499// (N pthread_create() ), and removes also the sequencial loop that waits completion
500// of these N working threads (N pthread_join() ).
501// It creates one <work> thread (in detached mode) per core in the target architecture.
502// Each <work> thread is identified by a continuous [tid] index.
503// For a regular architecture, defined by the [x_size , y_size , ncores] parameters,
504// the number of working threads can be the simply computed as (x_size * y_size * ncores),
505// and the coordinates[x,y,lid] of the core running the thread[tid] cand be directly
506// derived from the [tid] value with the following relations:
507//     . cid = (x * y_size) + y
508//     . tid = (cid * ncores ) + lid
509//     . lid = tid % ncores
510//     . cid = tid / ncores
511//     . y   = cid % y_size
512//     . x   = cid / y_size
513// The pthread_parallel_create() function returns only when all <work> threads completed
514// (successfully or not).
515//
516// WARNING : The function executed by the working thread is application specific,
517// but the structure defining the arguments passed to this function is imposed.
518// The "pthread_parallel_work_args_t" structure is defined below, and contains
519// two fields: the tid value, and a pointer on a pthread_barrier_t.
520// This barrier must be used by each working thread to signal completion before exit.
521// The global variables implementing these stuctures for each working thread
522// are allocated and initialised by the pthread_parallel_create() function.
523//
524// Implementation note: the pthread_parallel_create()a function creates a distributed
525// quad-tree (DQT) of <build> threads covering all cores required to execute the parallel
526// application. This quad tree is entirely defined by the root_level parameter.
527// Depending on the hardware topology, this DQT can be truncated, (i.e. some
528// parent nodes can have less than 4 chidren), if (x_size != y_size), or if one size
529// is not a power of 2. Each <build> thread is identified by two indexes [cid][level].
530// Each <build> thread makes the following tasks:
531// 1) It calls the pthread_create() function to create up to 4 children threads, that
532//    are <work> threads when (level == 0), or <build> threads, when (level > 0).
533// 2) It allocates and initializes the barrier, used to block the parent thread until
534//    children completion.
535// 3) It calls the pthread_barrier_wait( self ) to wait until all children threads
536//    completed (successfully or not).
537// 4) It calls the pthread_barrier_wait( parent ) to unblock the parent thread.
538//////////////////////////////////////////////////////////////////////////////////////////
539
540/*****************************************************************************************
541 *    structure defining the arguments for the <build> thread function
542 ****************************************************************************************/
543typedef struct pthread_parallel_build_args_s           
544{
545    unsigned char        cid;                    // this <build> thread cluster index
546    unsigned char        level;                  // this <build> thread level in quad-tree
547    unsigned char        parent_cid;             // parent <build> thread cluster index
548    pthread_barrier_t  * parent_barrier;         // pointer on parent <build> thread barrier
549    unsigned char        root_level;             // quad-tree root level
550    void               * work_func;              // pointer on working thread function
551    unsigned int         x_size;                 // platform global parameter
552    unsigned int         y_size;                 // platform global parameter
553    unsigned int         ncores;                 // platform global parameter
554    unsigned int         error;                  // return value : 0 if success
555}
556pthread_parallel_build_args_t;
557
558/*****************************************************************************************
559 *    structure defining the arguments for the <work> thread function
560 ****************************************************************************************/
561typedef struct pthread_parallel_work_args_s           
562{
563    unsigned int         tid;                    // thread identifier
564    pthread_barrier_t  * barrier;                // to signal completion
565}
566pthread_parallel_work_args_t;           
567
568/*****************************************************************************************
569 * This blocking function creates N working threads identified by the [tid] continuous
570 * index, that execute the code defined by the <work_func> argument, and returns only
571 * when all working threads completed.
572 * The number N of created threads is entirely defined by the <root_level> argument,
573 * that defines an abstract quad-tree, with a square base : root_level in [0,1,2,3,4],
574 * side in [1,2,4,8,16], nclusters in [1,4,16,64,256]. This base is called  macro_cluster.
575 * A working thread is created on all cores contained in this abstract macro-cluster.
576 * The actual number of physical clusters containing cores can be smaller than the number
577 * of clusters covered by the abstract quad tree.
578 * All threads execute the same <work_func> function, on different arguments, that are
579 * specified as an array of structures pthread_parallel_work_args_t, allocated and
580 * initialised by this function.
581 *****************************************************************************************
582 * @ root_level            : [in]  DQT root level in [0,1,2,3,4].
583 * @ work_func             : [in]  pointer on start function.
584 * @ return 0 if success / return -1 if failure.
585 ****************************************************************************************/
586int pthread_parallel_create( unsigned int         root_level,
587                             void               * work_func );
588
589
590
591/********* Non standard (ALMOS-MKH specific) Frame Buffer access syscalls   *************/
592
593//////////////////////////////////////////////////////////////////////////////////////////
594// The following system calls can be used to access the SoCLib Frame Buffer, that
595// is a very simple graphic controller, that is seen by the software as a single
596// buffer of <height> lines of <width> pixels.
597//////////////////////////////////////////////////////////////////////////////////////////
598
599/*****************************************************************************************
600 * This function returns in the <width>, <height> and <type> arguments
601 * the implementation specific frame buffer features.
602 *****************************************************************************************
603 * @ width   : [out] number of pixels per line.
604 * @ height  : [out] number of lines.
605 * @ type    : [out] pixel encoding type.
606 * @ returns 0 if success / returns -1 if not found.
607 ****************************************************************************************/
608int fbf_get_config( unsigned int * width,
609                    unsigned int * height,
610                    unsigned int * type );
611
612/*****************************************************************************************
613 * This function creates a new window defined by the <l_zero>, <p_zero>, <nlines>,
614 * and <npixels> arguments for the calling process, and register the process PID, the
615 * allocated <wid>, and the window size and coordinates in the FBF device descriptor.
616 * It returns in the output argument <buffer> the pointer on the buffer associated to
617 * the window, mapped in user space.
618 * Warning : Both pixel [p_zero,l_zero] and pixel [p_zero+npixels-1,l_zero+nlines-1]
619 * must be contained in the frame buffer.
620 *****************************************************************************************
621 * @ l_zero  : [in]  first line index in FBF coordinates system.
622 * @ p_zero  : [in]  first pixel index in FBF coordinates system.
623 * @ nlines  : [in]  number of lines in the window.
624 * @ npixels : [in]  number of pixels per line in the window.
625 * @ buffer  : [out] pointer on
626 * @ returns <wid> if success / returns -1 if illegal size or coordinates.
627 ****************************************************************************************/
628int fbf_create_window( unsigned int   l_zero,
629                       unsigned int   p_zero,
630                       unsigned int   nlines,
631                       unsigned int   npixels,
632                       void        ** buffer );
633
634/*****************************************************************************************
635 * This function deletes an existing window, identified by the <wid> argument.
636 * The calling process must be the window owner.
637 *****************************************************************************************
638 * @ wid     : window identifier.
639 * @ returns 0 if success / returns -1 if not found or process not owner.
640 ****************************************************************************************/
641int fbf_delete_window( unsigned int  wid );
642
643/*****************************************************************************************
644 * This function refreshes in FBF all lines of a window identified by the <wid> argument,
645 * when the line index is in the interval [line_first,line_last[.
646 * It scans all registered windows to take into account the windows overlap.
647 *****************************************************************************************
648 * @ wid        : window identifier.
649 * @ line_first : first line index.
650 * @ line_last  : last line index (excluded).
651 * @ returns 0 if success / returns -1 if illegal argument.
652 ****************************************************************************************/
653int fbf_refresh_window( unsigned int   wid,
654                        unsigned int   line_first,
655                        unsigned int   line_last );
656
657/*****************************************************************************************
658 * This function changes the size of a window identified by the <wid> argument as defined
659 * by the <width> and height> arguments. The calling process must be the window owner.
660 * WARNING : Both pixel [p_zero,l_zero] and pixel [p_zero+width-1,l_zero+height-1]
661 * must be contained in the frame buffer.
662 *****************************************************************************************
663 * @ wid     : window identifier.
664 * @ width   : number of pixels in line (one byte per pixel).
665 * @ height  : number of lines in window.
666 * @ returns 0 if success / returns -1 if illegal arguments.
667 ****************************************************************************************/
668int fbf_resize_window( unsigned int   wid,
669                       unsigned int   width,
670                       unsigned int   height );
671
672/*****************************************************************************************
673 * This function changes the <l_zero> & <p_zero> coordinates of a window identified
674 * by the <wid> argument. The calling process must be the window owner.
675 * WARNING : Both pixel [p_zero,l_zero] and pixel [p_zero+width-1,l_zero+height-1]
676 * must be contained in the frame buffer.
677 *****************************************************************************************
678 * @ wid     : window identifier.
679 * @ l_zero  : new first line index in FBF.
680 * @ p_zero  : new first pixel index in FBF.
681 * @ returns 0 if success / returns -1 if illegal arguments.
682 ****************************************************************************************/
683int fbf_move_window( unsigned int  wid,
684                     unsigned int  l_zero,
685                     unsigned int  p_zero );
686
687/*****************************************************************************************
688 * This syscall is deprecated (january 2020 AG)
689 * This blocking function moves <length> pixels from the user buffer defined by <buffer>
690 * argument to the frame buffer, starting at <offset> in FBF.
691 *****************************************************************************************
692 * @ buffer  : pointer on buffer in user space.
693 * @ length  : number of pixels (one byte per pixel).
694 * @ offset  : first pixel index in window.
695 * @ returns 0 if success / returns -1 if illegal arguments.
696 ****************************************************************************************/
697int fbf_write( void         * buffer,
698               unsigned int   length,
699               unsigned int   offset );
700
701/*****************************************************************************************
702 * This syscall is deprecated (january 2020 AG)
703 * This blocking function moves <length> pixels from the frame buffer, starting at
704 * <offset> in FBF, to the user buffer defined by <buffer>  argument.
705 *****************************************************************************************
706 * @ buffer  : pointer on buffer in user space.
707 * @ length  : number of pixels (one byte per pixel).
708 * @ offset  : first pixel index in window.
709 * @ returns 0 if success / returns -1 if illegal arguments.
710 ****************************************************************************************/
711int fbf_read( void         * buffer,
712              unsigned int   length,
713              unsigned int   offset );
714
715
716#endif /* _LIBALMOSMKH_H_ */
717
Note: See TracBrowser for help on using the repository browser.