From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5] [RFC] early_malloc for DM added.
Date: Sat, 22 Sep 2012 15:19:30 +0200 [thread overview]
Message-ID: <201209221519.30436.marex@denx.de> (raw)
In-Reply-To: <CAEB7QLD-_XQLHy8zNENEpytQLX8V5r_V4uhjr0f8OoXV80Swnw@mail.gmail.com>
Dear Tomas Hlavacek,
> Hello Marek,
>
> On Sat, Sep 22, 2012 at 2:28 AM, Marek Vasut <marex@denx.de> wrote:
> > Dear Tomas Hlavacek,
> >
> >> early_malloc for DM with support for more heaps and lightweight
> >> first heap in the same memory as an early stack.
> >>
> >> Adaptation layer for seamless calling of early_malloc or dlmalloc from
> >> DM based on init stage added (dmmalloc() and related functions).
> >>
> >> Signed-off-by: Tomas Hlavacek <tmshlvck@gmail.com>
> >
> > [...]
> >
> >> 31 files changed, 363 insertions(+)
> >> create mode 100644 common/dmmalloc.c
> >> create mode 100644 include/dmmalloc.h
> >
> > What exactly changed in this version? Changelog is missing.
>
> Preprocessor config-dependent (ifdef ... endif) blocks are different.
> early_brk call from early_malloc when the heaps are full.
> default early_brk checks existing heap for before setting.
>
> > [...]
> >
> >> +static int early_malloc_active(void)
> >> +{
> >> + if ((gd->flags & GD_FLG_RELOC) == GD_FLG_RELOC)
> >> + return 0;
> >
> > Did you completely ignore the comments?
>
> Yes, this is ugly and I did not notice the point of (your?) comment
> while reworking this tiny part again and again... Sorry.
I think it was GR.
> >> + return 1;
> >> +}
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> +#ifdef CONFIG_SYS_EARLY_MALLOC
> >> +void *dmmalloc(size_t size)
> >> +{
> >> + if (early_malloc_active())
> >> + return early_malloc(size);
> >> + return malloc(size);
> >> +}
> >> +#else /* CONFIG_SYS_EARLY_MALLOC */
> >> +#define dmmalloc malloc
> >
> > How is this actually supposed to work?
>
> Of course, this have to be in the header file dmmalloc.h. Just ignore
> the #else ... #endif part.
That won't work well either ... I'd say make the wrapper static inline for
typechecking, no ?
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> +#ifdef CONFIG_SYS_EARLY_MALLOC
> >> +void dmfree(void *ptr)
> >> +{
> >> + if (early_malloc_active())
> >> + return;
> >> + free(ptr);
> >> +}
> >> +#else /* CONFIG_SYS_EARLY_MALLOC */
> >> +#define dmfree free
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> +#ifdef CONFIG_SYS_EARLY_MALLOC
> >> +void *dmcalloc(size_t n, size_t elem_size)
> >> +{
> >> + if (early_malloc_active())
> >> + return NULL;
> >> + return calloc(n, elem_size);
> >> +}
> >> +#else /* CONFIG_SYS_EARLY_MALLOC */
> >> +#define dmcalloc calloc
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> +#ifdef CONFIG_SYS_EARLY_MALLOC
> >> +void *dmrealloc(void *oldmem, size_t bytes)
> >> +{
> >> + if (early_malloc_active())
> >> + return NULL;
> >> + return dmrealloc(oldmem, bytes);
> >> +}
> >> +#else /* CONFIG_SYS_EARLY_MALLOC */
> >> +#define dmrealloc realloc
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> diff --git a/include/dmmalloc.h b/include/dmmalloc.h
> >> new file mode 100644
> >> index 0000000..726c6c9
> >> --- /dev/null
> >> +++ b/include/dmmalloc.h
> >> @@ -0,0 +1,56 @@
> >> +/*
> >> + * (C) Copyright 2012
> >> + * Tomas Hlavacek (tmshlvck at gmail.com)
> >> + *
> >> + * See file CREDITS for list of people who contributed to this
> >> + * project.
> >> + *
> >> + * This program is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU General Public License as
> >> + * published by the Free Software Foundation; either version 2 of
> >> + * the License, or (at your option) any later version.
> >> + *
> >> + * This program 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 General Public License for more details.
> >> + *
> >> + * You should have received a copy of the GNU General Public License
> >> + * along with this program; if not, write to the Free Software
> >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> >> + * MA 02111-1307 USA
> >> + */
> >> +
> >> +#ifndef __INCLUDE_DMMALLOC_H
> >> +#define __INCLUDE_DMMALLOC_H
> >> +
> >> +#include <config.h>
> >> +#include <linux/stddef.h> /* for size_t */
> >> +
> >> +#if (!defined(CONFIG_SYS_EARLY_HEAP_ADDR)) || \
> >> + (!defined(CONFIG_SYS_EARLY_HEAP_SIZE))
> >> +#undef CONFIG_SYS_EARLY_MALLOC
> >> +#endif /* CONFIG_SYS_EARLY_HEAP_ADDR */
> >> +
> >> +#ifdef CONFIG_SYS_EARLY_MALLOC
> >> +struct early_heap_header {
> >> + void *free_space_pointer;
> >> + size_t free_bytes;
> >> + void *next_early_heap;
> >> +};
> >> +
> >> +struct early_heap_header *early_brk(size_t size);
> >> +void *early_malloc(size_t size);
> >> +
> >> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> >> +
> >> +#ifdef CONFIG_SYS_DM
> >
> > Isn't it CONFIG_DM ?
>
> I will change that. (Is it consistent with the naming convention? I
> mean: What the "_SYS_" exactly means?)
>
> Tomas
Best regards,
Marek Vasut
next prev parent reply other threads:[~2012-09-22 13:19 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-27 12:12 [U-Boot] [PATCH 1/1] [RFC] DM: early_malloc for DM added Tomas Hlavacek
2012-08-27 12:18 ` Marek Vasut
2012-08-27 12:37 ` Tomas Hlavacek
2012-08-27 12:42 ` [U-Boot] [PATCHv2 " Tomas Hlavacek
2012-08-27 23:02 ` Graeme Russ
2012-08-28 0:11 ` Graeme Russ
2012-08-28 0:18 ` Graeme Russ
2012-09-18 7:13 ` [U-Boot] [PATCHv4] " Tomas Hlavacek
2012-09-18 10:57 ` Marek Vasut
2012-09-18 23:29 ` Graeme Russ
2012-09-18 23:33 ` Marek Vasut
2012-09-18 23:44 ` Graeme Russ
2012-09-18 23:53 ` Marek Vasut
2012-09-19 18:29 ` Tom Rini
2012-09-22 0:37 ` Tomas Hlavacek
2012-09-18 23:25 ` Graeme Russ
2012-09-22 0:25 ` [U-Boot] [PATCH v5] [RFC] " Tomas Hlavacek
2012-09-22 0:28 ` Marek Vasut
2012-09-22 7:52 ` Tomas Hlavacek
2012-09-22 13:19 ` Marek Vasut [this message]
2012-09-22 22:09 ` [U-Boot] [PATCH v6] " Tomas Hlavacek
2012-09-23 13:06 ` Graeme Russ
2012-09-23 15:30 ` Tomas Hlavacek
2012-09-23 15:38 ` [U-Boot] [PATCH v7] " Tomas Hlavacek
2012-09-23 16:15 ` [U-Boot] [PATCH v8] " Tomas Hlavacek
2012-09-23 16:32 ` Wolfgang Denk
2012-09-23 16:47 ` Tomas Hlavacek
2012-09-24 21:48 ` Tom Rini
2012-09-23 23:11 ` Marek Vasut
2012-09-24 14:16 ` Tomas Hlavacek
2012-09-24 14:19 ` Marek Vasut
2012-09-25 0:37 ` Graeme Russ
2012-09-25 8:43 ` Tomas Hlavacek
2012-09-25 9:09 ` Graeme Russ
2012-09-25 23:04 ` Graeme Russ
2012-09-26 10:16 ` Tomas Hlavacek
2012-09-26 23:03 ` Graeme Russ
2012-09-24 0:00 ` Graeme Russ
2012-09-24 0:35 ` Tomas Hlavacek
2012-09-24 0:46 ` Graeme Russ
2012-10-24 23:49 ` [U-Boot] [PATCH v9] [RFC] Add dmmalloc module for DM Tomas Hlavacek
2012-10-25 1:40 ` Graeme Russ
2012-10-25 19:16 ` Tomas Hlavacek
2012-10-25 23:04 ` Graeme Russ
2012-10-28 23:20 ` [U-Boot] [PATCH v10] " Tomas Hlavacek
2013-11-05 15:26 ` Mateusz Zalega
2013-11-05 17:17 ` Tom Rini
2013-11-05 17:26 ` Mateusz Zalega
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=201209221519.30436.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/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