This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
blib kernel dependency patch
- From: Savin Zlobec <savin at elatec dot si>
- To: ecos-patches at sources dot redhat dot com
- Date: Mon, 28 Jun 2004 11:14:14 +0200
- Subject: blib kernel dependency patch
Hi,
this patch changes the cyg_mempool_fix_* based internal blib block
memory pool managment
with custom (much simpler) block memory pool funs. With this change blib
no more depends on
the kernel package.
savin
Index: services/blib/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/blib/current/ChangeLog,v
retrieving revision 1.1
diff -u -5 -w -r1.1 ChangeLog
--- services/blib/current/ChangeLog 19 Jan 2004 14:35:03 -0000 1.1
+++ services/blib/current/ChangeLog 28 Jun 2004 08:57:39 -0000
@@ -1,5 +1,12 @@
+2004-06-28 Savin Zlobec <savin@elatec.si>
+
+ * inc/blib.h:
+ * src/disk.c:
+ Implemented block memory pool without using the cyg_mempool_fix_*
+ API - blib is now free of kernel dependencies.
+
2003-09-01 Savin Zlobec <savin@elatec.si>
* cdl/blib.cdl:
* inc/blib.h:
* src/disk.c:
Index: services/blib/current/include/blib.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/blib/current/include/blib.h,v
retrieving revision 1.1
diff -u -5 -w -r1.1 blib.h
--- services/blib/current/include/blib.h 19 Jan 2004 14:35:03 -0000 1.1
+++ services/blib/current/include/blib.h 28 Jun 2004 08:57:40 -0000
@@ -47,11 +47,10 @@
//####DESCRIPTIONEND####
//
//==========================================================================
#include <cyg/infra/cyg_type.h>
-#include <cyg/kernel/kapi.h>
#include <cyg/io/io.h>
#include <linux/rbtree.h>
#include <linux/list.h>
@@ -83,12 +82,11 @@
struct rb_root rb_root; // block red-black tree root
cyg_uint32 block_size; // block size
cyg_uint32 block_size_log2; // block size log2
cyg_uint8 *mem_base; // memory base
cyg_uint32 mem_size; // memory size
- cyg_mempool_fix mem_pool; // memory pool struct
- cyg_handle_t mem_pool_h; // memory pool handle
+ struct list_head free_list_head; // list of free blocks
cyg_blib_bread_fn bread_fn; // block read function
cyg_blib_bwrite_fn bwrite_fn; // block write function
#ifdef CYGIMP_BLOCK_LIB_STATISTICS
cyg_blib_stat_t stat; // statistics
#endif
Index: services/blib/current/src/blib.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/blib/current/src/blib.c,v
retrieving revision 1.1
diff -u -5 -w -r1.1 blib.c
--- services/blib/current/src/blib.c 19 Jan 2004 14:35:03 -0000 1.1
+++ services/blib/current/src/blib.c 28 Jun 2004 08:57:40 -0000
@@ -45,16 +45,16 @@
//####DESCRIPTIONEND####
//
//==========================================================================
#include <cyg/io/io.h>
+#include <cyg/infra/cyg_type.h>
#include <cyg/infra/cyg_ass.h> // assertion support
#include <cyg/infra/diag.h> // diagnostic output
-#include <cyg/kernel/kapi.h>
#include <blib/blib.h>
-#include <string.h>
+#include <string.h> // memcpy
#include <linux/rbtree.h>
#include <linux/list.h>
// --------------------------------------------------------------------
@@ -65,10 +65,12 @@
# define D(_args_) diag_printf _args_
#else
# define D(_args_) CYG_EMPTY_STATEMENT
#endif
+#define ALIGN(_x_) (((_x_) + (CYGARC_ALIGNMENT-1)) & ~(CYGARC_ALIGNMENT-1))
+
#ifdef CYGIMP_BLOCK_LIB_STATISTICS
#define STAT_INIT(_bl_) do { \
bl->stat.n_gets = 0; \
bl->stat.n_reads = 0; \
@@ -182,10 +184,57 @@
list_add(&block->list_node, &bl->list_head);
}
// --------------------------------------------------------------------
+static __inline__ void
+free_block(cyg_blib_t *bl, blib_block_t *block)
+{
+ list_add(&block->list_node, &bl->free_list_head);
+}
+
+static __inline__ blib_block_t *
+alloc_block(cyg_blib_t *bl)
+{
+ if ( !list_empty(&bl->free_list_head) )
+ {
+ blib_block_t *new;
+
+ new = list_entry(bl->free_list_head.next, blib_block_t, list_node);
+ list_del(bl->free_list_head.next);
+
+ return new;
+ }
+ else
+ return NULL;
+}
+
+static void
+init_block_mem_pool(cyg_blib_t *bl)
+{
+ cyg_uint8 *block_mem;
+ cyg_uint32 avail_mem_size, block_mem_size;
+
+ INIT_LIST_HEAD(&bl->free_list_head);
+
+ block_mem = bl->mem_base;
+ avail_mem_size = bl->mem_size;
+ block_mem_size = ALIGN(sizeof(blib_block_t) + bl->block_size);
+
+ while (avail_mem_size >= block_mem_size)
+ {
+ blib_block_t *block = (blib_block_t *)block_mem;
+
+ list_add(&block->list_node, &bl->free_list_head);
+
+ block_mem += block_mem_size;
+ avail_mem_size -= block_mem_size;
+ }
+}
+
+// --------------------------------------------------------------------
+
static cyg_uint32
get_val_log2(cyg_uint32 val)
{
cyg_uint32 i, log2;
@@ -279,11 +328,11 @@
return ret;
}
D(("blib block=%d NOT found in cache\n", num));
- block = (blib_block_t *)cyg_mempool_fix_try_alloc(bl->mem_pool_h);
+ block = alloc_block(bl);
if (NULL == block)
{
CYG_ASSERTC(!list_empty(&bl->list_head));
@@ -310,11 +359,11 @@
len = 1;
ret = bl->bread_fn(bl->priv, (void *)block->data, &len, block->num);
if (ENOERR != ret)
{
- cyg_mempool_fix_free(bl->mem_pool_h, block);
+ free_block(bl, block);
return ret;
}
}
rb_add_block(bl, block);
list_add_block(bl, block);
@@ -322,32 +371,21 @@
*dblock = block;
return ret;
}
static int
-blib_free_cache(cyg_blib_t *bl)
-{
- int ret = ENOERR;
- ret = blib_sync(bl);
- if (ENOERR == ret)
- cyg_mempool_fix_delete(bl->mem_pool_h);
- return ret;
-}
-
-static int
blib_init_cache(cyg_blib_t *bl,
void *mem_base,
cyg_uint32 mem_size,
cyg_uint32 block_size,
cyg_bool reinit)
{
int ret = ENOERR;
- cyg_uint32 mem_block_size;
if (reinit)
{
- ret = blib_free_cache(bl);
+ ret = blib_sync(bl);
if (ENOERR != ret)
return ret;
}
bl->rb_root = RB_ROOT;
@@ -359,14 +397,11 @@
bl->block_size_log2 = get_val_log2(block_size);
if (0 == bl->block_size_log2)
return -EINVAL;
- mem_block_size = bl->block_size + sizeof(blib_block_t);
-
- cyg_mempool_fix_create(bl->mem_base, bl->mem_size, mem_block_size,
- &bl->mem_pool_h, &bl->mem_pool);
+ init_block_mem_pool(bl);
STAT_INIT(bl);
return ret;
}
@@ -418,11 +453,11 @@
}
int
cyg_blib_delete(cyg_blib_t *bl)
{
- return blib_free_cache(bl);
+ return blib_sync(bl);
}
int
cyg_blib_bread(cyg_blib_t *bl,
void *buf,