xrootd
XrdOucCacheReal.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCCACHEREAL_HH__
2 #define __XRDOUCCACHEREAL_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c C a c h e R e a l . h h */
6 /* */
7 /* (c) 2011 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 
35 #include "XrdSys/XrdSysPthread.hh"
36 
37 /* This class defines an actual implementation of an XrdOucCache object. */
38 
40 {
41 friend class XrdOucCacheData;
42 public:
43 
45 
46 int isAttached() {int n;
47  CMutex.Lock(); n = Attached; CMutex.UnLock();
48  return n;
49  }
50 
51  XrdOucCacheReal(int &rc, // Success = 0; o/w !0
52  Parms &Parms, // Parameters
53  XrdOucCacheIO::aprParms *aprP=0);
54 
56 
57 void PreRead();
58 
59 private:
60 
61 void eMsg(const char *Path, const char *What, long long xOff,
62  int xLen, int ec);
63 int Detach(XrdOucCacheIO *ioP);
64 char *Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO);
65 
66 int ioAdd(XrdOucCacheIO *KeyVal, int &iNum);
67 int ioDel(XrdOucCacheIO *KeyVal, int &iNum);
68 
69 inline
70 int ioEnt(XrdOucCacheIO *kVal)
71  {union {short sV[4]; XrdOucCacheIO *pV;} Key = {{0,0,0,0}};
72  Key.pV = kVal;
73  return ((Key.sV[0]^Key.sV[1]^Key.sV[2]^Key.sV[3])&0x7fff)%hMax;
74  }
75 inline
76 int ioLookup(int &pip, int hip, void *kval)
77  {pip = 0;
78  while(hip && kval != Slots[hip].Key)
79  {pip = hip; hip = Slots[hip].HLink;}
80  return hip;
81  }
82 
83 int Ref(char *Addr, int rAmt, int sFlags=0);
84 void Trunc(XrdOucCacheIO *ioP, long long lAddr);
85 void Upd(char *Addr, int wAmt, int wOff);
86 
87 static const long long Shift = 48;
88 static const long long Strip = 0x00000000ffffffffLL; //
89 static const long long MaxFO = 0x000007ffffffffffLL; // Min 4K page -> 8TB-1
90 
91 XrdOucCacheIO::aprParms aprDefault; // Default automatic preread
92 
94 XrdOucCacheSlot *Slots; // 1-to-1 slot to memory map
95 int *Slash; // Slot hash table
96 char *Base; // Base of memory cache
97 long long HNum;
98 long long SegCnt;
99 long long SegSize;
100 long long OffMask; // SegSize - 1
101 long long SegShft; // log2(SegSize)
102 int SegFull; // SegSize to mark
103 int maxCache; // Maximum read to cache
104 int maxFiles; // Maximum number of files to support
106 
107 // The following supports CacheIO object tracking
108 //
109 int *hTab; // -> Hash Table
110 int hMax; // Number of entries in table
111 int sFree; // Index of free file slot
112 int sBeg; // Index of file slot array in slot table
113 int sEnd; // Last index + 1
114 
115 // Various options
116 //
117 char Dbg; // Debug setting
118 char Lgs; // Log statistics
119 
120 // This is the attach/detach control area
121 //
124 
125 // This is the pre-read control area
126 //
127 struct prTask
130  };
131 void PreRead(XrdOucCacheReal::prTask *prReq);
137 int prNum;
138 };
139 #endif
char * Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO)
int HLink
Definition: XrdOucCacheSlot.hh:141
XrdSysSemaphore * AZero
Definition: XrdOucCacheReal.hh:122
int sBeg
Definition: XrdOucCacheReal.hh:112
void eMsg(const char *Path, const char *What, long long xOff, int xLen, int ec)
char Lgs
Definition: XrdOucCacheReal.hh:118
int ioEnt(XrdOucCacheIO *kVal)
Definition: XrdOucCacheReal.hh:70
Definition: XrdOucCacheReal.hh:127
Definition: XrdOucCacheData.hh:46
void Trunc(XrdOucCacheIO *ioP, long long lAddr)
Definition: XrdOucCache.hh:102
int maxFiles
Definition: XrdOucCacheReal.hh:104
int prNum
Definition: XrdOucCacheReal.hh:137
int isAttached()
Definition: XrdOucCacheReal.hh:46
void Upd(char *Addr, int wAmt, int wOff)
long long SegSize
Definition: XrdOucCacheReal.hh:99
int sFree
Definition: XrdOucCacheReal.hh:111
int Attached
Definition: XrdOucCacheReal.hh:123
XrdOucCacheReal(int &rc, Parms &Parms, XrdOucCacheIO::aprParms *aprP=0)
int hMax
Definition: XrdOucCacheReal.hh:110
long long HNum
Definition: XrdOucCacheReal.hh:97
int ioAdd(XrdOucCacheIO *KeyVal, int &iNum)
long long SegCnt
Definition: XrdOucCacheReal.hh:98
Definition: XrdSysPthread.hh:165
int Detach(XrdOucCacheIO *ioP)
int Options
Definition: XrdOucCacheReal.hh:105
char * Base
Definition: XrdOucCacheReal.hh:96
int SegFull
Definition: XrdOucCacheReal.hh:102
Definition: XrdOucCacheDram.hh:93
int ioDel(XrdOucCacheIO *KeyVal, int &iNum)
XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int Options=0)
const char * Path()
Definition: XrdOucCacheData.hh:56
Definition: XrdSysPthread.hh:403
XrdOucCacheSlot * Slots
Definition: XrdOucCacheReal.hh:94
Definition: XrdOucCacheReal.hh:39
prTask * Next
Definition: XrdOucCacheReal.hh:128
int * Slash
Definition: XrdOucCacheReal.hh:95
int * hTab
Definition: XrdOucCacheReal.hh:109
Definition: XrdOucCache.hh:286
XrdOucCacheData * Data
Definition: XrdOucCacheReal.hh:129
prTask * prLast
Definition: XrdOucCacheReal.hh:133
void Lock()
Definition: XrdSysPthread.hh:220
long long OffMask
Definition: XrdOucCacheReal.hh:100
static const long long Strip
Definition: XrdOucCacheReal.hh:88
int sEnd
Definition: XrdOucCacheReal.hh:113
long long SegShft
Definition: XrdOucCacheReal.hh:101
XrdSysMutex prMutex
Definition: XrdOucCacheReal.hh:134
int ioLookup(int &pip, int hip, void *kval)
Definition: XrdOucCacheReal.hh:76
Definition: XrdOucCacheSlot.hh:41
prTask * prFirst
Definition: XrdOucCacheReal.hh:132
static const long long Shift
Definition: XrdOucCacheReal.hh:87
static const long long MaxFO
Definition: XrdOucCacheReal.hh:89
XrdSysSemaphore * prStop
Definition: XrdOucCacheReal.hh:136
void UnLock()
Definition: XrdSysPthread.hh:222
XrdSysSemaphore prReady
Definition: XrdOucCacheReal.hh:135
int maxCache
Definition: XrdOucCacheReal.hh:103
char Dbg
Definition: XrdOucCacheReal.hh:117
XrdSysMutex CMutex
Definition: XrdOucCacheReal.hh:93
XrdOucCacheIO::aprParms aprDefault
Definition: XrdOucCacheReal.hh:91
int Ref(char *Addr, int rAmt, int sFlags=0)