source: rtems/cpukit/include/rtems/bdbuf.h

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 26.9 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bdbuf
5 *
6 * @brief Block Device Buffer Management
7 */
8
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 & Co. KG
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
35/**
36 * @defgroup rtems_libblock Block Device Library
37 *
38 * @ingroup RTEMSDeviceDrivers
39 *
40 * @brief Block device modules.
41 */
42
43/**
44 * @defgroup rtems_bdbuf Block Device Buffer Management
45 *
46 * @ingroup rtems_libblock
47 *
48 * The Block Device Buffer Management implements a cache between the disk
49 * devices and file systems.  The code provides read-ahead and write queuing to
50 * the drivers and fast cache look-up using an AVL tree.
51 *
52 * The block size used by a file system can be set at runtime and must be a
53 * multiple of the disk device block size.  The disk device's physical block
54 * size is called the media block size.  The file system can set the block size
55 * it uses to a larger multiple of the media block size.  The driver must be
56 * able to handle buffers sizes larger than one media block.
57 *
58 * The user configures the amount of memory to be used as buffers in the cache,
59 * and the minimum and maximum buffer size.  The cache will allocate additional
60 * memory for the buffer descriptors and groups.  There are enough buffer
61 * descriptors allocated so all the buffer memory can be used as minimum sized
62 * buffers.
63 *
64 * The cache is a single pool of buffers.  The buffer memory is divided into
65 * groups where the size of buffer memory allocated to a group is the maximum
66 * buffer size.  A group's memory can be divided down into small buffer sizes
67 * that are a multiple of 2 of the minimum buffer size.  A group is the minimum
68 * allocation unit for buffers of a specific size.  If a buffer of maximum size
69 * is request the group will have a single buffer.  If a buffer of minimum size
70 * is requested the group is divided into minimum sized buffers and the
71 * remaining buffers are held ready for use.  A group keeps track of which
72 * buffers are with a file system or driver and groups who have buffer in use
73 * cannot be realloced.  Groups with no buffers in use can be taken and
74 * realloced to a new size.  This is how buffers of different sizes move around
75 * the cache.
76
77 * The buffers are held in various lists in the cache.  All buffers follow this
78 * state machine:
79 *
80 * @dot
81 * digraph state {
82 *   size="16,8";
83 *   f [label="FREE",style="filled",fillcolor="aquamarine"];
84 *   e [label="EMPTY",style="filled",fillcolor="seagreen"];
85 *   c [label="CACHED",style="filled",fillcolor="chartreuse"];
86 *   ac [label="ACCESS CACHED",style="filled",fillcolor="royalblue"];
87 *   am [label="ACCESS MODIFIED",style="filled",fillcolor="royalblue"];
88 *   ae [label="ACCESS EMPTY",style="filled",fillcolor="royalblue"];
89 *   ap [label="ACCESS PURGED",style="filled",fillcolor="royalblue"];
90 *   t [label="TRANSFER",style="filled",fillcolor="red"];
91 *   tp [label="TRANSFER PURGED",style="filled",fillcolor="red"];
92 *   s [label="SYNC",style="filled",fillcolor="red"];
93 *   m [label="MODIFIED",style="filled",fillcolor="gold"];
94 *   i [label="INITIAL"];
95 *
96 *   legend_transfer [label="Transfer Wake-Up",fontcolor="red",shape="none"];
97 *   legend_access [label="Access Wake-Up",fontcolor="royalblue",shape="none"];
98 *
99 *   i -> f [label="Init"];
100 *   f -> e [label="Buffer Recycle"];
101 *   e -> ae [label="Get"];
102 *   e -> t [label="Read"];
103 *   e -> f [label="Nobody Waits"];
104 *   c -> ac [label="Get\nRead"];
105 *   c -> e [label="Buffer Recycle\nPurge"];
106 *   c -> f [label="Reallocate\nBlock Size Changed"];
107 *   t -> c [label="Transfer Done",color="red",fontcolor="red"];
108 *   t -> e [label="Transfer Error",color="red",fontcolor="red"];
109 *   t -> tp [label="Purge"];
110 *   tp -> e [label="Transfer Done\nTransfer Error",color="red",fontcolor="red"];
111 *   m -> t [label="Swapout"];
112 *   m -> s [label="Block Size Changed"];
113 *   m -> am [label="Get\nRead"];
114 *   m -> e [label="Purge"];
115 *   ac -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
116 *   ac -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
117 *   ac -> c [label="Release",color="royalblue",fontcolor="royalblue"];
118 *   ac -> ap [label="Purge"];
119 *   am -> m [label="Release\nRelease Modified",color="royalblue",fontcolor="royalblue"];
120 *   am -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
121 *   am -> ap [label="Purge"];
122 *   ae -> m [label="Release Modified",color="royalblue",fontcolor="royalblue"];
123 *   ae -> s [label="Sync",color="royalblue",fontcolor="royalblue"];
124 *   ae -> e [label="Release",color="royalblue",fontcolor="royalblue"];
125 *   ae -> ap [label="Purge"];
126 *   ap -> e [label="Release\nRelease Modified\nSync",color="royalblue",fontcolor="royalblue"];
127 *   s -> t [label="Swapout"];
128 *   s -> e [label="Purge",color="red",fontcolor="red"];
129 * }
130 * @enddot
131 *
132 * Empty or cached buffers are added to the LRU list and removed from this
133 * queue when a caller requests a buffer.  This is referred to as getting a
134 * buffer in the code and the event get in the state diagram.  The buffer is
135 * assigned to a block and inserted to the AVL based on the block/device key.
136 * If the block is to be read by the user and not in the cache it is transfered
137 * from the disk into memory.  If no buffers are on the LRU list the modified
138 * list is checked.  If buffers are on the modified the swap out task will be
139 * woken.  The request blocks until a buffer is available for recycle.
140 *
141 * A block being accessed is given to the file system layer and not accessible
142 * to another requester until released back to the cache.  The same goes to a
143 * buffer in the transfer state.  The transfer state means being read or
144 * written.  If the file system has modified the block and releases it as
145 * modified it placed on the cache's modified list and a hold timer
146 * initialised.  The buffer is held for the hold time before being written to
147 * disk.  Buffers are held for a configurable period of time on the modified
148 * list as a write sets the state to transfer and this locks the buffer out
149 * from the file system until the write completes.  Buffers are often accessed
150 * and modified in a series of small updates so if sent to the disk when
151 * released as modified the user would have to block waiting until it had been
152 * written.  This would be a performance problem.
153 *
154 * The code performs multiple block reads and writes.  Multiple block reads or
155 * read-ahead increases performance with hardware that supports it.  It also
156 * helps with a large cache as the disk head movement is reduced.  It however
157 * is a speculative operation so excessive use can remove valuable and needed
158 * blocks from the cache.  The read-ahead is triggered after two misses of
159 * ascending consecutive blocks or a read hit of a block read by the
160 * most-resent read-ahead transfer.  The read-ahead works per disk, but all
161 * transfers are issued by the read-ahead task.
162 *
163 * The cache has the following lists of buffers:
164 *  - LRU: Accessed or transfered buffers released in least recently used
165 *  order.  Empty buffers will be placed to the front.
166 *  - Modified: Buffers waiting to be written to disk.
167 *  - Sync: Buffers to be synchronized with the disk.
168 *
169 * A cache look-up will be performed to find a suitable buffer.  A suitable
170 * buffer is one that matches the same allocation size as the device the buffer
171 * is for.  The a buffer's group has no buffers in use with the file system or
172 * driver the group is reallocated.  This means the buffers in the group are
173 * invalidated, resized and placed on the LRU queue.  There is a performance
174 * issue with this design.  The reallocation of a group may forced recently
175 * accessed buffers out of the cache when they should not.  The design should be
176 * change to have groups on a LRU list if they have no buffers in use.
177 */
178/**@{**/
179
180/**
181 * @brief State of a buffer of the cache.
182 *
183 * The state has several implications.  Depending on the state a buffer can be
184 * in the AVL tree, in a list, in use by an entity and a group user or not.
185 *
186 * <table>
187 *   <tr>
188 *     <th>State</th><th>Valid Data</th><th>AVL Tree</th>
189 *     <th>LRU List</th><th>Modified List</th><th>Synchronization List</th>
190 *     <th>Group User</th><th>External User</th>
191 *   </tr>
192 *   <tr>
193 *     <td>FREE</td><td></td><td></td>
194 *     <td>X</td><td></td><td></td><td></td><td></td>
195 *   </tr>
196 *   <tr>
197 *     <td>EMPTY</td><td></td><td>X</td>
198 *     <td></td><td></td><td></td><td></td><td></td>
199 *   </tr>
200 *   <tr>
201 *     <td>CACHED</td><td>X</td><td>X</td>
202 *     <td>X</td><td></td><td></td><td></td><td></td>
203 *   </tr>
204 *   <tr>
205 *     <td>ACCESS CACHED</td><td>X</td><td>X</td>
206 *     <td></td><td></td><td></td><td>X</td><td>X</td>
207 *   </tr>
208 *   <tr>
209 *     <td>ACCESS MODIFIED</td><td>X</td><td>X</td>
210 *     <td></td><td></td><td></td><td>X</td><td>X</td>
211 *   </tr>
212 *   <tr>
213 *     <td>ACCESS EMPTY</td><td></td><td>X</td>
214 *     <td></td><td></td><td></td><td>X</td><td>X</td>
215 *   </tr>
216 *   <tr>
217 *     <td>ACCESS PURGED</td><td></td><td>X</td>
218 *     <td></td><td></td><td></td><td>X</td><td>X</td>
219 *   </tr>
220 *   <tr>
221 *     <td>MODIFIED</td><td>X</td><td>X</td>
222 *     <td></td><td>X</td><td></td><td>X</td><td></td>
223 *   </tr>
224 *   <tr>
225 *     <td>SYNC</td><td>X</td><td>X</td>
226 *     <td></td><td></td><td>X</td><td>X</td><td></td>
227 *   </tr>
228 *   <tr>
229 *     <td>TRANSFER</td><td>X</td><td>X</td>
230 *     <td></td><td></td><td></td><td>X</td><td>X</td>
231 *   </tr>
232 *   <tr>
233 *     <td>TRANSFER PURGED</td><td></td><td>X</td>
234 *     <td></td><td></td><td></td><td>X</td><td>X</td>
235 *   </tr>
236 * </table>
237 */
238typedef enum
239{
240  /**
241   * @brief Free.
242   */
243  RTEMS_BDBUF_STATE_FREE = 0,
244
245  /**
246   * @brief Empty.
247   */
248  RTEMS_BDBUF_STATE_EMPTY,
249
250  /**
251   * @brief Cached.
252   */
253  RTEMS_BDBUF_STATE_CACHED,
254
255  /**
256   * @brief Accessed by upper layer with cached data.
257   */
258  RTEMS_BDBUF_STATE_ACCESS_CACHED,
259
260  /**
261   * @brief Accessed by upper layer with modified data.
262   */
263  RTEMS_BDBUF_STATE_ACCESS_MODIFIED,
264
265  /**
266   * @brief Accessed by upper layer with invalid data.
267   */
268  RTEMS_BDBUF_STATE_ACCESS_EMPTY,
269
270  /**
271   * @brief Accessed by upper layer with purged data.
272   */
273  RTEMS_BDBUF_STATE_ACCESS_PURGED,
274
275  /**
276   * @brief Modified by upper layer.
277   */
278  RTEMS_BDBUF_STATE_MODIFIED,
279
280  /**
281   * @brief Scheduled for synchronization.
282   */
283  RTEMS_BDBUF_STATE_SYNC,
284
285  /**
286   * @brief In transfer by block device driver.
287   */
288  RTEMS_BDBUF_STATE_TRANSFER,
289
290  /**
291   * @brief In transfer by block device driver and purged.
292   */
293  RTEMS_BDBUF_STATE_TRANSFER_PURGED
294} rtems_bdbuf_buf_state;
295
296/**
297 * Forward reference to the block.
298 */
299struct rtems_bdbuf_group;
300typedef struct rtems_bdbuf_group rtems_bdbuf_group;
301
302/**
303 * To manage buffers we using buffer descriptors (BD). A BD holds a buffer plus
304 * a range of other information related to managing the buffer in the cache. To
305 * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
306 * 'dd' and 'block' are search keys.
307 */
308typedef struct rtems_bdbuf_buffer
309{
310  rtems_chain_node link;       /**< Link the BD onto a number of lists. */
311
312  struct rtems_bdbuf_avl_node
313  {
314    struct rtems_bdbuf_buffer* left;   /**< Left Child */
315    struct rtems_bdbuf_buffer* right;  /**< Right Child */
316    signed char                cache;  /**< Cache */
317    signed char                bal;    /**< The balance of the sub-tree */
318  } avl;
319
320  rtems_disk_device *dd;        /**< disk device */
321
322  rtems_blkdev_bnum block;      /**< block number on the device */
323
324  unsigned char*    buffer;     /**< Pointer to the buffer memory area */
325
326  rtems_bdbuf_buf_state state;           /**< State of the buffer. */
327
328  uint32_t waiters;              /**< The number of threads waiting on this
329                                  * buffer. */
330  rtems_bdbuf_group* group;      /**< Pointer to the group of BDs this BD is
331                                  * part of. */
332  uint32_t hold_timer;           /**< Timer to indicate how long a buffer
333                                  * has been held in the cache modified. */
334
335  int   references;              /**< Allow reference counting by owner. */
336  void* user;                    /**< User data. */
337} rtems_bdbuf_buffer;
338
339/**
340 * A group is a continuous block of buffer descriptors. A group covers the
341 * maximum configured buffer size and is the allocation size for the buffers to
342 * a specific buffer size. If you allocate a buffer to be a specific size, all
343 * buffers in the group, if there are more than 1 will also be that size. The
344 * number of buffers in a group is a multiple of 2, ie 1, 2, 4, 8, etc.
345 */
346struct rtems_bdbuf_group
347{
348  rtems_chain_node    link;          /**< Link the groups on a LRU list if they
349                                      * have no buffers in use. */
350  size_t              bds_per_group; /**< The number of BD allocated to this
351                                      * group. This value must be a multiple of
352                                      * 2. */
353  uint32_t            users;         /**< How many users the block has. */
354  rtems_bdbuf_buffer* bdbuf;         /**< First BD this block covers. */
355};
356
357/**
358 * Buffering configuration definition. See confdefs.h for support on using this
359 * structure.
360 */
361typedef struct rtems_bdbuf_config {
362  uint32_t            max_read_ahead_blocks;   /**< Number of blocks to read
363                                                * ahead. */
364  uint32_t            max_write_blocks;        /**< Number of blocks to write
365                                                * at once. */
366  rtems_task_priority swapout_priority;        /**< Priority of the swap out
367                                                * task. */
368  uint32_t            swapout_period;          /**< Period swap-out checks buf
369                                                * timers. */
370  uint32_t            swap_block_hold;         /**< Period a buffer is held. */
371  size_t              swapout_workers;         /**< The number of worker
372                                                * threads for the swap-out
373                                                * task. */
374  rtems_task_priority swapout_worker_priority; /**< Priority of the swap out
375                                                * task. */
376  size_t              task_stack_size;         /**< Task stack size for swap-out
377                                                * task and worker threads. */
378  size_t              size;                    /**< Size of memory in the
379                                                * cache */
380  uint32_t            buffer_min;              /**< Minimum buffer size. */
381  uint32_t            buffer_max;              /**< Maximum buffer size
382                                                * supported. It is also the
383                                                * allocation size. */
384  rtems_task_priority read_ahead_priority;     /**< Priority of the read-ahead
385                                                * task. */
386} rtems_bdbuf_config;
387
388/**
389 * External reference to the configuration.
390 *
391 * The configuration is provided by the application.
392 */
393extern const rtems_bdbuf_config rtems_bdbuf_configuration;
394
395/**
396 * The default value for the maximum read-ahead blocks disables the read-ahead
397 * feature.
398 */
399#define RTEMS_BDBUF_MAX_READ_AHEAD_BLOCKS_DEFAULT    0
400
401/**
402 * Default maximum number of blocks to write at once.
403 */
404#define RTEMS_BDBUF_MAX_WRITE_BLOCKS_DEFAULT         16
405
406/**
407 * Default swap-out task priority.
408 */
409#define RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT    15
410
411/**
412 * Default swap-out task swap period in milli seconds.
413 */
414#define RTEMS_BDBUF_SWAPOUT_TASK_SWAP_PERIOD_DEFAULT 250
415
416/**
417 * Default swap-out task block hold time in milli seconds.
418 */
419#define RTEMS_BDBUF_SWAPOUT_TASK_BLOCK_HOLD_DEFAULT  1000
420
421/**
422 * Default swap-out worker tasks. Currently disabled.
423 */
424#define RTEMS_BDBUF_SWAPOUT_WORKER_TASKS_DEFAULT     0
425
426/**
427 * Default swap-out worker task priority. The same as the swap-out task.
428 */
429#define RTEMS_BDBUF_SWAPOUT_WORKER_TASK_PRIORITY_DEFAULT \
430                             RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
431
432/**
433 * Default read-ahead task priority.  The same as the swap-out task.
434 */
435#define RTEMS_BDBUF_READ_AHEAD_TASK_PRIORITY_DEFAULT \
436  RTEMS_BDBUF_SWAPOUT_TASK_PRIORITY_DEFAULT
437
438/**
439 * Default task stack size for swap-out and worker tasks.
440 */
441#define RTEMS_BDBUF_TASK_STACK_SIZE_DEFAULT RTEMS_MINIMUM_STACK_SIZE
442
443/**
444 * Default size of memory allocated to the cache.
445 */
446#define RTEMS_BDBUF_CACHE_MEMORY_SIZE_DEFAULT (64 * 512)
447
448/**
449 * Default minimum size of buffers.
450 */
451#define RTEMS_BDBUF_BUFFER_MIN_SIZE_DEFAULT (512)
452
453/**
454 * Default maximum size of buffers.
455 */
456#define RTEMS_BDBUF_BUFFER_MAX_SIZE_DEFAULT (4096)
457
458/**
459 * Prepare buffering layer to work - initialize buffer descritors and (if it is
460 * neccessary) buffers. After initialization all blocks is placed into the
461 * ready state.
462 *
463 * @retval RTEMS_SUCCESSFUL Successful operation.
464 * @retval RTEMS_CALLED_FROM_ISR Called from an interrupt context.
465 * @retval RTEMS_INVALID_NUMBER The buffer maximum is not an integral multiple
466 * of the buffer minimum.  The maximum read-ahead blocks count is too large.
467 * @retval RTEMS_RESOURCE_IN_USE Already initialized.
468 * @retval RTEMS_UNSATISFIED Not enough resources.
469 */
470rtems_status_code
471rtems_bdbuf_init (void);
472
473/**
474 * Get block buffer for data to be written into. The buffers is set to the
475 * access or modified access state. If the buffer is in the cache and modified
476 * the state is access modified else the state is access. This buffer contents
477 * are not initialised if the buffer is not already in the cache. If the block
478 * is already resident in memory it is returned how-ever if not in memory the
479 * buffer is not read from disk. This call is used when writing the whole block
480 * on a disk rather than just changing a part of it. If there is no buffers
481 * available this call will block. A buffer obtained with this call will not be
482 * involved in a transfer request and will not be returned to another user
483 * until released. If the buffer is already with a user when this call is made
484 * the call is blocked until the buffer is returned. The highest priority
485 * waiter will obtain the buffer first.
486 *
487 * The block number is the linear block number. This is relative to the start
488 * of the partition on the media.
489 *
490 * Before you can use this function, the rtems_bdbuf_init() routine must be
491 * called at least once to initialize the cache, otherwise a fatal error will
492 * occur.
493 *
494 * @param dd [in] The disk device.
495 * @param block [in] Linear media block number.
496 * @param bd [out] Reference to the buffer descriptor pointer.
497 *
498 * @retval RTEMS_SUCCESSFUL Successful operation.
499 * @retval RTEMS_INVALID_ID Invalid block number.
500 */
501rtems_status_code
502rtems_bdbuf_get (
503  rtems_disk_device *dd,
504  rtems_blkdev_bnum block,
505  rtems_bdbuf_buffer** bd
506);
507
508/**
509 * Get the block buffer and if not already in the cache read from the disk. If
510 * specified block already cached return. The buffer is set to the access or
511 * modified access state. If the buffer is in the cache and modified the state
512 * is access modified else the state is access. If block is already being read
513 * from disk for being written to disk this call blocks. If the buffer is
514 * waiting to be written it is removed from modified queue and returned to the
515 * user. If the buffer is not in the cache a new buffer is obtained and the
516 * data read from disk. The call may block until these operations complete. A
517 * buffer obtained with this call will not be involved in a transfer request
518 * and will not be returned to another user until released. If the buffer is
519 * already with a user when this call is made the call is blocked until the
520 * buffer is returned. The highest priority waiter will obtain the buffer
521 * first.
522 *
523 * Before you can use this function, the rtems_bdbuf_init() routine must be
524 * called at least once to initialize the cache, otherwise a fatal error will
525 * occur.
526 *
527 * @param dd [in] The disk device.
528 * @param block [in] Linear media block number.
529 * @param bd [out] Reference to the buffer descriptor pointer.
530 *
531 * @retval RTEMS_SUCCESSFUL Successful operation.
532 * @retval RTEMS_INVALID_ID Invalid block number.
533 * @retval RTEMS_IO_ERROR IO error.
534 */
535rtems_status_code
536rtems_bdbuf_read (
537  rtems_disk_device *dd,
538  rtems_blkdev_bnum block,
539  rtems_bdbuf_buffer** bd
540);
541
542/**
543 * @brief Give a hint which blocks should be cached next.
544 *
545 * Provide a hint to the read ahead mechanism which blocks should be cached
546 * next. This overwrites the default linear pattern. You should use it in (for
547 * example) a file system to tell bdbuf where the next part of a fragmented file
548 * is. If you know the length of the file, you can provide that too.
549 *
550 * Before you can use this function, the rtems_bdbuf_init() routine must be
551 * called at least once to initialize everything. Otherwise you might get
552 * unexpected results.
553 *
554 * @param dd [in] The disk device.
555 * @param block [in] Linear media block number.
556 * @param nr_blocks [in] Number of consecutive blocks that can be pre-fetched.
557 */
558void
559rtems_bdbuf_peek (
560  rtems_disk_device *dd,
561  rtems_blkdev_bnum block,
562  uint32_t nr_blocks
563);
564
565/**
566 * Release the buffer obtained by a read call back to the cache. If the buffer
567 * was obtained by a get call and was not already in the cache the release
568 * modified call should be used. A buffer released with this call obtained by a
569 * get call may not be in sync with the contents on disk. If the buffer was in
570 * the cache and modified before this call it will be returned to the modified
571 * queue. The buffers is returned to the end of the LRU list.
572 *
573 * Before you can use this function, the rtems_bdbuf_init() routine must be
574 * called at least once to initialize the cache, otherwise a fatal error will
575 * occur.
576 *
577 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
578 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
579 * rtems_bdbuf_read().
580 *
581 * @retval RTEMS_SUCCESSFUL Successful operation.
582 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
583 */
584rtems_status_code
585rtems_bdbuf_release (rtems_bdbuf_buffer* bd);
586
587/**
588 * Release the buffer allocated with a get or read call placing it on the
589 * modified list.  If the buffer was not released modified before the hold
590 * timer is set to the configuration value. If the buffer had been released
591 * modified before but not written to disk the hold timer is not updated. The
592 * buffer will be written to disk when the hold timer has expired, there are
593 * not more buffers available in the cache and a get or read buffer needs one
594 * or a sync call has been made. If the buffer is obtained with a get or read
595 * before the hold timer has expired the buffer will be returned to the user.
596 *
597 * Before you can use this function, the rtems_bdbuf_init() routine must be
598 * called at least once to initialize the cache, otherwise a fatal error will
599 * occur.
600 *
601 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
602 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
603 * rtems_bdbuf_read().
604 *
605 * @retval RTEMS_SUCCESSFUL Successful operation.
606 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
607 */
608rtems_status_code
609rtems_bdbuf_release_modified (rtems_bdbuf_buffer* bd);
610
611/**
612 * Release the buffer as modified and wait until it has been synchronized with
613 * the disk by writing it. This buffer will be the first to be transfer to disk
614 * and other buffers may also be written if the maximum number of blocks in a
615 * requests allows it.
616 *
617 * @note This code does not lock the sync mutex and stop additions to the
618 *       modified queue.
619 *
620 * Before you can use this function, the rtems_bdbuf_init() routine must be
621 * called at least once to initialize the cache, otherwise a fatal error will
622 * occur.
623 *
624 * @param bd [in] Reference to the buffer descriptor.  The buffer descriptor
625 * reference must not be @c NULL and must be obtained via rtems_bdbuf_get() or
626 * rtems_bdbuf_read().
627 *
628 * @retval RTEMS_SUCCESSFUL Successful operation.
629 * @retval RTEMS_INVALID_ADDRESS The reference is NULL.
630 */
631rtems_status_code
632rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
633
634/**
635 * Synchronize all modified buffers for this device with the disk and wait
636 * until the transfers have completed. The sync mutex for the cache is locked
637 * stopping the addition of any further modified buffers. It is only the
638 * currently modified buffers that are written.
639 *
640 * @note Nesting calls to sync multiple devices will be handled sequentially. A
641 * nested call will be blocked until the first sync request has complete.
642 *
643 * Before you can use this function, the rtems_bdbuf_init() routine must be
644 * called at least once to initialize the cache, otherwise a fatal error will
645 * occur.
646 *
647 * @param dd [in] The disk device.
648 *
649 * @retval RTEMS_SUCCESSFUL Successful operation.
650 */
651rtems_status_code
652rtems_bdbuf_syncdev (rtems_disk_device *dd);
653
654/**
655 * @brief Purges all buffers corresponding to the disk device @a dd.
656 *
657 * This may result in loss of data.  The read-ahead state of this device is reset.
658 *
659 * Before you can use this function, the rtems_bdbuf_init() routine must be
660 * called at least once to initialize the cache, otherwise a fatal error will
661 * occur.
662 *
663 * @param dd [in] The disk device.
664 */
665void
666rtems_bdbuf_purge_dev (rtems_disk_device *dd);
667
668/**
669 * @brief Sets the block size of a disk device.
670 *
671 * This will set the block size derived fields of the disk device.  If
672 * requested the disk device is synchronized before the block size change
673 * occurs.  Since the cache is unlocked during the synchronization operation
674 * some tasks may access the disk device in the meantime.  This may result in
675 * loss of data.  After the synchronization the disk device is purged to ensure
676 * a consistent cache state and the block size change occurs.  This also resets
677 * the read-ahead state of this disk device.  Due to the purge operation this
678 * may result in loss of data.
679 *
680 * Before you can use this function, the rtems_bdbuf_init() routine must be
681 * called at least once to initialize the cache, otherwise a fatal error will
682 * occur.
683 *
684 * @param dd [in, out] The disk device.
685 * @param block_size [in] The new block size in bytes.
686 * @param sync [in] If @c true, then synchronize the disk device before the
687 * block size change.
688 *
689 * @retval RTEMS_SUCCESSFUL Successful operation.
690 * @retval RTEMS_INVALID_NUMBER Invalid block size.
691 */
692rtems_status_code
693rtems_bdbuf_set_block_size (rtems_disk_device *dd,
694                            uint32_t           block_size,
695                            bool               sync);
696
697/**
698 * @brief Returns the block device statistics.
699 */
700void
701rtems_bdbuf_get_device_stats (const rtems_disk_device *dd,
702                              rtems_blkdev_stats      *stats);
703
704/**
705 * @brief Resets the block device statistics.
706 */
707void
708rtems_bdbuf_reset_device_stats (rtems_disk_device *dd);
709
710/** @} */
711
712#ifdef __cplusplus
713}
714#endif
715
716#endif
Note: See TracBrowser for help on using the repository browser.