]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/isa/ErasureCodeIsaTableCache.h
import 15.2.0 Octopus source
[ceph.git] / 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/ceph_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, 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;
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() = default;
59
60 virtual ~ErasureCodeIsaTableCache();
61
62 // mutex used to protect modifications in encoding/decoding table maps
63 ceph::mutex codec_tables_guard = ceph::make_mutex("isa-lru-cache");
64
65 bool getDecodingTableFromCache(std::string &signature,
66 unsigned char* &table,
67 int matrixtype,
68 int k,
69 int m);
70
71 void putDecodingTableToCache(std::string&,
72 unsigned char*&,
73 int matrixtype,
74 int k,
75 int m);
76
77 unsigned char** getEncodingTable(int matrix, int k, int m);
78 unsigned char** getEncodingCoefficient(int matrix, int k, int m);
79
80 unsigned char** getEncodingTableNoLock(int matrix, int k, int m);
81 unsigned char** getEncodingCoefficientNoLock(int matrix, int k, int m);
82
83 unsigned char* setEncodingTable(int matrix, int k, int m, unsigned char*);
84 unsigned char* setEncodingCoefficient(int matrix, int k, int m, unsigned char*);
85
86 int getDecodingTableCacheSize(int matrixtype = 0);
87
88 private:
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]
91
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]
94
95 lru_map_t* getDecodingTables(int matrix_type);
96
97 lru_list_t* getDecodingTablesLru(int matrix_type);
98
99 ceph::mutex* getLock();
100
101 };
102
103 #endif