RTEMS CPU Kit with SuperCore  4.10.99.0
rtems/bdbuf.h
Go to the documentation of this file.
00001 
00008 /*
00009  * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
00010  * Author: Victor V. Vengerov <vvv@oktet.ru>
00011  *
00012  * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
00013  *    Rewritten to remove score mutex access. Fixes many performance
00014  *    issues.
00015  *    Change to support demand driven variable buffer sizes.
00016  *
00017  * Copyright (c) 2009-2012 embedded brains GmbH.
00018  */
00019 
00020 #ifndef _RTEMS_BDBUF_H
00021 #define _RTEMS_BDBUF_H
00022 
00023 #include <rtems.h>
00024 #include <rtems/libio.h>
00025 #include <rtems/chain.h>
00026 
00027 #include <rtems/blkdev.h>
00028 #include <rtems/diskdevs.h>
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00177 #if defined(RTEMS_POSIX_API)
00178   /*
00179    * Use the PTHREAD mutexes and condition variables if available.  This helps
00180    * on SMP configurations to avoid the home grown condition variables via
00181    * disabled preemption.
00182    */
00183   #define RTEMS_BDBUF_USE_PTHREAD
00184 #endif
00185 
00244 typedef enum
00245 {
00249   RTEMS_BDBUF_STATE_FREE = 0,
00250 
00254   RTEMS_BDBUF_STATE_EMPTY,
00255 
00259   RTEMS_BDBUF_STATE_CACHED,
00260 
00264   RTEMS_BDBUF_STATE_ACCESS_CACHED,
00265 
00269   RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
00270 
00274   RTEMS_BDBUF_STATE_ACCESS_EMPTY,
00275 
00279   RTEMS_BDBUF_STATE_ACCESS_PURGED,
00280 
00284   RTEMS_BDBUF_STATE_MODIFIED,
00285 
00289   RTEMS_BDBUF_STATE_SYNC,
00290 
00294   RTEMS_BDBUF_STATE_TRANSFER,
00295 
00299   RTEMS_BDBUF_STATE_TRANSFER_PURGED
00300 } rtems_bdbuf_buf_state;
00301 
00305 struct rtems_bdbuf_group;
00306 typedef struct rtems_bdbuf_group rtems_bdbuf_group;
00307 
00314 typedef struct rtems_bdbuf_buffer
00315 {
00316   rtems_chain_node link;       
00318   struct rtems_bdbuf_avl_node
00319   {
00320     struct rtems_bdbuf_buffer* left;   
00321     struct rtems_bdbuf_buffer* right;  
00322     signed char                cache;  
00323     signed char                bal;    
00324   } avl;
00325 
00326   rtems_disk_device *dd;        
00328   rtems_blkdev_bnum block;      
00330   unsigned char*    buffer;     
00332   rtems_bdbuf_buf_state state;           
00334   uint32_t waiters;              
00336   rtems_bdbuf_group* group;      
00338   uint32_t hold_timer;           
00341   int   references;              
00342   void* user;                    
00343 } rtems_bdbuf_buffer;
00344 
00352 struct rtems_bdbuf_group
00353 {
00354   rtems_chain_node    link;          
00356   size_t              bds_per_group; 
00359   uint32_t            users;         
00360   rtems_bdbuf_buffer* bdbuf;         
00361 };
00362 
00367 typedef struct rtems_bdbuf_config {
00368   uint32_t            max_read_ahead_blocks;   
00370   uint32_t            max_write_blocks;        
00372   rtems_task_priority swapout_priority;        
00374   uint32_t            swapout_period;          
00376   uint32_t            swap_block_hold;         
00377   size_t              swapout_workers;         
00380   rtems_task_priority swapout_worker_priority; 
00382   size_t              task_stack_size;         
00384   size_t              size;                    
00386   uint32_t            buffer_min;              
00387   uint32_t            buffer_max;              
00390   rtems_task_priority read_ahead_priority;     
00392 } rtems_bdbuf_config;
00393 
00399 extern const rtems_bdbuf_config rtems_bdbuf_configuration;
00400 
00405 #define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT    0
00406 
00410 #define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT         16
00411 
00415 #define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT    15
00416 
00420 #define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
00421 
00425 #define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT  1000
00426 
00430 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT     0
00431 
00435 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
00436                              RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
00437 
00441 #define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
00442   RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
00443 
00447 #define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
00448 
00452 #define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
00453 
00457 #define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
00458 
00462 #define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
00463 
00476 rtems_status_code
00477 rtems_bdbuf_init (void);
00478 
00507 rtems_status_code
00508 rtems_bdbuf_get (
00509   rtems_disk_device *dd,
00510   rtems_blkdev_bnum block,
00511   rtems_bdbuf_buffer** bd
00512 );
00513 
00541 rtems_status_code
00542 rtems_bdbuf_read (
00543   rtems_disk_device *dd,
00544   rtems_blkdev_bnum block,
00545   rtems_bdbuf_buffer** bd
00546 );
00547 
00567 rtems_status_code
00568 rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
00569 
00591 rtems_status_code
00592 rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
00593 
00614 rtems_status_code
00615 rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
00616 
00634 rtems_status_code
00635 rtems_bdbuf_syncdev (rtems_disk_device *dd);
00636 
00648 void
00649 rtems_bdbuf_purge_dev (rtems_disk_device *dd);
00650 
00675 rtems_status_code
00676 rtems_bdbuf_set_block_size (rtems_disk_device *dd,
00677                             uint32_t           block_size,
00678                             bool               sync);
00679 
00683 void
00684 rtems_bdbuf_get_device_stats (const rtems_disk_device *dd,
00685                               rtems_blkdev_stats      *stats);
00686 
00690 void
00691 rtems_bdbuf_reset_device_stats (rtems_disk_device *dd);
00692 
00695 #ifdef __cplusplus
00696 }
00697 #endif
00698 
00699 #endif