summaryrefslogtreecommitdiffstats
path: root/cpukit/libblock
diff options
context:
space:
mode:
authorThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2007-01-21 18:25:31 +0000
committerThomas Doerfler <Thomas.Doerfler@embedded-brains.de>2007-01-21 18:25:31 +0000
commit3d14a451e96ba84901eae5c140adb403116439f7 (patch)
treecbcfb83a20a165927f3043b4ed4679b9914ddfd6 /cpukit/libblock
parent * mvme5500/Makefile.am, mvme5500/preinstall.am, (diff)
downloadrtems-3d14a451e96ba84901eae5c140adb403116439f7.tar.bz2
mproved gen5200 MSCAN driver
fixed synchronization bug between ata.c and bdbuf.c
Diffstat (limited to 'cpukit/libblock')
-rw-r--r--cpukit/libblock/Makefile.am3
-rw-r--r--cpukit/libblock/include/rtems/bdbuf.h44
-rw-r--r--cpukit/libblock/src/bdbuf.c100
-rw-r--r--cpukit/libblock/src/show_bdbuf.c904
4 files changed, 982 insertions, 69 deletions
diff --git a/cpukit/libblock/Makefile.am b/cpukit/libblock/Makefile.am
index 27301ce91a..5f88af25b0 100644
--- a/cpukit/libblock/Makefile.am
+++ b/cpukit/libblock/Makefile.am
@@ -8,7 +8,8 @@ include $(top_srcdir)/automake/compile.am
if !UNIX
noinst_LIBRARIES = libblock.a
libblock_a_SOURCES = src/bdbuf.c src/blkdev.c src/diskdevs.c src/ramdisk.c \
- src/ide_part_table.c include/rtems/bdbuf.h include/rtems/blkdev.h \
+ src/ide_part_table.c src/show_bdbuf.c \
+ include/rtems/bdbuf.h include/rtems/blkdev.h \
include/rtems/diskdevs.h include/rtems/ramdisk.h \
include/rtems/ide_part_table.h
endif
diff --git a/cpukit/libblock/include/rtems/bdbuf.h b/cpukit/libblock/include/rtems/bdbuf.h
index c966b2836e..f4308963dd 100644
--- a/cpukit/libblock/include/rtems/bdbuf.h
+++ b/cpukit/libblock/include/rtems/bdbuf.h
@@ -8,7 +8,7 @@
* Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
* Author: Victor V. Vengerov <vvv@oktet.ru>
*
- * @(#) $Id$
+ * @(#) bdbuf.h,v 1.9 2005/02/02 00:06:18 joel Exp
*/
#ifndef _RTEMS_BDBUF_H
@@ -74,6 +74,48 @@ typedef struct bdbuf_buffer {
} bdbuf_buffer;
+/*
+ * the following data structures are internal to the bdbuf layer,
+ * but it is convenient to have them visible from the outside for inspection
+ */
+/*
+ * The groups of the blocks with the same size are collected in the
+ * bd_pool. Note that a several of the buffer's groups with the
+ * same size can exists.
+ */
+typedef struct bdbuf_pool
+{
+ bdbuf_buffer *tree; /* Buffer descriptor lookup AVL tree root */
+
+ Chain_Control free; /* Free buffers list */
+ Chain_Control lru; /* Last recently used list */
+
+ int blksize; /* The size of the blocks (in bytes) */
+ int nblks; /* Number of blocks in this pool */
+ rtems_id bufget_sema; /* Buffer obtain counting semaphore */
+ void *mallocd_bufs; /* Pointer to the malloc'd buffer memory,
+ or NULL, if buffer memory provided in
+ buffer configuration */
+ bdbuf_buffer *bdbufs; /* Pointer to table of buffer descriptors
+ allocated for this buffer pool. */
+} bdbuf_pool;
+
+/* Buffering layer context definition */
+struct bdbuf_context {
+ bdbuf_pool *pool; /* Table of buffer pools */
+ int npools; /* Number of entries in pool table */
+
+ Chain_Control mod; /* Modified buffers list */
+ rtems_id flush_sema; /* Buffer flush semaphore; counting
+ semaphore; incremented when buffer
+ flushed to the disk; decremented when
+ buffer modified */
+ rtems_id swapout_task; /* Swapout task ID */
+};
+ /*
+ * the context of the buffering layer, visible for inspection
+ */
+extern struct bdbuf_context rtems_bdbuf_ctx;
/* bdbuf_config structure describes block configuration (size,
* amount, memory location) for buffering layer
diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c
index 8fb7d515be..f695ede2ab 100644
--- a/cpukit/libblock/src/bdbuf.c
+++ b/cpukit/libblock/src/bdbuf.c
@@ -7,7 +7,7 @@
* Victor V. Vengerov <vvv@oktet.ru>
* Alexander Kukuta <kam@oktet.ru>
*
- * @(#) $Id$
+ * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
*/
#if HAVE_CONFIG_H
@@ -56,40 +56,6 @@ static rtems_task bdbuf_swapout_task(rtems_task_argument unused);
static rtems_status_code bdbuf_release(bdbuf_buffer *bd_buf);
/*
- * The groups of the blocks with the same size are collected in the
- * bd_pool. Note that a several of the buffer's groups with the
- * same size can exists.
- */
-typedef struct bdbuf_pool
-{
- bdbuf_buffer *tree; /* Buffer descriptor lookup AVL tree root */
-
- Chain_Control free; /* Free buffers list */
- Chain_Control lru; /* Last recently used list */
-
- int blksize; /* The size of the blocks (in bytes) */
- int nblks; /* Number of blocks in this pool */
- rtems_id bufget_sema; /* Buffer obtain counting semaphore */
- void *mallocd_bufs; /* Pointer to the malloc'd buffer memory,
- or NULL, if buffer memory provided in
- buffer configuration */
- bdbuf_buffer *bdbufs; /* Pointer to table of buffer descriptors
- allocated for this buffer pool. */
-} bdbuf_pool;
-
-/* Buffering layer context definition */
-struct bdbuf_context {
- bdbuf_pool *pool; /* Table of buffer pools */
- int npools; /* Number of entries in pool table */
-
- Chain_Control mod; /* Modified buffers list */
- rtems_id flush_sema; /* Buffer flush semaphore; counting
- semaphore; incremented when buffer
- flushed to the disk; decremented when
- buffer modified */
- rtems_id swapout_task; /* Swapout task ID */
-};
-/*
* maximum number of blocks that might be chained together to one
* write driver call
*/
@@ -108,8 +74,8 @@ typedef struct blkdev_request1 {
blkdev_sg_buffer sg[1];
} blkdev_request1;
-/* The static context of buffering layer */
-static struct bdbuf_context bd_ctx;
+/* The context of buffering layer */
+struct bdbuf_context rtems_bdbuf_ctx;
#define SAFE
#ifdef SAFE
@@ -711,7 +677,7 @@ avl_remove(bdbuf_buffer **root, const bdbuf_buffer *node)
static rtems_status_code
bdbuf_initialize_pool(rtems_bdbuf_config *config, int pool)
{
- bdbuf_pool *p = bd_ctx.pool + pool;
+ bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool;
unsigned char *bufs;
bdbuf_buffer *b;
rtems_status_code rc;
@@ -787,7 +753,7 @@ bdbuf_initialize_pool(rtems_bdbuf_config *config, int pool)
static rtems_status_code
bdbuf_release_pool(rtems_bdpool_id pool)
{
- bdbuf_pool *p = bd_ctx.pool + pool;
+ bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool;
rtems_semaphore_delete(p->bufget_sema);
free(p->bdbufs);
free(p->mallocd_bufs);
@@ -818,18 +784,18 @@ rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size)
if (size <= 0)
return RTEMS_INVALID_SIZE;
- bd_ctx.npools = size;
+ rtems_bdbuf_ctx.npools = size;
/*
* Allocate memory for buffer pool descriptors
*/
- bd_ctx.pool = calloc(size, sizeof(bdbuf_pool));
- if (bd_ctx.pool == NULL)
+ rtems_bdbuf_ctx.pool = calloc(size, sizeof(bdbuf_pool));
+ if (rtems_bdbuf_ctx.pool == NULL)
{
return RTEMS_NO_MEMORY;
}
- Chain_Initialize_empty(&bd_ctx.mod);
+ Chain_Initialize_empty(&rtems_bdbuf_ctx.mod);
/* Initialize buffer pools and roll out if something failed */
for (i = 0; i < size; i++)
@@ -851,12 +817,12 @@ rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size)
rtems_build_name('B', 'F', 'L', 'U'), 0,
RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY |
RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0,
- &bd_ctx.flush_sema);
+ &rtems_bdbuf_ctx.flush_sema);
if (rc != RTEMS_SUCCESSFUL)
{
for (i = 0; i < size; i++)
bdbuf_release_pool(i);
- free(bd_ctx.pool);
+ free(rtems_bdbuf_ctx.pool);
return rc;
}
@@ -869,24 +835,24 @@ rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size)
SWAPOUT_TASK_STACK_SIZE,
RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
RTEMS_DEFAULT_ATTRIBUTES,
- &bd_ctx.swapout_task);
+ &rtems_bdbuf_ctx.swapout_task);
if (rc != RTEMS_SUCCESSFUL)
{
- rtems_semaphore_delete(bd_ctx.flush_sema);
+ rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema);
for (i = 0; i < size; i++)
bdbuf_release_pool(i);
- free(bd_ctx.pool);
+ free(rtems_bdbuf_ctx.pool);
return rc;
}
- rc = rtems_task_start(bd_ctx.swapout_task, bdbuf_swapout_task, 0);
+ rc = rtems_task_start(rtems_bdbuf_ctx.swapout_task, bdbuf_swapout_task, 0);
if (rc != RTEMS_SUCCESSFUL)
{
- rtems_task_delete(bd_ctx.swapout_task);
- rtems_semaphore_delete(bd_ctx.flush_sema);
+ rtems_task_delete(rtems_bdbuf_ctx.swapout_task);
+ rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema);
for (i = 0; i < size; i++)
bdbuf_release_pool(i);
- free(bd_ctx.pool);
+ free(rtems_bdbuf_ctx.pool);
return rc;
}
@@ -933,7 +899,7 @@ find_or_assign_buffer(disk_device *dd,
int blksize;
device = dd->dev;
- bd_pool = bd_ctx.pool + dd->pool;
+ bd_pool = rtems_bdbuf_ctx.pool + dd->pool;
blksize = dd->block_size;
again:
@@ -1021,7 +987,7 @@ again:
* that our buffer descriptor is in the list. */
if (bd_buf->modified)
{
- rc = rtems_semaphore_obtain(bd_ctx.flush_sema,
+ rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema,
RTEMS_NO_WAIT, 0);
}
else
@@ -1476,7 +1442,7 @@ bdbuf_release(bdbuf_buffer *bd_buf)
if (bd_buf->use_count <= 0)
return RTEMS_INTERNAL_ERROR;
- bd_pool = bd_ctx.pool + bd_buf->pool;
+ bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool;
bd_buf->use_count--;
@@ -1487,10 +1453,10 @@ bdbuf_release(bdbuf_buffer *bd_buf)
/* Buffer was modified. Insert buffer to the modified buffers
* list and initiate flushing. */
- Chain_Append(&bd_ctx.mod, &bd_buf->link);
+ Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link);
/* Release the flush_sema */
- rc = rtems_semaphore_release(bd_ctx.flush_sema);
+ rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema);
}
else
{
@@ -1659,7 +1625,7 @@ rtems_bdbuf_syncdev(dev_t dev)
if (dd == NULL)
return RTEMS_INVALID_ID;
- pool = bd_ctx.pool + dd->pool;
+ pool = rtems_bdbuf_ctx.pool + dd->pool;
DISABLE_PREEMPTION(key);
do {
@@ -1718,13 +1684,13 @@ bdbuf_swapout_task(rtems_task_argument unused)
* otherwise do not wait, if no buffer available
*/
if (nxt_bd_buf == NULL) {
- rc = rtems_semaphore_obtain(bd_ctx.flush_sema,
+ rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema,
(req.req.count == 0)
? RTEMS_WAIT
: RTEMS_NO_WAIT,
0);
if (rc == RTEMS_SUCCESSFUL) {
- nxt_bd_buf = (bdbuf_buffer *)Chain_Get(&bd_ctx.mod);
+ nxt_bd_buf = (bdbuf_buffer *)Chain_Get(&rtems_bdbuf_ctx.mod);
if (nxt_bd_buf != NULL) {
nxt_bd_buf->in_progress = TRUE;
/* IMD try: clear "modified" bit early */
@@ -1764,7 +1730,7 @@ bdbuf_swapout_task(rtems_task_argument unused)
* for next main loop
*/
if (bd_buf != NULL) {
- bd_pool = bd_ctx.pool + bd_buf->pool;
+ bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool;
if (req.req.count == 0) {
/*
* this is the first block, so use its address
@@ -1818,8 +1784,8 @@ bdbuf_swapout_task(rtems_task_argument unused)
{
if (bd_buf->modified)
{
- Chain_Append(&bd_ctx.mod, &bd_buf->link);
- rc = rtems_semaphore_release(bd_ctx.flush_sema);
+ Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link);
+ rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema);
}
else
{
@@ -1860,7 +1826,7 @@ rtems_bdbuf_find_pool(int block_size, rtems_bdpool_id *pool)
if (j != 1)
return RTEMS_INVALID_SIZE;
- for (i = 0, p = bd_ctx.pool; i < bd_ctx.npools; i++, p++)
+ for (i = 0, p = rtems_bdbuf_ctx.pool; i < rtems_bdbuf_ctx.npools; i++, p++)
{
if ((p->blksize >= block_size) &&
(p->blksize < cursize))
@@ -1903,17 +1869,17 @@ rtems_status_code
rtems_bdbuf_get_pool_info(rtems_bdpool_id pool, int *block_size,
int *blocks)
{
- if (pool >= bd_ctx.npools)
+ if (pool >= rtems_bdbuf_ctx.npools)
return RTEMS_INVALID_NUMBER;
if (block_size != NULL)
{
- *block_size = bd_ctx.pool[pool].blksize;
+ *block_size = rtems_bdbuf_ctx.pool[pool].blksize;
}
if (blocks != NULL)
{
- *blocks = bd_ctx.pool[pool].nblks;
+ *blocks = rtems_bdbuf_ctx.pool[pool].nblks;
}
return RTEMS_SUCCESSFUL;
diff --git a/cpukit/libblock/src/show_bdbuf.c b/cpukit/libblock/src/show_bdbuf.c
new file mode 100644
index 0000000000..0deb28e854
--- /dev/null
+++ b/cpukit/libblock/src/show_bdbuf.c
@@ -0,0 +1,904 @@
+/*===============================================================*\
+| Project: RTEMS bdbuf inspector |
++-----------------------------------------------------------------+
+| File: show_bdbuf.c
++-----------------------------------------------------------------+
+| Copyright (c) 2005 |
+| Embedded Brains GmbH |
+| Obere Lagerstr. 30 |
+| D-82178 Puchheim |
+| Germany |
+| rtems@embedded-brains.de |
++-----------------------------------------------------------------+
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| this file contains functions to enable the monitor |
+| to show bdbuf information |
+| |
+| XXX!!! ATTETION!!! XXX!!! |
+| |
+| This module inspects the bdbuf data structures, |
+| assuming they are static, but in fact they are used very |
+| dynamically. Therefore the results show MAY BE INCORRECT in |
+| some cases. And, to cure this a bit, this module may block |
+| preemption for a rather long time and therefore it may |
+| BREAK THE REALTIME BEHAVIOUR OF YOUR SYSTEM (when in use) |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 26.09.06 creation doe |
+|*****************************************************************|
+\*===============================================================*/
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/bdbuf.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <rtems/libio.h>
+
+
+typedef struct {
+ boolean bdbuf_modified;
+ boolean bdbuf_in_progress;
+ boolean bdbuf_actual;
+ boolean bdbuf_used;
+ boolean bdbuf_all;
+ rtems_bdpool_id pool_id;
+} show_bdbuf_filter_t;
+
+typedef struct {
+ boolean show_all;
+ boolean show_node_chain;
+ boolean show_dev;
+ boolean show_blocknum;
+ boolean show_error;
+ boolean show_state;
+ boolean show_use_count;
+ boolean show_pool_id;
+ boolean show_sema;
+} show_bdbuf_selector_t;
+
+typedef enum {bdbuf_chain_ident_none,
+ bdbuf_chain_ident_free,
+ bdbuf_chain_ident_lru,
+ bdbuf_chain_ident_mod} bdbuf_chain_identifier_t;
+
+typedef struct {
+ rtems_bdpool_id pool_id;
+ int index;
+ bdbuf_chain_identifier_t in_chain;
+ dev_t dev;
+ blkdev_bnum blknum;
+ rtems_status_code status;
+ int error;
+ boolean modified;
+ boolean in_progress;
+ boolean actual;
+ int use_count;
+ const CORE_mutex_Control *sema;
+} show_bdbuf_bdbuf_info_t;
+
+typedef rtems_mode preemption_key_t;
+#define DISABLE_PREEMPTION(key) \
+ do { \
+ rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &(key)); \
+ } while (0)
+
+#define ENABLE_PREEMPTION(key) \
+ do { \
+ rtems_mode temp; \
+ rtems_task_mode((key), RTEMS_PREEMPT_MASK, &temp); \
+ } while (0)
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_follow_chain_node_to_head
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| follow a given chain to its head |
+| XXX: this is executed with preemption disabled |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const Chain_Node *the_node, /* input: node to track to its head */
+ Chain_Control **the_head /* storage for pointer to chain head */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ preemption_key_t preempt_key;
+ boolean preempt_disabled = FALSE;
+ /*
+ * disable preemption
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ DISABLE_PREEMPTION(preempt_key);
+ }
+ /*
+ * follow node to its head
+ * XXX: this is highly dependent on the chain implementation
+ * in score/src/chain.c and friends
+ */
+ while (the_node->previous != NULL) {
+ the_node = the_node->previous;
+ }
+ /*
+ * reenable preemption, if disabled
+ */
+ if (preempt_disabled) {
+ ENABLE_PREEMPTION(preempt_key);
+ }
+ /*
+ * XXX: this depends n the chain implementation in
+ * score/include/rtems/score/chain.h:
+ * Chain_Control is overlayed by two Cohain_Nodes
+ */
+ *the_head = (Chain_Control *)the_node;
+
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_determine_chain_of_bdbuf
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| find out, which chain this bdbuf is linked in |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const bdbuf_buffer *the_bdbuf, /* this is the bdbuf structure */
+ const bdbuf_pool *curr_pool, /* the pool this buffer belongs to */
+ bdbuf_chain_identifier_t *chn_ident /* result: identifier for chain */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ Chain_Control *the_chain_control;
+
+
+ *chn_ident = bdbuf_chain_ident_none;
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_follow_chain_node_to_head(&(the_bdbuf->link),
+ &(the_chain_control));
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (the_chain_control == &(curr_pool->free)) {
+ *chn_ident = bdbuf_chain_ident_free;
+ }
+ else if (the_chain_control == &(curr_pool->lru)) {
+ *chn_ident = bdbuf_chain_ident_lru;
+ }
+ else if (the_chain_control == &(rtems_bdbuf_ctx.mod)) {
+ *chn_ident = bdbuf_chain_ident_mod;
+ }
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_getargs
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| analyze cmd arguments |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int argc,
+ char **argv,
+ show_bdbuf_filter_t *filter,
+ show_bdbuf_selector_t *selector
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int arg_error = 0;
+ int i;
+ char *tmp_ptr;
+ int nm_argc = 0;
+ /*
+ * set filter and selector to default
+ */
+ memset(filter,0,sizeof(*filter));
+ filter->bdbuf_all = TRUE;
+ memset(selector,0,sizeof(*selector));
+ selector->show_all = TRUE;
+
+ /*
+ * scan arguments
+ */
+ for (i = 1;
+ (i < argc) && (arg_error == 0);
+ i++) {
+ if (argv[i][0] == '-') {
+ /*
+ * modifier arguments
+ */
+ switch(tolower(argv[i][1])) {
+ /*
+ * selection, which bdbufs to show
+ */
+ case 'm': /* only show bdbufs modified */
+ filter->bdbuf_modified = TRUE ;
+ filter->bdbuf_all = FALSE;
+ break;
+ case 'i': /* only show bdbufs in progress*/
+ filter->bdbuf_in_progress = TRUE ;
+ filter->bdbuf_all = FALSE;
+ break;
+ case 'v': /* only show bdbufs, which have valid data*/
+ filter->bdbuf_actual = TRUE ;
+ filter->bdbuf_all = FALSE;
+ break;
+ case 'u': /* only show bdbufs, which are in use */
+ filter->bdbuf_used = TRUE ;
+ filter->bdbuf_all = FALSE;
+ break;
+ case 'p': /* only show bdbufs, which belong to pool <n> */
+ filter->pool_id = strtol(argv[i]+2,&tmp_ptr,0);
+ if (tmp_ptr == argv[i]+2) { /* no conversion performed... */
+ arg_error = i;
+ }
+ filter->bdbuf_all = FALSE;
+ break;
+ /*
+ * selection, what fields to show
+ */
+ case 'n': /* show bdbuf node_chain */
+ selector->show_node_chain = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 'd': /* show device */
+ selector->show_dev = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 'b': /* show blocknum */
+ selector->show_blocknum = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 'e': /* show bdbuf error status */
+ selector->show_error = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 's': /* show bdbuf state */
+ selector->show_state = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 'c': /* show bdbuf use count */
+ selector->show_use_count = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 'l': /* show bdbuf pool id */
+ selector->show_pool_id = TRUE ;
+ selector->show_all = FALSE;
+ break;
+ case 't': /* show bdbuf transfer sema */
+ selector->show_sema = TRUE ;
+ break;
+ default:
+ arg_error = i;
+ break;
+ }
+ }
+ else {
+ /*
+ * non-modifier arguments
+ */
+ switch(++nm_argc) {
+ default: /* no further arguments defined */
+ arg_error = i;
+ break;
+ }
+ }
+ }
+ if (arg_error) {
+ printf("%s: unknown argument %s\n",argv[0],argv[arg_error]);
+ sc = RTEMS_NOT_DEFINED;
+ }
+ return sc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_get_bufpool
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| get buffer pool information |
+| XXX: this should be coupled closer to the bdbuf.c module |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ struct bdbuf_pool **pool_base_pptr,
+ int *pool_cnt_ptr
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+#if 0
+ rtems_status_code pool_rc = RTEMS_SUCCESSFUL;
+ struct bdbuf_pool *curr_pool,*pool_base, *pool_top;
+ int pool_cnt;
+ int pool_probe_size;
+ /*
+ * get first buffer pool
+ * XXX: this is highly dependent on how pools are defined
+ * and maintained in bdbuf.c
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ /*
+ * try all possible pool sizes, get highest/lowest pool address
+ */
+ pool_base = NULL;
+ pool_top = NULL;
+ curr_pool = NULL;
+ for (pool_probe_size = 1;
+ pool_probe_size < (INT_MAX>>1) && (pool_rc == RTEMS_SUCCESSFUL);
+ pool_probe_size <<= 1) {
+ pool_rc = rtems_bdbuf_find_pool(pool_probe_size,&curr_pool);
+ if (pool_rc == RTEMS_SUCCESSFUL) {
+ if (pool_base > curr_pool) {
+ pool_base = curr_pool;
+ }
+ if (pool_top < curr_pool) {
+ pool_top = curr_pool;
+ }
+ }
+ }
+ if (pool_base == NULL) {
+ rc = RTEMS_UNSATISFIED;
+ }
+ else {
+ pool_cnt = (pool_top - pool_base) + 1;
+ }
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ *pool_base_pptr = pool_base;
+ *pool_cnt_ptr = pool_cnt;
+ }
+#else
+ if (rc == RTEMS_SUCCESSFUL) {
+ *pool_base_pptr = rtems_bdbuf_ctx.pool;
+ *pool_cnt_ptr = rtems_bdbuf_ctx.npools;
+ }
+#endif
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_pool_header
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| print buffer pool information |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int pool_idx,
+ bdbuf_pool *pool_ptr
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ printf("------------------------------------------------------------------------------\n");
+ printf(" pool #%03d: blksize=%5u nblks=%5u buf_mem=0x%08x bdbuf_mem=0x%08x\n",
+ pool_idx,
+ pool_ptr->blksize,
+ pool_ptr->nblks,
+ (uint32_t)(pool_ptr->mallocd_bufs),
+ (uint32_t)(pool_ptr->bdbufs));
+ printf("------------------------------------------------------------------------------\n");
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_get_bdbuf_info
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| get buffer pool information |
+| XXX: this should be coupled closer to the bdbuf.c module |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const bdbuf_buffer *the_bdbuf, /* this is the bdbuf structure */
+ int bdbuf_idx, /* index of bdbuf */
+ const bdbuf_pool *curr_pool, /* the pool this buffer belongs to */
+ show_bdbuf_bdbuf_info_t *bdbuf_info /* struct to store info of bdbuf */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ /*
+ * determine the chain we are in
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_determine_chain_of_bdbuf(the_bdbuf,curr_pool,
+ &(bdbuf_info->in_chain));
+ if (rc != RTEMS_SUCCESSFUL) {
+ bdbuf_info->in_chain = bdbuf_chain_ident_none;
+ rc = RTEMS_SUCCESSFUL;
+ }
+ }
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ bdbuf_info->index = bdbuf_idx;
+ bdbuf_info->dev = the_bdbuf->dev;
+ bdbuf_info->blknum = the_bdbuf->block;
+ bdbuf_info->status = the_bdbuf->status;
+ bdbuf_info->error = the_bdbuf->error;
+ bdbuf_info->modified = the_bdbuf->modified;
+ bdbuf_info->in_progress = the_bdbuf->in_progress;
+ bdbuf_info->actual = the_bdbuf->actual;
+ bdbuf_info->use_count = the_bdbuf->use_count;
+ bdbuf_info->sema = &(the_bdbuf->transfer_sema);
+ bdbuf_info->pool_id = the_bdbuf->pool;
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_match_filter
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| match bdbuf info with given filter |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const show_bdbuf_bdbuf_info_t *bdbuf_info, /* struct to store info of bdbuf */
+ const show_bdbuf_filter_t *filter,
+ boolean *is_match
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ boolean unmatch = FALSE;
+
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (filter->bdbuf_all) {
+ unmatch = FALSE;
+ }
+ else {
+ unmatch = ((filter->bdbuf_modified && !bdbuf_info->modified) ||
+ (filter->bdbuf_in_progress && !bdbuf_info->in_progress) ||
+ (filter->bdbuf_actual && !bdbuf_info->actual) ||
+ (filter->bdbuf_used && !(bdbuf_info->use_count > 0)));
+
+ }
+ *is_match = !unmatch;
+ }
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_print_wait_chain
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| list tasks waiting in "transfer_sema" chain |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ bdbuf_buffer *the_bdbuf /* this is the bdbuf structure */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ Chain_Control *the_chain_head;
+ const Chain_Node *the_chain_node;
+ int thread_cnt = 0;
+ const Thread_Control *the_thread;
+ Objects_Id thread_id;
+ Objects_Name thread_name;
+ uint32_t thread_name_nonstring;
+ /*
+ * get head of (fifo) wait chain
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ the_chain_head = &(the_bdbuf->transfer_sema.Wait_queue.Queues.Fifo);
+ the_chain_node = the_chain_head->first;
+ }
+ /*
+ * walk through thread chain
+ */
+ while ((rc == RTEMS_SUCCESSFUL) &&
+ (the_chain_node != _Chain_Tail( the_chain_head ))) {
+ thread_cnt++;
+ the_thread = (const Thread_Control *)the_chain_node;
+
+ thread_id = the_thread->Object.id;
+ thread_name = the_thread->Object.name;
+ thread_name_nonstring = (uint32_t)thread_name;
+ printf("%20s %3d (0x%08x) %c%c%c%c\n",
+ ((thread_cnt == 1) ? "Threads waiting:" : ""),
+ thread_cnt,thread_id,
+ (thread_name_nonstring >> 24) & 0xff,
+ (thread_name_nonstring >> 16) & 0xff,
+ (thread_name_nonstring >> 8) & 0xff,
+ (thread_name_nonstring >> 0) & 0xff);
+
+ the_chain_node = the_chain_node->next;
+ }
+
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_show_bdbuf_print
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| print requested bdbuffer information |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ const show_bdbuf_bdbuf_info_t *bdbuf_info, /* info of bdbuf */
+ show_bdbuf_selector_t * selector, /* selector, what to show */
+ boolean print_header /* TRUE: print header, not info */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+
+ /*
+ * 6 chars: print index of buffer
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (print_header) {
+ printf("INDEX ");
+ }
+ else {
+ printf("%5u ",bdbuf_info->index);
+ }
+ }
+ /*
+ * 3 chars: print info about the pool id of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_use_count))) {
+ if (print_header) {
+ printf("PL ");
+ }
+ else {
+ printf("%2u ",bdbuf_info->pool_id);
+ }
+ }
+
+ /*
+ * 4 chars: print info about chain (lru/free/mod) of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_node_chain))) {
+ if (print_header) {
+ printf("CHN ");
+ }
+ else {
+ printf("%3s ",
+ ((bdbuf_info->in_chain == bdbuf_chain_ident_free) ? "FRE"
+ : (bdbuf_info->in_chain == bdbuf_chain_ident_lru) ? "LRU"
+ : (bdbuf_info->in_chain == bdbuf_chain_ident_mod) ? "MOD"
+ : "???"));
+ }
+ }
+
+ /*
+ * 7 chars: print info about device of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_dev))) {
+ if (print_header) {
+ printf("DEVICE ");
+ }
+ else {
+ printf("%3u,%2u ",
+ ((bdbuf_info->dev == -1)
+ ? 0 : rtems_filesystem_dev_major_t(bdbuf_info->dev)),
+ ((bdbuf_info->dev == -1)
+ ? 0 : rtems_filesystem_dev_minor_t(bdbuf_info->dev)));
+ }
+ }
+
+ /*
+ * 7 chars: print info about block number of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_blocknum))) {
+ if (print_header) {
+ printf("BLOCK ");
+ }
+ else {
+ printf("%6u ",bdbuf_info->blknum);
+ }
+ }
+
+ /*
+ * 4 chars: print info about use count of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_use_count))) {
+ if (print_header) {
+ printf("USE ");
+ }
+ else {
+ printf("%3u ",bdbuf_info->use_count);
+ }
+ }
+
+ /*
+ * 4 chars: print info about state of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_state))) {
+ if (print_header) {
+ printf("STA ");
+ }
+ else {
+ printf("%c%c%c ",
+ (bdbuf_info->modified ? 'M' : '.'),
+ (bdbuf_info->in_progress ? 'P' : '.'),
+ (bdbuf_info->actual ? 'A' : '.'));
+ }
+ }
+
+ /*
+ * 42 chars: print info about error of this buffer
+ */
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ ((selector->show_all) ||
+ (selector->show_error))) {
+ if (print_header) {
+ printf("%20s:%-10s ","RTEMS STATUS","ERRNO");
+ }
+ else {
+ printf("%20s:%-10s ",
+ ((bdbuf_info->status == RTEMS_SUCCESSFUL)
+ ? "SUCCESSFUL" : rtems_status_text(bdbuf_info->status)),
+ ((bdbuf_info->status == RTEMS_SUCCESSFUL)
+ ? "" : strerror(bdbuf_info->error)));
+ }
+ }
+ /*
+ * FIXME: add info about waiting chain
+ */
+ printf("\n");
+ return rc;
+}
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+void rtems_bdbuf_show_fnc
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| list all bdbufs with their content |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ int argc,
+ char **argv,
+ rtems_monitor_command_arg_t* command_arg,
+ boolean verbose
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code rc = RTEMS_SUCCESSFUL;
+ show_bdbuf_filter_t filter;
+ show_bdbuf_selector_t selector;
+ show_bdbuf_bdbuf_info_t bdbuf_info;
+
+ bdbuf_pool *curr_pool,*pool_base;
+ int pool_cnt,pool_idx;
+ int bdbuf_idx;
+ boolean bdbuf_matches;
+ int matched_cnt,un_matched_cnt;
+
+ /*
+ * analyze command line options
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_getargs (argc,argv,
+ &filter,&selector);
+ }
+
+ /*
+ * get buffer pool information
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_get_bufpool(&pool_base,&pool_cnt);
+ if (rc != RTEMS_SUCCESSFUL) {
+ printf("%s: ERROR: no buffer pool found\n",argv[0]);
+ }
+ }
+ /*
+ * for all or selected buffer pool(s)
+ */
+ for (pool_idx = 0;
+ (rc == RTEMS_SUCCESSFUL) && (pool_idx < pool_cnt);
+ pool_idx++) {
+ if ((filter.pool_id < 0) ||
+ (filter.pool_id == pool_idx)) {
+ curr_pool = pool_base + pool_idx;
+ /*
+ * print pool header
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_bdbuf_show_pool_header(pool_idx,curr_pool);
+ }
+ if (rc == RTEMS_SUCCESSFUL) {
+ matched_cnt = 0;
+ un_matched_cnt = 0;
+ /*
+ * print header for bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_print(NULL,&selector,
+ TRUE);
+ }
+ /*
+ * for all bdbufs in this pool
+ */
+ for (bdbuf_idx = 0;
+ ((rc == RTEMS_SUCCESSFUL) &&
+ (bdbuf_idx < curr_pool->nblks));
+ bdbuf_idx++) {
+ /*
+ * get infos about bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_get_bdbuf_info
+ (&(curr_pool->bdbufs[bdbuf_idx]),
+ bdbuf_idx,
+ curr_pool,
+ &bdbuf_info);
+ }
+ /*
+ * check, if bdbuf matches selection criteria
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ rc = rtems_show_bdbuf_match_filter(&bdbuf_info,&filter,
+ &bdbuf_matches);
+ }
+ /*
+ * print info about bdbuf
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ if (bdbuf_matches) {
+ rc = rtems_show_bdbuf_print(&bdbuf_info,&selector,
+ FALSE);
+ if ((rc == RTEMS_SUCCESSFUL) &&
+ selector.show_sema) {
+ rc = rtems_show_bdbuf_print_wait_chain(&(curr_pool->bdbufs[bdbuf_idx]));
+ }
+ matched_cnt++;
+ }
+ else {
+ un_matched_cnt++;
+ }
+ }
+ }
+ /*
+ * print match statistics and footer
+ */
+ if (rc == RTEMS_SUCCESSFUL) {
+ printf("%d bdbufs printed, %d bdbufs suppressed\n",
+ matched_cnt,un_matched_cnt);
+ }
+ }
+ }
+ }
+}
+
+static rtems_monitor_command_entry_t rtems_show_bdbuf_cmds[] = {
+ {
+ "bdbuf_show",
+ "usage: bdbuf_show\n",
+ 0,
+ rtems_bdbuf_show_fnc,
+ { 0 },
+ 0
+ }
+};
+
+#ifndef ARRAY_CNT
+#define ARRAY_CNT(arr) (sizeof((arr))/sizeof((arr)[0]))
+#endif
+
+/*=========================================================================*\
+| Function: |
+\*-------------------------------------------------------------------------*/
+rtems_status_code rtems_bdbuf_show_init
+(
+/*-------------------------------------------------------------------------*\
+| Purpose: |
+| add command(s) to monitor |
++---------------------------------------------------------------------------+
+| Input Parameters: |
+\*-------------------------------------------------------------------------*/
+ void /* none up to now */
+)
+/*-------------------------------------------------------------------------*\
+| Return Value: |
+| rtems_status_code |
+\*=========================================================================*/
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ int item;
+
+ for (item = 0;
+ (sc == RTEMS_SUCCESSFUL) && (item < ARRAY_CNT(rtems_show_bdbuf_cmds));
+ item++) {
+ if (0 == rtems_monitor_insert_cmd (&rtems_show_bdbuf_cmds[item])) {
+ sc = RTEMS_INVALID_NAME;
+ }
+ }
+ return sc;
+}