summaryrefslogtreecommitdiffstats
path: root/src/H5private.h
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2021-11-08 21:08:07 (GMT)
committerGitHub <noreply@github.com>2021-11-08 21:08:07 (GMT)
commita0445d806c480529e127d79fda257aa8bf70d594 (patch)
tree19cad85a7c0b2b1afdcbab4b913c25f6e9f62d55 /src/H5private.h
parente82d39ca0e4122facb87fe784e58a77f41a8814f (diff)
downloadhdf5-a0445d806c480529e127d79fda257aa8bf70d594.zip
hdf5-a0445d806c480529e127d79fda257aa8bf70d594.tar.gz
hdf5-a0445d806c480529e127d79fda257aa8bf70d594.tar.bz2
Simplify function enter macros for performance benefits (#1024)
* Take a stab at using constructors to initialize instead of function-entry macros. This is a work in progress. It's good enough to run `many_dsets`. * Committing clang-format changes * Add the `many_dsets` benchmark and some scripts I used on jelly for setting up the build/test environment and for recording/flame-graphing profiles. * Committing clang-format changes * Change my Makefile and environment script to work both on jelly and on mayll (and probably on Summit). * Disable clang-format "fix." * Replace the `if (!H5_TERM_GLOBAL)` test in each FUNC_ENTER_ macro with `if (true)`. * Fix bad grammar in a comment. * Instead of labeling the H5*__init_package routines constructors, fold each into an initialization routine, H5*_init(), and call each of the H5*_init() routines. Call most of the H5*_init() routines from H5_init_library() in an explicit order that I found out earlier by instrumenting each __init_package routine and running the library tests. Roll H5FD*__init_package routines into H5FD*_init() routines. This change ends just-in-time initialization of package dependencies by package initializers. Don't track in per-package variables (H5_PKG_INIT_VAR) whether each package has been initialized. Instead, track in a single library variable whether the whole library is initialized or not. Drive the initialization of packages by H5_init_library() with a table of initializer routines. Also drive the termination of packages by H5_term_library() with a table. Perform initialization as needed from FUNC_ENTER_API_INIT(err). This basically restores the old behavior of that macro. Delete a bunch of #definitions in H5private.h that have fallen out of use with these changes. * Committing clang-format changes * Undo the bad auto-formatting that appears to have occurred in spite of my disabling it. Bracket some code in /* clang-format off */ /* clang-format on */ to prevent a recurrence. * Remove a diagnostic abort(). * Fix a logic error: print a comma between every package terminator run, and don't print an initial comma. * Complete the changes I started in H5_term_library() that undo the bad auto-formatting. Stop tracking whether package "tops" were initialized in per-package variables H5*_top_package_initialize_s. H5_term_library() takes care of that for them. Remove H5R_top_term_package() and H5R_term_package(), they don't do anything. * Committing clang-format changes * NFCI. Simplify macro text: replace `if (true) {` with `{`. * Fix formatting and suppress clang-format on a longer range. * Quiet some unused label, unused variable complaints that cropped up after I simplified the FUNC_ENTER_ macros for the sake of performance. * Committing clang-format changes * Delete some programs and scripts that don't belong in the pull request. * Use the right function-entry macro. * Use a sensible format and disable auto-formatting. * Stop calling do-nothing initializer H5FS_init(). Delete it. * Document what changes to make if the default VFD changes. * While I am here, change an `await_prior` flag on the terminator table to `true` to match the previous, non-table-driven code that was here. Found the oversight making the following changes: NFCI: insert an empty line and copy over slightly-edited comments from the previous version, where those comments still correctly explained how library termination operated. * NFCI: lower a staircase. * Replace every occurrence of FUNC_ENTER_NOAPI_INIT(...) with H5_PUSH_FUNC since that is all that that macro does any more. Quiet a bunch of new warnings by changing FUNC_ENTER_NOAPI(...) to FUNC_ENTER_NOAPI_NOERR and removing disused `done:` labels. * NFCI: add curly braces around a multiline statement. * Quiet a signed/unsigned comparison warning. * Add some documentation about library initialization and shutdown. * Make sure that the library is initialized, or else that initialization is already underway, before performing any VFD's initialization. * Committing clang-format changes * Committing clang-format changes * Reduce differences from `develop` branch. * Always initialize `tot_init`. * Committing clang-format changes * Fix typo: H5SL_init initializes skip lists, not VOL. * Remove H5_TERM_GLOBAL test in H5T_init. H5T_init was unusual in that it tested H5_TERM_GLOBAL and exited early if it was set. No other module initializers did that, and I cannot find any reason that should be necessary. Tests still pass when I remove it, so away it goes. * Use HD prefix. * Add function header comments. * Drop the intermediate variable, it's only used once. * Extract subroutine `H5FDperform_init(hid_t (*init)(void))` that initializes the library, if necessary, before calling its VFD-initializer argument. Use H5FDperform_init in the definition of the symbols H5FD_<vfd> (e.g., H5FD_SEC2), which may be evaluated before the library is initialized, like so: ``` ``` I implement H5FDperform_init in its own source file, H5FDperform.c, and exclude that file from trace processing because the `bin/trace` cannot deal with the function-pointer type. * Straggler from last: add new source file src/H5FDperform.c. * Committing clang-format changes * Add a missing file to the MANIFEST. * Switch to FUNC_ENTER_API_NOINIT in H5FDperform_init() and hbool_t in H5_term_library(). Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src/H5private.h')
-rw-r--r--src/H5private.h109
1 files changed, 27 insertions, 82 deletions
diff --git a/src/H5private.h b/src/H5private.h
index 792cf00..1c3d358 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -99,8 +99,14 @@
#include <dirent.h>
#endif
-/* Define the default VFD for this platform.
- * Since the removal of the Windows VFD, this is sec2 for all platforms.
+/* Define the default VFD for this platform. Since the removal of the
+ * Windows VFD, this is sec2 for all platforms.
+ *
+ * Note well: if you change the default, then be sure to change
+ * H5_default_vfd_init() to call that default's initializer. Also,
+ * make sure that the initializer for each *non*-default VFD calls
+ * H5_init_library(); also, make sure that the initializer for default
+ * VFD does *not* call H5_init_library().
*/
#define H5_DEFAULT_VFD H5FD_SEC2
@@ -2016,33 +2022,6 @@ extern hbool_t H5_libterm_g; /* Is the library being shutdown? */
extern hbool_t H5_MPEinit_g; /* Has the MPE Library been initialized? */
#endif
-/* Macros for referencing package initialization symbols */
-#define H5_PACKAGE_INIT_VAR(x) H5_GLUE(x, _init_g)
-#define H5_PACKAGE_INIT_FUNC(x) H5_GLUE(x, __init_package)
-
-/* Macros for defining package initialization routines */
-#ifdef H5_MY_PKG
-#define H5_PKG_INIT_VAR H5_PACKAGE_INIT_VAR(H5_MY_PKG)
-#define H5_PKG_INIT_FUNC H5_PACKAGE_INIT_FUNC(H5_MY_PKG)
-#define H5_PACKAGE_YES_INIT(err) \
- /* Initialize this interface or bust */ \
- if (!H5_PKG_INIT_VAR && !H5_TERM_GLOBAL) { \
- H5_PKG_INIT_VAR = TRUE; \
- if (H5_PKG_INIT_FUNC() < 0) { \
- H5_PKG_INIT_VAR = FALSE; \
- HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, err, "interface initialization failed") \
- } \
- }
-#define H5_PACKAGE_NO_INIT(err) \
- /* Initialize this interface or bust */ \
- if (!H5_PKG_INIT_VAR && !H5_TERM_GLOBAL) \
- H5_PKG_INIT_VAR = TRUE;
-#define H5_PACKAGE_INIT(pkg_init, err) H5_GLUE3(H5_PACKAGE_, pkg_init, _INIT)(err)
-#else /* H5_MY_PKG */
-#define H5_PKG_INIT_VAR (TRUE)
-#define H5_PACKAGE_INIT(pkg_init, err)
-#endif /* H5_MY_PKG */
-
/* Forward declaration of H5CXpush() / H5CXpop() */
/* (Including H5CXprivate.h creates bad circular dependencies - QAK, 3/18/2018) */
H5_DLL herr_t H5CX_push(void);
@@ -2098,10 +2077,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
if (!H5_INIT_GLOBAL && !H5_TERM_GLOBAL) { \
if (H5_init_library() < 0) \
HGOTO_ERROR(H5E_FUNC, H5E_CANTINIT, err, "library initialization failed") \
- } /* end if */ \
- \
- /* Initialize the package, if appropriate */ \
- H5_PACKAGE_INIT(H5_MY_PKG_INIT, err)
+ }
#define FUNC_ENTER_API_PUSH(err) \
/* Push the name of this function on the function stack */ \
@@ -2210,27 +2186,19 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
FUNC_ENTER_COMMON_NOERR(H5_IS_API(__func__)); \
{
-/* Note: this macro only works when there's _no_ interface initialization routine for the module */
-#define FUNC_ENTER_NOAPI_INIT(err) \
- /* Initialize the package, if appropriate */ \
- H5_PACKAGE_INIT(H5_MY_PKG_INIT, err) \
- \
- /* Push the name of this function on the function stack */ \
- H5_PUSH_FUNC
-
/* Use this macro for all "normal" non-API functions */
#define FUNC_ENTER_NOAPI(err) \
{ \
FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \
- FUNC_ENTER_NOAPI_INIT(err) \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ H5_PUSH_FUNC \
+ {
/* Use this macro for all non-API functions, which propagate errors, but don't issue them */
#define FUNC_ENTER_NOAPI_NOERR \
{ \
FUNC_ENTER_COMMON_NOERR(!H5_IS_API(__func__)); \
- FUNC_ENTER_NOAPI_INIT(-) \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ H5_PUSH_FUNC \
+ {
/*
* Use this macro for non-API functions which fall into these categories:
@@ -2244,7 +2212,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
{ \
FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*
* Use this macro for non-API functions which fall into these categories:
@@ -2259,7 +2227,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
{ \
FUNC_ENTER_COMMON_NOERR(!H5_IS_API(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*
* Use this macro for non-API functions which fall into these categories:
@@ -2271,9 +2239,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
{ \
FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \
\
- /* Initialize the package, if appropriate */ \
- H5_PACKAGE_INIT(H5_MY_PKG_INIT, err) \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*
* Use this macro for non-API functions which fall into these categories:
@@ -2287,7 +2253,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
#define FUNC_ENTER_NOAPI_NOERR_NOFS \
{ \
FUNC_ENTER_COMMON_NOERR(!H5_IS_API(__func__)); \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*
* Use this macro for non-API functions that shouldn't perform _any_ initialization
@@ -2309,8 +2275,8 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
\
FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \
H5AC_tag(tag, &prev_tag); \
- FUNC_ENTER_NOAPI_INIT(err) \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ H5_PUSH_FUNC \
+ {
#define FUNC_ENTER_NOAPI_NOINIT_TAG(tag) \
{ \
@@ -2319,21 +2285,21 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
FUNC_ENTER_COMMON(!H5_IS_API(__func__)); \
H5AC_tag(tag, &prev_tag); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use this macro for all "normal" package-level functions */
#define FUNC_ENTER_PACKAGE \
{ \
FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use this macro for package-level functions which propgate errors, but don't issue them */
#define FUNC_ENTER_PACKAGE_NOERR \
{ \
FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use the following macro as replacement for the FUNC_ENTER_PACKAGE
* macro when the function needs to set up a metadata tag. */
@@ -2344,28 +2310,28 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \
H5AC_tag(tag, &prev_tag); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use this macro for all "normal" staticly-scoped functions */
#define FUNC_ENTER_STATIC \
{ \
FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use this macro for staticly-scoped functions which propgate errors, but don't issue them */
#define FUNC_ENTER_STATIC_NOERR \
{ \
FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(__func__)); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/* Use this macro for staticly-scoped functions which propgate errors, but don't issue them */
/* And that shouldn't push their name on the function stack */
#define FUNC_ENTER_STATIC_NOERR_NOFS \
{ \
FUNC_ENTER_COMMON_NOERR(H5_IS_PKG(__func__)); \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*
* Use this macro for non-API functions that shouldn't perform _any_ initialization
@@ -2387,7 +2353,7 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
FUNC_ENTER_COMMON(H5_IS_PKG(__func__)); \
H5AC_tag(tag, &prev_tag); \
H5_PUSH_FUNC \
- if (H5_PKG_INIT_VAR || !H5_TERM_GLOBAL) {
+ {
/*-------------------------------------------------------------------------
* Purpose: Register function exit for code profiling. This should be
@@ -2516,27 +2482,6 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props);
return (ret_value); \
} /*end scope from beginning of FUNC_ENTER*/
-/* Macros to declare package initialization function, if a package initialization routine is defined */
-#ifdef H5_PKG_SINGLE_SOURCE
-#define H5_PKG_DECLARE_YES_FUNC(pkg) static herr_t H5_PACKAGE_INIT_FUNC(pkg)(void);
-#else
-#define H5_PKG_DECLARE_YES_FUNC(pkg) extern herr_t H5_PACKAGE_INIT_FUNC(pkg)(void);
-#endif
-#define H5_PKG_DECLARE_NO_FUNC(pkg)
-
-/* Declare package initialization symbols (if in a package) */
-#ifdef H5_PKG_SINGLE_SOURCE
-#define H5_PKG_DECLARE_VAR(pkg) static hbool_t H5_PACKAGE_INIT_VAR(pkg);
-#else
-#define H5_PKG_DECLARE_VAR(pkg) extern hbool_t H5_PACKAGE_INIT_VAR(pkg);
-#endif
-#define H5_PKG_DECLARE_FUNC(pkg_init, pkg) H5_GLUE3(H5_PKG_DECLARE_, pkg_init, _FUNC)(pkg)
-
-#ifdef H5_MY_PKG
-H5_PKG_DECLARE_VAR(H5_MY_PKG)
-H5_PKG_DECLARE_FUNC(H5_MY_PKG_INIT, H5_MY_PKG)
-#endif
-
/* Macro to begin/end tagging (when FUNC_ENTER_*TAG macros are insufficient).
* Make sure to use HGOTO_ERROR_TAG and HGOTO_DONE_TAG between these macros! */
#define H5_BEGIN_TAG(tag) \