Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / erasure-code / isa / ErasureCodeIsaTableCache.h
1 /*
2  * Ceph - scalable distributed file system
3  *
4  * Copyright (C) 2014 CERN (Switzerland)
5  *
6  * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch>
7  *
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.
12  *
13  */
14
15 /**
16  * @file   ErasureCodeIsaTableCache.h
17  *
18  * @brief  Erasure Code Isa CODEC Table Cache
19  *
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.
23  */
24
25 #ifndef CEPH_ERASURE_CODE_ISA_TABLE_CACHE_H
26 #define CEPH_ERASURE_CODE_ISA_TABLE_CACHE_H
27
28 // -----------------------------------------------------------------------------
29 #include "common/Mutex.h"
30 #include "erasure-code/ErasureCodeInterface.h"
31 // -----------------------------------------------------------------------------
32 #include <list>
33 // -----------------------------------------------------------------------------
34
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   // ---------------------------------------------------------------------------
43
44 public:
45
46   // the cache size is sufficient up to (12,4) decodings
47
48   static const int decoding_tables_lru_length = 2516;
49
50   typedef std::pair<std::list<std::string>::iterator, bufferptr> 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;
54
55   typedef std::map< std::string, lru_entry_t > lru_map_t;
56   typedef std::list< std::string > lru_list_t;
57
58   ErasureCodeIsaTableCache() :
59   codec_tables_guard("isa-lru-cache")
60   {
61   }
62
63   virtual ~ErasureCodeIsaTableCache();
64
65   Mutex codec_tables_guard; // mutex used to protect modifications in encoding/decoding table maps
66
67   bool getDecodingTableFromCache(std::string &signature,
68                                  unsigned char* &table,
69                                  int matrixtype,
70                                  int k,
71                                  int m);
72
73   void putDecodingTableToCache(std::string&,
74                                unsigned char*&,
75                                int matrixtype,
76                                int k,
77                                int m);
78
79   unsigned char** getEncodingTable(int matrix, int k, int m);
80   unsigned char** getEncodingCoefficient(int matrix, int k, int m);
81
82   unsigned char** getEncodingTableNoLock(int matrix, int k, int m);
83   unsigned char** getEncodingCoefficientNoLock(int matrix, int k, int m);
84
85   unsigned char* setEncodingTable(int matrix, int k, int m, unsigned char*);
86   unsigned char* setEncodingCoefficient(int matrix, int k, int m, unsigned char*);
87
88   int getDecodingTableCacheSize(int matrixtype = 0);
89
90 private:
91   codec_technique_tables_t encoding_coefficient; // encoding coefficients accessed via table[matrix][k][m]
92   codec_technique_tables_t encoding_table; // encoding coefficients accessed via table[matrix][k][m]
93
94   std::map<int, lru_map_t*> decoding_tables; // decoding table cache accessed via map[matrixtype]
95   std::map<int, lru_list_t*> decoding_tables_lru; // decoding table lru list accessed via list[matrixtype]
96
97   lru_map_t* getDecodingTables(int matrix_type);
98
99   lru_list_t* getDecodingTablesLru(int matrix_type);
100
101   Mutex* getLock();
102
103 };
104
105 #endif