From d0e8aeaee48afcfaefb0fbae4b07710391e69200 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 12 Feb 2014 19:37:21 +0000 Subject: [PATCH] Add the time_t datatype to the DSS This commit was SVN r30700. --- opal/dss/dss_compare.c | 14 ++++++++++++++ opal/dss/dss_copy.c | 5 +++++ opal/dss/dss_internal.h | 14 ++++++++++++++ opal/dss/dss_open_close.c | 21 ++++++++++++++++++++- opal/dss/dss_pack.c | 31 ++++++++++++++++++++++++++++--- opal/dss/dss_print.c | 25 +++++++++++++++++++++++++ opal/dss/dss_types.h | 20 +++++++++++--------- opal/dss/dss_unpack.c | 29 +++++++++++++++++++++++++++++ 8 files changed, 146 insertions(+), 13 deletions(-) diff --git a/opal/dss/dss_compare.c b/opal/dss/dss_compare.c index 9482158aab..000b9a3dc6 100644 --- a/opal/dss/dss_compare.c +++ b/opal/dss/dss_compare.c @@ -10,6 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -18,7 +19,11 @@ */ #include "opal_config.h" + #include +#ifdef HAVE_SYS_TIME_H +#include /* for struct timeval */ +#endif #include "opal/dss/dss_internal.h" @@ -222,6 +227,15 @@ int opal_dss_compare_timeval(struct timeval *value1, struct timeval *value2, opa return OPAL_EQUAL; } +/* TIME */ +int opal_dss_compare_time(time_t *value1, time_t *value2, opal_data_type_t type) +{ + if (value1 > value2) return OPAL_VALUE1_GREATER; + if (value2 > value1) return OPAL_VALUE2_GREATER; + + return OPAL_EQUAL; +} + /* COMPARE FUNCTIONS FOR GENERIC OPAL TYPES */ /* OPAL_DATA_TYPE */ int opal_dss_compare_dt(opal_data_type_t *value1, opal_data_type_t *value2, opal_data_type_t type) diff --git a/opal/dss/dss_copy.c b/opal/dss/dss_copy.c index f5ee5c4467..d8bf33950c 100644 --- a/opal/dss/dss_copy.c +++ b/opal/dss/dss_copy.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -101,6 +102,10 @@ int opal_dss_std_copy(void **dest, void *src, opal_data_type_t type) datasize = sizeof(struct timeval); break; + case OPAL_TIME: + datasize = sizeof(time_t); + break; + default: return OPAL_ERR_UNKNOWN_DATA_TYPE; } diff --git a/opal/dss/dss_internal.h b/opal/dss/dss_internal.h index 3b73b8bd55..08d387e09d 100644 --- a/opal/dss/dss_internal.h +++ b/opal/dss/dss_internal.h @@ -11,6 +11,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -24,6 +25,10 @@ #include "opal_config.h" #include "opal/constants.h" +#ifdef HAVE_SYS_TIME_H +#include /* for struct timeval */ +#endif + #include "opal/class/opal_pointer_array.h" #include "opal/dss/dss.h" @@ -310,6 +315,9 @@ int opal_dss_pack_float(opal_buffer_t *buffer, const void *src, int opal_dss_pack_timeval(opal_buffer_t *buffer, const void *src, int32_t num_vals, opal_data_type_t type); +int opal_dss_pack_time(opal_buffer_t *buffer, const void *src, + int32_t num_vals, opal_data_type_t type); + /* * Internal unpack functions */ @@ -364,6 +372,9 @@ int opal_dss_unpack_float(opal_buffer_t *buffer, void *dest, int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest, int32_t *num_vals, opal_data_type_t type); +int opal_dss_unpack_time(opal_buffer_t *buffer, void *dest, + int32_t *num_vals, opal_data_type_t type); + /* * Internal copy functions */ @@ -436,6 +447,8 @@ int opal_dss_compare_float(float *value1, float *value2, opal_data_type_t type); int opal_dss_compare_timeval(struct timeval *value1, struct timeval *value2, opal_data_type_t type); +int opal_dss_compare_time(time_t *value1, time_t *value2, opal_data_type_t type); + /* * Internal print functions */ @@ -470,6 +483,7 @@ int opal_dss_print_value(char **output, char *prefix, opal_value_t *src, opal_da int opal_dss_print_buffer_contents(char **output, char *prefix, opal_buffer_t *src, opal_data_type_t type); int opal_dss_print_float(char **output, char *prefix, float *src, opal_data_type_t type); int opal_dss_print_timeval(char **output, char *prefix, struct timeval *src, opal_data_type_t type); +int opal_dss_print_time(char **output, char *prefix, time_t *src, opal_data_type_t type); /* diff --git a/opal/dss/dss_open_close.c b/opal/dss/dss_open_close.c index 3b507fbb81..dc17fb1362 100644 --- a/opal/dss/dss_open_close.c +++ b/opal/dss/dss_open_close.c @@ -11,6 +11,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -78,6 +79,14 @@ static void opal_value_destruct(opal_value_t* ptr) if (NULL != ptr->key) { free(ptr->key); } + if (OPAL_STRING == ptr->type && + NULL != ptr->data.string) { + free(ptr->data.string); + } + if (OPAL_BYTE_OBJECT == ptr->type && + NULL != ptr->data.bo.bytes) { + free(ptr->data.bo.bytes); + } } OBJ_CLASS_INSTANCE(opal_value_t, opal_list_item_t, @@ -546,7 +555,17 @@ int opal_dss_open(void) "OPAL_TIMEVAL", &tmp))) { return rc; } - /* All done */ + tmp = OPAL_TIME; + if (OPAL_SUCCESS != (rc = opal_dss.register_type(opal_dss_pack_time, + opal_dss_unpack_time, + (opal_dss_copy_fn_t)opal_dss_std_copy, + (opal_dss_compare_fn_t)opal_dss_compare_time, + (opal_dss_print_fn_t)opal_dss_print_time, + OPAL_DSS_UNSTRUCTURED, + "OPAL_TIME", &tmp))) { + return rc; + } + /* All done */ opal_dss_initialized = true; return OPAL_SUCCESS; diff --git a/opal/dss/dss_pack.c b/opal/dss/dss_pack.c index 595a4d3209..ea9b52477f 100644 --- a/opal/dss/dss_pack.c +++ b/opal/dss/dss_pack.c @@ -10,6 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -24,7 +25,8 @@ #include "opal/util/output.h" #include "opal/dss/dss_internal.h" -int opal_dss_pack(opal_buffer_t *buffer, const void *src, int32_t num_vals, +int opal_dss_pack(opal_buffer_t *buffer, + const void *src, int32_t num_vals, opal_data_type_t type) { int rc; @@ -48,8 +50,9 @@ int opal_dss_pack(opal_buffer_t *buffer, const void *src, int32_t num_vals, return opal_dss_pack_buffer(buffer, src, num_vals, type); } -int opal_dss_pack_buffer(opal_buffer_t *buffer, const void *src, int32_t num_vals, - opal_data_type_t type) +int opal_dss_pack_buffer(opal_buffer_t *buffer, + const void *src, int32_t num_vals, + opal_data_type_t type) { int rc; opal_dss_type_info_t *info; @@ -365,6 +368,28 @@ int opal_dss_pack_timeval(opal_buffer_t *buffer, const void *src, return OPAL_SUCCESS; } +/* TIME */ +int opal_dss_pack_time(opal_buffer_t *buffer, const void *src, + int32_t num_vals, opal_data_type_t type) +{ + int ret = OPAL_SUCCESS; + int32_t i; + time_t *ssrc = (time_t *)src; + uint64_t ui64; + + /* time_t is a system-dependent size, so cast it + * to uint64_t as a generic safe size + */ + for (i = 0; i < num_vals; ++i) { + ui64 = (uint64_t)ssrc[i]; + if (OPAL_SUCCESS != (ret = opal_dss_pack_int(buffer, &ui64, 1, OPAL_UINT64))) { + return ret; + } + } + + return OPAL_SUCCESS; +} + /* PACK FUNCTIONS FOR GENERIC OPAL TYPES */ diff --git a/opal/dss/dss_print.c b/opal/dss/dss_print.c index 93f94da83b..9d0309cc65 100644 --- a/opal/dss/dss_print.c +++ b/opal/dss/dss_print.c @@ -10,6 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -369,6 +370,30 @@ int opal_dss_print_float(char **output, char *prefix, return OPAL_SUCCESS; } +int opal_dss_print_time(char **output, char *prefix, + time_t *src, opal_data_type_t type) +{ + char *prefx; + char *t; + + /* deal with NULL prefix */ + if (NULL == prefix) asprintf(&prefx, " "); + else prefx = prefix; + + /* if src is NULL, just print data type and return */ + if (NULL == src) { + asprintf(output, "%sData type: OPAL_TIME\tValue: NULL pointer", prefx); + return OPAL_SUCCESS; + } + + t = ctime(src); + t[strlen(t)-1] = '\0'; // remove trailing newline + + asprintf(output, "%sData type: OPAL_TIME\tValue: %s", prefx, t); + + return OPAL_SUCCESS; +} + int opal_dss_print_timeval(char **output, char *prefix, struct timeval *src, opal_data_type_t type) { diff --git a/opal/dss/dss_types.h b/opal/dss/dss_types.h index 25048bd2d9..031bdafb35 100644 --- a/opal/dss/dss_types.h +++ b/opal/dss/dss_types.h @@ -12,6 +12,7 @@ * All rights reserved. * Copyright (c) 2007-2011 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -29,7 +30,7 @@ #include "opal_config.h" -#ifdef OPAL_HAVE_SYS_TIME_H +#ifdef HAVE_SYS_TIME_H #include /* for struct timeval */ #endif @@ -76,15 +77,16 @@ typedef uint64_t opal_identifier_t; #define OPAL_FLOAT (opal_data_type_t) 16 /* system types */ #define OPAL_TIMEVAL (opal_data_type_t) 17 +#define OPAL_TIME (opal_data_type_t) 18 /* OPAL types */ -#define OPAL_BYTE_OBJECT (opal_data_type_t) 18 /**< byte object structure */ -#define OPAL_DATA_TYPE (opal_data_type_t) 19 /**< data type */ -#define OPAL_NULL (opal_data_type_t) 20 /**< don't interpret data type */ -#define OPAL_PSTAT (opal_data_type_t) 21 /**< process statistics */ -#define OPAL_NODE_STAT (opal_data_type_t) 22 /**< node statistics */ -#define OPAL_HWLOC_TOPO (opal_data_type_t) 23 /**< hwloc topology */ -#define OPAL_VALUE (opal_data_type_t) 24 /**< opal value structure */ -#define OPAL_BUFFER (opal_data_type_t) 25 /**< pack the remaining contents of a buffer as an object */ +#define OPAL_BYTE_OBJECT (opal_data_type_t) 19 /**< byte object structure */ +#define OPAL_DATA_TYPE (opal_data_type_t) 20 /**< data type */ +#define OPAL_NULL (opal_data_type_t) 21 /**< don't interpret data type */ +#define OPAL_PSTAT (opal_data_type_t) 22 /**< process statistics */ +#define OPAL_NODE_STAT (opal_data_type_t) 23 /**< node statistics */ +#define OPAL_HWLOC_TOPO (opal_data_type_t) 24 /**< hwloc topology */ +#define OPAL_VALUE (opal_data_type_t) 25 /**< opal value structure */ +#define OPAL_BUFFER (opal_data_type_t) 26 /**< pack the remaining contents of a buffer as an object */ #define OPAL_DSS_ID_DYNAMIC (opal_data_type_t) 30 diff --git a/opal/dss/dss_unpack.c b/opal/dss/dss_unpack.c index 3f3c4a1d34..d0a69baa71 100644 --- a/opal/dss/dss_unpack.c +++ b/opal/dss/dss_unpack.c @@ -10,6 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. + * Copyright (c) 2014 Intel, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -450,6 +451,34 @@ int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest, return OPAL_SUCCESS; } +int opal_dss_unpack_time(opal_buffer_t *buffer, void *dest, + int32_t *num_vals, opal_data_type_t type) +{ + int32_t i, n; + time_t *desttmp = (time_t *) dest; + int ret; + uint64_t ui64; + + /* time_t is a system-dependent size, so cast it + * to uint64_t as a generic safe size + */ + + OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_time * %d\n", (int)*num_vals ) ); + /* check to see if there's enough data in buffer */ + if (opal_dss_too_small(buffer, (*num_vals)*(sizeof(uint64_t)))) { + return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER; + } + + /* unpack the data */ + for (i = 0; i < (*num_vals); ++i) { + n=1; + if (OPAL_SUCCESS != (ret = opal_dss_unpack_int64(buffer, &ui64, &n, OPAL_UINT64))) { + return ret; + } + desttmp[i] = (time_t)ui64; + } + return OPAL_SUCCESS; +} /* UNPACK FUNCTIONS FOR GENERIC OPAL TYPES */