mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [RFC PATCH 1/3] import TLSF 2.0 from http://tlsf.baisoku.org/tlsf-2.0.zip
Date: Fri, 9 Dec 2011 10:24:51 +0100	[thread overview]
Message-ID: <20111209092451.GA27267@pengutronix.de> (raw)
In-Reply-To: <1323353029-17281-2-git-send-email-antonynpavlov@gmail.com>

On Thu, Dec 08, 2011 at 06:03:47PM +0400, Antony Pavlov wrote:
> TLSF: Two Level Segregated Fit memory allocator implementation.
> Written by Matthew Conte (matt@baisoku.org).
> Public Domain, no restrictions.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  common/tlsf.c      |  961 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/tlsf.h     |   52 +++
>  include/tlsfbits.h |  180 ++++++++++
>  3 files changed, 1193 insertions(+), 0 deletions(-)
>  create mode 100644 common/tlsf.c
>  create mode 100644 include/tlsf.h
>  create mode 100644 include/tlsfbits.h
> 
> diff --git a/common/tlsf.c b/common/tlsf.c
> new file mode 100644
> index 0000000..02dc8d4
> --- /dev/null
> +++ b/common/tlsf.c
> @@ -0,0 +1,961 @@

We should probably add a header here and at least say where the code
comes from. 'not subject to any licensing restrictions' for me means
that we can just add the standard GPL header here, but I'm no lawyer.


> diff --git a/include/tlsfbits.h b/include/tlsfbits.h
> new file mode 100644
> index 0000000..3e5c82a
> --- /dev/null
> +++ b/include/tlsfbits.h
> @@ -0,0 +1,180 @@
> +#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

We should throw these ifdefs away and just use:

#include <linux/bitops.h>

tlsf_decl int tlsf_ffs(unsigned int word)
{
	return ffs(word) - 1;
}

tlsf_decl int tlsf_fls(unsigned int word)
{
	return fls(word) - 1;
}

You could fold this into the barebox adoption patch so that we still
have the original import clean.


Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2011-12-09  9:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-08 14:03 [RFC PATCH 0/3] add tlsf memory allocator Antony Pavlov
2011-12-08 14:03 ` [RFC PATCH 1/3] import TLSF 2.0 from http://tlsf.baisoku.org/tlsf-2.0.zip Antony Pavlov
2011-12-09  9:24   ` Sascha Hauer [this message]
2011-12-08 14:03 ` [RFC PATCH 2/3] adapt tlsf for barebox Antony Pavlov
2011-12-08 14:03 ` [RFC PATCH 3/3] add tlsf-based malloc implementation Antony Pavlov
2011-12-09  9:31   ` Sascha Hauer
2011-12-09  9:17 ` [RFC PATCH 0/3] add tlsf memory allocator Sascha Hauer
2011-12-23 10:04   ` Sascha Hauer
2011-12-23 11:20     ` Antony Pavlov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111209092451.GA27267@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox