[Darshan-commits] [Git][darshan/darshan][mmap-dev] 4 commits: fix compile error when mmap is disabled

Shane Snyder xgitlab at cels.anl.gov
Tue Jun 14 12:21:17 CDT 2016


Shane Snyder pushed to branch mmap-dev at darshan / darshan


Commits:
30c06099 by Shane Snyder at 2016-06-13T21:44:26+00:00
fix compile error when mmap is disabled

- - - - -
c407379a by Shane Snyder at 2016-06-14T16:08:02+00:00
bug fix in initializing static modules

- - - - -
fba89f42 by Shane Snyder at 2016-06-14T16:08:36+00:00
port bgq module over to new interface changes

- - - - -
246c491e by Shane Snyder at 2016-06-14T16:56:34+00:00
parser shouldn't abort with no-name records

- - - - -


4 changed files:

- darshan-bgq-log-format.h
- darshan-runtime/lib/darshan-bgq.c
- darshan-runtime/lib/darshan-core.c
- darshan-util/darshan-parser.c


Changes:

=====================================
darshan-bgq-log-format.h
=====================================
--- a/darshan-bgq-log-format.h
+++ b/darshan-bgq-log-format.h
@@ -68,7 +68,6 @@ enum darshan_bgq_f_indices
 struct darshan_bgq_record
 {
     struct darshan_base_record base_rec;
-    int alignment;
     int64_t counters[BGQ_NUM_INDICES];
     double fcounters[BGQ_F_NUM_INDICES];
 };


=====================================
darshan-runtime/lib/darshan-bgq.c
=====================================
--- a/darshan-runtime/lib/darshan-bgq.c
+++ b/darshan-runtime/lib/darshan-bgq.c
@@ -37,29 +37,20 @@
  */
 struct bgq_runtime
 {
-    struct darshan_bgq_record record;
-
-    /* TODO: we don't need the mmap and regular buffer, both */
-    struct darshan_bgq_record *mmap_buf;
+    struct darshan_bgq_record *record;
 };
 
 static struct bgq_runtime *bgq_runtime = NULL;
 static pthread_mutex_t bgq_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
-/* the instrumentation_disabled flag is used to toggle functions on/off */
-static int instrumentation_disabled = 0;
-
 /* my_rank indicates the MPI rank of this process */
 static int my_rank = -1;
-static int darshan_mem_alignment = 1;
 
 /* internal helper functions for the BGQ module */
 void bgq_runtime_initialize(void);
 
-/* forward declaration for module functions needed to interface with darshan-core */
-static void bgq_begin_shutdown(void);
-static void bgq_get_output_data(MPI_Comm mod_comm, darshan_record_id *shared_recs, int shared_rec_count, void **buffer, int *size);
-static void bgq_shutdown(void);
+/* forward declaration for shutdown function needed to interface with darshan-core */
+static void bgq_shutdown(MPI_Comm mod_comm, darshan_record_id *shared_recs, int shared_rec_count, void **buffer, int *size);
 
 /* macros for obtaining/releasing the BGQ module lock */
 #define BGQ_LOCK() pthread_mutex_lock(&bgq_runtime_mutex)
@@ -68,7 +59,7 @@ static void bgq_shutdown(void);
 /*
  * Function which updates all the counter data
  */
-static void capture(struct darshan_bgq_record *rec)
+static void capture(struct darshan_bgq_record *rec, darshan_record_id rec_id)
 {
     Personality_t person;
     int r;
@@ -96,7 +87,8 @@ static void capture(struct darshan_bgq_record *rec)
         rec->counters[BGQ_DDRPERNODE] = person.DDR_Config.DDRSizeMB;
     }
 
-    rec->rank = my_rank;
+    rec->base_rec.id = rec_id;
+    rec->base_rec.rank = my_rank;
     rec->fcounters[BGQ_F_TIMESTAMP] = darshan_core_wtime();
 
     return;
@@ -108,46 +100,33 @@ static void capture(struct darshan_bgq_record *rec)
 
 void bgq_runtime_initialize()
 {
-    /* struct of function pointers for interfacing with darshan-core */
-    struct darshan_module_funcs bgq_mod_fns =
-    {
-        .begin_shutdown = bgq_begin_shutdown,
-        .get_output_data = bgq_get_output_data,
-        .shutdown = bgq_shutdown
-    };
-    int mem_limit;
-    void *mmap_buf;
-    int mmap_buf_size;
-    char *recname = "darshan-internal-bgq";
+    int bgq_buf_size;
+    darshan_record_id rec_id;
 
     BGQ_LOCK();
 
-    /* don't do anything if already initialized or instrumenation is disabled */
-    if(bgq_runtime || instrumentation_disabled)
+    /* don't do anything if already initialized */
+    if(bgq_runtime)
+    {
+        BGQ_UNLOCK();
         return;
+    }
+
+    /* we just need to store one single record */
+    bgq_buf_size = sizeof(struct darshan_bgq_record);
 
     /* register the BG/Q module with the darshan-core component */
     darshan_core_register_module(
         DARSHAN_BGQ_MOD,
-        &bgq_mod_fns,
+        &bgq_shutdown,
+        &bgq_buf_size,
         &my_rank,
-        &mem_limit,
-        &mmap_buf,
-        &mmap_buf_size,
-        &darshan_mem_alignment);
-
-    /* return if no memory assigned by darshan-core */
-    if(mem_limit == 0)
-    {
-        instrumentation_disabled = 1;
-        BGQ_UNLOCK();
-        return;
-    }
+        NULL);
 
