Skip to content

Commit

Permalink
[POSIX] Implement Cache Context Management plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Jun 13, 2018
1 parent 3873346 commit 1f8b4d1
Show file tree
Hide file tree
Showing 14 changed files with 505 additions and 115 deletions.
2 changes: 2 additions & 0 deletions src/XrdHeaders.cmake
Expand Up @@ -48,6 +48,7 @@ set( XROOTD_PUBLIC_HEADERS
XrdOuc/XrdOucBuffer.hh
XrdOuc/XrdOucCRC.hh
XrdOuc/XrdOucCache.hh
XrdOuc/XrdOucCacheStats.hh
XrdOuc/XrdOucCallBack.hh
XrdOuc/XrdOucChain.hh
XrdOuc/XrdOucDLlist.hh
Expand All @@ -74,6 +75,7 @@ set( XROOTD_PUBLIC_HEADERS
XrdOuc/XrdOucEnum.hh
XrdOuc/XrdOucCompiler.hh
XrdPosix/XrdPosix.hh
XrdPosix/XrdPosixCache.hh
XrdPosix/XrdPosixCallBack.hh
XrdPosix/XrdPosixExtern.hh
XrdPosix/XrdPosixOsDep.hh
Expand Down
60 changes: 1 addition & 59 deletions src/XrdOuc/XrdOucCache.hh
Expand Up @@ -30,8 +30,8 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include "XrdOuc/XrdOucCacheStats.hh"
#include "XrdOuc/XrdOucIOVec.hh"
#include "XrdSys/XrdSysPthread.hh"

/* The classes defined here can be used to implement a general cache for
data from an arbitrary source (e.g. files, sockets, etc); as follows:
Expand Down Expand Up @@ -80,64 +80,6 @@
delete cacheIO->Detach(); // Deletes cacheIO and physIO
*/

/******************************************************************************/
/* C l a s s X r d O u c C a c h e S t a t s */
/******************************************************************************/

/* The XrdOucCacheStats object holds statistics on cache usage. It is available
in for each XrdOucCacheIO and each XrdOucCache object. The former usually
identifies a specific file while the latter provides summary information.
*/

class XrdOucCacheStats
{
public:
long long BytesPead; // Bytes read via preread (not included in BytesRead)
long long BytesRead; // Total number of bytes read into the cache
long long BytesGet; // Number of bytes delivered from the cache
long long BytesPass; // Number of bytes read but not cached
long long BytesWrite; // Total number of bytes written from the cache
long long BytesPut; // Number of bytes updated in the cache
int Hits; // Number of times wanted data was in the cache
int Miss; // Number of times wanted data was *not* in the cache
int HitsPR; // Number of pages wanted data was just preread
int MissPR; // Number of pages wanted data was just read

inline void Get(XrdOucCacheStats &Dst)
{sMutex.Lock();
Dst.BytesRead = BytesPead; Dst.BytesGet = BytesRead;
Dst.BytesPass = BytesPass;
Dst.BytesWrite = BytesWrite; Dst.BytesPut = BytesPut;
Dst.Hits = Hits; Dst.Miss = Miss;
Dst.HitsPR = HitsPR; Dst.MissPR = MissPR;
sMutex.UnLock();
}

inline void Add(XrdOucCacheStats &Src)
{sMutex.Lock();
BytesRead += Src.BytesPead; BytesGet += Src.BytesRead;
BytesPass += Src.BytesPass;
BytesWrite += Src.BytesWrite; BytesPut += Src.BytesPut;
Hits += Src.Hits; Miss += Src.Miss;
HitsPR += Src.HitsPR; MissPR += Src.MissPR;
sMutex.UnLock();
}

inline void Add(long long &Dest, int &Val)
{sMutex.Lock(); Dest += Val; sMutex.UnLock();}

inline void Lock() {sMutex.Lock();}
inline void UnLock() {sMutex.UnLock();}

XrdOucCacheStats() : BytesPead(0), BytesRead(0), BytesGet(0),
BytesPass(0), BytesWrite(0), BytesPut(0),
Hits(0), Miss(0),
HitsPR(0), MissPR(0) {}
~XrdOucCacheStats() {}
private:
XrdSysMutex sMutex;
};

/******************************************************************************/
/* X r d O u c C a c h e I O C B */
Expand Down
96 changes: 96 additions & 0 deletions src/XrdOuc/XrdOucCacheCM.hh
@@ -0,0 +1,96 @@
#ifndef __XRDPUCCACHECM_HH__
#define __XRDPUCCACHECM_HH__
/******************************************************************************/
/* */
/* X r d O u c C a c h e C M . h h */
/* */
/* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

/* The class defined here is used to implement a cache context management
plugin. It is loaded as run time can interact with the cache, as needed.
The pss.ccmlib directive is used to load the plugin. However, it is only
loaded if a cache has been enabled for use.
Your plug-in must exist in a shared library and have the following extern C
function defined:
*/

//------------------------------------------------------------------------------
//! Initialize a cache context management plugin.
//!
//! @param Cache Reference to the object that interacts with the cache.
//! @param Logger -> The message routing object to be used in conjunction
//! with an XrdSysError object for error messages. When
//! nil, you should use cerr.
//! @param Config -> The name of the config file. When nil there was no
//! configuration file.
//! @param Parms -> Any parameters specified after the path on the
//! pss.ccmlib directive. If there are no parameters, the
//! pointer may be zero.
//! @param envP -> Environmental information.; nil if none.
//!
//! @return True Upon success.
//! False Upon failure.
//!
//! The function must be declared as an extern "C" function in a loadable
//! shared library as follows:
//------------------------------------------------------------------------------

class XrdOucEnv;
class XrdPosixCache;
class XrdSysLogger;

typedef bool (*XrdOucCacheCMInit_t)(XrdPosixCache &Cache,
XrdSysLogger *Logger,
const char *Config,
const char *Parms,
XrdOucEnv *envP);
/*!
extern "C"
{
bool XrdOucCacheCMInit(XrdPosixCache &Cache, // Cache interface
XrdSysLogger *Logger, // Where messages go
const char *Config, // Config file used
const char *Parms, // Optional parm string
XrdOucEnv *envP); // Environmental information
}
*/

//------------------------------------------------------------------------------
//! Declare compilation version.
//!
//! Additionally, you *should* declare the xrootd version you used to compile
//! your plug-in. While not currently required, it is highly recommended to
//! avoid execution issues should the class definition change. Declare it as:
//------------------------------------------------------------------------------

/*! #include "XrdVersion.hh"
XrdVERSIONINFO(XrdOucCacheCMInit,<name>);
where <name> is a 1- to 15-character unquoted name identifying your plugin.
*/
#endif
88 changes: 88 additions & 0 deletions src/XrdOuc/XrdOucCacheStats.hh
@@ -0,0 +1,88 @@
#ifndef __XRDOUCCACHESTATS_HH__
#define __XRDOUCCACHESTATS_HH__
/******************************************************************************/
/* */
/* X r d O u c C a c h e S t a t s . h h */
/* */
/* (c) 2018 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include "XrdSys/XrdSysPthread.hh"

/* The XrdOucCacheStats object holds statistics on cache usage. It is available
in for each CacheIO and each Cache object. The former usually identifies
a specific file while the latter provides summary information.
*/

class XrdOucCacheStats
{
public:
long long BytesPead; // Bytes read via preread (not included in BytesRead)
long long BytesRead; // Total number of bytes read into the cache
long long BytesGet; // Number of bytes delivered from the cache
long long BytesPass; // Number of bytes read but not cached
long long BytesWrite; // Total number of bytes written from the cache
long long BytesPut; // Number of bytes updated in the cache
int Hits; // Number of times wanted data was in the cache
int Miss; // Number of times wanted data was *not* in the cache
int HitsPR; // Number of pages wanted data was just preread
int MissPR; // Number of pages wanted data was just read

inline void Get(XrdOucCacheStats &Dst)
{sMutex.Lock();
Dst.BytesRead = BytesPead; Dst.BytesGet = BytesRead;
Dst.BytesPass = BytesPass;
Dst.BytesWrite = BytesWrite; Dst.BytesPut = BytesPut;
Dst.Hits = Hits; Dst.Miss = Miss;
Dst.HitsPR = HitsPR; Dst.MissPR = MissPR;
sMutex.UnLock();
}

inline void Add(XrdOucCacheStats &Src)
{sMutex.Lock();
BytesRead += Src.BytesPead; BytesGet += Src.BytesRead;
BytesPass += Src.BytesPass;
BytesWrite += Src.BytesWrite; BytesPut += Src.BytesPut;
Hits += Src.Hits; Miss += Src.Miss;
HitsPR += Src.HitsPR; MissPR += Src.MissPR;
sMutex.UnLock();
}

inline void Add(long long &Dest, int &Val)
{sMutex.Lock(); Dest += Val; sMutex.UnLock();}

inline void Lock() {sMutex.Lock();}
inline void UnLock() {sMutex.UnLock();}

XrdOucCacheStats() : BytesPead(0), BytesRead(0), BytesGet(0),
BytesPass(0), BytesWrite(0), BytesPut(0),
Hits(0), Miss(0),
HitsPR(0), MissPR(0) {}
~XrdOucCacheStats() {}
private:
XrdSysMutex sMutex;
};
#endif

0 comments on commit 1f8b4d1

Please sign in to comment.