RTEMS CPU Kit with SuperCore  4.10.99.0
bdbuf.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
10  * Author: Victor V. Vengerov <vvv@oktet.ru>
11  *
12  * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
13  * Rewritten to remove score mutex access. Fixes many performance
14  * issues.
15  * Change to support demand driven variable buffer sizes.
16  *
17  * Copyright (c) 2009-2012 embedded brains GmbH.
18  */
19 
20 #ifndef _RTEMS_BDBUF_H
21 #define _RTEMS_BDBUF_H
22 
23 #include <rtems.h>
24 #include <rtems/libio.h>
25 #include <rtems/chain.h>
26 
27 #include <rtems/blkdev.h>
28 #include <rtems/diskdevs.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
177 #if defined(RTEMS_POSIX_API)
178  /*
179  * Use the PTHREAD mutexes and condition variables if available. This helps
180  * on SMP configurations to avoid the home grown condition variables via
181  * disabled preemption.
182  */
183  #define RTEMS_BDBUF_USE_PTHREAD
184 #endif
185 
244 typedef enum
245 {
250 
255 
260 
265 
270 
275 
280 
285 
290 
295 
301 
305 struct rtems_bdbuf_group;
306 typedef struct rtems_bdbuf_group rtems_bdbuf_group;
307 
314 typedef struct rtems_bdbuf_buffer
315 {
319  {
322  signed char cache;
323  signed char bal;
324  } avl;
325 
330  unsigned char* buffer;
334  uint32_t waiters;
338  uint32_t hold_timer;
342  void* user;
344 
353 {
356  size_t bds_per_group;
359  uint32_t users;
361 };
362 
367 typedef struct rtems_bdbuf_config {
370  uint32_t max_write_blocks;
374  uint32_t swapout_period;
376  uint32_t swap_block_hold;
384  size_t size;
386  uint32_t buffer_min;
387  uint32_t buffer_max;
393 
400 
405 #define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT 0
406 
410 #define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT 16
411 
415 #define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT 15
416 
420 #define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
421 
425 #define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT 1000
426 
430 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT 0
431 
435 #define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
436  RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
437 
441 #define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
442  RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
443 
447 #define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
448 
452 #define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
453 
457 #define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
458 
462 #define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
463 
477 rtems_bdbuf_init (void);
478 
509  rtems_disk_device *dd,
510  rtems_blkdev_bnum block,
511  rtems_bdbuf_buffer** bd
512 );
513 
543  rtems_disk_device *dd,
544  rtems_blkdev_bnum block,
545  rtems_bdbuf_buffer** bd
546 );
547 
569 
593 
616 
636 
648 void
650 
677  uint32_t block_size,
678  bool sync);
679 
683 void
685  rtems_blkdev_stats *stats);
686 
690 void
692 
695 #ifdef __cplusplus
696 }
697 #endif
698 
699 #endif
void rtems_bdbuf_purge_dev(rtems_disk_device *dd)
Purges all buffers corresponding to the disk device dd.
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
void * user
User data.
Definition: bdbuf.h:342
uint32_t rtems_blkdev_bnum
Block device block index type.
Definition: diskdevs.h:46
rtems_bdbuf_group * group
Pointer to the group of BDs this BD is part of.
Definition: bdbuf.h:336
Accessed by upper layer with modified data.
Definition: bdbuf.h:269
rtems_task_priority swapout_priority
Priority of the swap out task.
Definition: bdbuf.h:372
void rtems_bdbuf_get_device_stats(const rtems_disk_device *dd, rtems_blkdev_stats *stats)
Returns the block device statistics.
int references
Allow reference counting by owner.
Definition: bdbuf.h:341
uint32_t waiters
The number of threads waiting on this buffer.
Definition: bdbuf.h:334
A group is a continuous block of buffer descriptors.
Definition: bdbuf.h:352
rtems_status_code rtems_bdbuf_syncdev(rtems_disk_device *dd)
Synchronize all modified buffers for this device with the disk and wait until the transfers have comp...
signed char cache
Cache.
Definition: bdbuf.h:322
In transfer by block device driver and purged.
Definition: bdbuf.h:299
size_t swapout_workers
The number of worker threads for the swap-out task.
Definition: bdbuf.h:377
struct rtems_bdbuf_buffer * left
Left Child.
Definition: bdbuf.h:320
Scheduled for synchronization.
Definition: bdbuf.h:289
Empty.
Definition: bdbuf.h:254
void rtems_bdbuf_reset_device_stats(rtems_disk_device *dd)
Resets the block device statistics.
size_t size
Size of memory in the cache.
Definition: bdbuf.h:384
rtems_task_priority swapout_worker_priority
Priority of the swap out task.
Definition: bdbuf.h:380
size_t task_stack_size
Task stack size for swap-out task and worker threads.
Definition: bdbuf.h:382
rtems_status_code rtems_bdbuf_init(void)
Prepare buffering layer to work - initialize buffer descritors and (if it is neccessary) buffers...
Buffering configuration definition.
Definition: bdbuf.h:367
uint32_t max_write_blocks
Number of blocks to write at once.
Definition: bdbuf.h:370
unsigned char * buffer
Pointer to the buffer memory area.
Definition: bdbuf.h:330
Cached.
Definition: bdbuf.h:259
signed char bal
The balance of the sub-tree.
Definition: bdbuf.h:323
rtems_status_code rtems_bdbuf_read(rtems_disk_device *dd, rtems_blkdev_bnum block, rtems_bdbuf_buffer **bd)
Get the block buffer and if not already in the cache read from the disk.
size_t bds_per_group
The number of BD allocated to this group.
Definition: bdbuf.h:356
Block device statistics.
Definition: diskdevs.h:93
struct rtems_bdbuf_buffer rtems_bdbuf_buffer
To manage buffers we using buffer descriptors (BD).
Description of a disk device (logical and physical disks).
Definition: diskdevs.h:158
uint32_t max_read_ahead_blocks
Number of blocks to read ahead.
Definition: bdbuf.h:368
uint32_t swap_block_hold
Period a buffer is held.
Definition: bdbuf.h:376
Priority_Control rtems_task_priority
Define the type for an RTEMS API task priority.
Definition: tasks.h:79
Modified by upper layer.
Definition: bdbuf.h:284
rtems_status_code
Classic API Status.
Definition: status.h:46
rtems_task_priority read_ahead_priority
Priority of the read-ahead task.
Definition: bdbuf.h:390
rtems_status_code rtems_bdbuf_set_block_size(rtems_disk_device *dd, uint32_t block_size, bool sync)
Sets the block size of a disk device.
uint32_t hold_timer
Timer to indicate how long a buffer has been held in the cache modified.
Definition: bdbuf.h:338
rtems_bdbuf_buffer * bdbuf
First BD this block covers.
Definition: bdbuf.h:360
rtems_disk_device * dd
disk device
Definition: bdbuf.h:326
Block Device Disk Management API.
rtems_status_code rtems_bdbuf_release(rtems_bdbuf_buffer *bd)
Release the buffer obtained by a read call back to the cache.
rtems_chain_node link
Link the groups on a LRU list if they have no buffers in use.
Definition: bdbuf.h:354
To manage buffers we using buffer descriptors (BD).
Definition: bdbuf.h:314
struct rtems_bdbuf_buffer * right
Right Child.
Definition: bdbuf.h:321
Chain API.
rtems_status_code rtems_bdbuf_get(rtems_disk_device *dd, rtems_blkdev_bnum block, rtems_bdbuf_buffer **bd)
Get block buffer for data to be written into.
const rtems_bdbuf_config rtems_bdbuf_configuration
External reference to the configuration.
Accessed by upper layer with cached data.
Definition: bdbuf.h:264
rtems_bdbuf_buf_state
State of a buffer of the cache.
Definition: bdbuf.h:244
uint32_t buffer_max
Maximum buffer size supported.
Definition: bdbuf.h:387
rtems_bdbuf_buf_state state
State of the buffer.
Definition: bdbuf.h:332
Free.
Definition: bdbuf.h:249
rtems_status_code rtems_bdbuf_sync(rtems_bdbuf_buffer *bd)
Release the buffer as modified and wait until it has been synchronized with the disk by writing it...
Accessed by upper layer with purged data.
Definition: bdbuf.h:279
struct rtems_bdbuf_config rtems_bdbuf_config
Buffering configuration definition.
rtems_blkdev_bnum block
block number on the device
Definition: bdbuf.h:328
uint32_t users
How many users the block has.
Definition: bdbuf.h:359
uint32_t buffer_min
Minimum buffer size.
Definition: bdbuf.h:386
rtems_status_code rtems_bdbuf_release_modified(rtems_bdbuf_buffer *bd)
Release the buffer allocated with a get or read call placing it on the modified list.
rtems_chain_node link
Link the BD onto a number of lists.
Definition: bdbuf.h:316
Block Device Management.
Accessed by upper layer with invalid data.
Definition: bdbuf.h:274
In transfer by block device driver.
Definition: bdbuf.h:294
uint32_t swapout_period
Period swap-out checks buf timers.
Definition: bdbuf.h:374