1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 FUJITSU LIMITED
7 * Copyright (C) 2014 CERN (Switzerland)
9 * Author: Takanori Nakao <nakao.takanori@jp.fujitsu.com>
10 * Author: Takeshi Miyamae <miyamae.takeshi@jp.fujitsu.com>
11 * Author: Andreas-Joachim Peters <Andreas.Joachim.Peters@cern.ch>
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
20 #ifndef CEPH_ERASURE_CODE_SHEC_TABLE_CACHE_H
21 #define CEPH_ERASURE_CODE_SHEC_TABLE_CACHE_H
23 // -----------------------------------------------------------------------------
24 #include "common/Mutex.h"
25 #include "erasure-code/ErasureCodeInterface.h"
26 // -----------------------------------------------------------------------------
28 // -----------------------------------------------------------------------------
30 class ErasureCodeShecTableCache {
31 // ---------------------------------------------------------------------------
32 // This class implements a table cache for encoding and decoding matrices.
33 // Encoding matrices are shared for the same (k,m,c,w) combination.
34 // It supplies a decoding matrix lru cache which is shared for identical
35 // matrix types e.g. there is one cache (lru-list + lru-map)
36 // ---------------------------------------------------------------------------
38 class DecodingCacheParameter {
40 int* decoding_matrix; // size: k*k
41 int* dm_row; // size: k
42 int* dm_column; // size: k
43 int* minimum; // size: k+m
44 DecodingCacheParameter() {
50 ~DecodingCacheParameter() {
51 if (decoding_matrix) {
52 delete[] decoding_matrix;
68 static const int decoding_tables_lru_length = 10000;
69 typedef std::pair<std::list<uint64_t>::iterator,
70 DecodingCacheParameter> lru_entry_t;
71 typedef std::map< int, int** > codec_table_t;
72 typedef std::map< int, codec_table_t > codec_tables_t__;
73 typedef std::map< int, codec_tables_t__ > codec_tables_t_;
74 typedef std::map< int, codec_tables_t_ > codec_tables_t;
75 typedef std::map< int, codec_tables_t > codec_technique_tables_t;
76 // int** matrix = codec_technique_tables_t[technique][k][m][c][w]
78 typedef std::map< uint64_t, lru_entry_t > lru_map_t;
79 typedef std::list< uint64_t > lru_list_t;
81 ErasureCodeShecTableCache() :
82 codec_tables_guard("shec-lru-cache")
86 virtual ~ErasureCodeShecTableCache();
88 Mutex codec_tables_guard; // mutex used to protect modifications in encoding/decoding table maps
90 bool getDecodingTableFromCache(int* matrix,
91 int* dm_row, int* dm_column,
94 int k, int m, int c, int w,
95 int* want, int* avails);
97 void putDecodingTableToCache(int* matrix,
98 int* dm_row, int* dm_column,
101 int k, int m, int c, int w,
102 int* want, int* avails);
104 int** getEncodingTable(int technique, int k, int m, int c, int w);
105 int** getEncodingTableNoLock(int technique, int k, int m, int c, int w);
106 int* setEncodingTable(int technique, int k, int m, int c, int w, int*);
109 // encoding table accessed via table[matrix][k][m][c][w]
110 // decoding table cache accessed via map[matrixtype]
111 // decoding table lru list accessed via list[matrixtype]
112 codec_technique_tables_t encoding_table;
113 std::map<int, lru_map_t*> decoding_tables;
114 std::map<int, lru_list_t*> decoding_tables_lru;
116 lru_map_t* getDecodingTables(int technique);
117 lru_list_t* getDecodingTablesLru(int technique);
118 uint64_t getDecodingCacheSignature(int k, int m, int c, int w,
119 int *want, int *avails);