Commit 35f07b38 authored by Shane Snyder's avatar Shane Snyder

code cleanup / bug fixes

parent af20f42a
......@@ -4169,7 +4169,7 @@ done
# libc functions wrapped by darshan
#CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,write,-wrap,open,-wrap,creat,-wrap,creat64,-wrap,open64,-wrap,close,-wrap,read,-wrap,lseek,-wrap,lseek64,-wrap,pread,-wrap,pwrite,-wrap,readv,-wrap,writev,-wrap,__xstat,-wrap,__lxstat,-wrap,__fxstat,-wrap,__xstat64,-wrap,__lxstat64,-wrap,__fxstat64,-wrap,mmap,-wrap,mmap64,-wrap,fopen,-wrap,fclose,-wrap,fread,-wrap,fwrite,-wrap,fseek,-wrap,fopen64,-wrap,pread64,-wrap,pwrite64,-wrap,fsync,-wrap,fdatasync,-wrap,ncmpi_create,-wrap,ncmpi_open,-wrap,ncmpi_close,-wrap,H5Fcreate,-wrap,H5Fopen,-wrap,H5Fclose,-wrap,aio_write,-wrap,aio_write64,-wrap,aio_read,-wrap,aio_read64,-wrap,lio_listio,-wrap,lio_listio64,-wrap,aio_return,-wrap,aio_return64"
CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,open,-wrap,close"
CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,open,-wrap,open64,-wrap,close"
# We need to know the value of the $libdir and $bindir variables so that
# we can reference the correct path in the darshan compiler wrappers.
......
......@@ -190,7 +190,7 @@ AC_CHECK_HEADERS(mntent.h sys/mount.h)
# libc functions wrapped by darshan
#CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,write,-wrap,open,-wrap,creat,-wrap,creat64,-wrap,open64,-wrap,close,-wrap,read,-wrap,lseek,-wrap,lseek64,-wrap,pread,-wrap,pwrite,-wrap,readv,-wrap,writev,-wrap,__xstat,-wrap,__lxstat,-wrap,__fxstat,-wrap,__xstat64,-wrap,__lxstat64,-wrap,__fxstat64,-wrap,mmap,-wrap,mmap64,-wrap,fopen,-wrap,fclose,-wrap,fread,-wrap,fwrite,-wrap,fseek,-wrap,fopen64,-wrap,pread64,-wrap,pwrite64,-wrap,fsync,-wrap,fdatasync,-wrap,ncmpi_create,-wrap,ncmpi_open,-wrap,ncmpi_close,-wrap,H5Fcreate,-wrap,H5Fopen,-wrap,H5Fclose,-wrap,aio_write,-wrap,aio_write64,-wrap,aio_read,-wrap,aio_read64,-wrap,lio_listio,-wrap,lio_listio64,-wrap,aio_return,-wrap,aio_return64"
CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,open,-wrap,close"
CP_WRAPPERS="-Wl,-u,MPI_Init,-u,MPI_Wtime,-wrap,open,-wrap,open64,-wrap,close"
# We need to know the value of the $libdir and $bindir variables so that
# we can reference the correct path in the darshan compiler wrappers.
......
......@@ -30,6 +30,7 @@
struct darshan_module_funcs
{
void (*disable_instrumentation)(void);
void (*get_output_data)(
MPI_Comm mod_comm, /* communicator to use for module shutdown */
void** buf, /* output parameter to save module buffer address */
......
......@@ -139,6 +139,7 @@ static void darshan_core_initialize(int *argc, char ***argv)
if(internal_timing_flag)
init_start = DARSHAN_MPI_CALL(PMPI_Wtime)();
DARSHAN_CORE_LOCK();
/* setup darshan runtime if darshan is enabled and hasn't been initialized already */
if(!getenv("DARSHAN_DISABLE") && !darshan_core)
{
......@@ -190,6 +191,7 @@ static void darshan_core_initialize(int *argc, char ***argv)
darshan_core->trailing_data = darshan_get_exe_and_mounts(darshan_core);
}
}
DARSHAN_CORE_UNLOCK();
if(internal_timing_flag)
{
......@@ -234,17 +236,27 @@ static void darshan_core_shutdown()
if(getenv("DARSHAN_INTERNAL_TIMING"))
internal_timing_flag = 1;
/* disable darhan-core while we shutdown */
DARSHAN_CORE_LOCK();
if(!darshan_core)
{
DARSHAN_CORE_UNLOCK();
return;
}
/* disable further tracing while hanging onto the data so that we can
* write it out
*/
final_core = darshan_core;
darshan_core = NULL;
/* we also need to set which modules were registerd on this process and
* disable tracing within those modules while we shutdown
*/
for(i = 0; i < DARSHAN_MAX_MODS; i++)
{
if(final_core->mod_array[i])
{
local_mod_use[i] = 1;
final_core->mod_array[i]->mod_funcs.disable_instrumentation();
}
}
DARSHAN_CORE_UNLOCK();
start_log_time = DARSHAN_MPI_CALL(PMPI_Wtime)();
......@@ -319,13 +331,6 @@ static void darshan_core_shutdown()
final_core->log_job.end_time = last_end_time;
}
/* set which local modules were actually used */
for(i = 0; i < DARSHAN_MAX_MODS; i++)
{
if(final_core->mod_array[i])
local_mod_use[i] = 1;
}
/* reduce the number of times a module was opened globally and bcast to everyone */
DARSHAN_MPI_CALL(PMPI_Allreduce)(local_mod_use, global_mod_use_count, DARSHAN_MAX_MODS, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
......@@ -1210,10 +1215,9 @@ void darshan_core_register_module(
int *runtime_mem_limit)
{
struct darshan_core_module* mod;
*runtime_mem_limit = 0;
DARSHAN_CORE_LOCK();
*runtime_mem_limit = 0;
if(!darshan_core || (id >= DARSHAN_MAX_MODS))
{
DARSHAN_CORE_UNLOCK();
......@@ -1261,16 +1265,15 @@ void darshan_core_lookup_record_id(
darshan_record_id tmp_id;
struct darshan_core_record_ref* ref;
if(!darshan_core || !name)
if(!darshan_core)
return;
/* TODO: what do you do with printable flag? */
/* hash the input name to get a unique id for this record */
tmp_id = darshan_hash(name, len, 0);
DARSHAN_CORE_LOCK();
DARSHAN_CORE_LOCK();
/* check to see if we've already stored the id->name mapping for this record */
HASH_FIND(hlink, darshan_core->rec_hash, &tmp_id, sizeof(darshan_record_id), ref);
if(!ref)
......@@ -1287,11 +1290,8 @@ void darshan_core_lookup_record_id(
HASH_ADD(hlink, darshan_core->rec_hash, rec.id, sizeof(darshan_record_id), ref);
}
}
DARSHAN_CORE_UNLOCK();
printf("New Darshan record: %s (%"PRIu64")\n", (char *)name, tmp_id);
*id = tmp_id;
return;
}
......
......@@ -70,6 +70,7 @@ struct posix_runtime
static struct posix_runtime *posix_runtime = NULL;
static pthread_mutex_t posix_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static int instrumentation_disabled = 0;
static int my_rank = -1;
/* these are paths that we will not trace */
......@@ -88,14 +89,17 @@ NULL
};
DARSHAN_FORWARD_DECL(open, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(open64, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(close, int, (int fd));
static void posix_runtime_initialize(void);
static struct posix_runtime_file* posix_file_by_name(const char *name);
static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int fd);
static struct posix_runtime_file* posix_file_by_fd(int fd);
static void posix_file_close_fd(int fd);
static void posix_disable_instrumentation(void);
static void posix_get_output_data(MPI_Comm comm, void **buffer, int *size);
static void posix_shutdown(void);
......@@ -200,10 +204,44 @@ int DARSHAN_DECL(open)(const char *path, int flags, ...)
return(ret);
}
int DARSHAN_DECL(open64)(const char *path, int flags, ...)
{
int mode = 0;
int ret;
double tm1, tm2;
MAP_OR_FAIL(open);
if(flags & O_CREAT)
{
va_list arg;
va_start(arg, flags);
mode = va_arg(arg, int);
va_end(arg);
tm1 = darshan_core_wtime();
ret = __real_open64(path, flags, mode);
tm2 = darshan_core_wtime();
}
else
{
tm1 = darshan_core_wtime();
ret = __real_open64(path, flags);
tm2 = darshan_core_wtime();
}
POSIX_LOCK();
posix_runtime_initialize();
POSIX_RECORD_OPEN(ret, path, mode, 0, tm1, tm2);
POSIX_UNLOCK();
return(ret);
}
int DARSHAN_DECL(close)(int fd)
{
struct darshan_file_runtime* file;
int tmp_fd = fd;
struct posix_runtime_file* file;
double tm1, tm2;
int ret;
......@@ -216,8 +254,12 @@ int DARSHAN_DECL(close)(int fd)
POSIX_LOCK();
posix_runtime_initialize();
posix_file_close_fd(tmp_fd);
file = posix_file_by_fd(fd);
if(file)
{
POSIX_F_SET(file, CP_F_CLOSE_TIMESTAMP, darshan_core_wtime());
posix_file_close_fd(fd);
}
POSIX_UNLOCK();
return(ret);
......@@ -233,11 +275,13 @@ static void posix_runtime_initialize()
int mem_limit;
struct darshan_module_funcs posix_mod_fns =
{
.disable_instrumentation = &posix_disable_instrumentation,
.get_output_data = &posix_get_output_data,
.shutdown = &posix_shutdown
};
if(posix_runtime)
/* don't do anything if already initialized or instrumenation is disabled */
if(posix_runtime || instrumentation_disabled)
return;
/* register the posix module with darshan core */
......@@ -275,34 +319,7 @@ static void posix_runtime_initialize()
memset(posix_runtime->file_record_array, 0, posix_runtime->file_array_size *
sizeof(struct darshan_posix_file));
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &my_rank);
#if 0
/* set the memory alignment according to config or environment variables */
#if (__CP_MEM_ALIGNMENT < 1)
#error Darshan must be configured with a positive value for --with-mem-align
#endif
alignstr = getenv(CP_MEM_ALIGNMENT_OVERRIDE);
if(alignstr)
{
ret = sscanf(alignstr, "%d", &tmpval);
/* silently ignore if the env variable is set poorly */
if(ret == 1 && tmpval > 0)
{
darshan_mem_alignment = tmpval;
}
}
else
{
darshan_mem_alignment = __CP_MEM_ALIGNMENT;
}
/* avoid floating point errors on faulty input */
if(darshan_mem_alignment < 1)
{
darshan_mem_alignment = 1;
}
#endif
DARSHAN_MPI_CALL(PMPI_Comm_rank)(MPI_COMM_WORLD, &my_rank); /* TODO: can we move this out of here? */
return;
}
......@@ -313,7 +330,7 @@ static struct posix_runtime_file* posix_file_by_name(const char *name)
char *newname = NULL;
darshan_record_id file_id;
if(!posix_runtime)
if(!posix_runtime || instrumentation_disabled)
return(NULL);
newname = darshan_clean_file_path(name);
......@@ -359,7 +376,7 @@ static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int
struct posix_runtime_file* file;
struct posix_runtime_file_ref* ref;
if(!posix_runtime)
if(!posix_runtime || instrumentation_disabled)
return(NULL);
/* find file record by name first */
......@@ -386,19 +403,34 @@ static struct posix_runtime_file* posix_file_by_name_setfd(const char* name, int
if(!ref)
return(NULL);
memset(ref, 0, sizeof(*ref));
ref->file = file;
ref->fd = fd;
HASH_ADD(hlink, posix_runtime->fd_hash, fd, sizeof(int), ref);
return(file);
}
static struct posix_runtime_file* posix_file_by_fd(int fd)
{
struct posix_runtime_file_ref* ref;
if(!posix_runtime || instrumentation_disabled)
return(NULL);
/* search hash table for existing file ref for this fd */
HASH_FIND(hlink, posix_runtime->fd_hash, &fd, sizeof(int), ref);
if(ref)
return(ref->file);
return(NULL);
}
static void posix_file_close_fd(int fd)
{
struct posix_runtime_file_ref* ref;
if(!posix_runtime)
if(!posix_runtime || instrumentation_disabled)
return;
/* search hash table for this fd */
......@@ -415,21 +447,18 @@ static void posix_file_close_fd(int fd)
/* ***************************************************** */
static void posix_get_output_data(MPI_Comm comm, void **buffer, int *size)
static void posix_disable_instrumentation()
{
int comm_cmp;
DARSHAN_MPI_CALL(PMPI_Comm_compare)(MPI_COMM_WORLD, comm, &comm_cmp);
POSIX_LOCK();
instrumentation_disabled = 1;
POSIX_UNLOCK();
/* only do shared file reductions if this communicator includes _everyone_ */
if((comm_cmp == MPI_IDENT) || (comm_cmp == MPI_CONGRUENT))
{
/* don't reduce shared files if that feature is disabled, either */
if(!getenv("DARSHAN_DISABLE_SHARED_REDUCTION"))
{
/* TODO reduction code */
}
}
return;
}
static void posix_get_output_data(MPI_Comm comm, void **buffer, int *size)
{
/* TODO: shared file reduction */
*buffer = (void *)(posix_runtime->file_record_array);
*size = posix_runtime->file_array_ndx * sizeof(struct darshan_posix_file);
......
......@@ -169,8 +169,9 @@ int main(int argc, char **argv)
printf("\tRecord %d: id=%"PRIu64" (path=%s, rank=%"PRId64")\n",
i, next_rec.f_id, ref->rec.name, next_rec.rank);
printf("\t\tPOSIX_OPENS:\t%"PRIu64"\n\t\tF_OPEN_TIMESTAMP:\t%lf\n",
next_rec.counters[CP_POSIX_OPENS], next_rec.fcounters[CP_F_OPEN_TIMESTAMP]);
printf("\t\tPOSIX_OPENS:\t%"PRIu64"\n\t\tF_OPEN_TIMESTAMP:\t%lf\n\t\tF_CLOSE_TIMESTAMP:\t%lf\n",
next_rec.counters[CP_POSIX_OPENS], next_rec.fcounters[CP_F_OPEN_TIMESTAMP],
next_rec.fcounters[CP_F_CLOSE_TIMESTAMP]);
i++;
} while((ret = darshan_log_getfile(file, &next_rec)) == 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment