Transplantation of Uclinux-2008r1-rc8 (bf561) to VDSP5: Problems of Kmalloc and Kzalloc

Source: Internet
Author: User
Tags goto

These two functions are defined in INCLUDE/LINUX/SLAB_DEF.H and are implemented as follows:

static inline void *kmalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
{
extern void __you_cannot_kmalloc_that_much (void);
__you_cannot_kmalloc_that_much ();
}
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_alloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_alloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kmalloc (size, flags);
}
static inline void *kzalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
{
extern void __you_cannot_kzalloc_that_much (void);
__you_cannot_kzalloc_that_much ();
}
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kzalloc (size, flags);
}

In both functions, depending on whether the size is a compile-time constant, but as VDSP5 does not support the __builtin_constant_p macro when porting, the two functions are changed directly to:

static inline void *kmalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
// {
extern void __you_cannot_kmalloc_that_much (void);
__you_cannot_kmalloc_that_much ();
// }
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_alloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_alloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kmalloc (size, flags);
}
static inline void *kzalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
// {
extern void __you_cannot_kzalloc_that_much (void);
__you_cannot_kzalloc_that_much ();
// }
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kzalloc (size, flags);
}

Although the performance will be slightly affected, but also to complete the correct function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.