Skip to content

Commit

Permalink
Merge pull request #287 from kahnevan/sync_with_cronus
Browse files Browse the repository at this point in the history
Syncing up with what's in Cronus
  • Loading branch information
kahnevan authored Dec 18, 2019
2 parents dea474f + 58e7492 commit 4bb490b
Show file tree
Hide file tree
Showing 16 changed files with 937 additions and 20 deletions.
143 changes: 143 additions & 0 deletions ecmd-core/capi/ecmdSharedUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <string.h>
#include <stdlib.h>
#include <fstream>
#include <map>

#include <ecmdSharedUtils.H>
#include <ecmdStructs.H>
Expand Down Expand Up @@ -1013,6 +1014,148 @@ uint32_t ecmdReadDcard(const char *i_filename, std::list<ecmdMemoryEntry> &o_dat
return rc;
}

uint32_t ecmdPadAndMerge(std::list<ecmdMemoryEntry> &io_data, uint32_t i_size)
{
uint32_t rc = 0;

// mask values for address checking based on cache line size
uint64_t blockalignmask = i_size - 1;
uint64_t blockstartmask = ~blockalignmask;

// create map of input data
std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator> representation;
std::list<ecmdMemoryEntry>::iterator io_dataIter;
for (io_dataIter = io_data.begin(); io_dataIter != io_data.end(); io_dataIter++)
{
representation[io_dataIter->address] = io_dataIter;
}

std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator>::iterator repIter = representation.begin();
while(repIter != representation.end())
{
#ifdef DEBUG_MEM_MERGE
#ifndef UINT64_HEX_FORMAT
#define UINT64_HEX_FORMAT "%lX"
#endif
printf("block " UINT64_HEX_FORMAT ",%X %s\n",
repIter->first, repIter->second->data.getByteLength(),
repIter->second->data.genHexLeftStr().c_str());
#endif
uint64_t blockstart = repIter->first & blockstartmask;
if (blockstart != repIter->first)
{
// extend current iter forward
uint64_t prepend = repIter->first - blockstart;
#ifdef DEBUG_MEM_MERGE
uint64_t newlength = repIter->second->data.getByteLength() + prepend;
printf("prepend change " UINT64_HEX_FORMAT ",%X to " UINT64_HEX_FORMAT "," UINT64_HEX_FORMAT "\n",
repIter->first, repIter->second->data.getByteLength(), blockstart, newlength);
#endif
// record change
rc = repIter->second->data.shiftRightAndResize(prepend * 8);
if (rc) return rc;
repIter->second->address = blockstart;
std::pair<std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator>::iterator, bool> insertresult =
representation.insert(std::pair<uint64_t, std::list<ecmdMemoryEntry>::iterator>(blockstart, repIter->second));
representation.erase(repIter);
repIter = insertresult.first;

// check if previous block is now adjacent
if (repIter != representation.begin())
{
std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator>::iterator prevIter = repIter;
prevIter--;
if ((prevIter->first + prevIter->second->data.getByteLength()) == repIter->first)
{
// switch back to previous block and continue
repIter = prevIter;
#ifdef DEBUG_MEM_MERGE
printf("rewinding\n");
#endif
continue;
}
}
}

// check if ends on cache line
if (repIter->second->data.getByteLength() & blockalignmask)
{
// does not end on cache line
uint64_t curstop = blockstart + repIter->second->data.getByteLength();
uint64_t blockstop = (curstop & 0xFFFFFFFFFFFFFF80ull) + 0x80ull;
// check if next entry is inside current data cache line
std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator>::iterator nextIter = repIter;
nextIter++;
if (nextIter != representation.end())
{
if (nextIter->first < blockstop)
{
// check what padding is needed between blocks
uint64_t paddingsize = nextIter->first - curstop;
#ifdef DEBUG_MEM_MERGE
printf("merge " UINT64_HEX_FORMAT ",%X %s with " UINT64_HEX_FORMAT ",%X %s\n",
repIter->first, repIter->second->data.getByteLength(), repIter->second->data.genHexLeftStr().c_str(),
nextIter->first, nextIter->second->data.getByteLength(), nextIter->second->data.genHexLeftStr().c_str());
#endif
// merge this block with next
uint32_t originallength = repIter->second->data.getBitLength();
rc = repIter->second->data.growBitLength(originallength + (8 * paddingsize) + nextIter->second->data.getBitLength());
if (rc) return rc;
rc = repIter->second->data.insert(nextIter->second->data, originallength + (8 * paddingsize), nextIter->second->data.getBitLength());
if (rc) return rc;
io_data.erase(nextIter->second);
representation.erase(nextIter);
continue; // recheck current block after merge
}
}

// otherwise extend block to end of cache line
uint64_t postpend = blockstop - curstop;
uint64_t newlength = repIter->second->data.getByteLength() + postpend;
#ifdef DEBUG_MEM_MERGE
printf("postpend change " UINT64_HEX_FORMAT ",%X to " UINT64_HEX_FORMAT "," UINT64_HEX_FORMAT "\n",
repIter->first, repIter->second->data.getByteLength(), repIter->first, newlength);
#endif
repIter->second->data.growBitLength(8 * newlength);
}

// check if next block is adjacent
std::map<uint64_t, std::list<ecmdMemoryEntry>::iterator>::iterator nextIter = repIter;
nextIter++;
if (nextIter != representation.end())
{
if ((repIter->first + repIter->second->data.getByteLength()) == nextIter->first)
{
#ifdef DEBUG_MEM_MERGE
printf("merge " UINT64_HEX_FORMAT ",%X %s with " UINT64_HEX_FORMAT ",%X %s\n",
repIter->first, repIter->second->data.getByteLength(), repIter->second->data.genHexLeftStr().c_str(),
nextIter->first, nextIter->second->data.getByteLength(), nextIter->second->data.genHexLeftStr().c_str());
#endif
// merge this block with next
uint32_t originallength = repIter->second->data.getBitLength();
rc = repIter->second->data.growBitLength(originallength + nextIter->second->data.getBitLength());
if (rc) return rc;
rc = repIter->second->data.insert(nextIter->second->data, originallength, nextIter->second->data.getBitLength());
if (rc) return rc;
io_data.erase(nextIter->second);
representation.erase(nextIter);
continue; // recheck current block after merge
}
}
repIter++;
}

#ifdef DEBUG_MEM_MERGE
for (io_dataIter = io_data.begin(); io_dataIter != io_data.end(); io_dataIter++)
{
printf("resulting block " UINT64_HEX_FORMAT ",%X\n",
io_dataIter->address, io_dataIter->data.getByteLength());
}
#endif

return rc;
}

