library: revised sort + new allocate APIs for slabinfo

With this patch, we will be close to an implementation
which will be needed when accommodating tasks/threads.
The following explanation was from an earlier message:

The slabtop requirements are similar to those of PIDs.
One must accommodate the variable number of slab nodes
(PIDs) while also accepting different data (char * and
unsigned long). Furthermore, some generalized means to
sort all that acquired stuff must somehow be provided.
------------------------------------------------------

So this patch expands the API to provide dynamic chain
allocation plus allow sorting of those dynamic chains.
While specific to slab needs (nodes, not global stats)
it is not too early to begin to think of newlib chains
as the opaque replacement for a deprecated old proc_t.

Better yet, any newlib chain is inherently variable in
length, something the old proc_t couldn't claim to be.
Of course, as we get to PIDs we'll want to grow/shrink
chains (easily accomplished with a special item enum).
And we'll want to grow/shrink those **head arrays too.
But these minor details don't seem insurmountable now.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2015-07-11 00:00:00 -05:00
committed by Craig Small
parent 4dea69067e
commit 5c3542c4e1
3 changed files with 559 additions and 359 deletions

View File

@@ -1,25 +1,46 @@
/*
* slab.h - slab related functions for libproc
*
* Copyright (C) 1998-2005 Albert Cahalan
* Copyright (C) 2015 Craig Small <csmall@enc.com.au>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _PROC_SLAB_H
#define _PROC_SLAB_H
__BEGIN_DECLS
enum procps_slabinfo_stat {
PROCPS_SLABINFO_OBJS,
PROCPS_SLABINFO_AOBJS,
PROCPS_SLABINFO_PAGES,
PROCPS_SLABINFO_SLABS,
PROCPS_SLABINFO_ASLABS,
PROCPS_SLABINFO_CACHES,
PROCPS_SLABINFO_ACACHES,
PROCPS_SLABINFO_SIZE_AVG,
PROCPS_SLABINFO_SIZE_MIN,
PROCPS_SLABINFO_SIZE_MAX,
PROCPS_SLABINFO_SIZE_TOTAL,
PROCPS_SLABINFO_SIZE_ACTIVE,
enum slabs_item {
PROCPS_SLABS_OBJS,
PROCPS_SLABS_AOBJS,
PROCPS_SLABS_PAGES,
PROCPS_SLABS_SLABS,
PROCPS_SLABS_ASLABS,
PROCPS_SLABS_CACHES,
PROCPS_SLABS_ACACHES,
PROCPS_SLABS_SIZE_AVG,
PROCPS_SLABS_SIZE_MIN,
PROCPS_SLABS_SIZE_MAX,
PROCPS_SLABS_SIZE_TOTAL,
PROCPS_SLABS_SIZE_ACTIVE,
PROCPS_SLABS_noop
};
enum procps_slabinfo_nodeitem {
PROCPS_SLABNODE_NAME,
enum slabnode_item {
PROCPS_SLABNODE_SIZE,
PROCPS_SLABNODE_OBJS,
PROCPS_SLABNODE_AOBJS,
@@ -28,22 +49,30 @@ enum procps_slabinfo_nodeitem {
PROCPS_SLABNODE_PAGES_PER_SLAB,
PROCPS_SLABNODE_SLABS,
PROCPS_SLABNODE_ASLABS,
PROCPS_SLABNODE_USE
PROCPS_SLABNODE_USE,
PROCPS_SLABNODE_NAME,
PROCPS_SLABNODE_noop
};
struct procps_slabinfo;
struct procps_slabnode;
struct procps_slabinfo_result {
enum procps_slabinfo_stat item;
struct slabs_result {
enum slabs_item item;
unsigned long result;
struct procps_slabinfo_result *next;
struct slabs_result *next;
};
struct procps_slabnode_result {
enum procps_slabinfo_nodeitem item;
unsigned long result;
struct procps_slabnode_result *next;
struct slabnode_chain {
struct slabnode_result *head;
};
struct slabnode_result {
enum slabnode_item item;
union {
unsigned long num;
char *str;
} result;
struct slabnode_result *next;
};
int procps_slabinfo_new (struct procps_slabinfo **info);
@@ -52,26 +81,58 @@ int procps_slabinfo_read (struct procps_slabinfo *info);
int procps_slabinfo_ref (struct procps_slabinfo *info);
int procps_slabinfo_unref (struct procps_slabinfo **info);
unsigned long procps_slabinfo_stat_get (struct procps_slabinfo *info,
enum procps_slabinfo_stat item);
unsigned long procps_slabs_get (
struct procps_slabinfo *info,
enum slabs_item item);
int procps_slabinfo_stat_getchain (struct procps_slabinfo *info,
struct procps_slabinfo_result *result);
int procps_slabs_getchain (
struct procps_slabinfo *info,
struct slabs_result *these);
int procps_slabinfo_sort( struct procps_slabinfo *info,
const enum procps_slabinfo_nodeitem item);
int procps_slabnode_count (const struct procps_slabinfo *info);
int procps_slabinfo_node_count(const struct procps_slabinfo *info);
const char *procps_slabnode_getname (
struct procps_slabinfo *info,
int nodeid);
int procps_slabinfo_node_get (struct procps_slabinfo *info,
struct procps_slabnode **node);
int procps_slabinfo_node_getchain (struct procps_slabinfo *info,
struct procps_slabnode_result *result,
int nodeid);
unsigned long procps_slabnode_get (
struct procps_slabinfo *info,
enum slabnode_item item,
int nodeid);
int procps_slabnode_getchain (
struct procps_slabinfo *info,
struct slabnode_result *these,
int nodeid);
int procps_slabnode_chain_fill (
struct procps_slabinfo *info,
struct slabnode_chain *chain,
int nodeid);
int procps_slabnode_chains_fill (
struct procps_slabinfo *info,
struct slabnode_chain **chains,
int maxchains);
struct slabnode_chain *procps_slabnode_chain_alloc (
struct procps_slabinfo *info,
int maxitems,
enum slabnode_item *items);
struct slabnode_chain **procps_slabnode_chains_alloc (
struct procps_slabinfo *info,
int maxchains,
int chain_extra,
int maxitems,
enum slabnode_item *items);
struct slabnode_chain **procps_slabnode_chains_sort (
struct procps_slabinfo *info,
struct slabnode_chain **chains,
int numchained,
enum slabnode_item sort);
char *procps_slabinfo_node_getname(struct procps_slabinfo *info,
int nodeid);
__END_DECLS
#endif /* _PROC_SLAB_H */