1*424fb153SAndroid Build Coastguard Worker // Copyright 2008 Google Inc. All Rights Reserved. 2*424fb153SAndroid Build Coastguard Worker 3*424fb153SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*424fb153SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*424fb153SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*424fb153SAndroid Build Coastguard Worker 7*424fb153SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*424fb153SAndroid Build Coastguard Worker 9*424fb153SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*424fb153SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*424fb153SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*424fb153SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*424fb153SAndroid Build Coastguard Worker // limitations under the License. 14*424fb153SAndroid Build Coastguard Worker 15*424fb153SAndroid Build Coastguard Worker // error_diag.h: Ambiguous error diagnosis class 16*424fb153SAndroid Build Coastguard Worker 17*424fb153SAndroid Build Coastguard Worker #ifndef STRESSAPPTEST_ERROR_DIAG_H_ 18*424fb153SAndroid Build Coastguard Worker #define STRESSAPPTEST_ERROR_DIAG_H_ 19*424fb153SAndroid Build Coastguard Worker 20*424fb153SAndroid Build Coastguard Worker #include <pthread.h> 21*424fb153SAndroid Build Coastguard Worker #include <list> 22*424fb153SAndroid Build Coastguard Worker #include <map> 23*424fb153SAndroid Build Coastguard Worker #include <set> 24*424fb153SAndroid Build Coastguard Worker #include <string> 25*424fb153SAndroid Build Coastguard Worker 26*424fb153SAndroid Build Coastguard Worker // This file must work with autoconf on its public version, 27*424fb153SAndroid Build Coastguard Worker // so these includes are correct. 28*424fb153SAndroid Build Coastguard Worker #include "sattypes.h" 29*424fb153SAndroid Build Coastguard Worker #include "os.h" 30*424fb153SAndroid Build Coastguard Worker 31*424fb153SAndroid Build Coastguard Worker class ErrorInstance; 32*424fb153SAndroid Build Coastguard Worker 33*424fb153SAndroid Build Coastguard Worker // This describes the components of the system. 34*424fb153SAndroid Build Coastguard Worker class DeviceTree { 35*424fb153SAndroid Build Coastguard Worker public: 36*424fb153SAndroid Build Coastguard Worker explicit DeviceTree(string name); 37*424fb153SAndroid Build Coastguard Worker ~DeviceTree(); 38*424fb153SAndroid Build Coastguard Worker 39*424fb153SAndroid Build Coastguard Worker // Atomically find arbitrary device in subtree. 40*424fb153SAndroid Build Coastguard Worker DeviceTree *FindInSubTree(string name); 41*424fb153SAndroid Build Coastguard Worker // Find or add named device. 42*424fb153SAndroid Build Coastguard Worker DeviceTree *FindOrAddDevice(string name); 43*424fb153SAndroid Build Coastguard Worker // Atomically add sub device. 44*424fb153SAndroid Build Coastguard Worker void InsertSubDevice(string name); 45*424fb153SAndroid Build Coastguard Worker // Returns parent device. GetParent()46*424fb153SAndroid Build Coastguard Worker DeviceTree *GetParent() { return parent_; } 47*424fb153SAndroid Build Coastguard Worker // Pretty prints device tree. 48*424fb153SAndroid Build Coastguard Worker void PrettyPrint(string spacer = " "); 49*424fb153SAndroid Build Coastguard Worker // Atomically add error instance to device. 50*424fb153SAndroid Build Coastguard Worker void AddErrorInstance(ErrorInstance *error_instance); 51*424fb153SAndroid Build Coastguard Worker // Returns true of device is known to be bad. 52*424fb153SAndroid Build Coastguard Worker bool KnownBad(); 53*424fb153SAndroid Build Coastguard Worker // Returns number of direct sub devices. NumDirectSubDevices()54*424fb153SAndroid Build Coastguard Worker int NumDirectSubDevices() { return subdevices_.size(); } 55*424fb153SAndroid Build Coastguard Worker 56*424fb153SAndroid Build Coastguard Worker private: 57*424fb153SAndroid Build Coastguard Worker // Unlocked version of FindInSubTree. 58*424fb153SAndroid Build Coastguard Worker DeviceTree *UnlockedFindInSubTree(string name); 59*424fb153SAndroid Build Coastguard Worker 60*424fb153SAndroid Build Coastguard Worker std::map<string, DeviceTree*> subdevices_; // Map of sub-devices. 61*424fb153SAndroid Build Coastguard Worker std::list<ErrorInstance*> errors_; // Log of errors. 62*424fb153SAndroid Build Coastguard Worker DeviceTree *parent_; // Pointer to parent device. 63*424fb153SAndroid Build Coastguard Worker string name_; // Device name. 64*424fb153SAndroid Build Coastguard Worker pthread_mutex_t device_tree_mutex_; // Mutex protecting device tree. 65*424fb153SAndroid Build Coastguard Worker }; 66*424fb153SAndroid Build Coastguard Worker 67*424fb153SAndroid Build Coastguard Worker 68*424fb153SAndroid Build Coastguard Worker // enum type for collected errors. 69*424fb153SAndroid Build Coastguard Worker enum SATErrorType { 70*424fb153SAndroid Build Coastguard Worker SAT_ERROR_NONE = 0, 71*424fb153SAndroid Build Coastguard Worker SAT_ERROR_ECC, 72*424fb153SAndroid Build Coastguard Worker SAT_ERROR_MISCOMPARE, 73*424fb153SAndroid Build Coastguard Worker SAT_ERROR_SECTOR_TAG, 74*424fb153SAndroid Build Coastguard Worker }; 75*424fb153SAndroid Build Coastguard Worker 76*424fb153SAndroid Build Coastguard Worker // enum type for error severity. 77*424fb153SAndroid Build Coastguard Worker enum SATErrorSeverity { 78*424fb153SAndroid Build Coastguard Worker SAT_ERROR_CORRECTABLE = 0, 79*424fb153SAndroid Build Coastguard Worker SAT_ERROR_FATAL, 80*424fb153SAndroid Build Coastguard Worker }; 81*424fb153SAndroid Build Coastguard Worker 82*424fb153SAndroid Build Coastguard Worker // This describes an error and it's likely causes. 83*424fb153SAndroid Build Coastguard Worker class ErrorInstance { 84*424fb153SAndroid Build Coastguard Worker public: ErrorInstance()85*424fb153SAndroid Build Coastguard Worker ErrorInstance(): type_(SAT_ERROR_NONE), severity_(SAT_ERROR_CORRECTABLE) {} 86*424fb153SAndroid Build Coastguard Worker 87*424fb153SAndroid Build Coastguard Worker SATErrorType type_; // Type of error: ECC, miscompare, sector. 88*424fb153SAndroid Build Coastguard Worker SATErrorSeverity severity_; // Correctable, or fatal. 89*424fb153SAndroid Build Coastguard Worker std::set<DeviceTree*> causes_; // Devices that can cause this type of error. 90*424fb153SAndroid Build Coastguard Worker }; 91*424fb153SAndroid Build Coastguard Worker 92*424fb153SAndroid Build Coastguard Worker // This describes ECC errors. 93*424fb153SAndroid Build Coastguard Worker class ECCErrorInstance: public ErrorInstance { 94*424fb153SAndroid Build Coastguard Worker public: ECCErrorInstance()95*424fb153SAndroid Build Coastguard Worker ECCErrorInstance() { type_ = SAT_ERROR_ECC; } 96*424fb153SAndroid Build Coastguard Worker 97*424fb153SAndroid Build Coastguard Worker uint64 addr_; // Address where error occured. 98*424fb153SAndroid Build Coastguard Worker }; 99*424fb153SAndroid Build Coastguard Worker 100*424fb153SAndroid Build Coastguard Worker // This describes miscompare errors. 101*424fb153SAndroid Build Coastguard Worker class MiscompareErrorInstance: public ErrorInstance { 102*424fb153SAndroid Build Coastguard Worker public: MiscompareErrorInstance()103*424fb153SAndroid Build Coastguard Worker MiscompareErrorInstance() { type_ = SAT_ERROR_MISCOMPARE; } 104*424fb153SAndroid Build Coastguard Worker 105*424fb153SAndroid Build Coastguard Worker uint64 addr_; // Address where miscompare occured. 106*424fb153SAndroid Build Coastguard Worker }; 107*424fb153SAndroid Build Coastguard Worker 108*424fb153SAndroid Build Coastguard Worker // This describes HDD miscompare errors. 109*424fb153SAndroid Build Coastguard Worker class HDDMiscompareErrorInstance: public MiscompareErrorInstance { 110*424fb153SAndroid Build Coastguard Worker public: 111*424fb153SAndroid Build Coastguard Worker uint64 addr2_; // addr_ and addr2_ are src and dst memory addr. 112*424fb153SAndroid Build Coastguard Worker int offset_; // offset. 113*424fb153SAndroid Build Coastguard Worker int block_; // error block. 114*424fb153SAndroid Build Coastguard Worker }; 115*424fb153SAndroid Build Coastguard Worker 116*424fb153SAndroid Build Coastguard Worker // This describes HDD miscompare errors. 117*424fb153SAndroid Build Coastguard Worker class HDDSectorTagErrorInstance: public ErrorInstance { 118*424fb153SAndroid Build Coastguard Worker public: HDDSectorTagErrorInstance()119*424fb153SAndroid Build Coastguard Worker HDDSectorTagErrorInstance() { type_ = SAT_ERROR_SECTOR_TAG; } 120*424fb153SAndroid Build Coastguard Worker 121*424fb153SAndroid Build Coastguard Worker uint64 addr_; 122*424fb153SAndroid Build Coastguard Worker uint64 addr2_; // addr_ and addr2_ are src and dst memory addr. 123*424fb153SAndroid Build Coastguard Worker int sector_; // error sector. 124*424fb153SAndroid Build Coastguard Worker int block_; // error block. 125*424fb153SAndroid Build Coastguard Worker }; 126*424fb153SAndroid Build Coastguard Worker 127*424fb153SAndroid Build Coastguard Worker // Generic error storage and sorting class. 128*424fb153SAndroid Build Coastguard Worker class ErrorDiag { 129*424fb153SAndroid Build Coastguard Worker public: 130*424fb153SAndroid Build Coastguard Worker ErrorDiag(); 131*424fb153SAndroid Build Coastguard Worker virtual ~ErrorDiag(); 132*424fb153SAndroid Build Coastguard Worker 133*424fb153SAndroid Build Coastguard Worker // Add info about a CECC. 134*424fb153SAndroid Build Coastguard Worker virtual int AddCeccError(string dimm_string); 135*424fb153SAndroid Build Coastguard Worker 136*424fb153SAndroid Build Coastguard Worker // Add info about a UECC. 137*424fb153SAndroid Build Coastguard Worker virtual int AddUeccError(string dimm_string); 138*424fb153SAndroid Build Coastguard Worker 139*424fb153SAndroid Build Coastguard Worker // Add info about a miscompare. 140*424fb153SAndroid Build Coastguard Worker virtual int AddMiscompareError(string dimm_string, uint64 addr, int count); 141*424fb153SAndroid Build Coastguard Worker 142*424fb153SAndroid Build Coastguard Worker // Add info about a miscompare from a drive. 143*424fb153SAndroid Build Coastguard Worker virtual int AddHDDMiscompareError(string devicename, int block, int offset, 144*424fb153SAndroid Build Coastguard Worker void *src_addr, void *dst_addr); 145*424fb153SAndroid Build Coastguard Worker 146*424fb153SAndroid Build Coastguard Worker // Add info about a sector tag miscompare from a drive. 147*424fb153SAndroid Build Coastguard Worker virtual int AddHDDSectorTagError(string devicename, int block, int offset, 148*424fb153SAndroid Build Coastguard Worker int sector, void *src_addr, void *dst_addr); 149*424fb153SAndroid Build Coastguard Worker 150*424fb153SAndroid Build Coastguard Worker // Set platform specific handle and initialize device tree. 151*424fb153SAndroid Build Coastguard Worker bool set_os(OsLayer *os); 152*424fb153SAndroid Build Coastguard Worker 153*424fb153SAndroid Build Coastguard Worker protected: 154*424fb153SAndroid Build Coastguard Worker // Create and initialize system device tree. 155*424fb153SAndroid Build Coastguard Worker virtual bool InitializeDeviceTree(); 156*424fb153SAndroid Build Coastguard Worker 157*424fb153SAndroid Build Coastguard Worker // Utility Function to translate a virtual address to DIMM number. 158*424fb153SAndroid Build Coastguard Worker string AddressToDimmString(OsLayer *os, void *addr, int offset); 159*424fb153SAndroid Build Coastguard Worker 160*424fb153SAndroid Build Coastguard Worker DeviceTree *system_tree_root_; // System device tree. 161*424fb153SAndroid Build Coastguard Worker OsLayer *os_; // Platform handle. 162*424fb153SAndroid Build Coastguard Worker 163*424fb153SAndroid Build Coastguard Worker private: 164*424fb153SAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(ErrorDiag); 165*424fb153SAndroid Build Coastguard Worker }; 166*424fb153SAndroid Build Coastguard Worker 167*424fb153SAndroid Build Coastguard Worker #endif // STRESSAPPTEST_ERROR_DIAG_H_ 168