uint32_t ecmdGenB32FromHex (uint32_t * o_numPtr, const char * i_hexChars, int startPos) {

uint32_t tempB32 = 0;
Expand Down
9 changes: 9 additions & 0 deletions ecmd-core/capi/ecmdSharedUtils.H
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ uint32_t ecmdSetTargetDepth(ecmdChipTarget & io_target, ecmdTargetDepth_t i_dept
*/
uint32_t ecmdReadDcard(const char *i_filename, std::list<ecmdMemoryEntry> &o_data, uint64_t i_addressOffset = 0);

/**
* @brief Pads and Merges Fields of ecmdMemoryEntry_t
* @param io_data list to be merged and padded
* @param i_size byte size to align and pad to
* @retval ECMD_SUCCESS if setting successful
* @retval ECMD_INVALID_ARGS if unsuccessful in finding a matching depth
*/
uint32_t ecmdPadAndMerge(std::list<ecmdMemoryEntry> &io_data, uint32_t i_size);

/**
@brief Returns a formatted string containing the data in the given ecmdChipTarget
@return String with formatted target data
Expand Down
2 changes: 1 addition & 1 deletion ecmd-core/cmd/ecmdCommandUtils.C
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ uint32_t ecmdGetProcessingUnit(ecmdChipTarget & i_target, std::string & o_proces
o_processingUnitName = "core"; //p7 and prior processors
if ( (chipData.chipType == "p8") || (chipData.chipType == "s1") || (chipData.chipType == "n1") ) {
o_processingUnitName = "ex"; // we use ex
} else if ( (chipData.chipType == "p9c") || (chipData.chipType == "p9n") ) {
} else if ( (chipData.chipType == "p9c") || (chipData.chipType == "p9n") || (chipData.chipType == "p9a") ) {
o_processingUnitName = "c"; // we use core
}

Expand Down
10 changes: 10 additions & 0 deletions ecmd-core/cmd/ecmdMemUser.C
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,16 @@ uint32_t ecmdPutMemPbaUser(int argc, char * argv[]) {
memdata.push_back(memEntry);
}

if (pbaMode == PBA_MODE_LCO) {
// pad with zeros to fill cache lines -- 128 byte cache line
rc = ecmdPadAndMerge(memdata, 128);
if (rc) {
printLine = cmdlineName + " - Problems occurred padding and merging data\n";
ecmdOutputError(printLine.c_str());
return rc;
}
}

/************************************************************************/
/* Kickoff Looping Stuff */
/************************************************************************/
Expand Down
22 changes: 21 additions & 1 deletion ecmd-core/dll/ecmdDllCapi.C
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ struct ecmdLatchCacheEntry {

/* @brief Used by get/putlatch to buffer scandef entries in memory to improve performance */
std::list<ecmdLatchCacheEntry> latchCache;
pthread_mutex_t latchCacheMutex = PTHREAD_MUTEX_INITIALIZER;

class LockGuard
{
public:
LockGuard(pthread_mutex_t * i_mutex) : iv_mutex(i_mutex)
{
pthread_mutex_lock(iv_mutex);
}
~LockGuard()
{
pthread_mutex_unlock(iv_mutex);
}
private:
pthread_mutex_t * iv_mutex;
};


/** @brief Used to sort latch entries from the scandef */
bool operator<(const ecmdLatchEntry & lhs, const ecmdLatchEntry & rhs) {
Expand Down Expand Up @@ -438,10 +455,10 @@ uint32_t dllLooperInit(ecmdChipTarget & io_target, ecmdLoopType_t i_looptype, ec
}
if (rc) return rc;

/* Standard physical targets */
} else {
#endif // ECMD_REMOVE_UNITID_FUNCTIONS

/* Standard physical targets */
io_state.ecmdUseUnitid = false;

queryTarget = io_target;
Expand Down Expand Up @@ -5438,6 +5455,7 @@ uint32_t readScandef(ecmdChipTarget & target, const char* i_ringName, const char
return rc;
}

LockGuard lg(&latchCacheMutex);
if (findLatchInCache(l_fileLocs, latchHashKey64, ringName, o_latchdata))
{
/* We're done, get out of here */
Expand Down Expand Up @@ -5875,6 +5893,7 @@ uint32_t readScandefHash(ecmdChipTarget & target, const char* i_ringName, const
return rc;
}

LockGuard lg(&latchCacheMutex);
if (findLatchInCache(l_fileLocs, latchHashKey64, ringName, o_latchdata))
{
/* We're done, get out of here */
Expand Down Expand Up @@ -6352,6 +6371,7 @@ std::string dllParseReturnCode(uint32_t i_returnCode) {

// Assume for now we only have one helptext path returned
filePath = paths.begin()->textFile;

if (rc || (filePath.length()==0)) {
ret = "ERROR FINDING DECODE FILE";
return ret;
Expand Down
20 changes: 17 additions & 3 deletions ecmd-core/ext/cip/cmd/cipProcUser.C
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ uint32_t cipInstructUser(int argc, char * argv[]) {

threadFound = false;
firstThreadLoop = true;
/* Added hack for occ chipunit for p8 - MKL 04/10/2012 */
/* On some chips, we have to start the threads in reverse order to keep the chip in the proper SMT mode */
/* This code will accomplish that by looping over cores in order above, but threads in reverse below */
if (target.chipUnitType == "occ") {
Expand Down Expand Up @@ -1541,6 +1540,16 @@ uint32_t cipPutMemPbaUser(int argc, char * argv[]) {
memdata.push_back(memEntry);
}

if (pbaMode == PBA_MODE_LCO) {
// pad with zeros to fill cache lines -- 128 byte cache line
rc = ecmdPadAndMerge(memdata, 128);
if (rc) {
printLine = cmdlineName + " - Problems occurred padding and merging data\n";
ecmdOutputError(printLine.c_str());
return rc;
}
}

/************************************************************************/
/* Kickoff Looping Stuff */
/************************************************************************/
Expand Down Expand Up @@ -4052,8 +4061,13 @@ uint32_t cipGetMemProcVarUser(int argc, char * argv[])
printed=ecmdWriteTarget(target); printed+="\n"; ecmdOutput(printed.c_str());
printed= "Address Req Bytes Req Mem Tags Mem ECC Err\n"; ecmdOutput(printed.c_str());
printed= "==================== ========= ======== ===========\n"; ecmdOutput(printed.c_str());
const char * l_ecc = "";
if (l_bufErr.getBitLength())
{
l_ecc = l_bufErr.genHexLeftStr().c_str();
}
sprintf(buf,"%-20s %9d %-8s %-11s\n",ll_address_80.genHexLeftStr().c_str(),l_bytes,
l_bufTags.genHexLeftStr().c_str(),l_bufErr.genHexLeftStr().c_str());
l_bufTags.genHexLeftStr().c_str(),l_ecc);
ecmdOutput(buf);
// now display the data
ecmdOutput("GETMEM DATA READ\n");
Expand All @@ -4063,7 +4077,7 @@ uint32_t cipGetMemProcVarUser(int argc, char * argv[])
// ECC varies depending on the size of data, so display it at the end
ecmdOutput("Memory ECC\n");
ecmdOutput("==========\n");
sprintf(buf,"%-32s\n",l_bufECC.genHexLeftStr().c_str());
sprintf(buf,"%-32s\n",l_ecc);
ecmdOutput(buf);
}

Expand Down
23 changes: 16 additions & 7 deletions ecmd-core/ext/fapi2/capi/collect_reg_ffdc.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* IBM_PROLOG_END_TAG */
/* IBM_PROLOG_END_TAG */
#ifndef FAPI2_COLLECT_REG_FFDC_H_
#define FAPI2_COLLECT_REG_FFDC_H_
#include <stdint.h>
Expand Down Expand Up @@ -376,6 +376,12 @@ ReturnCode collectRegisterData(std::vector<T>& i_addresses, U& i_reader,
if(l_rc)
{
l_data = 0xbaddbadd;

#ifdef __DELETE_PLATFORMDATA_SUPPORTED
// delete the platform log if it exits
deletePlatformDataPointer(l_rc);
#endif

}
else
{
Expand All @@ -397,34 +403,37 @@ ReturnCode collectRegisterAndAddressData(std::vector<T>& i_addresses, U& i_reade
FAPI_DBG("collectRegisterAndAddressData -> address count: 0x%lx", i_addresses.size());

T l_data = 0;
uint32_t l_addr = 0;

ReturnCode l_rc = FAPI2_RC_SUCCESS;

for( auto address : i_addresses )
{
fapi2::buffer<T> l_buf;

T l_address = address + i_offset;
l_addr = address + i_offset;

l_rc = i_reader.read_register(l_address, l_buf);
l_rc = i_reader.read_register(l_addr, l_buf);

if(l_rc)
{
l_data = 0xbaddbadd;
#ifdef __DELETE_PLATFORMDATA_SUPPORTED
// delete the platform data pointer if it exists
deletePlatformDataPointer(l_rc);
#endif
}
else
{
l_data = l_buf();
}

l_address = htobe32(l_address);
l_data = htobe64(l_data);
l_data = htobe64(l_data);

memcpy(o_pData, &l_address, sizeof(uint32_t));
memcpy(o_pData, &l_addr, sizeof(uint32_t));
o_pData += sizeof(uint32_t);

memcpy(o_pData, &l_data, sizeof(T));

o_pData += sizeof(T);

}
Expand Down
5 changes: 5 additions & 0 deletions ecmd-core/ext/fapi2/capi/fapi2.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@

#include <mvpd_access.H>

// Block of headers not currently in fapi2
#ifdef FAPI2_MISSING_HEADERS
#include <mbvpdAccess.H>
#endif

#endif // __FAPI2_TOP_LEVEL__
1 change: 1 addition & 0 deletions ecmd-core/ext/fapi2/capi/fapi2Structs.H
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum AttributeSource

#define FAPI_ATTRIBUTE_MODE_CONST 0x80000000
#define FAPI_ATTRIBUTE_MODE_HOSTBOOT 0x40000000
#define FAPI_ATTRIBUTE_MODE_SCRATCH 0x20000000
/**
@brief Used by the get/set configuration functions to return the data
*/
Expand Down
Loading

0 comments on commit 4bb490b

Please sign in to comment.