uclinux-2008R1-RC8(bf561)到VDSP5的移植(44):kmalloc和kzalloc的问题

 
快乐虾
http://blog.csdn.net/lights_joy/
  
 
本文适用于
ADI bf561 DSP
uclinux-2008r1-rc8 (移植到vdsp5)
Visual DSP++ 5.0
 
欢迎转载,但请保留作者信息
 
这两个函数的定义均在include/linux/slab_def.h中,其实现如下:
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);
}
在这两个函数中,根据size是否为编译时常数做了优化,但是在移植时由于VDSP5不支持 __builtin_constant_p这个宏,因此直接将这两个函数改为:
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);
}
虽然对性能会略有影响,但是也能完成正确的功能。

你可能感兴趣的:(优化,cache)