From: Jim Warner Date: Sat, 17 Sep 2016 09:44:44 +0000 (-0500) Subject: library: add priming read at 'new' time X-Git-Tag: v4.0.0~768 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a2b62c7793f5f6865eec56a6f996e55495725bf;p=procps-ng library: add priming read at 'new' time A priming read at 'new' time in that module was important so that permission problems are detected early. Plus, it also had the potential of making delta values valid when 'get' or 'select' were first called. It is for that latter reason that such a read was also incorporated in the module 'new' function. No other module, however, employed such priming reads. This patch just brings those potential benefits to all of our other newlib modules with the exception of that guy. That module is, of necessity, sufficiently different from those others to justify such exclusion. Not only are there precious few DELTA enums in , but the costs of a priming read would be much greater. [ otherwise, these newly added priming reads have no ] [ measurable negative impact on performance/timings. ] Signed-off-by: Jim Warner --- diff --git a/proc/meminfo.c b/proc/meminfo.c index 0882a493..53d4e46f 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -749,6 +749,14 @@ PROCPS_EXPORT int procps_meminfo_new ( return rc; } + /* do a priming read here for the following potential benefits: | + 1) ensure there will be no problems with subsequent access | + 2) make delta results potentially useful, even if 1st time | */ + if ((rc = meminfo_read_failed(p))) { + procps_meminfo_unref(&p); + return rc; + } + *info = p; return 0; } // end: procps_meminfo_new diff --git a/proc/stat.c b/proc/stat.c index d81f817e..141873c7 100644 --- a/proc/stat.c +++ b/proc/stat.c @@ -828,6 +828,7 @@ PROCPS_EXPORT int procps_stat_new ( struct stat_info **info) { struct stat_info *p; + int rc; if (info == NULL || *info != NULL) return -EINVAL; @@ -869,6 +870,14 @@ PROCPS_EXPORT int procps_stat_new ( #endif #endif + /* do a priming read here for the following potential benefits: | + 1) ensure there will be no problems with subsequent access | + 2) make delta results potentially useful, even if 1st time | */ + if ((rc = stat_read_failed(p))) { + procps_stat_unref(&p); + return rc; + } + *info = p; return 0; } // end :procps_stat_new diff --git a/proc/vmstat.c b/proc/vmstat.c index 62d480eb..71b374b5 100644 --- a/proc/vmstat.c +++ b/proc/vmstat.c @@ -1133,6 +1133,14 @@ PROCPS_EXPORT int procps_vmstat_new ( return rc; } + /* do a priming read here for the following potential benefits: | + 1) ensure there will be no problems with subsequent access | + 2) make delta results potentially useful, even if 1st time | */ + if ((rc = vmstat_read_failed(p))) { + procps_vmstat_unref(&p); + return rc; + } + *info = p; return 0; } // end: procps_vmstat_new