Commit 76e23680 authored by Shane Snyder's avatar Shane Snyder
Browse files

implement proper handling of dup family of calls

parent cfc92e59
......@@ -28,6 +28,8 @@
X(POSIX_FDSYNCS) \
/* count of number of filenos */\
X(POSIX_FILENOS) \
/* count of number of dups */\
X(POSIX_DUPS) \
/* mode of file */\
X(POSIX_MODE) \
/* total bytes read */\
......
......@@ -43,6 +43,9 @@ DARSHAN_FORWARD_DECL(open64, int, (const char *path, int flags, ...));
DARSHAN_FORWARD_DECL(__open_2, int, (const char *path, int oflag));
DARSHAN_FORWARD_DECL(creat, int, (const char* path, mode_t mode));
DARSHAN_FORWARD_DECL(creat64, int, (const char* path, mode_t mode));
DARSHAN_FORWARD_DECL(dup, int, (int oldfd));
DARSHAN_FORWARD_DECL(dup2, int, (int oldfd, int newfd));
DARSHAN_FORWARD_DECL(dup3, int, (int oldfd, int newfd, int flags));
DARSHAN_FORWARD_DECL(mkstemp, int, (char *template));
DARSHAN_FORWARD_DECL(mkostemp, int, (char *template, int flags));
DARSHAN_FORWARD_DECL(mkstemps, int, (char *template, int suffixlen));
......@@ -195,40 +198,50 @@ static int enable_dxt_io_trace = 0;
POSIX_UNLOCK(); \
} while(0)
#define POSIX_RECORD_OPEN(__ret, __path, __mode, __tm1, __tm2, __linked_counter) do { \
darshan_record_id rec_id; \
struct posix_file_record_ref *rec_ref; \
char *newpath; \
#define POSIX_RECORD_OPEN(__ret, __path, __mode, __tm1, __tm2) do { \
darshan_record_id __rec_id; \
struct posix_file_record_ref *__rec_ref; \
char *__newpath; \
if(__ret < 0) break; \
newpath = darshan_clean_file_path(__path); \
if(!newpath) newpath = (char *)__path; \
if(darshan_core_excluded_path(newpath)) { \
if(newpath != __path) free(newpath); \
__newpath = darshan_clean_file_path(__path); \
if(!__newpath) __newpath = (char *)__path; \
if(darshan_core_excluded_path(__newpath)) { \
if(__newpath != __path) free(__newpath); \
break; \
} \
rec_id = darshan_core_gen_record_id(newpath); \
rec_ref = darshan_lookup_record_ref(posix_runtime->rec_id_hash, &rec_id, sizeof(darshan_record_id)); \
if(!rec_ref) rec_ref = posix_track_new_file_record(rec_id, newpath); \
if(!rec_ref) { \
if(newpath != __path) free(newpath); \
__rec_id = darshan_core_gen_record_id(__newpath); \
__rec_ref = darshan_lookup_record_ref(posix_runtime->rec_id_hash, &__rec_id, sizeof(darshan_record_id)); \
if(!__rec_ref) __rec_ref = posix_track_new_file_record(__rec_id, __newpath); \
if(!__rec_ref) { \
if(__newpath != __path) free(__newpath); \
break; \
} \
if(__mode) \
rec_ref->file_rec->counters[POSIX_MODE] = __mode; \
rec_ref->offset = 0; \
rec_ref->last_byte_written = 0; \
rec_ref->last_byte_read = 0; \
rec_ref->file_rec->counters[POSIX_OPENS] += 1; \
if(__linked_counter >= 0) rec_ref->file_rec->counters[__linked_counter] += 1; \
if(rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] == 0 || \
rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] > __tm1) \
rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] = __tm1; \
rec_ref->file_rec->fcounters[POSIX_F_OPEN_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(rec_ref->file_rec->fcounters[POSIX_F_META_TIME], \
__tm1, __tm2, rec_ref->last_meta_end); \
darshan_add_record_ref(&(posix_runtime->fd_hash), &__ret, sizeof(int), rec_ref); \
darshan_instrument_fs_data(rec_ref->fs_type, newpath, __ret); \
if(newpath != __path) free(newpath); \
_POSIX_RECORD_OPEN(__ret, __rec_ref, __mode, __tm1, __tm2, 1, -1); \
darshan_instrument_fs_data(__rec_ref->fs_type, __newpath, __ret); \
if(__newpath != __path) free(__newpath); \
} while(0)
#define POSIX_RECORD_REFOPEN(__ret, __rec_ref, __tm1, __tm2, __ref_counter) do { \
if(__ret < 0 || !__rec_ref) break; \
_POSIX_RECORD_OPEN(__ret, __rec_ref, 0, __tm1, __tm2, 0, __ref_counter); \
} while(0)
#define _POSIX_RECORD_OPEN(__ret, __rec_ref, __mode, __tm1, __tm2, __reset_flag, __ref_counter) do { \
if(__mode) __rec_ref->file_rec->counters[POSIX_MODE] = __mode; \
if(__reset_flag) { \
__rec_ref->offset = 0; \
__rec_ref->last_byte_written = 0; \
__rec_ref->last_byte_read = 0; \
} \
__rec_ref->file_rec->counters[POSIX_OPENS] += 1; \
if(__ref_counter >= 0) __rec_ref->file_rec->counters[__ref_counter] += 1; \
if(__rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] == 0 || \
__rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] > __tm1) \
__rec_ref->file_rec->fcounters[POSIX_F_OPEN_START_TIMESTAMP] = __tm1; \
__rec_ref->file_rec->fcounters[POSIX_F_OPEN_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(__rec_ref->file_rec->fcounters[POSIX_F_META_TIME], \
__tm1, __tm2, __rec_ref->last_meta_end); \
darshan_add_record_ref(&(posix_runtime->fd_hash), &__ret, sizeof(int), __rec_ref); \
} while(0)
#define POSIX_RECORD_READ(__ret, __fd, __pread_flag, __pread_offset, __aligned, __tm1, __tm2) do { \
......@@ -403,7 +416,7 @@ int DARSHAN_DECL(open)(const char *path, int flags, ...)
}
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -421,7 +434,7 @@ int DARSHAN_DECL(__open_2)(const char *path, int oflag)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, path, 0, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, path, 0, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -454,7 +467,7 @@ int DARSHAN_DECL(open64)(const char *path, int flags, ...)
}
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -472,7 +485,7 @@ int DARSHAN_DECL(creat)(const char* path, mode_t mode)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -490,12 +503,84 @@ int DARSHAN_DECL(creat64)(const char* path, mode_t mode)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, path, mode, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
}
int DARSHAN_DECL(dup)(int oldfd)
{
int ret;
struct posix_file_record_ref *rec_ref;
double tm1, tm2;
MAP_OR_FAIL(dup);
tm1 = darshan_core_wtime();
ret = __real_dup(oldfd);
tm2 = darshan_core_wtime();
if(ret >= 0)
{
POSIX_PRE_RECORD();
rec_ref = darshan_lookup_record_ref(posix_runtime->fd_hash,
&oldfd, sizeof(oldfd));
POSIX_RECORD_REFOPEN(ret, rec_ref, tm1, tm2, POSIX_DUPS);
POSIX_POST_RECORD();
}
return(ret);
}
int DARSHAN_DECL(dup2)(int oldfd, int newfd)
{
int ret;
struct posix_file_record_ref *rec_ref;
double tm1, tm2;
MAP_OR_FAIL(dup2);
tm1 = darshan_core_wtime();
ret = __real_dup2(oldfd, newfd);
tm2 = darshan_core_wtime();
if(ret >=0)
{
POSIX_PRE_RECORD();
rec_ref = darshan_lookup_record_ref(posix_runtime->fd_hash,
&oldfd, sizeof(oldfd));
POSIX_RECORD_REFOPEN(ret, rec_ref, tm1, tm2, POSIX_DUPS);
POSIX_POST_RECORD();
}
return(ret);
}
int DARSHAN_DECL(dup3)(int oldfd, int newfd, int flags)
{
int ret;
struct posix_file_record_ref *rec_ref;
double tm1, tm2;
MAP_OR_FAIL(dup3);
tm1 = darshan_core_wtime();
ret = __real_dup3(oldfd, newfd, flags);
tm2 = darshan_core_wtime();
if(ret >=0)
{
POSIX_PRE_RECORD();
rec_ref = darshan_lookup_record_ref(posix_runtime->fd_hash,
&oldfd, sizeof(oldfd));
POSIX_RECORD_REFOPEN(ret, rec_ref, tm1, tm2, POSIX_DUPS);
POSIX_POST_RECORD();
}
return(ret);
}
int DARSHAN_DECL(mkstemp)(char* template)
{
int ret;
......@@ -508,7 +593,7 @@ int DARSHAN_DECL(mkstemp)(char* template)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -526,7 +611,7 @@ int DARSHAN_DECL(mkostemp)(char* template, int flags)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -544,7 +629,7 @@ int DARSHAN_DECL(mkstemps)(char* template, int suffixlen)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -562,7 +647,7 @@ int DARSHAN_DECL(mkostemps)(char* template, int suffixlen, int flags)
tm2 = darshan_core_wtime();
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2, -1);
POSIX_RECORD_OPEN(ret, template, 0, tm1, tm2);
POSIX_POST_RECORD();
return(ret);
......@@ -1434,10 +1519,18 @@ static void posix_aio_tracker_add(int fd, void *aiocbp)
int darshan_posix_add_open_fd(int fd, char *rec_name, int counter,
double tm1, double tm2)
{
darshan_record_id rec_id;
struct posix_file_record_ref *rec_ref;
int ret = 0;
POSIX_PRE_RECORD();
POSIX_RECORD_OPEN(fd, rec_name, 0, tm1, tm2, counter);
rec_id = darshan_core_gen_record_id(rec_name);
rec_ref = darshan_lookup_record_ref(posix_runtime->rec_id_hash, &rec_id,
sizeof(darshan_record_id));
if(!rec_ref)
rec_ref = posix_track_new_file_record(rec_id, rec_name);
POSIX_RECORD_REFOPEN(fd, rec_ref, tm1, tm2, counter);
POSIX_POST_RECORD();
return(ret);
......@@ -1805,14 +1898,14 @@ void darshan_posix_shutdown_bench_setup(int test_case)
case 1: /* single file-per-process */
snprintf(filepath, 256, "fpp-0_rank-%d", my_rank);
POSIX_RECORD_OPEN(fd_array[0], filepath, 777, 0, 1, -1);
POSIX_RECORD_OPEN(fd_array[0], filepath, 777, 0, 1);
POSIX_RECORD_WRITE(size_array[0], fd_array[0], 0, 0, 1, 1, 2);
break;
case 2: /* single shared file */
snprintf(filepath, 256, "shared-0");
POSIX_RECORD_OPEN(fd_array[0], filepath, 777, 0, 1, -1);
POSIX_RECORD_OPEN(fd_array[0], filepath, 777, 0, 1);
POSIX_RECORD_WRITE(size_array[0], fd_array[0], 0, 0, 1, 1, 2);
break;
......@@ -1821,7 +1914,7 @@ void darshan_posix_shutdown_bench_setup(int test_case)
{
snprintf(filepath, 256, "fpp-%d_rank-%d", i , my_rank);
POSIX_RECORD_OPEN(fd_array[i], filepath, 777, 0, 1, -1);
POSIX_RECORD_OPEN(fd_array[i], filepath, 777, 0, 1);
POSIX_RECORD_WRITE(size_array[i % DARSHAN_COMMON_VAL_MAX_RUNTIME_COUNT],
fd_array[i], 0, 0, 1, 1, 2);
}
......@@ -1832,7 +1925,7 @@ void darshan_posix_shutdown_bench_setup(int test_case)
{
snprintf(filepath, 256, "shared-%d", i);
POSIX_RECORD_OPEN(fd_array[i], filepath, 777, 0, 1, -1);
POSIX_RECORD_OPEN(fd_array[i], filepath, 777, 0, 1);
POSIX_RECORD_WRITE(size_array[i % DARSHAN_COMMON_VAL_MAX_RUNTIME_COUNT],
fd_array[i], 0, 0, 1, 1, 2);
}
......
......@@ -3,6 +3,9 @@
--wrap=__open_2
--wrap=creat
--wrap=creat64
--wrap=dup
--wrap=dup2
--wrap=dup3
--wrap=mkstemp
--wrap=mkostemp
--wrap=mkstemps
......
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