Ejemplo n.º 1
0
int CodeCache::cache(  const AssemblyKeyBase& keyBase,
                            const sp<Assembly>& assembly)
{
    pthread_mutex_lock(&mLock);

    const ssize_t assemblySize = assembly->size();
    while (mCacheInUse + assemblySize > mCacheSize) {
        // evict the LRU
        size_t lru = 0;
        size_t count = mCacheData.size();
        for (size_t i=0 ; i<count ; i++) {
            const cache_entry_t& e = mCacheData.valueAt(i);
            if (e.when < mCacheData.valueAt(lru).when) {
                lru = i;
            }
        }
        const cache_entry_t& e = mCacheData.valueAt(lru);
        mCacheInUse -= e.entry->size();
        mCacheData.removeItemsAt(lru);
    }

    ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen));
    if (err >= 0) {
        mCacheInUse += assemblySize;
        mWhen++;
        // synchronize caches...
        char* base = reinterpret_cast<char*>(assembly->base());
        char* curr = reinterpret_cast<char*>(base + assembly->size());
        __builtin___clear_cache(base, curr);
    }

    pthread_mutex_unlock(&mLock);
    return err;
}
Ejemplo n.º 2
0
void
MetaDataStore::maybe_add_to_cache_(const FrontendPath& p,
                                   DirectoryEntryPtr& dentry)
{
    LOG_TRACE(p << ", object id " << dentry->object_id());

    if (use_cache_ == UseCache::T and
        dentry->type() == DirectoryEntry::Type::Volume)
    {
        LOG_TRACE(p);

        WLOCK_CACHE();
        /* Should insert_or_modify perform much better here?
         * For at least a small number of entries (<2048)
         * */
        bimap_cache_.left.erase(p);
        bimap_cache_.insert(cache_entry_t(p, dentry->object_id(), dentry));
    }
}
Ejemplo n.º 3
0
int CodeCache::cache(  const AssemblyKeyBase& keyBase,
                       const sp<Assembly>& assembly)
{
    pthread_mutex_lock(&mLock);

    const ssize_t assemblySize = assembly->size();
    while (mCacheInUse + assemblySize > mCacheSize) {
        // evict the LRU
        size_t lru = 0;
        size_t count = mCacheData.size();
        for (size_t i=0 ; i<count ; i++) {
            const cache_entry_t& e = mCacheData.valueAt(i);
            if (e.when < mCacheData.valueAt(lru).when) {
                lru = i;
            }
        }
        const cache_entry_t& e = mCacheData.valueAt(lru);
        mCacheInUse -= e.entry->size();
        mCacheData.removeItemsAt(lru);
    }

    ssize_t err = mCacheData.add(key_t(keyBase), cache_entry_t(assembly, mWhen));
    if (err >= 0) {
        mCacheInUse += assemblySize;
        mWhen++;
        // synchronize caches...
#if defined(__arm__)
        const long base = long(assembly->base());
        const long curr = base + long(assembly->size());
        err = cacheflush(base, curr, 0);
        LOGE_IF(err, "__ARM_NR_cacheflush error %s\n",
                strerror(errno));
#endif
    }

    pthread_mutex_unlock(&mLock);
    return err;
}