RTEMS: cpukit/include/rtems/bdbuf.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
bdbuf.h
Go to the documentation of this file.
1
9/*
10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 *
13 * Copyright (C) 2008,2009 Chris Johns <chrisj@rtems.org>
14 * Rewritten to remove score mutex access. Fixes many performance
15 * issues.
16 * Change to support demand driven variable buffer sizes.
17 *
18 * Copyright (c) 2009-2012 embedded brains GmbH.
19 */
20
21#ifndef _RTEMS_BDBUF_H
22#define _RTEMS_BDBUF_H
23
24#include <rtems.h>
25#include <rtems/libio.h>
26#include <rtems/chain.h>
27
28#include <rtems/blkdev.h>
29#include <rtems/diskdevs.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
238 typedef enum
239{
243 RTEMS_BDBUF_STATE_FREE = 0,
244
248 RTEMS_BDBUF_STATE_EMPTY,
249
253 RTEMS_BDBUF_STATE_CACHED,
254
258 RTEMS_BDBUF_STATE_ACCESS_CACHED,
259
263 RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
264
268 RTEMS_BDBUF_STATE_ACCESS_EMPTY,
269
273 RTEMS_BDBUF_STATE_ACCESS_PURGED,
274
278 RTEMS_BDBUF_STATE_MODIFIED,
279
283 RTEMS_BDBUF_STATE_SYNC,
284
288 RTEMS_BDBUF_STATE_TRANSFER,
289
293 RTEMS_BDBUF_STATE_TRANSFER_PURGED
294} rtems_bdbuf_buf_state;
295
299struct rtems_bdbuf_group;
300typedef struct rtems_bdbuf_group rtems_bdbuf_group;
301
308 typedef struct rtems_bdbuf_buffer
309{
310 rtems_chain_node link;
312 struct rtems_bdbuf_avl_node
313 {
314 struct rtems_bdbuf_buffer* left;
315 struct rtems_bdbuf_buffer* right;
316 signed char cache;
317 signed char bal;
318 } avl;
319
320 rtems_disk_device *dd;
322 rtems_blkdev_bnum block;
324 unsigned char* buffer;
326 rtems_bdbuf_buf_state state;
328 uint32_t waiters;
330 rtems_bdbuf_group* group;
332 uint32_t hold_timer;
335 int references;
336 void* user;
337} rtems_bdbuf_buffer;
338
346 struct rtems_bdbuf_group
347{
348 rtems_chain_node link;
350 size_t bds_per_group;
353 uint32_t users;
354 rtems_bdbuf_buffer* bdbuf;
355};
356
361 typedef struct rtems_bdbuf_config {
362 uint32_t max_read_ahead_blocks;
364 uint32_t max_write_blocks;
366 rtems_task_priority swapout_priority;
368 uint32_t swapout_period;
370 uint32_t swap_block_hold;
371 size_t swapout_workers;
374 rtems_task_priority swapout_worker_priority;
376 size_t task_stack_size;
378 size_t size;
380 uint32_t buffer_min;
381 uint32_t buffer_max;
384 rtems_task_priority read_ahead_priority;
386} rtems_bdbuf_config;
387
393extern const rtems_bdbuf_config rtems_bdbuf_configuration;
394
399#define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT 0
400
404#define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT 16
405
409#define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT 15
410
414#define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
415
419#define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT 1000
420
424#define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT 0
425
429#define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
430 RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
431
435#define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
436 RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
437
441#define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
442
446#define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
447
451#define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
452
456#define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
457
470 rtems_status_code
471 rtems_bdbuf_init (void);
472
501 rtems_status_code
502 rtems_bdbuf_get (
503 rtems_disk_device *dd,
504 rtems_blkdev_bnum block,
505 rtems_bdbuf_buffer** bd
506);
507
535 rtems_status_code
536 rtems_bdbuf_read (
537 rtems_disk_device *dd,
538 rtems_blkdev_bnum block,
539 rtems_bdbuf_buffer** bd
540);
541
561 rtems_status_code
562 rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
563
585 rtems_status_code
586 rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
587
608 rtems_status_code
609 rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
610
628 rtems_status_code
629 rtems_bdbuf_syncdev (rtems_disk_device *dd);
630
642void
643 rtems_bdbuf_purge_dev (rtems_disk_device *dd);
644
669 rtems_status_code
670 rtems_bdbuf_set_block_size (rtems_disk_device *dd,
671 uint32_t block_size,
672 bool sync);
673
677void
678 rtems_bdbuf_get_device_stats (const rtems_disk_device *dd,
679 rtems_blkdev_stats *stats);
680
684void
685 rtems_bdbuf_reset_device_stats (rtems_disk_device *dd);
686
689#ifdef __cplusplus
690}
691#endif
692
693#endif
blkdev.h
Block Device Management.
chain.h
Chain API.
diskdevs.h
Block Device Disk Management API.
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
rtems_task_priority
uint32_t rtems_task_priority
Definition: tasks.h:55
rtems_bdbuf_release
rtems_status_code rtems_bdbuf_release(rtems_bdbuf_buffer *bd)
Definition: bdbuf.c:2131
rtems_bdbuf_buf_state
rtems_bdbuf_buf_state
State of a buffer of the cache.
Definition: bdbuf.h:239
rtems_bdbuf_get
rtems_status_code rtems_bdbuf_get(rtems_disk_device *dd, rtems_blkdev_bnum block, rtems_bdbuf_buffer **bd)
Definition: bdbuf.c:1789
rtems_bdbuf_syncdev
rtems_status_code rtems_bdbuf_syncdev(rtems_disk_device *dd)
Definition: bdbuf.c:2229
rtems_bdbuf_reset_device_stats
void rtems_bdbuf_reset_device_stats(rtems_disk_device *dd)
Resets the block device statistics.
Definition: bdbuf.c:2993
rtems_bdbuf_release_modified
rtems_status_code rtems_bdbuf_release_modified(rtems_bdbuf_buffer *bd)
Definition: bdbuf.c:2165
rtems_bdbuf_set_block_size
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.
Definition: bdbuf.c:2869
rtems_bdbuf_read
rtems_status_code rtems_bdbuf_read(rtems_disk_device *dd, rtems_blkdev_bnum block, rtems_bdbuf_buffer **bd)
Definition: bdbuf.c:2057
rtems_bdbuf_sync
rtems_status_code rtems_bdbuf_sync(rtems_bdbuf_buffer *bd)
Definition: bdbuf.c:2197
rtems_bdbuf_get_device_stats
void rtems_bdbuf_get_device_stats(const rtems_disk_device *dd, rtems_blkdev_stats *stats)
Returns the block device statistics.
Definition: bdbuf.c:2985
rtems_bdbuf_configuration
const rtems_bdbuf_config rtems_bdbuf_configuration
rtems_bdbuf_purge_dev
void rtems_bdbuf_purge_dev(rtems_disk_device *dd)
Purges all buffers corresponding to the disk device dd.
Definition: bdbuf.c:2861
rtems_bdbuf_init
rtems_status_code rtems_bdbuf_init(void)
Definition: bdbuf.c:1509
RTEMS_BDBUF_STATE_SYNC
@ RTEMS_BDBUF_STATE_SYNC
Scheduled for synchronization.
Definition: bdbuf.h:283
RTEMS_BDBUF_STATE_ACCESS_CACHED
@ RTEMS_BDBUF_STATE_ACCESS_CACHED
Accessed by upper layer with cached data.
Definition: bdbuf.h:258
RTEMS_BDBUF_STATE_ACCESS_EMPTY
@ RTEMS_BDBUF_STATE_ACCESS_EMPTY
Accessed by upper layer with invalid data.
Definition: bdbuf.h:268
RTEMS_BDBUF_STATE_ACCESS_PURGED
@ RTEMS_BDBUF_STATE_ACCESS_PURGED
Accessed by upper layer with purged data.
Definition: bdbuf.h:273
RTEMS_BDBUF_STATE_TRANSFER
@ RTEMS_BDBUF_STATE_TRANSFER
In transfer by block device driver.
Definition: bdbuf.h:288
RTEMS_BDBUF_STATE_FREE
@ RTEMS_BDBUF_STATE_FREE
Free.
Definition: bdbuf.h:243
RTEMS_BDBUF_STATE_ACCESS_MODIFIED
@ RTEMS_BDBUF_STATE_ACCESS_MODIFIED
Accessed by upper layer with modified data.
Definition: bdbuf.h:263
RTEMS_BDBUF_STATE_CACHED
@ RTEMS_BDBUF_STATE_CACHED
Cached.
Definition: bdbuf.h:253
RTEMS_BDBUF_STATE_TRANSFER_PURGED
@ RTEMS_BDBUF_STATE_TRANSFER_PURGED
In transfer by block device driver and purged.
Definition: bdbuf.h:293
RTEMS_BDBUF_STATE_MODIFIED
@ RTEMS_BDBUF_STATE_MODIFIED
Modified by upper layer.
Definition: bdbuf.h:278
RTEMS_BDBUF_STATE_EMPTY
@ RTEMS_BDBUF_STATE_EMPTY
Empty.
Definition: bdbuf.h:248
rtems_blkdev_bnum
uint32_t rtems_blkdev_bnum
Block device block index type.
Definition: diskdevs.h:45
libio.h
Basic IO API.
rtems.h
Chain_Node_struct
Definition: chain.h:68
rtems_bdbuf_buffer::rtems_bdbuf_avl_node
Definition: bdbuf.h:313
rtems_bdbuf_buffer::rtems_bdbuf_avl_node::cache
signed char cache
Definition: bdbuf.h:316
rtems_bdbuf_buffer::rtems_bdbuf_avl_node::bal
signed char bal
Definition: bdbuf.h:317
rtems_bdbuf_buffer::rtems_bdbuf_avl_node::right
struct rtems_bdbuf_buffer * right
Definition: bdbuf.h:315
rtems_bdbuf_buffer::rtems_bdbuf_avl_node::left
struct rtems_bdbuf_buffer * left
Definition: bdbuf.h:314
rtems_bdbuf_buffer
Definition: bdbuf.h:309
rtems_bdbuf_buffer::waiters
uint32_t waiters
Definition: bdbuf.h:328
rtems_bdbuf_buffer::dd
rtems_disk_device * dd
Definition: bdbuf.h:320
rtems_bdbuf_buffer::buffer
unsigned char * buffer
Definition: bdbuf.h:324
rtems_bdbuf_buffer::block
rtems_blkdev_bnum block
Definition: bdbuf.h:322
rtems_bdbuf_buffer::user
void * user
Definition: bdbuf.h:336
rtems_bdbuf_buffer::references
int references
Definition: bdbuf.h:335
rtems_bdbuf_buffer::group
rtems_bdbuf_group * group
Definition: bdbuf.h:330
rtems_bdbuf_buffer::link
rtems_chain_node link
Definition: bdbuf.h:310
rtems_bdbuf_buffer::hold_timer
uint32_t hold_timer
Definition: bdbuf.h:332
rtems_bdbuf_buffer::state
rtems_bdbuf_buf_state state
Definition: bdbuf.h:326
rtems_bdbuf_config
Definition: bdbuf.h:361
rtems_bdbuf_config::swapout_workers
size_t swapout_workers
Definition: bdbuf.h:371
rtems_bdbuf_config::swapout_worker_priority
rtems_task_priority swapout_worker_priority
Definition: bdbuf.h:374
rtems_bdbuf_config::size
size_t size
Definition: bdbuf.h:378
rtems_bdbuf_config::task_stack_size
size_t task_stack_size
Definition: bdbuf.h:376
rtems_bdbuf_config::buffer_min
uint32_t buffer_min
Definition: bdbuf.h:380
rtems_bdbuf_config::swap_block_hold
uint32_t swap_block_hold
Definition: bdbuf.h:370
rtems_bdbuf_config::max_write_blocks
uint32_t max_write_blocks
Definition: bdbuf.h:364
rtems_bdbuf_config::swapout_period
uint32_t swapout_period
Definition: bdbuf.h:368
rtems_bdbuf_config::swapout_priority
rtems_task_priority swapout_priority
Definition: bdbuf.h:366
rtems_bdbuf_config::read_ahead_priority
rtems_task_priority read_ahead_priority
Definition: bdbuf.h:384
rtems_bdbuf_config::buffer_max
uint32_t buffer_max
Definition: bdbuf.h:381
rtems_bdbuf_config::max_read_ahead_blocks
uint32_t max_read_ahead_blocks
Definition: bdbuf.h:362
rtems_bdbuf_group
Definition: bdbuf.h:347
rtems_bdbuf_group::bdbuf
rtems_bdbuf_buffer * bdbuf
Definition: bdbuf.h:354
rtems_bdbuf_group::users
uint32_t users
Definition: bdbuf.h:353
rtems_bdbuf_group::bds_per_group
size_t bds_per_group
Definition: bdbuf.h:350
rtems_bdbuf_group::link
rtems_chain_node link
Definition: bdbuf.h:348
rtems_blkdev_stats
Block device statistics.
Definition: diskdevs.h:92
rtems_disk_device
Description of a disk device (logical and physical disks).
Definition: diskdevs.h:157