PiP - Process-in-Process
|
00001 /* 00002 * $RIKEN_copyright: 2018 Riken Center for Computational Sceience, 00003 * System Software Devlopment Team. All rights researved$ 00004 * $PIP_VERSION: Version 1.0$ 00005 * $PIP_license: <Simplified BSD License> 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are 00008 * met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * 00028 * The views and conclusions contained in the software and documentation 00029 * are those of the authors and should not be interpreted as representing 00030 * official policies, either expressed or implied, of the PiP project.$ 00031 */ 00032 /* 00033 * Written by Atsushi HORI <ahori@riken.jp>, 2016, 2017 00034 */ 00035 00036 #ifndef _pip_h_ 00037 #define _pip_h_ 00038 00132 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00133 00134 #define PIP_OPTS_NONE (0x0) 00135 00136 #define PIP_MODE_PTHREAD (0x1000) 00137 #define PIP_MODE_PROCESS (0x2000) 00138 /* the following two modes are a submode of PIP_MODE_PROCESS */ 00139 #define PIP_MODE_PROCESS_PRELOAD (0x2100) 00140 #define PIP_MODE_PROCESS_PIPCLONE (0x2200) 00141 #define PIP_MODE_MASK (0xFF00) 00142 00143 #define PIP_ENV_MODE "PIP_MODE" 00144 #define PIP_ENV_MODE_THREAD "thread" 00145 #define PIP_ENV_MODE_PTHREAD "pthread" 00146 #define PIP_ENV_MODE_PROCESS "process" 00147 #define PIP_ENV_MODE_PROCESS_PRELOAD "process:preload" 00148 #define PIP_ENV_MODE_PROCESS_PIPCLONE "process:pipclone" 00149 00150 #define PIP_OPT_MASK (0XFF) 00151 #define PIP_OPT_FORCEEXIT (0x01) 00152 #define PIP_OPT_PGRP (0x02) 00153 00154 #define PIP_ENV_OPTS "PIP_OPTS" 00155 #define PIP_ENV_OPTS_FORCEEXIT "forceexit" 00156 #define PIP_ENV_OPTS_PGRP "pgrp" 00157 00158 #define PIP_VALID_OPTS \ 00159 ( PIP_MODE_PTHREAD | PIP_MODE_PROCESS_PRELOAD | PIP_MODE_PROCESS_PIPCLONE | \ 00160 PIP_OPT_FORCEEXIT | PIP_OPT_PGRP ) 00161 00162 #define PIP_ENV_STACKSZ "PIP_STACKSZ" 00163 00164 #define PIP_PIPID_ROOT (-1) 00165 #define PIP_PIPID_ANY (-2) 00166 #define PIP_PIPID_MYSELF (-3) 00167 00168 #define PIP_NTASKS_MAX (260) 00169 00170 #define PIP_CPUCORE_ASIS (-1) 00171 00172 #include <sys/types.h> 00173 #include <sys/stat.h> 00174 #include <sys/time.h> 00175 #include <pthread.h> 00176 #include <link.h> 00177 #include <dlfcn.h> 00178 #include <dirent.h> 00179 #include <fcntl.h> 00180 #include <stdint.h> 00181 #include <stdlib.h> 00182 #include <unistd.h> 00183 #include <stdio.h> 00184 #include <string.h> 00185 #include <errno.h> 00186 00187 typedef int (*pip_spawnhook_t) ( void* ); 00188 00189 typedef struct pip_barrier { 00190 int count_init; 00191 volatile uint32_t count; 00192 volatile int gsense; 00193 } pip_barrier_t; 00194 00195 #define PIP_BARRIER_INIT(N) {(N),(N),0} 00196 00197 #ifdef __cplusplus 00198 extern "C" { 00199 #endif 00200 00201 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00202 00241 int pip_init( int *pipidp, int *ntasks, void **root_expp, int opts ); 00253 int pip_fin( void ); 00297 int pip_spawn( char *filename, char **argv, char **envv, 00298 int coreno, int *pipidp, 00299 pip_spawnhook_t before, pip_spawnhook_t after, void *hookarg); 00321 int pip_export( void *exp ); 00341 int pip_import( int pipid, void **expp ); 00365 int pip_get_addr( int pipid, const char *symnam, void **addrp ); 00377 int pip_get_pipid( int *pipidp ); 00389 int pip_get_ntasks( int *ntasksp ); 00401 int pip_isa_piptask( void ); 00413 int pip_get_mode( int *modep ); 00428 int pip_exit( int retval ); 00446 int pip_wait( int pipid, int *retval ); 00461 int pip_trywait( int pipid, int *retval ); 00476 int pip_kill( int pipid, int signal ); 00491 int pip_get_id( int pipid, intptr_t *idp ); 00504 const char *pip_get_mode_str( void ); 00515 void pip_barrier_init( pip_barrier_t *barrp, int n ); 00527 void pip_barrier_wait( pip_barrier_t *barrp ); 00530 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00531 00532 int pip_idstr( char *buf, size_t sz ); 00533 00534 #ifdef PIP_EXPERIMENTAL 00535 void *pip_malloc( size_t size ); 00536 void pip_free( void *ptr ); 00537 #endif 00538 00539 #ifdef __cplusplus 00540 } 00541 #endif 00542 00543 #ifdef PIP_INTERNAL_FUNCS 00544 #include <pip_internal.h> 00545 #endif /* PIP_INTERNAL_FUNCS */ 00546 00547 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00548 00554 #endif /* _pip_h_ */