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 
00235 typedef enum
00236 {
00240   RTEMS_BDBUF_STATE_FREE = 0,
00241 
00245   RTEMS_BDBUF_STATE_EMPTY,
00246 
00250   RTEMS_BDBUF_STATE_CACHED,
00251 
00255   RTEMS_BDBUF_STATE_ACCESS_CACHED,
00256 
00260   RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
00261 
00265   RTEMS_BDBUF_STATE_ACCESS_EMPTY,
00266 
00270   RTEMS_BDBUF_STATE_ACCESS_PURGED,
00271 
00275   RTEMS_BDBUF_STATE_MODIFIED,
00276 
00280   RTEMS_BDBUF_STATE_SYNC,
00281 
00285   RTEMS_BDBUF_STATE_TRANSFER,
00286 
00290   RTEMS_BDBUF_STATE_TRANSFER_PURGED
00291 } rtems_bdbuf_buf_state;
00292 
00296 struct rtems_bdbuf_group;
00297 typedef struct rtems_bdbuf_group rtems_bdbuf_group;
00298 
00305 typedef struct rtems_bdbuf_buffer
00306 {
00307   rtems_chain_node link;       
00309   struct rtems_bdbuf_avl_node
00310   {
00311     struct rtems_bdbuf_buffer* left;   
00312     struct rtems_bdbuf_buffer* right;  
00313     signed char                cache;  
00314     signed char                bal;    
00315   } avl;
00316 
00317   rtems_disk_device *dd;        
00319   rtems_blkdev_bnum block;      
00321   unsigned char*    buffer;     
00323   rtems_bdbuf_buf_state state;           
00325   uint32_t waiters;              
00327   rtems_bdbuf_group* group;      
00329   uint32_t hold_timer;           
00332   int   references;              
00333   void* user;                    
00334 } rtems_bdbuf_buffer;
00335 
00343 struct rtems_bdbuf_group
00344 {
00345   rtems_chain_node    link;          
00347   size_t              bds_per_group; 
00350   uint32_t            users;         
00351   rtems_bdbuf_buffer* bdbuf;         
00352 };
00353 
00358 typedef struct rtems_bdbuf_config {
00359   uint32_t            max_read_ahead_blocks;   
00361   uint32_t            max_write_blocks;        
00363   rtems_task_priority swapout_priority;        
00365   uint32_t            swapout_period;          
00367   uint32_t            swap_block_hold;         
00368   size_t              swapout_workers;         
00371   rtems_task_priority swapout_worker_priority; 
00373   size_t              task_stack_size;         
00375   size_t              size;                    
00377   uint32_t            buffer_min;              
00378   uint32_t            buffer_max;              
00381   rtems_task_priority read_ahead_priority;     
00383 } rtems_bdbuf_config;
00384 
00390 extern const rtems_bdbuf_config rtems_bdbuf_configuration;
00391 
00396 #define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT    0
00397 
00401 #define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT         16
00402 
00406 #define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT    15
00407 
00411 #define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
00412 
00416 #define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT  1000
00417 
00421 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT     0
00422 
00426 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
00427                              RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
00428 
00432 #define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
00433   RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
00434 
00438 #define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
00439 
00443 #define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
00444 
00448 #define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
00449 
00453 #define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
00454 
00467 rtems_status_code
00468 rtems_bdbuf_init (void);
00469 
00498 rtems_status_code
00499 rtems_bdbuf_get (
00500   rtems_disk_device *dd,
00501   rtems_blkdev_bnum block,
00502   rtems_bdbuf_buffer** bd
00503 );
00504 
00532 rtems_status_code
00533 rtems_bdbuf_read (
00534   rtems_disk_device *dd,
00535   rtems_blkdev_bnum block,
00536   rtems_bdbuf_buffer** bd
00537 );
00538 
00558 rtems_status_code
00559 rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
00560 
00582 rtems_status_code
00583 rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
00584 
00605 rtems_status_code
00606 rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
00607 
00625 rtems_status_code
00626 rtems_bdbuf_syncdev (rtems_disk_device *dd);
00627 
00639 void
00640 rtems_bdbuf_purge_dev (rtems_disk_device *dd);
00641 
00666 rtems_status_code
00667 rtems_bdbuf_set_block_size (rtems_disk_device *dd,
00668                             uint32_t           block_size,
00669                             bool               sync);
00670 
00674 void
00675 rtems_bdbuf_get_device_stats (const rtems_disk_device *dd,
00676                               rtems_blkdev_stats      *stats);
00677 
00681 void
00682 rtems_bdbuf_reset_device_stats (rtems_disk_device *dd);
00683 
00686 #ifdef __cplusplus
00687 }
00688 #endif
00689 
00690 #endif