Changeset 1d8cdb1 in mainline


Ignore:
Timestamp:
2008-11-18T20:28:17Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18c485a
Parents:
26fa0f9f
Message:

Avoid unnecessary block reads in block_get().

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    r26fa0f9f r1d8cdb1  
    297297 * @param dev_handle            Device handle of the block device.
    298298 * @param boff                  Block offset.
     299 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     300 *                              will not read the contents of the block from the
     301 *                              device.
    299302 *
    300303 * @return                      Block structure.
    301304 */
    302 block_t *block_get(dev_handle_t dev_handle, bn_t boff)
     305block_t *block_get(dev_handle_t dev_handle, bn_t boff, int flags)
    303306{
    304307        devcon_t *devcon;
     
    386389                        abort();        /* TODO: block_write() */
    387390                }
    388                 /*
    389                  * The block contains old or no data. We need to read the new
    390                  * contents from the device.
    391                  */
    392                 rc = block_read(dev_handle, &bufpos, &buflen, &pos, b->data,
    393                     cache->block_size, cache->block_size);
    394                 assert(rc == EOK);
     391                if (!(flags & BLOCK_FLAGS_NOREAD)) {
     392                        /*
     393                         * The block contains old or no data. We need to read
     394                         * the new contents from the device.
     395                         */
     396                        rc = block_read(dev_handle, &bufpos, &buflen, &pos,
     397                            b->data, cache->block_size, cache->block_size);
     398                        assert(rc == EOK);
     399                }
    395400
    396401                futex_up(&b->lock);
  • uspace/lib/libblock/libblock.h

    r26fa0f9f r1d8cdb1  
    4545#include <libadt/list.h>
    4646
     47/*
     48 * Flags that can be used with block_get().
     49 */
     50
     51/**
     52 * This macro is a symbolic value for situations where no special flags are
     53 * needed.
     54 */
     55#define BLOCK_FLAGS_NONE        0
     56
     57/**
     58 * When the client of block_get() intends to overwrite the current contents of
     59 * the block, this flag is used to avoid the unnecessary read.
     60 */
     61#define BLOCK_FLAGS_NOREAD      1
     62
    4763typedef unsigned bn_t;  /**< Block number type. */
    4864
     
    7894extern int block_cache_init(dev_handle_t, size_t, unsigned);
    7995
    80 extern block_t *block_get(dev_handle_t, bn_t);
     96extern block_t *block_get(dev_handle_t, bn_t, int flags);
    8197extern void block_put(block_t *);
    8298
  • uspace/srv/fs/fat/fat_fat.c

    r26fa0f9f r1d8cdb1  
    9595                fidx = clst % (bps / sizeof(fat_cluster_t));
    9696                /* read FAT1 */
    97                 b = block_get(dev_handle, rscnt + fsec);
     97                b = block_get(dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE);
    9898                clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
    9999                assert(clst != FAT_CLST_BAD);
     
    115115 *                      is empty.
    116116 * @param bn            Block number.
     117 * @param flags         Flags passed to libblock.
    117118 *
    118119 * @return              Block structure holding the requested block.
     
    120121block_t *
    121122_fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
    122     bn_t bn)
     123    bn_t bn, int flags)
    123124{
    124125        block_t *b;
     
    144145                /* root directory special case */
    145146                assert(bn < rds);
    146                 b = block_get(dev_handle, rscnt + bs->fatcnt * sf + bn);
     147                b = block_get(dev_handle, rscnt + bs->fatcnt * sf + bn, flags);
    147148                return b;
    148149        }
     
    154155
    155156        b = block_get(dev_handle, ssa + (lastc - FAT_CLST_FIRST) * bs->spc +
    156             bn % bs->spc);
     157            bn % bs->spc, flags);
    157158
    158159        return b;
     
    184185        for (o = nodep->size - 1; o < pos && o < boundary;
    185186            o = ALIGN_DOWN(o + bps, bps)) {
    186                 b = fat_block_get(bs, nodep, o / bps);
     187                int flags = (o % bps == 0) ?
     188                    BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE;
     189                b = fat_block_get(bs, nodep, o / bps, flags);
    187190                memset(b->data + o % bps, 0, bps - o % bps);
    188191                b->dirty = true;                /* need to sync node */
     
    196199        for (o = boundary; o < pos; o += bps) {
    197200                b = _fat_block_get(bs, nodep->idx->dev_handle, mcl,
    198                     (o - boundary) / bps);
     201                    (o - boundary) / bps, BLOCK_FLAGS_NOREAD);
    199202                memset(b->data, 0, min(bps, pos - o));
    200203                b->dirty = true;                /* need to sync node */
     
    222225        rscnt = uint16_t_le2host(bs->rscnt);
    223226
    224         b = block_get(dev_handle, rscnt + (clst * sizeof(fat_cluster_t)) / bps);
     227        b = block_get(dev_handle, rscnt + (clst * sizeof(fat_cluster_t)) / bps,
     228            BLOCK_FLAGS_NONE);
    225229        cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
    226230        value = uint16_t_le2host(*cp);
     
    254258        assert(fatno < bs->fatcnt);
    255259        b = block_get(dev_handle, rscnt + sf * fatno +
    256             (clst * sizeof(fat_cluster_t)) / bps);
     260            (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
    257261        cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
    258262        *cp = host2uint16_t_le(value);
     
    324328        futex_down(&fat_alloc_lock);
    325329        for (b = 0, cl = 0; b < sf; blk++) {
    326                 blk = block_get(dev_handle, rscnt + b);
     330                blk = block_get(dev_handle, rscnt + b, BLOCK_FLAGS_NOREAD);
    327331                for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) {
    328332                        fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
  • uspace/srv/fs/fat/fat_fat.h

    r26fa0f9f r1d8cdb1  
    6464    fat_cluster_t *, uint16_t);
    6565
    66 #define fat_block_get(bs, np, bn) \
    67     _fat_block_get((bs), (np)->idx->dev_handle, (np)->firstc, (bn))
     66#define fat_block_get(bs, np, bn, flags) \
     67    _fat_block_get((bs), (np)->idx->dev_handle, (np)->firstc, (bn), (flags))
    6868
    6969extern struct block *_fat_block_get(struct fat_bs *, dev_handle_t,
    70     fat_cluster_t, bn_t);
     70    fat_cluster_t, bn_t, int);
    7171 
    7272extern void fat_append_clusters(struct fat_bs *, struct fat_node *,
  • uspace/srv/fs/fat/fat_ops.c

    r26fa0f9f r1d8cdb1  
    9090        /* Read the block that contains the dentry of interest. */
    9191        b = _fat_block_get(bs, node->idx->dev_handle, node->idx->pfc,
    92             (node->idx->pdi * sizeof(fat_dentry_t)) / bps);
     92            (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
    9393
    9494        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
     
    182182        /* Read the block that contains the dentry of interest. */
    183183        b = _fat_block_get(bs, idxp->dev_handle, idxp->pfc,
    184             (idxp->pdi * sizeof(fat_dentry_t)) / bps);
     184            (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
    185185        assert(b);
    186186
     
    283283        blocks = parentp->size / bps;
    284284        for (i = 0; i < blocks; i++) {
    285                 b = fat_block_get(bs, parentp, i);
     285                b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NONE);
    286286                for (j = 0; j < dps; j++) {
    287287                        d = ((fat_dentry_t *)b->data) + j;
     
    373373                fat_dentry_t *d;
    374374       
    375                 b = fat_block_get(bs, nodep, i);
     375                b = fat_block_get(bs, nodep, i, BLOCK_FLAGS_NONE);
    376376                for (j = 0; j < dps; j++) {
    377377                        d = ((fat_dentry_t *)b->data) + j;
     
    575575                        bytes = min(len, bps - pos % bps);
    576576                        bytes = min(bytes, nodep->size - pos);
    577                         b = fat_block_get(bs, nodep, pos / bps);
     577                        b = fat_block_get(bs, nodep, pos / bps,
     578                            BLOCK_FLAGS_NONE);
    578579                        (void) ipc_data_read_finalize(callid, b->data + pos % bps,
    579580                            bytes);
     
    600601                        off_t o;
    601602
    602                         b = fat_block_get(bs, nodep, bnum);
     603                        b = fat_block_get(bs, nodep, bnum, BLOCK_FLAGS_NONE);
    603604                        for (o = pos % (bps / sizeof(fat_dentry_t));
    604605                            o < bps / sizeof(fat_dentry_t);
     
    648649        unsigned bpc;           /* bytes per cluster */
    649650        off_t boundary;
     651        int flags = BLOCK_FLAGS_NONE;
    650652       
    651653        if (!nodep) {
     
    676678         */
    677679        bytes = min(len, bps - pos % bps);
     680        if (bytes == bps)
     681                flags |= BLOCK_FLAGS_NOREAD;
    678682       
    679683        boundary = ROUND_UP(nodep->size, bpc);
     
    686690                 */
    687691                fat_fill_gap(bs, nodep, FAT_CLST_RES0, pos);
    688                 b = fat_block_get(bs, nodep, pos / bps);
     692                b = fat_block_get(bs, nodep, pos / bps, flags);
    689693                (void) ipc_data_write_finalize(callid, b->data + pos % bps,
    690694                    bytes);
     
    719723                /* zero fill any gaps */
    720724                fat_fill_gap(bs, nodep, mcl, pos);
    721                 b = _fat_block_get(bs, dev_handle, lcl, (pos / bps) % spc);
     725                b = _fat_block_get(bs, dev_handle, lcl, (pos / bps) % spc,
     726                    flags);
    722727                (void) ipc_data_write_finalize(callid, b->data + pos % bps,
    723728                    bytes);
Note: See TracChangeset for help on using the changeset viewer.