xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdRmcReal.hh
Go to the documentation of this file.
1 #ifndef __XRDRMCREAL_HH__
2 #define __XRDRMCREAL_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d R m c R e a l . h h */
6 /* */
7 /* (c) 2019 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include "XrdRmc/XrdRmc.hh"
34 #include "XrdRmc/XrdRmcSlot.hh"
35 #include "XrdSys/XrdSysPthread.hh"
36 
37 /* This class defines an actual implementation of an XrdOucCache object. */
38 
39 class XrdRmcReal : public XrdOucCache
40 {
41 friend class XrdRmcData;
42 public:
43 
45 
46  XrdRmcReal(int &rc,
47  XrdRmc::Parms &Parms,
48  XrdOucCacheIO::aprParms *aprP=0);
49 
50  ~XrdRmcReal();
51 
52 void PreRead();
53 
54 private:
55 
56 void eMsg(const char *Path, const char *What, long long xOff,
57  int xLen, int ec);
58 int Detach(XrdOucCacheIO *ioP);
59 char *Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO);
60 
61 int ioAdd(XrdOucCacheIO *KeyVal, int &iNum);
62 int ioDel(XrdOucCacheIO *KeyVal, int &iNum);
63 
64 inline
65 int ioEnt(XrdOucCacheIO *kVal)
66  {union {short sV[4]; XrdOucCacheIO *pV;} Key = {{0,0,0,0}};
67  Key.pV = kVal;
68  return ((Key.sV[0]^Key.sV[1]^Key.sV[2]^Key.sV[3])&0x7fff)%hMax;
69  }
70 inline
71 int ioLookup(int &pip, int hip, void *kval)
72  {pip = 0;
73  while(hip && kval != Slots[hip].Key)
74  {pip = hip; hip = Slots[hip].HLink;}
75  return hip;
76  }
77 
78 int Ref(char *Addr, int rAmt, int sFlags=0);
79 void Trunc(XrdOucCacheIO *ioP, long long lAddr);
80 void Upd(char *Addr, int wAmt, int wOff);
81 
82 static const long long Shift = 48;
83 static const long long Strip = 0x00000000ffffffffLL; //
84 static const long long MaxFO = 0x000007ffffffffffLL; // Min 4K page -> 8TB-1
85 
86 XrdOucCacheIO::aprParms aprDefault; // Default automatic preread
87 
89 XrdRmcSlot *Slots; // 1-to-1 slot to memory map
90 int *Slash; // Slot hash table
91 char *Base; // Base of memory cache
92 long long HNum;
93 long long SegCnt;
94 long long SegSize;
95 long long OffMask; // SegSize - 1
96 long long SegShft; // log2(SegSize)
97 int SegFull; // SegSize to mark
98 int maxCache; // Maximum read to cache
99 int maxFiles; // Maximum number of files to support
101 
102 // The following supports CacheIO object tracking
103 //
104 int *hTab; // -> Hash Table
105 int hMax; // Number of entries in table
106 int sFree; // Index of free file slot
107 int sBeg; // Index of file slot array in slot table
108 int sEnd; // Last index + 1
109 
110 // Various options
111 //
112 char Dbg; // Debug setting
113 char Lgs; // Log statistics
114 
115 // This is the attach/detach control area
116 //
119 
120 // This is the pre-read control area
121 //
122 struct prTask
125  };
126 void PreRead(XrdRmcReal::prTask *prReq);
132 int prNum;
133 };
134 #endif
int Attached
Definition: XrdRmcReal.hh:118
int ioDel(XrdOucCacheIO *KeyVal, int &iNum)
long long SegCnt
Definition: XrdRmcReal.hh:93
int * Slash
Definition: XrdRmcReal.hh:90
void Upd(char *Addr, int wAmt, int wOff)
XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int Options=0)
Definition: XrdRmcReal.hh:122
Definition: XrdOucCache.hh:104
prTask * prLast
Definition: XrdRmcReal.hh:128
XrdSysMutex prMutex
Definition: XrdRmcReal.hh:129
Definition: XrdRmcSlot.hh:41
int * hTab
Definition: XrdRmcReal.hh:104
XrdRmcReal(int &rc, XrdRmc::Parms &Parms, XrdOucCacheIO::aprParms *aprP=0)
void eMsg(const char *Path, const char *What, long long xOff, int xLen, int ec)
int hMax
Definition: XrdRmcReal.hh:105
int Ref(char *Addr, int rAmt, int sFlags=0)
int Options
Definition: XrdRmcReal.hh:100
long long SegShft
Definition: XrdRmcReal.hh:96
XrdOucCacheIO::aprParms aprDefault
Definition: XrdRmcReal.hh:86
int maxCache
Definition: XrdRmcReal.hh:98
Definition: XrdSysPthread.hh:164
int maxFiles
Definition: XrdRmcReal.hh:99
Parameters for a newly created memory cache.
Definition: XrdRmc.hh:98
Definition: XrdOucCache.hh:497
XrdSysSemaphore * AZero
Definition: XrdRmcReal.hh:117
char * Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO)
int sEnd
Definition: XrdRmcReal.hh:108
static const long long Shift
Definition: XrdRmcReal.hh:82
XrdSysMutex CMutex
Definition: XrdRmcReal.hh:88
int ioAdd(XrdOucCacheIO *KeyVal, int &iNum)
Definition: XrdSysPthread.hh:493
int prNum
Definition: XrdRmcReal.hh:132
Definition: XrdOucCache.hh:290
const char * Path()
Definition: XrdRmcData.hh:50
void PreRead()
int ioLookup(int &pip, int hip, void *kval)
Definition: XrdRmcReal.hh:71
char Lgs
Definition: XrdRmcReal.hh:113
Definition: XrdRmcData.hh:42
long long OffMask
Definition: XrdRmcReal.hh:95
int SegFull
Definition: XrdRmcReal.hh:97
XrdSysSemaphore * prStop
Definition: XrdRmcReal.hh:131
static const long long Strip
Definition: XrdRmcReal.hh:83
static const long long MaxFO
Definition: XrdRmcReal.hh:84
int HLink
Definition: XrdRmcSlot.hh:141
prTask * prFirst
Definition: XrdRmcReal.hh:127
XrdRmcSlot * Slots
Definition: XrdRmcReal.hh:89
int Detach(XrdOucCacheIO *ioP)
int sFree
Definition: XrdRmcReal.hh:106
void Trunc(XrdOucCacheIO *ioP, long long lAddr)
char * Base
Definition: XrdRmcReal.hh:91
long long SegSize
Definition: XrdRmcReal.hh:94
prTask * Next
Definition: XrdRmcReal.hh:123
XrdSysSemaphore prReady
Definition: XrdRmcReal.hh:130
int sBeg
Definition: XrdRmcReal.hh:107
int ioEnt(XrdOucCacheIO *kVal)
Definition: XrdRmcReal.hh:65
Definition: XrdRmcReal.hh:39
long long HNum
Definition: XrdRmcReal.hh:92
char Dbg
Definition: XrdRmcReal.hh:112
XrdRmcData * Data
Definition: XrdRmcReal.hh:124