library: minimize the use of 'cleanup_stacks' routines
Some parts of our newlib implementation are the result of functions which have been propagated from module to module. In particular, those 'cleanup_stacks' routines are all similar & likely originated in the <pids> api. In that interface there was a need to free dynamically acquired memory before the result structure was reused to satisfy subsequent 'get', 'select' or 'reap' calls. This, in turn, led to a concept of 'dirty' stacks with the need to call one of two 'cleanup_stack' functions. None of the remaining interfaces deal with such memory yet they each had their own 'cleanup_stack' functions. Those functions were responsible for resetting each of the result unions to zero, excluding any 'noop' items. The bottom line is that for all interfaces, repetitive calls would require iterating through the stack(s) two separate times: once to 'cleanup' another to 'assign'. With this commit we will reduce iterations to just the 'assign' routine. A reset to zero will be accomplished in the 'extra' item set routine (which is the only one actually requiring any reset). All other items will be reinitialized automatically by a new current set value or upon reallocation when an items compliment changes. In the <pids> interface, any freeing of dynamic memory could have been accomplished by adding that 'freefunc' check to the 'assign' function. However, that requires an Item_table test with every item. Instead, we'll now satisfy such needs as the very first step in those set functions responsible for dynamically acquired memory. [ the <pids> api retains 2 'cleanup_stack' functions ] [ to accommodate stack(s) 'reset' & to serve 'unref' ] Lastly, all the 'itemize_stack' functions were tweaked by eliminating an unnecessary initialization of result unions. That objective was already accomplished by the calloc() in a 'stacks_alloc' function or the remaining 'cleanup_stack' routine found in the <pids> interface. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@ -203,7 +203,6 @@ struct stacks_extent {
|
||||
struct vmstat_info {
|
||||
int refcount;
|
||||
int vmstat_fd;
|
||||
int dirty_stacks;
|
||||
struct vmstat_hist hist;
|
||||
int numitems;
|
||||
enum vmstat_item *items;
|
||||
@ -224,8 +223,8 @@ struct vmstat_info {
|
||||
// delta assignment
|
||||
#define HST_set(e,x) setDECL(e) { R->result.sl_int = ( H->new . x - H->old. x ); }
|
||||
|
||||
setDECL(noop) { (void)R; (void)H; }
|
||||
setDECL(extra) { (void)R; (void)H; }
|
||||
setDECL(noop) { (void)R; (void)H; }
|
||||
setDECL(extra) { (void)H; R->result.ul_int = 0; }
|
||||
|
||||
REG_set(ALLOCSTALL_DMA, allocstall_dma)
|
||||
REG_set(ALLOCSTALL_DMA32, allocstall_dma32)
|
||||
@ -844,34 +843,6 @@ static inline void vmstat_assign_results (
|
||||
} // end: vmstat_assign_results
|
||||
|
||||
|
||||
static inline void vmstat_cleanup_stack (
|
||||
struct vmstat_result *this)
|
||||
{
|
||||
for (;;) {
|
||||
if (this->item >= VMSTAT_logical_end)
|
||||
break;
|
||||
if (this->item > VMSTAT_noop)
|
||||
this->result.ul_int = 0;
|
||||
++this;
|
||||
}
|
||||
} // end: vmstat_cleanup_stack
|
||||
|
||||
|
||||
static inline void vmstat_cleanup_stacks_all (
|
||||
struct vmstat_info *info)
|
||||
{
|
||||
struct stacks_extent *ext = info->extents;
|
||||
int i;
|
||||
|
||||
while (ext) {
|
||||
for (i = 0; ext->stacks[i]; i++)
|
||||
vmstat_cleanup_stack(ext->stacks[i]->head);
|
||||
ext = ext->next;
|
||||
};
|
||||
info->dirty_stacks = 0;
|
||||
} // end: vmstat_cleanup_stacks_all
|
||||
|
||||
|
||||
static void vmstat_extents_free_all (
|
||||
struct vmstat_info *info)
|
||||
{
|
||||
@ -893,7 +864,6 @@ static inline struct vmstat_result *vmstat_itemize_stack (
|
||||
|
||||
for (i = 0; i < depth; i++) {
|
||||
p->item = items[i];
|
||||
p->result.ul_int = 0;
|
||||
++p;
|
||||
}
|
||||
return p_sav;
|
||||
@ -1369,13 +1339,9 @@ PROCPS_EXPORT struct vmstat_stack *procps_vmstat_select (
|
||||
&& (!vmstat_stacks_alloc(info, 1)))
|
||||
return NULL;
|
||||
|
||||
if (info->dirty_stacks)
|
||||
vmstat_cleanup_stacks_all(info);
|
||||
|
||||
if (vmstat_read_failed(info))
|
||||
return NULL;
|
||||
vmstat_assign_results(info->extents->stacks[0], &info->hist);
|
||||
info->dirty_stacks = 1;
|
||||
|
||||
return info->extents->stacks[0];
|
||||
} // end: procps_vmstat_select
|
||||
|
Reference in New Issue
Block a user