Changeset 683 for trunk/kernel/mm/kmem.h


Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (3 years ago)
Author:
alain
Message:

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/kmem.h

    r656 r683  
    11/*
    2  * kmem.h - kernel unified memory allocator interface
     2 * kmem.h - unified kernel memory allocator definition
    33 *
    4  * Authors  Alain Greiner (2016,2017,2018,2019)
     4 * Authors  Alain Greiner     (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2929
    3030/*************************************************************************************
    31  * This enum defines the three Kernel Memory Allocaror types
    32  ************************************************************************************/
    33 
    34 enum
    35 {
    36     KMEM_PPM              = 0,   /*! PPM allocator                                  */
    37     KMEM_KCM              = 1,   /*! KCM allocator                                  */
    38     KMEM_KHM              = 2,   /*! KHM allocator                                  */
    39 };
    40 
    41 /*************************************************************************************
    4231 * This defines the generic Allocation Flags that can be associated to
    4332 * a Kernel Memory Request.
     
    4534
    4635#define AF_NONE       0x0000   // no attributes
    47 #define AF_KERNEL     0x0001   // for kernel use
    48 #define AF_ZERO       0x0002   // must be reset to 0
    49 
    50 /*************************************************************************************
    51  * This structure defines a Kernel Memory Request.
    52  ************************************************************************************/
    53 
    54 typedef struct kmem_req_s
    55 {
    56     uint32_t      type;   /*! KMEM_PPM / KMEM_KCM / KMEM_KHM                        */
    57     uint32_t      order;  /*! PPM: ln2(pages) / KCM: ln2(bytes) / KHM: bytes        */
    58     uint32_t      flags;  /*! request attributes                                    */
    59     void        * ptr;    /*! local pointer on allocated buffer (only used by free) */
    60 }
    61 kmem_req_t;
     36#define AF_KERNEL     0x0001   // for kernel use ???
     37#define AF_ZERO       0x0002   // data buffer must be reset to 0
    6238
    6339/*************************************************************************************
    6440 * These two functions allocate physical memory in a local or remote cluster
    65  * as specified by the kmem_req_t request descriptor, and return a local pointer
    66  * on the allocated buffer. It uses three specialised physical memory allocators:
    67  * - PPM (Physical Pages Manager) allocates N contiguous small physical pages.
    68  *       N is a power of 2, and req.order = ln(N). Implement the buddy algorithm.
    69  * - KCM (Kernel Cache Manager) allocates aligned blocks of M bytes from a cache.
    70  *       M is a power of 2, and req.order = ln( M ). One cache per block size.
    71  * - KHM (Kernel Heap Manager) allocates physical memory buffers of M bytes,
    72  *       M can have any value, and req.order = M.
    73  *
    74  * WARNING: the physical memory allocated with a given allocator type must be
    75  *          released using the same allocator type.
     41 * as specified by the <cxy>, <order> and <flags> arguments, and return a local
     42 * pointer on the allocated buffer. The buffer size (in bytes) is a power of 2,
     43 * equal to (1 << order) bytes. It can be initialized to zero if requested.
     44 * Depending on the <order> value, it uses two specialised allocators:
     45 * - When order is larger or equal to CONFIG_PPM_PAGE_ORDER, the PPM (Physical Pages
     46 *   Manager) allocates 2**(order - PPM_PAGE_ORDER) contiguous small physical pages.
     47 *   This allocator implements the buddy algorithm.
     48 * - When order is smaller than CONFIG_PPM_PAGE_ORDER, the KCM (Kernel Cache Manager)
     49 *   allocates an aligned block of 2**order bytes from specialised KCM[ORDER] caches
     50 *  (one KCM cache per block size). 
    7651 *************************************************************************************
    77  * @ cxy   : target cluster identifier for a remote access.
    78  * @ req   : local pointer on allocation request.
     52 * @ cxy    : [in] target cluster identifier for a remote access).
     53 * @ order  : [in] ln( block size in bytes).
     54 * @ flags  : [in] allocation flags defined above.
    7955 * @ return local pointer on allocated buffer if success / return NULL if no memory.
    8056 ************************************************************************************/
    81 void * kmem_alloc( kmem_req_t * req );
     57void * kmem_alloc( uint32_t  order,
     58                   uint32_t  flags );
    8259
    83 void * kmem_remote_alloc( cxy_t        cxy,
    84                           kmem_req_t * req );
     60void * kmem_remote_alloc( cxy_t     cxy,
     61                          uint32_t  order,
     62                          uint32_t  flags );
    8563
    8664/*************************************************************************************
    87  * These two functions release previously allocated physical memory, as specified
    88  * by the <type> and <ptr> fields of the kmem_req_t request descriptor.
     65 * These two functions release a previously allocated physical memory block,
     66 * as specified by the <cxy>, <order> and <ptr> arguments.
     67 * - When order is larger or equal to CONFIG_PPM_PAGE_ORDER, the PPM (Physical Pages
     68 *   Manager) releases 2**(order - PPM_PAGE_ORDER) contiguous small physical pages.
     69 *   This allocator implements the buddy algorithm.
     70 * - When order is smaller than CONFIG_PPM_PAGE_ORDER, the KCM (Kernel Cache Manager)
     71 *   release release the block of 2**order bytes to the specialised KCM[order] cache.
    8972 *************************************************************************************
    90  * @ cxy   : target cluster identifier for a remote access.
    91  * @ req : local pointer to request descriptor.
     73 * @ cxy    : [in] target cluster identifier for a remote access.
     74 * @ ptr    : [in] local pointer to released block.
     75 * @ order  : [in] ln( block size in bytes ).
    9276 ************************************************************************************/
    93 void  kmem_free ( kmem_req_t * req );
     77void  kmem_free( void    * ptr,
     78                 uint32_t  order );
    9479
    95 void  kmem_remote_free( cxy_t        cxy,
    96                         kmem_req_t * req );
     80void  kmem_remote_free( cxy_t     cxy,
     81                        void    * ptr,
     82                        uint32_t  order );
    9783
    9884
Note: See TracChangeset for help on using the changeset viewer.