src/components/rocm_smi/linux-rocm-smi.c
//------------------------------------------------------------------------------
// This is our iterator for the sorted list we built in scanEvents.  If
// 'currentEvent' is NULL, it will find the first event matching the text with
// the same device number. If not, it will find the first event after the
// currentEvent that matches the text.  If no event matches the text and
// device, it will return NULL. Note the list is in ascending order, by device,
// text, variant, and subvariant. 
//------------------------------------------------------------------------------
This is our iterator for the sorted list we built in scanEvents.  If
'currentEvent' is NULL, it will find the first event matching the text with
the same device number. If not, it will find the first event after the
currentEvent that matches the text.  If no event matches the text and
device, it will return NULL. Note the list is in ascending order, by device,
text, variant, and subvariant.
This is our iterator for the sorted list we built in scanEvents . If ' currentEvent ' is NULL it will find the first event matching the text with the same device number . If not it will find the first event after the currentEvent that matches the text . If no event matches the text and device it will return NULL . Note the list is in ascending order by device text variant and subvariant .
scanEvent_info_t* nextEvent(scanEvent_info_t* currentEvent, int device, char* funcname)
{
    int i;
    if (currentEvent==NULL) {                                       
        for (i=0; i<TotalScanEvents; i++) {
            if (ScanEvents[i].device == device &&                   
                strcmp(ScanEvents[i].funcname, funcname) == 0) {    
                ScanEvents[i].used = 1;                             
                return(&ScanEvents[i]);                             
            }
        } 
#ifdef REPORT_KNOWN_EVENTS_NOT_SUPPORTED_BY_DEVICE
        fprintf(stderr, "Known Event not supported by hardware: '%s'\n", funcname);
#endif 
        return(NULL);                                           
    }
    currentEvent++;                                                     
    if (currentEvent->device < 0) return(NULL);                         
    if (strcmp(currentEvent->funcname, funcname) != 0) return(NULL);    
    currentEvent->used = 1;                                             
    return(currentEvent);                                               
}
scanEvent_info_t * nextEvent ( scanEvent_info_t * currentEvent , int device , char * funcname ) { int i ; if ( currentEvent == NULL ) { for ( i = 0 ; i < TotalScanEvents ; i ++ ) { if ( ScanEvents [ i ] . device == device && strcmp ( ScanEvents [ i ] . funcname , funcname ) == 0 ) { ScanEvents [ i ] . used = 1 ; return ( & ScanEvents [ i ] ) ; } } #ifdef REPORT_KNOWN_EVENTS_NOT_SUPPORTED_BY_DEVICE fprintf ( stderr , " \n " , funcname ) ; #endif return ( NULL ) ; } currentEvent ++ ; if ( currentEvent -> device < 0 ) return ( NULL ) ; if ( strcmp ( currentEvent -> funcname , funcname ) != 0 ) return ( NULL ) ; currentEvent -> used = 1 ; return ( currentEvent ) ; }
This is our iterator for the sorted list we built in scanEvents.
This is our iterator for the sorted list we built in scanEvents .
// If starting from scratch do a brute force search. // matched on device, // matched on function name, // Mark as one to be used. // Exit with pointer to first found. // end loop through events. // Never found. // Here, we already have a current event. // Remember, they are in sorted order. // Point at the next one, don't want to return same as last time. // Got to end of list. // Got to end of this funcname. // else found it, mark it used. // Return with next one.