mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* tlsf patches
@ 2012-01-02 13:50 Sascha Hauer
  2012-01-02 13:50 ` [PATCH 1/3] tlsf: enable assertions Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-01-02 13:50 UTC (permalink / raw)
  To: barebox

The following are some improvements to the tlsf support, most notably
the support for the meminfo command.

Sascha

Sascha Hauer (3):
      tlsf: enable assertions
      tlsf: implement malloc_stats
      tlsf: remove unused stuff from tlsfbits.h

 common/tlsf.c        |   17 ++---
 common/tlsf_malloc.c |   25 +++++++-
 common/tlsfbits.h    |   55 +++++++++++++++
 include/tlsfbits.h   |  180 --------------------------------------------------
 4 files changed, 85 insertions(+), 192 deletions(-)
 create mode 100644 common/tlsfbits.h
 delete mode 100644 include/tlsfbits.h


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] tlsf: enable assertions
  2012-01-02 13:50 tlsf patches Sascha Hauer
@ 2012-01-02 13:50 ` Sascha Hauer
  2012-01-02 13:50 ` [PATCH] uart drivers: use xzalloc instead of xmalloc Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-01-02 13:50 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/tlsf.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/common/tlsf.c b/common/tlsf.c
index b3de976..c810e8d 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -1,20 +1,17 @@
-#ifndef __BAREBOX__
-#include <assert.h>
-#include <limits.h>
-#endif
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <linux/stringify.h>
 
 #include "tlsf.h"
 #include "tlsfbits.h"
 
-#ifdef __BAREBOX__
-#ifndef _DEBUG
-#define _DEBUG 0
-#endif
-#define tlsf_assert(expr)           ((void) (0))
+#ifdef DEBUG
+#define tlsf_assert(expr)	\
+	((expr) ? (void)(0) : printf("%s\n", __stringify(expr)))
+#else
+#define tlsf_assert(expr)	(void)(0)
 #endif
 
 /*
@@ -759,7 +756,7 @@ tlsf_pool tlsf_create(void* mem, size_t bytes)
 	const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE);
 	pool_t* pool = tlsf_cast(pool_t*, mem);
 
-#if _DEBUG
+#ifdef DEBUG
 	/* Verify ffs/fls work properly. */
 	int rv = 0;
 	rv += (tlsf_ffs(0) == -1) ? 0 : 0x1;
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] uart drivers: use xzalloc instead of xmalloc
  2012-01-02 13:50 tlsf patches Sascha Hauer
  2012-01-02 13:50 ` [PATCH 1/3] tlsf: enable assertions Sascha Hauer
