Commit 9801de53 authored by Shane Snyder's avatar Shane Snyder
Browse files

more POSIX wrappers added and improved docs

parent 910d55f2
...@@ -53,12 +53,22 @@ static char * const darshan_module_names[] = ...@@ -53,12 +53,22 @@ static char * const darshan_module_names[] =
"PNETCDF" "PNETCDF"
}; };
/* the darshan_log_map structure is used to indicate the location of
* specific module data in a Darshan log. Note that 'off' and 'len' are
* the respective offset and length of the data in the file, in *uncompressed*
* terms -- this is nonintuitive since the data is compressed, but this is
* done so we can utilize the gzread interface for all Darshan log reading
* utilities.
*/
struct darshan_log_map struct darshan_log_map
{ {
uint64_t off; uint64_t off;
uint64_t len; uint64_t len;
}; };
/* the darshan header stores critical metadata needed for correctly
* reading the contents of the corresponding Darshan log
*/
struct darshan_header struct darshan_header
{ {
char version_string[8]; char version_string[8];
...@@ -67,7 +77,7 @@ struct darshan_header ...@@ -67,7 +77,7 @@ struct darshan_header
struct darshan_log_map mod_map[DARSHAN_MAX_MODS]; struct darshan_log_map mod_map[DARSHAN_MAX_MODS];
}; };
/* statistics for the job as a whole */ /* job-level metadata stored for this application */
#define DARSHAN_JOB_METADATA_LEN 1024 /* including null terminator! */ #define DARSHAN_JOB_METADATA_LEN 1024 /* including null terminator! */
struct darshan_job struct darshan_job
{ {
...@@ -79,6 +89,7 @@ struct darshan_job ...@@ -79,6 +89,7 @@ struct darshan_job
char metadata[DARSHAN_JOB_METADATA_LEN]; char metadata[DARSHAN_JOB_METADATA_LEN];
}; };
/* minimal record stored for each file/object accessed by Darshan */
struct darshan_record struct darshan_record
{ {
char* name; char* name;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "darshan-log-format.h" #include "darshan-log-format.h"
/* integer statistics for POSIX file records */
enum darshan_posix_indices enum darshan_posix_indices
{ {
POSIX_OPENS, /* count of posix opens */ POSIX_OPENS, /* count of posix opens */
...@@ -27,16 +28,16 @@ enum darshan_posix_indices ...@@ -27,16 +28,16 @@ enum darshan_posix_indices
POSIX_FDSYNCS, POSIX_FDSYNCS,
#endif #endif
POSIX_MODE, /* mode of file */ POSIX_MODE, /* mode of file */
#if 0
POSIX_BYTES_READ, /* total bytes read */ POSIX_BYTES_READ, /* total bytes read */
POSIX_BYTES_WRITTEN, /* total bytes written */ POSIX_BYTES_WRITTEN, /* total bytes written */
POSIX_MAX_BYTE_READ, /* highest offset byte read */ POSIX_MAX_BYTE_READ, /* highest offset byte read */
POSIX_MAX_BYTE_WRITTEN, /* highest offset byte written */ POSIX_MAX_BYTE_WRITTEN, /* highest offset byte written */
CONSEC_READS, /* count of consecutive reads */ POSIX_CONSEC_READS, /* count of consecutive reads */
CONSEC_WRITES, /* count of consecutive writes */ POSIX_CONSEC_WRITES, /* count of consecutive writes */
SEQ_READS, /* count of sequential reads */ POSIX_SEQ_READS, /* count of sequential reads */
SEQ_WRITES, /* count of sequential writes */ POSIX_SEQ_WRITES, /* count of sequential writes */
RW_SWITCHES, /* number of times switched between read and write */ POSIX_RW_SWITCHES, /* number of times switched between read and write */
#if 0
MEM_NOT_ALIGNED, /* count of accesses not mem aligned */ MEM_NOT_ALIGNED, /* count of accesses not mem aligned */
MEM_ALIGNMENT, /* mem alignment in bytes */ MEM_ALIGNMENT, /* mem alignment in bytes */
FILE_NOT_ALIGNED, /* count of accesses not file aligned */ FILE_NOT_ALIGNED, /* count of accesses not file aligned */
...@@ -95,7 +96,7 @@ enum darshan_posix_indices ...@@ -95,7 +96,7 @@ enum darshan_posix_indices
POSIX_NUM_INDICES, POSIX_NUM_INDICES,
}; };
/* floating point statistics */ /* floating point statistics for POSIX file records */
enum darshan_posix_f_indices enum darshan_posix_f_indices
{ {
/* NOTE: adjust cp_normalize_timestamps() function if any TIMESTAMPS are /* NOTE: adjust cp_normalize_timestamps() function if any TIMESTAMPS are
...@@ -126,6 +127,14 @@ enum darshan_posix_f_indices ...@@ -126,6 +127,14 @@ enum darshan_posix_f_indices
POSIX_F_NUM_INDICES, POSIX_F_NUM_INDICES,
}; };
/* file record structure for POSIX files. a record is created and stored for
* every POSIX file opened by the original application. For the POSIX module,
* the record includes:
* - a corresponding record identifier (created by hashing the file path)
* - the rank of the process which opened the file (-1 for shared files)
* - integer file I/O statistics (open, read/write counts, etc)
* - floating point I/O statistics (timestamps, cumulative timers, etc.)
*/
struct darshan_posix_file struct darshan_posix_file
{ {
darshan_record_id f_id; darshan_record_id f_id;
......
...@@ -66,6 +66,41 @@ ...@@ -66,6 +66,41 @@
/* macros for manipulating module's counter variables */ /* macros for manipulating module's counter variables */
/* NOTE: */ /* NOTE: */
#define DARSHAN_COUNTER_SET(__rec_p, __counter, __value) do{ \
(__rec_p)->counters[__counter] = __value; \
} while(0)
#define DARSHAN_COUNTER_F_SET(__rec_p, __counter, __value) do{ \
(__rec_p)->fcounters[__counter] = __value; \
} while(0)
#define DARSHAN_COUNTER_INC(__rec_p, __counter, __value) do{ \
(__rec_p)->counters[__counter] = __value; \
} while(0)
#define DARSHAN_COUNTER_F_INC(__rec_p, __counter, __value) do{ \
(__rec_p)->fcounters[__counter] = __value; \
} while(0)
#define DARSHAN_COUNTER_F_INC_NO_OVERLAP(__rec_p, __tm1, __tm2, __last, __counter) do{ \
if(__tm1 > __last) \
DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __tm1)); \
else \
DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __last)); \
if(__tm2 > __last) \
__last = __tm2; \
} while(0)
#define DARSHAN_COUNTER_VALUE(__rec_p, __counter) \
((__rec_p)->counters[__counter])
#define DARSHAN_COUNTER_F_VALUE(__rec_p, __counter) \
((__rec_p)->fcounters[__counter])
#define DARSHAN_COUNTER_MAX(__rec_p, __counter, __value) do{ \
if((__rec_p)->counters[__counter] < __value) \
(__rec_p)->counters[__counter] = __value; \
} while(0)
/* module developers provide the following functions to darshan-core */ /* module developers provide the following functions to darshan-core */
struct darshan_module_funcs struct darshan_module_funcs
......
...@@ -65,15 +65,44 @@ static void posix_record_reduction_op(void* infile_v, void* inoutfile_v, ...@@ -65,15 +65,44 @@ static void posix_record_reduction_op(void* infile_v, void* inoutfile_v,
static void posix_get_output_data(void **buffer, int *size); static void posix_get_output_data(void **buffer, int *size);
static void posix_shutdown(void); static void posix_shutdown(void);
enum posix_io_type
{
POSIX_READ = 1,
POSIX_WRITE = 2,
};
/* The posix_file_runtime structure maintains necessary runtime metadata
* for the POSIX file record (darshan_posix_file structure, defined in
* darshan-posix-log-format.h) pointed to by 'file_record'. This metadata
* assists with the instrumenting of specific statistics in the file record.
* 'hlink' is a hash table link structure used to add/remove this record
* from the hash table of POSIX file records for this process.
*/
struct posix_file_runtime struct posix_file_runtime
{ {
struct darshan_posix_file* file_record; struct darshan_posix_file* file_record;
int64_t offset;
int64_t last_byte_read;
int64_t last_byte_written;
enum posix_io_type last_io_type;
double last_meta_end; double last_meta_end;
double last_read_end; double last_read_end;
double last_write_end; double last_write_end;
UT_hash_handle hlink; UT_hash_handle hlink;
}; };
/* The posix_file_runtime_ref structure is used to associate a POSIX
* file descriptor with an already existing POSIX file record. This is
* necessary as many POSIX I/O functions take only an input file descriptor,
* but POSIX file records are indexed by their full file paths (i.e., darshan
* record identifiers for POSIX files are created by hashing the file path).
* In other words, this structure is necessary as it allows us to look up a
* file record either by a pathname (posix_file_runtime) or by POSIX file
* descriptor (posix_file_runtime_ref), depending on which parameters are
* available. This structure includes another hash table link, since separate
* hashes are maintained for posix_file_runtime structures and posix_file_runtime_ref
* structures.
*/
struct posix_file_runtime_ref struct posix_file_runtime_ref
{ {
struct posix_file_runtime* file; struct posix_file_runtime* file;
...@@ -81,6 +110,10 @@ struct posix_file_runtime_ref ...@@ -81,6 +110,10 @@ struct posix_file_runtime_ref
UT_hash_handle hlink; UT_hash_handle hlink;
}; };
/* The posix_runtime structure maintains necessary state for storing
* POSIX file records and for coordinating with darshan-core at
* shutdown time.
*/
struct posix_runtime struct posix_runtime
{ {
struct posix_file_runtime* file_runtime_array; struct posix_file_runtime* file_runtime_array;
...@@ -101,44 +134,6 @@ static int my_rank = -1; ...@@ -101,44 +134,6 @@ static int my_rank = -1;
#define POSIX_LOCK() pthread_mutex_lock(&posix_runtime_mutex) #define POSIX_LOCK() pthread_mutex_lock(&posix_runtime_mutex)
#define POSIX_UNLOCK() pthread_mutex_unlock(&posix_runtime_mutex) #define POSIX_UNLOCK() pthread_mutex_unlock(&posix_runtime_mutex)
#define POSIX_SET(__file, __counter, __value) do {\
(__file)->file_record->counters[__counter] = __value; \
} while(0)
#define POSIX_F_SET(__file, __counter, __value) do {\
(__file)->file_record->fcounters[__counter] = __value; \
} while(0)
#define POSIX_INC(__file, __counter, __value) do {\
(__file)->file_record->counters[__counter] += __value; \
} while(0)
#define POSIX_F_INC(__file, __counter, __value) do {\
(__file)->file_record->fcounters[__counter] += __value; \
} while(0)
#define POSIX_F_INC_NO_OVERLAP(__file, __tm1, __tm2, __last, __counter) do { \
if(__tm1 > __last) \
POSIX_F_INC(__file, __counter, (__tm2-__tm1)); \
else \
POSIX_F_INC(__file, __counter, (__tm2 - __last)); \
if(__tm2 > __last) \
__last = __tm2; \
} while(0)
#define POSIX_VALUE(__file, __counter) \
((__file)->file_record->counters[__counter])
#define POSIX_F_VALUE(__file, __counter) \
((__file)->file_record->fcounters[__counter])
#define POSIX_MAX(__file, __counter, __value) do {\
if((__file)->file_record->counters[__counter] < __value) \
{ \
(__file)->file_record->counters[__counter] = __value; \
} \
} while(0)
#define POSIX_RECORD_OPEN(__ret, __path, __mode, __stream_flag, __tm1, __tm2) do { \ #define POSIX_RECORD_OPEN(__ret, __path, __mode, __stream_flag, __tm1, __tm2) do { \
struct posix_file_runtime* file; \ struct posix_file_runtime* file; \
char* exclude; \ char* exclude; \
...@@ -155,119 +150,123 @@ static int my_rank = -1; ...@@ -155,119 +150,123 @@ static int my_rank = -1;
/* CP_STAT_FILE(file, __path, __ret); */ \ /* CP_STAT_FILE(file, __path, __ret); */ \
file->file_record->rank = my_rank; \ file->file_record->rank = my_rank; \
if(__mode) \ if(__mode) \
POSIX_SET(file, POSIX_MODE, __mode); \ DARSHAN_COUNTER_SET(file->file_record, POSIX_MODE, __mode); \
/* file->offset = 0; */ \ file->offset = 0; \
/* file->last_byte_written = 0; */ \ file->last_byte_written = 0; \
/* file->last_byte_read = 0; */ \ file->last_byte_read = 0; \
if(__stream_flag)\ if(__stream_flag)\
POSIX_INC(file, POSIX_FOPENS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_FOPENS, 1); \
else \ else \
POSIX_INC(file, POSIX_OPENS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_OPENS, 1); \
if(POSIX_F_VALUE(file, POSIX_F_OPEN_TIMESTAMP) == 0) \ if(DARSHAN_COUNTER_F_VALUE(file->file_record, POSIX_F_OPEN_TIMESTAMP) == 0) \
POSIX_F_SET(file, POSIX_F_OPEN_TIMESTAMP, __tm1); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_OPEN_TIMESTAMP, __tm1); \
POSIX_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_meta_end, POSIX_F_META_TIME); \ DARSHAN_COUNTER_F_INC_NO_OVERLAP(file->file_record, __tm1, __tm2, file->last_meta_end, POSIX_F_META_TIME); \
} while(0) } while(0)
#define POSIX_RECORD_READ(__ret, __fd, __pread_flag, __pread_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \ #define POSIX_RECORD_READ(__ret, __fd, __pread_flag, __pread_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \
/* size_t stride; \ /* size_t stride; */\
int64_t this_offset; */ \ int64_t this_offset; \
struct posix_file_runtime* file; \ struct posix_file_runtime* file; \
/* int64_t file_alignment; */ \ /* int64_t file_alignment; */ \
double __elapsed = __tm2-__tm1; \ double __elapsed = __tm2-__tm1; \
if(__ret < 0) break; \ if(__ret < 0) break; \
file = posix_file_by_fd(__fd); \ file = posix_file_by_fd(__fd); \
if(!file) break; \ if(!file) break; \
/* if(__pread_flag) \ if(__pread_flag) \
this_offset = __pread_offset; \ this_offset = __pread_offset; \
else \ else \
this_offset = file->offset; \ this_offset = file->offset; \
file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); \ /* file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); */\
if(this_offset > file->last_byte_read) \ if(this_offset > file->last_byte_read) \
CP_INC(file, CP_SEQ_READS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_SEQ_READS, 1); \
if(this_offset == (file->last_byte_read + 1)) \ if(this_offset == (file->last_byte_read + 1)) \
CP_INC(file, CP_CONSEC_READS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_CONSEC_READS, 1); \
if(this_offset > 0 && this_offset > file->last_byte_read \ /* if(this_offset > 0 && this_offset > file->last_byte_read \
&& file->last_byte_read != 0) \ && file->last_byte_read != 0) \
stride = this_offset - file->last_byte_read - 1; \ stride = this_offset - file->last_byte_read - 1; \
else \ else \
stride = 0; \ stride = 0; */\
file->last_byte_read = this_offset + __ret - 1; \ file->last_byte_read = this_offset + __ret - 1; \
file->offset = this_offset + __ret; \ file->offset = this_offset + __ret; \
CP_MAX(file, CP_MAX_BYTE_READ, (this_offset + __ret -1)); \ DARSHAN_COUNTER_MAX(file->file_record, POSIX_MAX_BYTE_READ, (this_offset + __ret - 1)); \
CP_INC(file, CP_BYTES_READ, __ret); */\ DARSHAN_COUNTER_INC(file->file_record, POSIX_BYTES_READ, __ret); \
if(__stream_flag)\ if(__stream_flag)\
POSIX_INC(file, POSIX_FREADS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_FREADS, 1); \
else\ else\
POSIX_INC(file, POSIX_READS, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_READS, 1); \
/* CP_BUCKET_INC(file, CP_SIZE_READ_0_100, __ret); \ /* CP_BUCKET_INC(file, CP_SIZE_READ_0_100, __ret); \
cp_access_counter(file, stride, CP_COUNTER_STRIDE); \ cp_access_counter(file, stride, CP_COUNTER_STRIDE); \
if(!__aligned) \ if(!__aligned) \
CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \ CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \
if(file_alignment > 0 && (this_offset % file_alignment) != 0) \ if(file_alignment > 0 && (this_offset % file_alignment) != 0) \
CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \ CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \
cp_access_counter(file, __ret, CP_COUNTER_ACCESS); \ cp_access_counter(file, __ret, CP_COUNTER_ACCESS); */\
if(file->last_io_type == CP_WRITE) \ if(file->last_io_type == POSIX_WRITE) \
CP_INC(file, CP_RW_SWITCHES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_RW_SWITCHES, 1); \
file->last_io_type = CP_READ; */ \ file->last_io_type = POSIX_READ; \
POSIX_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_read_end, POSIX_F_READ_TIME); \ DARSHAN_COUNTER_F_INC_NO_OVERLAP(file->file_record, __tm1, __tm2, file->last_read_end, POSIX_F_READ_TIME); \
if(POSIX_F_VALUE(file, POSIX_F_READ_START_TIMESTAMP) == 0) \ if(DARSHAN_COUNTER_F_VALUE(file->file_record, POSIX_F_READ_START_TIMESTAMP) == 0) \
POSIX_F_SET(file, POSIX_F_READ_START_TIMESTAMP, __tm1); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_READ_START_TIMESTAMP, __tm1); \
POSIX_F_SET(file, POSIX_F_READ_END_TIMESTAMP, __tm2); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_READ_END_TIMESTAMP, __tm2); \
if(POSIX_F_VALUE(file, POSIX_F_MAX_READ_TIME) < __elapsed){ \ if(DARSHAN_COUNTER_F_VALUE(file->file_record, POSIX_F_MAX_READ_TIME) < __elapsed){ \
POSIX_F_SET(file, POSIX_F_MAX_READ_TIME, __elapsed); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_MAX_READ_TIME, __elapsed); \
POSIX_SET(file, POSIX_MAX_READ_TIME_SIZE, __ret); } \ DARSHAN_COUNTER_SET(file->file_record, POSIX_MAX_READ_TIME_SIZE, __ret); } \
} while(0) } while(0)
#define POSIX_RECORD_WRITE(__ret, __fd, __pwrite_flag, __pwrite_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \ #define POSIX_RECORD_WRITE(__ret, __fd, __pwrite_flag, __pwrite_offset, __aligned, __stream_flag, __tm1, __tm2) do{ \
/* size_t stride; \ /* size_t stride; */\
int64_t this_offset; */ \ int64_t this_offset; \
struct posix_file_runtime* file; \ struct posix_file_runtime* file; \
/* int64_t file_alignment; */ \ /* int64_t file_alignment; */ \
double __elapsed = __tm2-__tm1; \ double __elapsed = __tm2-__tm1; \
if(__ret < 0) break; \ if(__ret < 0) break; \
file = posix_file_by_fd(__fd); \ file = posix_file_by_fd(__fd); \
if(!file) break; \ if(!file) break; \
/* if(__pwrite_flag) \ if(__pwrite_flag) \
this_offset = __pwrite_offset; \ this_offset = __pwrite_offset; \
else \ else \
this_offset = file->offset; \ this_offset = file->offset; \
file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); \ /* file_alignment = CP_VALUE(file, CP_FILE_ALIGNMENT); */\
if(this_offset > file->last_byte_written) \ if(this_offset > file->last_byte_written) \
CP_INC(file, CP_SEQ_WRITES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_SEQ_WRITES, 1); \
if(this_offset == (file->last_byte_written + 1)) \ if(this_offset == (file->last_byte_written + 1)) \
CP_INC(file, CP_CONSEC_WRITES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_CONSEC_WRITES, 1); \
if(this_offset > 0 && this_offset > file->last_byte_written \ /* if(this_offset > 0 && this_offset > file->last_byte_written \
&& file->last_byte_written != 0) \ && file->last_byte_written != 0) \
stride = this_offset - file->last_byte_written - 1; \ stride = this_offset - file->last_byte_written - 1; \
else \ else \
stride = 0; \ stride = 0; */\
file->last_byte_written = this_offset + __ret - 1; \ file->last_byte_written = this_offset + __ret - 1; \
file->offset = this_offset + __ret; \ file->offset = this_offset + __ret; \
CP_MAX(file, CP_MAX_BYTE_WRITTEN, (this_offset + __ret -1)); \ DARSHAN_COUNTER_MAX(file->file_record, POSIX_MAX_BYTE_WRITTEN, (this_offset + __ret - 1)); \
CP_INC(file, CP_BYTES_WRITTEN, __ret); */ \ DARSHAN_COUNTER_INC(file->file_record, POSIX_BYTES_WRITTEN, __ret); \
if(__stream_flag) \ if(__stream_flag) \
POSIX_INC(file, POSIX_FWRITES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_FWRITES, 1); \
else \ else \
POSIX_INC(file, POSIX_WRITES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_WRITES, 1); \
/* CP_BUCKET_INC(file, CP_SIZE_WRITE_0_100, __ret); \ /* CP_BUCKET_INC(file, CP_SIZE_WRITE_0_100, __ret); \
cp_access_counter(file, stride, CP_COUNTER_STRIDE); \ cp_access_counter(file, stride, CP_COUNTER_STRIDE); \
if(!__aligned) \ if(!__aligned) \
CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \ CP_INC(file, CP_MEM_NOT_ALIGNED, 1); \
if(file_alignment > 0 && (this_offset % file_alignment) != 0) \ if(file_alignment > 0 && (this_offset % file_alignment) != 0) \
CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \ CP_INC(file, CP_FILE_NOT_ALIGNED, 1); \
cp_access_counter(file, __ret, CP_COUNTER_ACCESS); \ cp_access_counter(file, __ret, CP_COUNTER_ACCESS); */\
if(file->last_io_type == CP_READ) \ if(file->last_io_type == POSIX_READ) \
CP_INC(file, CP_RW_SWITCHES, 1); \ DARSHAN_COUNTER_INC(file->file_record, POSIX_RW_SWITCHES, 1); \
file->last_io_type = CP_WRITE; */ \ file->last_io_type = POSIX_WRITE; \
POSIX_F_INC_NO_OVERLAP(file, __tm1, __tm2, file->last_write_end, POSIX_F_WRITE_TIME); \ DARSHAN_COUNTER_F_INC_NO_OVERLAP(file->file_record, __tm1, __tm2, file->last_write_end, POSIX_F_WRITE_TIME); \
if(POSIX_F_VALUE(file, POSIX_F_WRITE_START_TIMESTAMP) == 0) \ if(DARSHAN_COUNTER_F_VALUE(file->file_record, POSIX_F_WRITE_START_TIMESTAMP) == 0) \
POSIX_F_SET(file, POSIX_F_WRITE_START_TIMESTAMP, __tm1); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_WRITE_START_TIMESTAMP, __tm1); \
POSIX_F_SET(file, POSIX_F_WRITE_END_TIMESTAMP, __tm2); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_WRITE_END_TIMESTAMP, __tm2); \
if(POSIX_F_VALUE(file, POSIX_F_MAX_WRITE_TIME) < __elapsed){ \ if(DARSHAN_COUNTER_F_VALUE(file->file_record, POSIX_F_MAX_WRITE_TIME) < __elapsed){ \
POSIX_F_SET(file, POSIX_F_MAX_WRITE_TIME, __elapsed); \ DARSHAN_COUNTER_F_SET(file->file_record, POSIX_F_MAX_WRITE_TIME, __elapsed); \
POSIX_SET(file, POSIX_MAX_WRITE_TIME_SIZE, __ret); } \ DARSHAN_COUNTER_SET(file->file_record, POSIX_MAX_WRITE_TIME_SIZE, __ret); } \
} while(0) } while(0)
/**********************************************************
* Wrappers for POSIX I/O functions of interest *
**********************************************************/
int DARSHAN_DECL(open)(const char *path, int flags, ...) int DARSHAN_DECL(open)(const char *path, int flags, ...)
{ {
int mode = 0; int mode = 0;
...@@ -577,10 +576,12 @@ int DARSHAN_DECL(close)(int fd) ...@@ -577,10 +576,12 @@ int DARSHAN_DECL(close)(int fd)
file = posix_file_by_fd(fd); file = posix_file_by_fd(fd);
if(file) if(file)
{ {
/* file->last_byte_written = 0; */ file->last_byte_written = 0;
/* file->last_byte_read = 0; */ file->last_byte_read = 0;
POSIX_F_SET(file, POSIX_F_CLOSE_TIMESTAMP, darshan_core_wtime()); DARSHAN_COUNTER_F_SET(file->file_record,
POSIX_F_INC_NO_OVERLAP(file, tm1, tm2, file->last_meta_end, POSIX_F_META_TIME); POSIX_F_CLOSE_TIMESTAMP, darshan_core_wtime());
DARSHAN_COUNTER_F_INC_NO_OVERLAP(file->file_record,
tm1, tm2, file->last_meta_end, POSIX_F_META_TIME);
posix_file_close_fd(fd); posix_file_close_fd(fd);
} }
POSIX_UNLOCK(); POSIX_UNLOCK();
...@@ -588,8 +589,11 @@ int DARSHAN_DECL(close)(int fd) ...@@ -588,8 +589,11 @@ int DARSHAN_DECL(close)(int fd)
return(ret); return(ret);
} }
/* ***************************************************** */ /**********************************************************
* Internal functions for manipulating POSIX module state *
**********************************************************/
/* initialize internal POSIX module data structures and register with darshan-core */
static void posix_runtime_initialize() static void posix_runtime_initialize()
{ {
int mem_limit; int mem_limit;
...@@ -597,7 +601,7 @@ static void posix_runtime_initialize() ...@@ -597,7 +601,7 @@ static void posix_runtime_initialize()
{ {
.disable_instrumentation = &posix_disable_instrumentation, .disable_instrumentation = &posix_disable_instrumentation,
.prepare_for_reduction = &posix_prepare_for_reduction, .prepare_for_reduction = &posix_prepare_for_reduction,
.record_reduction_op = &posix_record_reduction_op, .record_reduction_op = NULL,//&posix_record_reduction_op,
.get_output_data = &posix_get_output_data, .get_output_data = &posix_get_output_data,
.shutdown = &posix_shutdown .shutdown = &posix_shutdown
}; };
...@@ -648,6 +652,7 @@ static void posix_runtime_initialize() ...@@ -648,6 +652,7 @@ static void posix_runtime_initialize()
return; return;
} }
/* get a POSIX file record for the given file path */
static struct posix_file_runtime* posix_file_by_name(const char *name) static struct posix_file_runtime* posix_file_by_name(const char *name)
{ {
struct posix_file_runtime *file = NULL; struct posix_file_runtime *file = NULL;
...@@ -696,6 +701,9 @@ static struct posix_file_runtime* posix_file_by_name(const char *name) ...@@ -696,6 +701,9 @@ static struct posix_file_runtime* posix_file_by_name(const char *name)
return(file); return(file);
} }
/* get a POSIX file record for the given file path, and also create a
* reference structure using the returned file descriptor
*/
static struct posix_file_runtime* posix_file_by_name_setfd(const char* name, int fd) static struct posix_file_runtime* posix_file_by_name_setfd(const char* name, int fd)
{ {
struct posix_file_runtime* file; struct posix_file_runtime* file;
...@@ -736,6 +744,7 @@ static struct posix_file_runtime* posix_file_by_name_setfd(const char* name, int ...@@ -736,6 +744,7 @@ static struct posix_file_runtime* posix_file_by_name_setfd(const char* name, int
return(file); return(file);
} }
/* get a POSIX file record for the given file descriptor */
static struct posix_file_runtime* posix_file_by_fd(int fd) static struct posix_file_runtime* posix_file_by_fd(int fd)
{ {
struct posix_file_runtime_ref* ref; struct posix_file_runtime_ref* ref;
...@@ -751,6 +760,7 @@ static struct posix_file_runtime* posix_file_by_fd(int fd) ...@@ -751,6 +760,7 @@ static struct posix_file_runtime* posix_file_by_fd(int fd)
return(NULL); return(NULL);
} }
/* free up reference data structures for the given file descriptor */
static void posix_file_close_fd(int fd) static void posix_file_close_fd(int fd)
{ {
struct posix_file_runtime_ref* ref; struct posix_file_runtime_ref* ref;
...@@ -770,6 +780,7 @@ static void posix_file_close_fd(int fd) ...@@ -770,6 +780,7 @@ static void posix_file_close_fd(int fd)
return; return;
} }
/* compare function for sorting file records by descending rank */
static int posix_file_compare(const void* a, const void* b) static int posix_file_compare(const void* a, const void* b)