src/components/powercap_ppc/linux-powercap-ppc.c
/*
 * Called when PAPI process is initialized (i.e. PAPI_library_init)
 */
Called when PAPI process is initialized
Called when PAPI process is initialized
static int
_powercap_ppc_init_component( int cidx )
{
    int e = -1;
    char events_dir[128];
    char event_path[128];
    DIR *events;
    const PAPI_hw_info_t *hw_info;
    hw_info=&( _papi_hwi_system_info.hw_info );
    if ( hw_info->vendor!=PAPI_VENDOR_IBM ) {
        strncpy(_powercap_ppc_vector.cmp_info.disabled_reason, "Not an IBM Power9 processor", PAPI_MAX_STR_LEN);
        return PAPI_ENOSUPP;
    }
    num_events = 0;
    size_t ret = snprintf(events_dir, sizeof(events_dir), "/sys/firmware/opal/powercap/system-powercap/");
    if (ret <= 0 || sizeof(events_dir) <= ret)
        return PAPI_ENOSUPP;
    if ( NULL == (events = opendir(events_dir)) ) {
        strncpy(_powercap_ppc_vector.cmp_info.disabled_reason,
            "Directory /sys/firmware/opal/powercap/system-powercap missing.",
            PAPI_MAX_STR_LEN);
        return PAPI_ENOSUPP;
    }
    closedir(events);
    for ( e = 0; e < PKG_NUM_EVENTS; ++e ) {
        size_t ret = snprintf(event_path, sizeof(event_path), "%s%s", events_dir, pkg_sys_names[e]);
        if (ret <= 0 || sizeof(event_path) <= ret)
            continue;
        if (access(event_path, F_OK) == -1) continue;
        ret = snprintf(powercap_ppc_ntv_events[num_events].name,
                       sizeof(powercap_ppc_ntv_events[num_events].name),
                       "%s", pkg_event_names[e]);
        if (ret <= 0 || sizeof(powercap_ppc_ntv_events[num_events].name) <= ret) continue;
        ret = snprintf(powercap_ppc_ntv_events[num_events].description,
                       sizeof(powercap_ppc_ntv_events[num_events].description),
                       "%s", pkg_event_descs[e]);
        if (ret <= 0 || sizeof(powercap_ppc_ntv_events[num_events].description) <= ret) continue;
        ret = snprintf(powercap_ppc_ntv_events[num_events].units,
                       sizeof(powercap_ppc_ntv_events[num_events].name), "W");
        if (ret <= 0 || sizeof(powercap_ppc_ntv_events[num_events].name) <= ret) continue;
        powercap_ppc_ntv_events[num_events].return_type = PAPI_DATATYPE_INT64;
        powercap_ppc_ntv_events[num_events].type = pkg_events[e];
        powercap_ppc_ntv_events[num_events].resources.selector = num_events + 1;
        event_fds[num_events] = open(event_path, O_SYNC|pkg_sys_flags[e]);
        num_events++;
    }
    _powercap_ppc_vector.cmp_info.num_native_events = num_events;
    _powercap_ppc_vector.cmp_info.num_cntrs = num_events;
    _powercap_ppc_vector.cmp_info.num_mpx_cntrs = num_events;
    _powercap_ppc_vector.cmp_info.CmpIdx = cidx;
    return PAPI_OK;
}
static int _powercap_ppc_init_component ( int cidx ) { int e = -1 ; char events_dir [ 128 ] ; char event_path [ 128 ] ; DIR * events ; const PAPI_hw_info_t * hw_info ; hw_info = & ( _papi_hwi_system_info . hw_info ) ; if ( hw_info -> vendor != PAPI_VENDOR_IBM ) { strncpy ( _powercap_ppc_vector . cmp_info . disabled_reason , " " , PAPI_MAX_STR_LEN ) ; return PAPI_ENOSUPP ; } num_events = 0 ; size_t ret = snprintf ( events_dir , sizeof ( events_dir ) , " " ) ; if ( ret <= 0 || sizeof ( events_dir ) <= ret ) return PAPI_ENOSUPP ; if ( NULL == ( events = opendir ( events_dir ) ) ) { strncpy ( _powercap_ppc_vector . cmp_info . disabled_reason , " " , PAPI_MAX_STR_LEN ) ; return PAPI_ENOSUPP ; } closedir ( events ) ; for ( e = 0 ; e < PKG_NUM_EVENTS ; ++ e ) { size_t ret = snprintf ( event_path , sizeof ( event_path ) , " " , events_dir , pkg_sys_names [ e ] ) ; if ( ret <= 0 || sizeof ( event_path ) <= ret ) continue ; if ( access ( event_path , F_OK ) == -1 ) continue ; ret = snprintf ( powercap_ppc_ntv_events [ num_events ] . name , sizeof ( powercap_ppc_ntv_events [ num_events ] . name ) , " " , pkg_event_names [ e ] ) ; if ( ret <= 0 || sizeof ( powercap_ppc_ntv_events [ num_events ] . name ) <= ret ) continue ; ret = snprintf ( powercap_ppc_ntv_events [ num_events ] . description , sizeof ( powercap_ppc_ntv_events [ num_events ] . description ) , " " , pkg_event_descs [ e ] ) ; if ( ret <= 0 || sizeof ( powercap_ppc_ntv_events [ num_events ] . description ) <= ret ) continue ; ret = snprintf ( powercap_ppc_ntv_events [ num_events ] . units , sizeof ( powercap_ppc_ntv_events [ num_events ] . name ) , " " ) ; if ( ret <= 0 || sizeof ( powercap_ppc_ntv_events [ num_events ] . name ) <= ret ) continue ; powercap_ppc_ntv_events [ num_events ] . return_type = PAPI_DATATYPE_INT64 ; powercap_ppc_ntv_events [ num_events ] . type = pkg_events [ e ] ; powercap_ppc_ntv_events [ num_events ] . resources . selector = num_events + 1 ; event_fds [ num_events ] = open ( event_path , O_SYNC | pkg_sys_flags [ e ] ) ; num_events ++ ; } _powercap_ppc_vector . cmp_info . num_native_events = num_events ; _powercap_ppc_vector . cmp_info . num_cntrs = num_events ; _powercap_ppc_vector . cmp_info . num_mpx_cntrs = num_events ; _powercap_ppc_vector . cmp_info . CmpIdx = cidx ; return PAPI_OK ; }
Called when PAPI process is initialized (i.e.
Called when PAPI process is initialized ( i . e .
/* check if IBM processor */ /* Check the existence, and correct access modes to pkg directory path */ /* opendir needs clean up. */ /* loop through events and create powercap event entries */ /* compose string to individual event */ /* if it's not a valid pkg event path we skip it */ /* Export the total number of events available */ /* Export the component id */