2 * Ceph - scalable distributed file system
4 * Copyright (C) 2014 CERN (Switzerland)
6 * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
16 * @file ErasureCodeIsaTableCache.h
18 * @brief Erasure Code Isa CODEC Table Cache
20 * The INTEL ISA-L library supports two pre-defined encoding matrices (cauchy = default, reed_sol_van = default)
21 * The default CODEC implementation using these two matrices is implemented in class ErasureCodeIsaDefault.
22 * ISA-L allows to use custom matrices which might be added later as implementations deriving from the base class ErasoreCodeIsa.
25 #ifndef CEPH_ERASURE_CODE_ISA_TABLE_CACHE_H
26 #define CEPH_ERASURE_CODE_ISA_TABLE_CACHE_H
28 // -----------------------------------------------------------------------------
29 #include "common/ceph_mutex.h"
30 #include "erasure-code/ErasureCodeInterface.h"
31 // -----------------------------------------------------------------------------
33 // -----------------------------------------------------------------------------
35 class ErasureCodeIsaTableCache
{
36 // ---------------------------------------------------------------------------
37 // This class implements a table cache for encoding and decoding matrices.
38 // Encoding matrices are shared for the same (k,m) combination. It supplies
39 // a decoding matrix lru cache which is shared for identical
40 // matrix types e.g. there is one cache (lru-list + lru-map) for Cauchy and
41 // one for Vandermonde matrices!
42 // ---------------------------------------------------------------------------
46 // the cache size is sufficient up to (12,4) decodings
48 static const int decoding_tables_lru_length
= 2516;
50 typedef std::pair
<std::list
<std::string
>::iterator
, ceph::buffer::ptr
> lru_entry_t
;
51 typedef std::map
< int, unsigned char** > codec_table_t
;
52 typedef std::map
< int, codec_table_t
> codec_tables_t
;
53 typedef std::map
< int, codec_tables_t
> codec_technique_tables_t
;
55 typedef std::map
< std::string
, lru_entry_t
> lru_map_t
;
56 typedef std::list
< std::string
> lru_list_t
;
58 ErasureCodeIsaTableCache() = default;
60 virtual ~ErasureCodeIsaTableCache();
62 // mutex used to protect modifications in encoding/decoding table maps
63 ceph::mutex codec_tables_guard
= ceph::make_mutex("isa-lru-cache");
65 bool getDecodingTableFromCache(std::string
&signature
,
66 unsigned char* &table
,
71 void putDecodingTableToCache(std::string
&,
77 unsigned char** getEncodingTable(int matrix
, int k
, int m
);
78 unsigned char** getEncodingCoefficient(int matrix
, int k
, int m
);
80 unsigned char** getEncodingTableNoLock(int matrix
, int k
, int m
);
81 unsigned char** getEncodingCoefficientNoLock(int matrix
, int k
, int m
);
83 unsigned char* setEncodingTable(int matrix
, int k
, int m
, unsigned char*);
84 unsigned char* setEncodingCoefficient(int matrix
, int k
, int m
, unsigned char*);
86 int getDecodingTableCacheSize(int matrixtype
= 0);
89 codec_technique_tables_t encoding_coefficient
; // encoding coefficients accessed via table[matrix][k][m]
90 codec_technique_tables_t encoding_table
; // encoding coefficients accessed via table[matrix][k][m]
92 std::map
<int, lru_map_t
*> decoding_tables
; // decoding table cache accessed via map[matrixtype]
93 std::map
<int, lru_list_t
*> decoding_tables_lru
; // decoding table lru list accessed via list[matrixtype]
95 lru_map_t
* getDecodingTables(int matrix_type
);
97 lru_list_t
* getDecodingTablesLru(int matrix_type
);
99 ceph::mutex
* getLock();