diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index d44bae4abd..8b87bbcee9 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -3948,6 +3948,13 @@ build are a few optimizations that can can be done and (2) the GRAN_HANDLE is not needed. +
  • + CONFIG_GRAN_INTR: + Normally mutual exclusive access to granule allocator data is assured using a semaphore. + If this option is set then, instead, mutual exclusion logic will disable interrupts. + While this options is more invasive to system performance, it will also support use of the + granule allocator from interrupt level logic. +
  • CONFIG_DEBUG_GRAM: Just like CONFIG_DEBUG_MM, but only generates ouput from the gran diff --git a/configs/README.txt b/configs/README.txt index b3d0e91f51..1c14e8388f 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -299,6 +299,11 @@ defconfig -- This is a configuration file similar to the Linux gran_initialize will be called only once. In this case, (1) there are a few optimizations that can can be done and (2) the GRAN_HANDLE is not needed. + CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator + data is assured using a semaphore. If this option is set then, instead, + mutual exclusion logic will disable interrupts. While this options is + more invasive to system performance, it will also support use of the + granule allocator from interrupt level logic. CONFIG_DEBUG_GRAM Just like CONFIG_DEBUG_MM, but only generates ouput from the gran allocation logic. diff --git a/configs/fire-stm32v2/src/fire-internal.h b/configs/fire-stm32v2/src/fire-internal.h index f51bd0ef99..801fb127ea 100644 --- a/configs/fire-stm32v2/src/fire-internal.h +++ b/configs/fire-stm32v2/src/fire-internal.h @@ -296,7 +296,7 @@ void stm32_selectlcd(void); * * Description: * Initialize the SPI-based SD card. Requires CONFIG_DISABLE_MOUNTPOINT=n - * and CONFIG_STM32_SPI1=y + * and CONFIG_STM32_SDIO=y * ****************************************************************************/ diff --git a/configs/fire-stm32v2/src/up_mmcsd.c b/configs/fire-stm32v2/src/up_mmcsd.c index d3fa611bd7..c0c6693d34 100644 --- a/configs/fire-stm32v2/src/up_mmcsd.c +++ b/configs/fire-stm32v2/src/up_mmcsd.c @@ -65,7 +65,7 @@ /* Can't support MMC/SD features if mountpoints are disabled */ -#ifndef CONFIG_DISABLE_MOUNTPOINT +#ifdef CONFIG_DISABLE_MOUNTPOINT # undef HAVE_MMCSD #endif @@ -78,7 +78,7 @@ * * Description: * Initialize the SPI-based SD card. Requires CONFIG_DISABLE_MOUNTPOINT=n - * and CONFIG_STM32_SPI1=y + * and CONFIG_STM32_SDIO=y * ****************************************************************************/ @@ -93,7 +93,7 @@ int stm32_sdinitialize(int minor) sdio = sdio_initialize(STM32_MMCSDSLOTNO); if (!sdio) { - message("Failed to initialize SDIO slot %d\n", STM32_MMCSDSLOTNO); + fdbg("Failed to initialize SDIO slot %d\n", STM32_MMCSDSLOTNO); return -ENODEV; } @@ -104,7 +104,7 @@ int stm32_sdinitialize(int minor) ret = mmcsd_slotinitialize(minor, sdio); if (ret != OK) { - message("Failed to bind SDIO slot %d to the MMC/SD driver, minor=%d\n", + fdbg("Failed to bind SDIO slot %d to the MMC/SD driver, minor=%d\n", STM32_MMCSDSLOTNO, minor); } diff --git a/include/nuttx/gran.h b/include/nuttx/gran.h index 8e009ab810..f3a6d0fe9b 100644 --- a/include/nuttx/gran.h +++ b/include/nuttx/gran.h @@ -2,7 +2,7 @@ * include/nuttx/gran.h * General purpose granule memory allocator. * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -57,6 +57,11 @@ * granule allocator (i.e., gran_initialize will be called only once. * In this case, (1) there are a few optimizations that can can be done * and (2) the GRAN_HANDLE is not needed. + * CONFIG_GRAN_INTR - Normally mutual exclusive access to granule allocator + * data is assured using a semaphore. If this option is set then, instead, + * mutual exclusion logic will disable interrupts. While this options is + * more invasive to system performance, it will also support use of the + * granule allocator from interrupt level logic. * CONFIG_DEBUG_GRAN - Just like CONFIG_DEBUG_MM, but only generates ouput * from the gran allocation logic. */ diff --git a/mm/Kconfig b/mm/Kconfig index 2e5bc95db8..5da12b65e9 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -65,6 +65,17 @@ config GRAN_SINGLE are a few optimizations that can can be done and (2) the GRAN_HANDLE is not needed. +config GRAN_INTR + bool "Interrupt level support" + default n + depends on GRAN + ---help--- + Normally mutual exclusive access to granule allocator data is assured + using a semaphore. If this option is set then, instead, mutual + exclusion logic will disable interrupts. While this options is more + invasive to system performance, it will also support use of the granule + allocator from interrupt level logic. + config DEBUG_GRAN bool "Granule Allocator Debug" default n diff --git a/mm/Makefile b/mm/Makefile index 0cd28b23d1..0ccf5a09a9 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -1,7 +1,7 @@ ############################################################################ # mm/Makefile # -# Copyright (C) 2007 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,7 +41,7 @@ CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk mm_memalign.c mm_free.c mm_mallinfo.c ifeq ($(CONFIG_GRAN),y) -CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c +CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c mm_grancritical.c endif AOBJS = $(ASRCS:.S=$(OBJEXT)) diff --git a/mm/mm_gran.h b/mm/mm_gran.h index 4a76397c82..a4f51490d7 100644 --- a/mm/mm_gran.h +++ b/mm/mm_gran.h @@ -45,6 +45,7 @@ #include #include +#include #include /**************************************************************************** @@ -88,7 +89,11 @@ struct gran_s { uint8_t log2gran; /* Log base 2 of the size of one granule */ uint16_t ngranules; /* The total number of (aligned) granules in the heap */ +#ifdef CONFIG_GRAN_INTR + irqstate_t irqstate; /* For exclusive access to the GAT */ +#else sem_t exclsem; /* For exclusive access to the GAT */ +#endif uintptr_t heapstart; /* The aligned start of the granule heap */ uint32_t gat[1]; /* Start of the granule allocation table */ }; @@ -108,11 +113,10 @@ extern FAR struct gran_s *g_graninfo; ****************************************************************************/ /**************************************************************************** - * Name: gran_semtake and gran_semgive + * Name: gran_enter_critical and gran_leave_critical * * Description: - * Managed semaphore for the granule allocator. gran_semgive is - * implemented as a macro. + * Critical section management for the granule allocator. * * Input Parameters: * priv - Pointer to the gran state @@ -122,7 +126,7 @@ extern FAR struct gran_s *g_graninfo; * ****************************************************************************/ -void gran_semtake(FAR struct gran_s *priv); -#define gran_semgive(p) sem_post(&(p)->exclsem); +void gran_enter_critical(FAR struct gran_s *priv); +void gran_leave_critical(FAR struct gran_s *priv); #endif /* __MM_MM_GRAN_H */ diff --git a/mm/mm_granalloc.c b/mm/mm_granalloc.c index 62fbc0870a..e8022bf721 100644 --- a/mm/mm_granalloc.c +++ b/mm/mm_granalloc.c @@ -127,12 +127,12 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) { unsigned int ngranules; size_t tmpmask; - uintptr_t alloc; - uint32_t curr; - uint32_t next; - uint32_t mask; - int i; - int j; + uintptr_t alloc; + uint32_t curr; + uint32_t next; + uint32_t mask; + int i; + int j; DEBUGASSERT(priv && size <= 32 * (1 << priv->log2gran)); @@ -140,7 +140,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) { /* Get exclusive access to the GAT */ - gran_semtake(priv); + gran_enter_critical(priv); /* How many contiguous granules we we need to find? */ @@ -199,7 +199,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) /* And return the allocation address */ - gran_semgive(priv); + gran_leave_critical(priv); return (FAR void *)alloc; } @@ -221,7 +221,7 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size) } } - gran_semgive(priv); + gran_leave_critical(priv); return NULL; } diff --git a/mm/mm_granfree.c b/mm/mm_granfree.c index 96fdda87e0..aa14207f36 100644 --- a/mm/mm_granfree.c +++ b/mm/mm_granfree.c @@ -75,13 +75,13 @@ static inline void gran_common_free(FAR struct gran_s *priv, unsigned int granmask; unsigned int ngranules; unsigned int avail; - uint32_t gatmask; + uint32_t gatmask; DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran)); /* Get exclusive access to the GAT */ - gran_semtake(priv); + gran_enter_critical(priv); /* Determine the granule number of the first granule in the allocation */ @@ -121,7 +121,7 @@ static inline void gran_common_free(FAR struct gran_s *priv, priv->gat[gatidx] &= ~(gatmask << gatbit); } - gran_semgive(priv); + gran_leave_critical(priv); } /**************************************************************************** diff --git a/mm/mm_graninit.c b/mm/mm_graninit.c index d3144b2aa6..cde2370d0b 100644 --- a/mm/mm_graninit.c +++ b/mm/mm_graninit.c @@ -119,7 +119,12 @@ static inline FAR struct gran_s *gran_common_initialize(FAR void *heapstart, priv->log2gran = log2gran; priv->ngranules = ngranules; priv->heapstart = alignedstart; + + /* Initialize mutual exclusion support */ + +#ifndef CONFIG_GRAN_INTR sem_init(&priv->exclsem, 0, 1); +#endif } return priv; @@ -172,38 +177,4 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gr } #endif -/**************************************************************************** - * Name: gran_semtake and gran_semgive - * - * Description: - * Managed semaphore for the granule allocator. gran_semgive is - * implemented as a macro. - * - * Input Parameters: - * priv - Pointer to the gran state - * - * Returned Value: - * None - * - ****************************************************************************/ - -void gran_semtake(FAR struct gran_s *priv) -{ - int ret; - - /* Continue waiting if we are awakened by a signal */ - - do - { - ret = sem_wait(&priv->exclsem); - if (ret < 0) - { - DEBUGASSERT(errno == EINTR); - } - } - while (ret < 0); -} - #endif /* CONFIG_GRAN */ - -