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);
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  };
137 int prNum;
138 };
139 #endif
XrdOucCacheReal::PreRead
void PreRead()
XrdOucCacheData
Definition: XrdOucCacheData.hh:47
XrdOucCacheReal::Strip
static const long long Strip
Definition: XrdOucCacheReal.hh:88
XrdOucCacheIO
Definition: XrdOucCache.hh:128
XrdOucCacheReal::aprDefault
XrdOucCacheIO::aprParms aprDefault
Definition: XrdOucCacheReal.hh:91
XrdOucCacheReal::maxFiles
int maxFiles
Definition: XrdOucCacheReal.hh:104
XrdOucCacheReal::hMax
int hMax
Definition: XrdOucCacheReal.hh:110
XrdOucCacheReal::HNum
long long HNum
Definition: XrdOucCacheReal.hh:97
XrdSysMutex
Definition: XrdSysPthread.hh:166
XrdOucCacheReal::isAttached
int isAttached()
Definition: XrdOucCacheReal.hh:46
XrdSysPthread.hh
XrdOucCacheReal::prLast
prTask * prLast
Definition: XrdOucCacheReal.hh:133
XrdOucCacheReal::prReady
XrdSysSemaphore prReady
Definition: XrdOucCacheReal.hh:135
XrdOucCacheReal::Shift
static const long long Shift
Definition: XrdOucCacheReal.hh:87
XrdOucCacheReal::MaxFO
static const long long MaxFO
Definition: XrdOucCacheReal.hh:89
XrdOucCacheReal::Dbg
char Dbg
Definition: XrdOucCacheReal.hh:117
XrdOucCacheReal::sBeg
int sBeg
Definition: XrdOucCacheReal.hh:112
XrdOucCacheReal::ioLookup
int ioLookup(int &pip, int hip, void *kval)
Definition: XrdOucCacheReal.hh:76
XrdOucCacheReal::Lgs
char Lgs
Definition: XrdOucCacheReal.hh:118
XrdOucCacheReal::OffMask
long long OffMask
Definition: XrdOucCacheReal.hh:100
XrdOucCacheReal::ioEnt
int ioEnt(XrdOucCacheIO *kVal)
Definition: XrdOucCacheReal.hh:70
XrdOucCacheDram
Definition: XrdOucCacheDram.hh:94
XrdOucCacheData::Path
const char * Path()
Definition: XrdOucCacheData.hh:56
XrdOucCacheReal::SegFull
int SegFull
Definition: XrdOucCacheReal.hh:102
XrdOucCacheReal::prFirst
prTask * prFirst
Definition: XrdOucCacheReal.hh:132
XrdOucCacheReal::Attach
XrdOucCacheIO * Attach(XrdOucCacheIO *ioP, int Options=0)
XrdOucCacheReal::CMutex
XrdSysMutex CMutex
Definition: XrdOucCacheReal.hh:93
XrdOucCacheReal::Ref
int Ref(char *Addr, int rAmt, int sFlags=0)
XrdOucCacheReal::prTask::Next
prTask * Next
Definition: XrdOucCacheReal.hh:128
XrdOucCacheReal::prTask
Definition: XrdOucCacheReal.hh:128
XrdOucCacheReal::Get
char * Get(XrdOucCacheIO *ioP, long long lAddr, int &rGot, int &bIO)
XrdOucCacheReal::PreRead
void PreRead(XrdOucCacheReal::prTask *prReq)
XrdSysSemaphore
Definition: XrdSysPthread.hh:404
XrdOucCacheReal
Definition: XrdOucCacheReal.hh:40
XrdOucCacheReal::prNum
int prNum
Definition: XrdOucCacheReal.hh:137
XrdOucCacheReal::Detach
int Detach(XrdOucCacheIO *ioP)
XrdOucCacheReal::Options
int Options
Definition: XrdOucCacheReal.hh:105
XrdOucCacheSlot.hh
XrdOucCacheReal::XrdOucCacheReal
XrdOucCacheReal(int &rc, Parms &Parms, XrdOucCacheIO::aprParms *aprP=0)
XrdOucCacheReal::prTask::Data
XrdOucCacheData * Data
Definition: XrdOucCacheReal.hh:129
XrdOucCacheReal::SegSize
long long SegSize
Definition: XrdOucCacheReal.hh:99
XrdOucCacheReal::AZero
XrdSysSemaphore * AZero
Definition: XrdOucCacheReal.hh:122
XrdOucCacheReal::Trunc
void Trunc(XrdOucCacheIO *ioP, long long lAddr)
XrdOucCacheReal::maxCache
int maxCache
Definition: XrdOucCacheReal.hh:103
XrdOucCacheReal::SegShft
long long SegShft
Definition: XrdOucCacheReal.hh:101
XrdOucCacheReal::Slots
XrdOucCacheSlot * Slots
Definition: XrdOucCacheReal.hh:94
XrdOucCacheIO::aprParms
Definition: XrdOucCache.hh:248
XrdOucCacheSlot::HLink
int HLink
Definition: XrdOucCacheSlot.hh:141
XrdOucCacheReal::Upd
void Upd(char *Addr, int wAmt, int wOff)
XrdOucCacheReal::Slash
int * Slash
Definition: XrdOucCacheReal.hh:95
XrdOucCacheReal::sFree
int sFree
Definition: XrdOucCacheReal.hh:111
XrdOucCacheReal::prStop
XrdSysSemaphore * prStop
Definition: XrdOucCacheReal.hh:136
XrdOucCacheSlot
Definition: XrdOucCacheSlot.hh:42
XrdSysMutex::UnLock
void UnLock()
Definition: XrdSysPthread.hh:222
XrdSysMutex::Lock
void Lock()
Definition: XrdSysPthread.hh:220
XrdOucCache::Parms
Definition: XrdOucCache.hh:321
XrdOucCacheReal::sEnd
int sEnd
Definition: XrdOucCacheReal.hh:113
XrdOucCacheReal::eMsg
void eMsg(const char *Path, const char *What, long long xOff, int xLen, int ec)
XrdOucCacheDram.hh
XrdOucCacheReal::Base
char * Base
Definition: XrdOucCacheReal.hh:96
XrdOucCacheReal::prMutex
XrdSysMutex prMutex
Definition: XrdOucCacheReal.hh:134
XrdOucCacheReal::hTab
int * hTab
Definition: XrdOucCacheReal.hh:109
XrdOucCacheReal::ioAdd
int ioAdd(XrdOucCacheIO *KeyVal, int &iNum)
XrdOucCacheReal::SegCnt
long long SegCnt
Definition: XrdOucCacheReal.hh:98
XrdOucCacheReal::~XrdOucCacheReal
~XrdOucCacheReal()
XrdOucCacheReal::Attached
int Attached
Definition: XrdOucCacheReal.hh:123
XrdOucCacheReal::ioDel
int ioDel(XrdOucCacheIO *KeyVal, int &iNum)