1
1

Add the time_t datatype to the DSS

This commit was SVN r30700.
Этот коммит содержится в:
Ralph Castain 2014-02-12 19:37:21 +00:00
родитель 010a806a58
Коммит d0e8aeaee4
8 изменённых файлов: 146 добавлений и 13 удалений

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -18,7 +19,11 @@
*/ */
#include "opal_config.h" #include "opal_config.h"
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* for struct timeval */
#endif
#include "opal/dss/dss_internal.h" #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; 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 */ /* COMPARE FUNCTIONS FOR GENERIC OPAL TYPES */
/* OPAL_DATA_TYPE */ /* OPAL_DATA_TYPE */
int opal_dss_compare_dt(opal_data_type_t *value1, opal_data_type_t *value2, opal_data_type_t type) int opal_dss_compare_dt(opal_data_type_t *value1, opal_data_type_t *value2, opal_data_type_t type)

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * 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); datasize = sizeof(struct timeval);
break; break;
case OPAL_TIME:
datasize = sizeof(time_t);
break;
default: default:
return OPAL_ERR_UNKNOWN_DATA_TYPE; return OPAL_ERR_UNKNOWN_DATA_TYPE;
} }

Просмотреть файл

@ -11,6 +11,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -24,6 +25,10 @@
#include "opal_config.h" #include "opal_config.h"
#include "opal/constants.h" #include "opal/constants.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* for struct timeval */
#endif
#include "opal/class/opal_pointer_array.h" #include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss.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, int opal_dss_pack_timeval(opal_buffer_t *buffer, const void *src,
int32_t num_vals, opal_data_type_t type); 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 * 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, int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest,
int32_t *num_vals, opal_data_type_t type); 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 * 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_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 * 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_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_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_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);
/* /*

Просмотреть файл

@ -11,6 +11,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, 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$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -78,6 +79,14 @@ static void opal_value_destruct(opal_value_t* ptr)
if (NULL != ptr->key) { if (NULL != ptr->key) {
free(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, OBJ_CLASS_INSTANCE(opal_value_t,
opal_list_item_t, opal_list_item_t,
@ -546,7 +555,17 @@ int opal_dss_open(void)
"OPAL_TIMEVAL", &tmp))) { "OPAL_TIMEVAL", &tmp))) {
return rc; 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; opal_dss_initialized = true;
return OPAL_SUCCESS; return OPAL_SUCCESS;

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -24,7 +25,8 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/dss/dss_internal.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) opal_data_type_t type)
{ {
int rc; 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); 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, int opal_dss_pack_buffer(opal_buffer_t *buffer,
opal_data_type_t type) const void *src, int32_t num_vals,
opal_data_type_t type)
{ {
int rc; int rc;
opal_dss_type_info_t *info; 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; 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 */ /* PACK FUNCTIONS FOR GENERIC OPAL TYPES */

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -369,6 +370,30 @@ int opal_dss_print_float(char **output, char *prefix,
return OPAL_SUCCESS; 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, int opal_dss_print_timeval(char **output, char *prefix,
struct timeval *src, opal_data_type_t type) struct timeval *src, opal_data_type_t type)
{ {

Просмотреть файл

@ -12,6 +12,7 @@
* All rights reserved. * All rights reserved.
* Copyright (c) 2007-2011 Cisco Systems, Inc. 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) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -29,7 +30,7 @@
#include "opal_config.h" #include "opal_config.h"
#ifdef OPAL_HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> /* for struct timeval */ #include <sys/time.h> /* for struct timeval */
#endif #endif
@ -76,15 +77,16 @@ typedef uint64_t opal_identifier_t;
#define OPAL_FLOAT (opal_data_type_t) 16 #define OPAL_FLOAT (opal_data_type_t) 16
/* system types */ /* system types */
#define OPAL_TIMEVAL (opal_data_type_t) 17 #define OPAL_TIMEVAL (opal_data_type_t) 17
#define OPAL_TIME (opal_data_type_t) 18
/* OPAL types */ /* OPAL types */
#define OPAL_BYTE_OBJECT (opal_data_type_t) 18 /**< byte object structure */ #define OPAL_BYTE_OBJECT (opal_data_type_t) 19 /**< byte object structure */
#define OPAL_DATA_TYPE (opal_data_type_t) 19 /**< data type */ #define OPAL_DATA_TYPE (opal_data_type_t) 20 /**< data type */
#define OPAL_NULL (opal_data_type_t) 20 /**< don't interpret data type */ #define OPAL_NULL (opal_data_type_t) 21 /**< don't interpret data type */
#define OPAL_PSTAT (opal_data_type_t) 21 /**< process statistics */ #define OPAL_PSTAT (opal_data_type_t) 22 /**< process statistics */
#define OPAL_NODE_STAT (opal_data_type_t) 22 /**< node statistics */ #define OPAL_NODE_STAT (opal_data_type_t) 23 /**< node statistics */
#define OPAL_HWLOC_TOPO (opal_data_type_t) 23 /**< hwloc topology */ #define OPAL_HWLOC_TOPO (opal_data_type_t) 24 /**< hwloc topology */
#define OPAL_VALUE (opal_data_type_t) 24 /**< opal value structure */ #define OPAL_VALUE (opal_data_type_t) 25 /**< opal value structure */
#define OPAL_BUFFER (opal_data_type_t) 25 /**< pack the remaining contents of a buffer as an object */ #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 #define OPAL_DSS_ID_DYNAMIC (opal_data_type_t) 30

Просмотреть файл

@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -450,6 +451,34 @@ int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest,
return OPAL_SUCCESS; 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 */ /* UNPACK FUNCTIONS FOR GENERIC OPAL TYPES */