@ 2012-01-02 13:50 ` Sascha Hauer
  2012-01-02 13:50 ` [PATCH 2/3] tlsf: implement malloc_stats Sascha Hauer
  2012-01-02 13:50 ` [PATCH 3/3] tlsf: remove unused stuff from tlsfbits.h Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-01-02 13:50 UTC (permalink / raw)
  To: barebox

The flags in struct console_device have to be initialized
to zero. Otherwise the following can happen:

- console_register sets the initial baudrate of a new console
  before we set the global console init state to CONSOLE_INIT_FULL.
- In console_baudrate_set we test whether the current console is
  active which may be true because of unitialized flags.
- we then call getc() to wait for the user to accept the new settings
  and we are stuck because of the CONSOLE_UNINITIALIZED state
  we will never get anything from getc().

Looking back this explains some cases for me when barebox refused
to start and I really wonder why this did not become a more visible
problem before.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/serial/amba-pl011.c         |    2 +-
 drivers/serial/atmel.c              |    2 +-
 drivers/serial/serial_altera.c      |    2 +-
 drivers/serial/serial_altera_jtag.c |    2 +-
 drivers/serial/serial_blackfin.c    |    2 +-
 drivers/serial/serial_imx.c         |    2 +-
 drivers/serial/serial_netx.c        |    2 +-
 drivers/serial/serial_pl010.c       |    2 +-
 drivers/serial/serial_s3c24x0.c     |    2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index 148bdbf..56f6f15 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -159,7 +159,7 @@ static int pl011_probe(struct device_d *dev)
 	struct amba_uart_port *uart;
 	struct console_device *cdev;
 
-	uart = xmalloc(sizeof(struct amba_uart_port));
+	uart = xzalloc(sizeof(struct amba_uart_port));
 	uart->clk = clk_get(dev, NULL);
 
 	if (IS_ERR(uart->clk))
diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index 9ba4ca9..de58465 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -399,7 +399,7 @@ static int atmel_serial_probe(struct device_d *dev)
 	struct atmel_uart_port *uart;
 	struct console_device *cdev;
 
-	uart = xmalloc(sizeof(struct atmel_uart_port));
+	uart = xzalloc(sizeof(struct atmel_uart_port));
 	cdev = &uart->uart;
 	dev->type_data = cdev;
 	cdev->dev = dev;
diff --git a/drivers/serial/serial_altera.c b/drivers/serial/serial_altera.c
index 8fd5d8a..e4d3c40 100644
--- a/drivers/serial/serial_altera.c
+++ b/drivers/serial/serial_altera.c
@@ -85,7 +85,7 @@ static int altera_serial_probe(struct device_d *dev)
 	struct console_device *cdev;
 	struct altera_serial_priv *priv;
 
-	priv = xmalloc(sizeof(*priv));
+	priv = xzalloc(sizeof(*priv));
 	cdev = &priv->cdev;
 
 	priv->regs = dev_request_mem_region(dev, 0);
diff --git a/drivers/serial/serial_altera_jtag.c b/drivers/serial/serial_altera_jtag.c
index 3e1b0cf..140ca26 100644
--- a/drivers/serial/serial_altera_jtag.c
+++ b/drivers/serial/serial_altera_jtag.c
@@ -90,7 +90,7 @@ static int altera_serial_jtag_probe(struct device_d *dev) {
 	struct console_device *cdev;
 	struct altera_serial_jtag_priv *priv;
 
-	priv = xmalloc(sizeof(*priv));
+	priv = xzalloc(sizeof(*priv));
 	cdev = &priv->cdev;
 
 	priv->regs = dev_request_mem_region(dev, 0);
diff --git a/drivers/serial/serial_blackfin.c b/drivers/serial/serial_blackfin.c
index 9ad5579..d38a06c 100644
--- a/drivers/serial/serial_blackfin.c
+++ b/drivers/serial/serial_blackfin.c
@@ -115,7 +115,7 @@ static int blackfin_serial_probe(struct device_d *dev)
 {
 	struct console_device *cdev;
 
-	cdev = xmalloc(sizeof(struct console_device));
+	cdev = xzalloc(sizeof(struct console_device));
 	dev->type_data = cdev;
 	cdev->dev = dev;
 	cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c
index 4923dcb..8547f36 100644
--- a/drivers/serial/serial_imx.c
+++ b/drivers/serial/serial_imx.c
@@ -320,7 +320,7 @@ static int imx_serial_probe(struct device_d *dev)
 	struct imx_serial_priv *priv;
 	uint32_t val;
 
-	priv = xmalloc(sizeof(*priv));
+	priv = xzalloc(sizeof(*priv));
 	cdev = &priv->cdev;
 
 	priv->regs = dev_request_mem_region(dev, 0);
diff --git a/drivers/serial/serial_netx.c b/drivers/serial/serial_netx.c
index a3273e9..4f4fb2d 100644
--- a/drivers/serial/serial_netx.c
+++ b/drivers/serial/serial_netx.c
@@ -140,7 +140,7 @@ static int netx_serial_probe(struct device_d *dev)
 {
 	struct console_device *cdev;
 
-	cdev = xmalloc(sizeof(struct console_device));
+	cdev = xzalloc(sizeof(struct console_device));
 	dev->type_data = cdev;
 	dev->priv = dev_request_mem_region(dev, 0);
 	cdev->dev = dev;
diff --git a/drivers/serial/serial_pl010.c b/drivers/serial/serial_pl010.c
index cb87541..e11406d 100644
--- a/drivers/serial/serial_pl010.c
+++ b/drivers/serial/serial_pl010.c
@@ -141,7 +141,7 @@ static int pl010_probe(struct device_d *dev)
 {
 	struct console_device *cdev;
 
-	cdev = xmalloc(sizeof(struct console_device));
+	cdev = xzalloc(sizeof(struct console_device));
 	dev->type_data = cdev;
 	dev->priv = dev_request_mem_region(dev, 0);
 	cdev->dev = dev;
diff --git a/drivers/serial/serial_s3c24x0.c b/drivers/serial/serial_s3c24x0.c
index abc08e0..1e27d48 100644
--- a/drivers/serial/serial_s3c24x0.c
+++ b/drivers/serial/serial_s3c24x0.c
@@ -129,7 +129,7 @@ static int s3c24x0_serial_probe(struct device_d *dev)
 {
 	struct console_device *cdev;
 
-	cdev = xmalloc(sizeof(struct console_device));
+	cdev = xzalloc(sizeof(struct console_device));
 	dev->type_data = cdev;
 	dev->priv = dev_request_mem_region(dev, 0);
 	cdev->dev = dev;
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] tlsf: implement malloc_stats
  2012-01-02 13:50 tlsf patches Sascha Hauer
  2012-01-02 13:50 ` [PATCH 1/3] tlsf: enable assertions Sascha Hauer
  2012-01-02 13:50 ` [PATCH] uart drivers: use xzalloc instead of xmalloc Sascha Hauer
@ 2012-01-02 13:50 ` Sascha Hauer
  2012-01-02 13:50 ` [PATCH 3/3] tlsf: remove unused stuff from tlsfbits.h Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-01-02 13:50 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/tlsf_malloc.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index a6f82ba..2fe443b 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -71,8 +71,29 @@ void *memalign(size_t alignment, size_t bytes)
 }
 EXPORT_SYMBOL(memalign);
 
-#ifdef CONFIG_CMD_MEMINFO
+struct malloc_stats {
+	size_t free;
+	size_t used;
+};
+
+static void malloc_walker(void* ptr, size_t size, int used, void *user)
+{
+	struct malloc_stats *s = user;
+
+	if (used)
+		s->used += size;
+	else
+		s->free += size;
+}
+
 void malloc_stats(void)
 {
+	struct malloc_stats s;
+
+	s.used = 0;
+	s.free = 0;
+
+	tlsf_walk_heap(tlsf_mem_pool, malloc_walker, &s);
+
+	printf("used: %10d\nfree: %10d\n", s.used, s.free);
 }
-#endif /* CONFIG_CMD_MEMINFO */
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] tlsf: remove unused stuff from tlsfbits.h
  2012-01-02 13:50 tlsf patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-01-02 13:50 ` [PATCH 2/3] tlsf: implement malloc_stats Sascha Hauer