-    /* not enough memory to fit bgq module */
-    if (mem_limit < sizeof(*bgq_runtime))
+    /* not enough memory to fit bgq module record */
+    if(bgq_buf_size < sizeof(struct darshan_bgq_record))
     {
-        instrumentation_disabled = 1;
+        darshan_core_unregister_module(DARSHAN_BGQ_MOD);
         BGQ_UNLOCK();
         return;
     }
@@ -156,51 +135,31 @@ void bgq_runtime_initialize()
     bgq_runtime = malloc(sizeof(*bgq_runtime));
     if(!bgq_runtime)
     {
-        instrumentation_disabled = 1;
+        darshan_core_unregister_module(DARSHAN_BGQ_MOD);
         BGQ_UNLOCK();
         return;
     }
     memset(bgq_runtime, 0, sizeof(*bgq_runtime));
 
-    darshan_core_register_record(
-        recname,
-        strlen(recname),
+    rec_id = darshan_core_gen_record_id("darshan-bgq-record");
+
+    /* register the bgq file record with darshan-core */
+    bgq_runtime->record = darshan_core_register_record(
+        rec_id,
+        NULL,
         DARSHAN_BGQ_MOD,
-        1,
-        0,
-        &bgq_runtime->record.f_id,
-        &bgq_runtime->record.alignment);
-
-    /* if record is set to 0, darshan-core is out of space and will not
-     * track this record, so we should avoid tracking it, too
-     */
-    if(bgq_runtime->record.f_id == 0)
+        sizeof(struct darshan_bgq_record),
+        NULL);
+    if(!(bgq_runtime->record))
     {
-        instrumentation_disabled = 1;
+        darshan_core_unregister_module(DARSHAN_BGQ_MOD);
         free(bgq_runtime);
         bgq_runtime = NULL;
         BGQ_UNLOCK();
         return;
     }
 
-    capture(&bgq_runtime->record);
-
-    BGQ_UNLOCK();
-
-    return;
-}
-
-/* Perform any necessary steps prior to shutting down for the BGQ module. */
-static void bgq_begin_shutdown()
-{
-    BGQ_LOCK();
-
-    /* In general, we want to disable all wrappers while Darshan shuts down. 
-     * This is to avoid race conditions and ensure data consistency, as
-     * executing wrappers could potentially modify module state while Darshan
-     * is in the process of shutting down. 
-     */
-    instrumentation_disabled = 1;
+    capture(bgq_runtime->record, rec_id);
 
     BGQ_UNLOCK();
 
@@ -214,22 +173,25 @@ static int cmpr(const void *p1, const void *p2)
     return ((*a == *b) ?  0 : ((*a < *b) ? -1 : 1));
 }
 
+/********************************************************************************
+ * shutdown function exported by this module for coordinating with darshan-core *
+ ********************************************************************************/
+
 /* Pass output data for the BGQ module back to darshan-core to log to file. */
-static void bgq_get_output_data(
+static void bgq_shutdown(
     MPI_Comm mod_comm,
     darshan_record_id *shared_recs,
     int shared_rec_count,
     void **buffer,
     int *size)
 {
-    /* Just set the output buffer to point at the array of the BGQ module's
-     * I/O records, and set the output size according to the number of records
-     * currently being tracked.
-     */
     int nprocs;
     int result;
     uint64_t *ion_ids;
 
+    BGQ_LOCK();
+    assert(bgq_runtime);
+
     if (my_rank == 0)
     {
         DARSHAN_MPI_CALL(PMPI_Comm_size)(mod_comm, &nprocs);
@@ -238,12 +200,13 @@ static void bgq_get_output_data(
     }
     DARSHAN_MPI_CALL(PMPI_Bcast)(&result, 1, MPI_INT, 0, mod_comm);
 
-    if (bgq_runtime && result)
+    /* caclulate the number of I/O nodes */
+    if (result)
     {
         int i, found;
         uint64_t val;
 
-        DARSHAN_MPI_CALL(PMPI_Gather)(&bgq_runtime->record.counters[BGQ_INODES],
+        DARSHAN_MPI_CALL(PMPI_Gather)(&bgq_runtime->record->counters[BGQ_INODES],
                                       1,
                                       MPI_LONG_LONG_INT,
                                       ion_ids,
@@ -262,32 +225,21 @@ static void bgq_get_output_data(
                     found += 1;
                 }
             }
-            bgq_runtime->record.counters[BGQ_INODES] = found;
+            bgq_runtime->record->counters[BGQ_INODES] = found;
         }
     }
 
-    if ((bgq_runtime) && (my_rank == 0))
-    {
-        *buffer = &bgq_runtime->record;
-        *size = sizeof(struct darshan_bgq_record);
-    }
-    else
+    /* non-zero ranks throw out their BGQ record */
+    if (my_rank != 0)
     {
         *buffer = NULL;
         *size   = 0;
     }
 
-    return;
-}
+    free(bgq_runtime);
+    bgq_runtime = NULL;
 
-/* Shutdown the BGQ module by freeing up all data structures. */
-static void bgq_shutdown()
-{
-    if (bgq_runtime)
-    {
-        free(bgq_runtime);
-        bgq_runtime = NULL;
-    }
+    BGQ_UNLOCK();
 
     return;
 }


=====================================
darshan-runtime/lib/darshan-core.c
=====================================
--- a/darshan-runtime/lib/darshan-core.c
+++ b/darshan-runtime/lib/darshan-core.c
@@ -91,8 +91,10 @@ static struct mnt_data mnt_data_array[DARSHAN_MAX_MNTS];
 static int mnt_data_count = 0;
 
 /* prototypes for internal helper functions */
+#ifdef __DARSHAN_ENABLE_MMAP_LOGS
 static void *darshan_init_mmap_log(
     struct darshan_core_runtime* core, int jobid);
+#endif
 static void darshan_log_record_hints_and_ver(
     struct darshan_core_runtime* core);
 static void darshan_get_exe_and_mounts(
@@ -269,14 +271,6 @@ void darshan_core_initialize(int argc, char **argv)
             /* collect information about command line and mounted file systems */
             darshan_get_exe_and_mounts(init_core, argc, argv);
 
-            /* bootstrap any modules with static initialization routines */
-            i = 0;
-            while(mod_static_init_fns[i])
-            {
-                (*mod_static_init_fns[i])();
-                i++;
-            }
-
             darshan_core = init_core;
         }
     }
@@ -293,10 +287,21 @@ void darshan_core_initialize(int argc, char **argv)
         }
     }
 
-    /* if darshan was successfully initialized, set the global pointer */
+    /* if darshan was successfully initialized, set the global pointer and
+     * bootstrap any modules with static initialization routines
+     */
     if(init_core)
+    {
         darshan_core = init_core;
 
+        i = 0;
+        while(mod_static_init_fns[i])
+        {
+            (*mod_static_init_fns[i])();
+            i++;
+        }
+    }
+
     return;
 }
 
@@ -749,6 +754,7 @@ void darshan_core_shutdown()
 
 /* *********************************** */
 
+#ifdef __DARSHAN_ENABLE_MMAP_LOGS
 static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
 {
     int ret;
@@ -822,6 +828,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
 
     return(mmap_p);
 }
+#endif
 
 /* record any hints used to write the darshan log in the job data */
 static void darshan_log_record_hints_and_ver(struct darshan_core_runtime* core)


=====================================
darshan-util/darshan-parser.c
=====================================
--- a/darshan-util/darshan-parser.c
+++ b/darshan-util/darshan-parser.c
@@ -422,24 +422,35 @@ int main(int argc, char **argv)
         {
             char *mnt_pt = NULL;
             char *fs_type = NULL;
+            char *rec_name = NULL;
             hash_entry_t *hfile = NULL;
             base_rec = (struct darshan_base_record *)mod_buf;
 
             /* get the pathname for this record */
             HASH_FIND(hlink, name_hash, &(base_rec->id), sizeof(darshan_record_id), ref);
-            assert(ref);
 
-            /* get mount point and fs type associated with this record */
-            for(j=0; j<mount_count; j++)
+            if(ref)
             {
-                if(strncmp(mnt_data_array[j].mnt_path, ref->name_record->name,
-                    strlen(mnt_data_array[j].mnt_path)) == 0)
+                rec_name = ref->name_record->name;
+
+                /* get mount point and fs type associated with this record */
+                for(j=0; j<mount_count; j++)
                 {
-                    mnt_pt = mnt_data_array[j].mnt_path;
-                    fs_type = mnt_data_array[j].mnt_type;
-                    break;
+                    if(strncmp(mnt_data_array[j].mnt_path, rec_name,
+                        strlen(mnt_data_array[j].mnt_path)) == 0)
+                    {
+                        mnt_pt = mnt_data_array[j].mnt_path;
+                        fs_type = mnt_data_array[j].mnt_type;
+                        break;
+                    }
                 }
             }
+            else
+            {
+                if(i == DARSHAN_BGQ_MOD)
+                    rec_name = "darshan-bgq-record";
+            }
+
             if(!mnt_pt)
                 mnt_pt = "UNKNOWN";
             if(!fs_type)
@@ -448,7 +459,7 @@ int main(int argc, char **argv)
             if(mask & OPTION_BASE)
             {
                 /* print the corresponding module data for this record */
-                mod_logutils[i]->log_print_record(mod_buf, ref->name_record->name,
+                mod_logutils[i]->log_print_record(mod_buf, rec_name,
                     mnt_pt, fs_type, fd->mod_ver[i]);
             }
 



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/compare/d599c58343b1798d792153bef97e64ef28014265...246c491ea50b01ea3223704888c00a374bce13a0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160614/d7f9c1c8/attachment-0001.html>


More information about the Darshan-commits mailing list