@ 2012-01-02 13:50 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-01-02 13:50 UTC (permalink / raw)
  To: barebox

Also, as this file is locally used by the tlsf implementation,
move this file to common.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/tlsfbits.h  |   55 ++++++++++++++++
 include/tlsfbits.h |  180 ----------------------------------------------------
 2 files changed, 55 insertions(+), 180 deletions(-)
 create mode 100644 common/tlsfbits.h
 delete mode 100644 include/tlsfbits.h

diff --git a/common/tlsfbits.h b/common/tlsfbits.h
new file mode 100644
index 0000000..93466e4
--- /dev/null
+++ b/common/tlsfbits.h
@@ -0,0 +1,55 @@
+#ifndef INCLUDED_tlsfbits
+#define INCLUDED_tlsfbits
+
+#include <linux/bitops.h>
+
+/*
+** Architecture-specific bit manipulation routines.
+**
+** TLSF achieves O(1) cost for malloc and free operations by limiting
+** the search for a free block to a free list of guaranteed size
+** adequate to fulfill the request, combined with efficient free list
+** queries using bitmasks and architecture-specific bit-manipulation
+** routines.
+**
+** Most modern processors provide instructions to count leading zeroes
+** in a word, find the lowest and highest set bit, etc. These
+** specific implementations will be used when available, falling back
+** to a reasonably efficient generic implementation.
+**
+** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
+** ffs/fls return 1-32 by default, returning 0 for error.
+*/
+
+static int tlsf_ffs(unsigned int word)
+{
+	return ffs(word) - 1;
+}
+
+static int tlsf_fls(unsigned int word)
+{
+	return fls(word) - 1;
+}
+
+/* Possibly 64-bit version of tlsf_fls. */
+#if defined (TLSF_64BIT)
+tlsf_decl int tlsf_fls_sizet(size_t size)
+{
+	int high = (int)(size >> 32);
+	int bits = 0;
+	if (high)
+	{
+		bits = 32 + tlsf_fls(high);
+	}
+	else
+	{
+		bits = tlsf_fls((int)size & 0xffffffff);
+
+	}
+	return bits;
+}
+#else
+#define tlsf_fls_sizet tlsf_fls
+#endif
+
+#endif
diff --git a/include/tlsfbits.h b/include/tlsfbits.h
deleted file mode 100644
index 3e5c82a..0000000
--- a/include/tlsfbits.h
+++ /dev/null
@@ -1,180 +0,0 @@
-#ifndef INCLUDED_tlsfbits
-#define INCLUDED_tlsfbits
-
-#if defined(__cplusplus)
-#define tlsf_decl inline
-#else
-#define tlsf_decl static
-#endif
-
-/*
-** Architecture-specific bit manipulation routines.
-**
-** TLSF achieves O(1) cost for malloc and free operations by limiting
-** the search for a free block to a free list of guaranteed size
-** adequate to fulfill the request, combined with efficient free list
-** queries using bitmasks and architecture-specific bit-manipulation
-** routines.
-**
-** Most modern processors provide instructions to count leading zeroes
-** in a word, find the lowest and highest set bit, etc. These
-** specific implementations will be used when available, falling back
-** to a reasonably efficient generic implementation.
-**
-** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
-** ffs/fls return 1-32 by default, returning 0 for error.
-*/
-
-/*
-** Detect whether or not we are building for a 32- or 64-bit (LP/LLP)
-** architecture. There is no reliable portable method at compile-time.
-*/
-#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \
-	|| defined (_WIN64) || defined (__LP64__) || defined (__LLP64__)
-#define TLSF_64BIT
-#endif
-
-/*
-** gcc 3.4 and above have builtin support, specialized for architecture.
-** Some compilers masquerade as gcc; patchlevel test filters them out.
-*/
-#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
-	&& defined (__GNUC_PATCHLEVEL__)
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	return __builtin_ffs(word) - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = word ? 32 - __builtin_clz(word) : 0;
-	return bit - 1;
-}
-
-#elif defined (_MSC_VER) && defined (_M_IX86) && (_MSC_VER >= 1400)
-/* Microsoft Visual C++ 2005 support on x86 architectures. */
-
-#include <intrin.h>
-
-#pragma intrinsic(_BitScanReverse)
-#pragma intrinsic(_BitScanForward)
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	unsigned long index;
-	return _BitScanReverse(&index, word) ? index : -1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	unsigned long index;
-	return _BitScanForward(&index, word) ? index : -1;
-}
-
-#elif defined (_MSC_VER) && defined (_M_PPC)
-/* Microsoft Visual C++ support on PowerPC architectures. */
-
-#include <ppcintrinsics.h>
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = 32 - _CountLeadingZeros(word);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - _CountLeadingZeros(reverse);
-	return bit - 1;
-}
-
-#elif defined (__ARMCC_VERSION)
-/* RealView Compilation Tools for ARM */
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - __clz(reverse);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = word ? 32 - __clz(word) : 0;
-	return bit - 1;
-}
-
-#elif defined (__ghs__)
-/* Green Hills support for PowerPC */
-
-#include <ppc_ghs.h>
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - __CLZ32(reverse);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = word ? 32 - __CLZ32(word) : 0;
-	return bit - 1;
-}
-
-#else
-/* Fall back to generic implementation. */
-
-tlsf_decl int tlsf_fls_generic(unsigned int word)
-{
-	int bit = 32;
-
-	if (!word) bit -= 1;
-	if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; }
-	if (!(word & 0xff000000)) { word <<= 8; bit -= 8; }
-	if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; }
-	if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; }
-	if (!(word & 0x80000000)) { word <<= 1; bit -= 1; }
-
-	return bit;
-}
-
-/* Implement ffs in terms of fls. */
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	return tlsf_fls_generic(word & (~word + 1)) - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	return tlsf_fls_generic(word) - 1;
-}
-
-#endif
-
-/* Possibly 64-bit version of tlsf_fls. */
-#if defined (TLSF_64BIT)
-tlsf_decl int tlsf_fls_sizet(size_t size)
-{
-	int high = (int)(size >> 32);
-	int bits = 0;
-	if (high)
-	{
-		bits = 32 + tlsf_fls(high);
-	}
-	else
-	{
-		bits = tlsf_fls((int)size & 0xffffffff);
-
-	}
-	return bits;
-}
-#else
-#define tlsf_fls_sizet tlsf_fls
-#endif
-
-#undef tlsf_decl
-
-#endif
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-02 13:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-02 13:50 tlsf patches Sascha Hauer
2012-01-02 13:50 ` [PATCH 1/3] tlsf: enable assertions Sascha Hauer
2012-01-02 13:50 ` [PATCH] uart drivers: use xzalloc instead of xmalloc Sascha Hauer
2012-01-02 13:50 ` [PATCH 2/3] tlsf: implement malloc_stats Sascha Hauer
2012-01-02 13:50 ` [PATCH 3/3] tlsf: remove unused stuff from tlsfbits.h Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox