29#define HANDLE_STRING_ERROR {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}
41 char *
retval = strncpy( dst, src, size );
42 if ( size > 0 ) dst[size-1] =
'\0';
47#define DESC_LINE_SIZE_ALLOWED 66
51 size_t len = strlen(
buf);
85 for (
rc = bytes = 0; bytes < to_read; bytes +=
rc) {
87 if (!
rc ||
rc < 0)
break;
93 pong[occ_id] =
ping[occ_id] + (pong_off - ping_off);
101 if (0 ==
y)
return 1.;
102 if (0 ==
x)
return 0.;
103 if (0 >
y)
return 1. /
_pow(
x, -
y);
104 if (1 ==
y)
return 1. *
x;
109#define TO_FP(f) ((f >> 8) * _pow(10, ((int8_t)(f & 0xFF))))
119 occ_sensor_record_t *record = NULL;
124 occ_sensor_record_t *sping = (occ_sensor_record_t *)((uint64_t)
ping[
s] + offset);
125 occ_sensor_record_t *spong = (occ_sensor_record_t *)((uint64_t)
pong[
s] + offset);
128 if (be64toh(sping->timestamp) > be64toh(spong->timestamp))
143 value = (uint64_t)(be64toh(record->accumulator) /
TO_FP(
freq));
148 value = (uint64_t)(be16toh((&record->sample)[midx]) *
TO_FP(scale));
162 occ_sensor_counter_t *counter = NULL;
167 occ_sensor_counter_t *sping = (occ_sensor_counter_t *)((uint64_t)
ping[
s] + offset);
168 occ_sensor_counter_t *spong = (occ_sensor_counter_t *)((uint64_t)
pong[
s] + offset);
171 if (be64toh(sping->timestamp) > be64toh(spong->timestamp))
183 uint64_t value = be64toh(counter->accumulator) *
TO_FP(scale);
249 char events_dir[128];
250 char event_path[128];
265 int ret = snprintf(events_dir,
sizeof(events_dir),
"/sys/firmware/opal/exports/");
267 if (NULL == (
events = opendir(events_dir))) {
269 "%s:%i Could not open events_dir='%s'.", __FILE__, __LINE__, events_dir);
276 ret = snprintf(event_path,
sizeof(event_path),
"%s%s", events_dir,
pkg_sys_name);
278 if (-1 == access(event_path, F_OK)) {
280 "%s:%i Could not access event_path='%s'.", __FILE__, __LINE__, event_path);
290 "%s:%i Could not open event_path='%s'.", __FILE__, __LINE__, event_path);
318 if (!
rc ||
rc < 0)
break;
342 ping[
s] = (uint32_t*)malloc(buff_size);
343 if (
ping[
s] == NULL) {
345 "%s:%i Failed to alloc %i bytes for ping[%i].", __FILE__, __LINE__, buff_size,
s);
355 "%s:%i Failed to alloc %i bytes for double_ping[%i].", __FILE__, __LINE__, buff_size,
s);
411 SUBDBG(
"Enter _sensors_ppc_start\n");
451 long long **
events,
int flags )
453 SUBDBG(
"Enter _sensors_ppc_read\n");
459 long long start_val = 0;
460 long long curr_val = 0;
475 if(start_val > curr_val) {
476 curr_val += (0x100000000 - start_val);
479 else if (start_val < curr_val) {
480 curr_val -= start_val;
484 control->
count[
c]=curr_val;
517 SUBDBG(
"Enter: ctx: %p\n", ctx );
587 *EventCode = *EventCode + 1;
624 if (ret <= 0 || 512 <= ret)
638 int index = EventCode;
658 if (ret <= 0 || 512 <= ret)
680 if (!strncmp(
name,
"GPU", 3)) {
681 char z[] = {
name[3],
'\0'};
684 if (!strncmp(
name,
"GPUzHWTHROT", 11))
685 ret = snprintf(
buf, 512,
"Total time GPU %d has been throttled by hardware (thermal or power brake)", tgt);
686 else if (!strncmp(
name,
"GPUzSWTHROT", 11))
687 ret = snprintf(
buf, 512,
"Total time GPU %d has been throttled by software for any reason", tgt);
688 else if (!strncmp(
name,
"GPUzSWOTTHROT", 13))
689 ret = snprintf(
buf, 512,
"Total time GPU %d has been throttled by software due to thermal", tgt);
690 else if (!strncmp(
name,
"GPUzSWPWRTHROT", 14))
691 ret = snprintf(
buf, 512,
"Total time GPU %d has been throttled by software due to power", tgt);
693 ret = snprintf(
buf, 512,
"[PERFORMANCE] Unexpected: GPU-%d %s", tgt,
name);
695 else if (!strncmp(
name,
"IPSCxx", 4)) {
697 ret = snprintf(
buf, 512,
"Instructions per second for core %d on this Processor", tgt);
699 else if (!strncmp(
name,
"IPS", 3))
700 ret = snprintf(
buf, 512,
"Vector sensor that takes the average of all the cores this Processor");
701 else if (!strncmp(
name,
"STOPDEEPACTCxx", 12)) {
703 ret = snprintf(
buf, 512,
"Deepest actual stop state that was fully entered during sample time for core %d", tgt);
705 else if (!strncmp(
name,
"STOPDEEPREQCxx", 12)) {
707 ret = snprintf(
buf, 512,
"Deepest stop state that has been requested during sample time for core %d", tgt);
709 else if (!strncmp(
name,
"MEMPWRTHROT", 11))
710 ret = snprintf(
buf, 512,
"Count of memory throttled due to power");
711 else if (!strncmp(
name,
"MEMOTTHROT", 10))
712 ret = snprintf(
buf, 512,
"Count of memory throttled due to memory Over temperature");
713 else if (!strncmp(
name,
"PROCOTTHROT", 11))
714 ret = snprintf(
buf, 512,
"Count of processor throttled for temperature");
715 else if (!strncmp(
name,
"PROCPWRTHROT", 12))
716 ret = snprintf(
buf, 512,
"Count of processor throttled due to power");
717 else if (!strncmp(
name,
"MWRM", 4)) {
719 ret = snprintf(
buf, 512,
"Memory write requests per sec for MC %d", tgt);
721 else if (!strncmp(
name,
"MRDM", 4)) {
723 ret = snprintf(
buf, 512,
"Memory read requests per sec for MC %d", tgt);
726 ret = snprintf(
buf, 512,
"[PERFORMANCE] Unexpected: %s",
name);
731 if (!strncmp(
name,
"PWRSYS", 6))
732 ret = snprintf(
buf, 512,
"Bulk power of the system/node");
733 else if (!strncmp(
name,
"PWRGPU", 6))
734 ret = snprintf(
buf, 512,
"Power consumption for GPUs per socket (OCC) read from APSS");
735 else if (!strncmp(
name,
"PWRPROC", 7))
736 ret = snprintf(
buf, 512,
"Power consumption for this Processor");
737 else if (!strncmp(
name,
"PWRVDD", 6))
738 ret = snprintf(
buf, 512,
"Power consumption for this Processor's Vdd (calculated from AVSBus readings)");
739 else if (!strncmp(
name,
"PWRVDN", 6))
740 ret = snprintf(
buf, 512,
"Power consumption for this Processor's Vdn (nest) (calculated from AVSBus readings)");
741 else if (!strncmp(
name,
"PWRMEM", 6))
742 ret = snprintf(
buf, 512,
"Power consumption for Memory for this Processor read from APSS");
743 else if (!strncmp(
name,
"PWRAPSSCH", 9)) {
745 ret = snprintf(
buf, 512,
"Power Provided by APSS channel %d", tgt);
748 ret = snprintf(
buf, 512,
"[POWER] Unexpected: %s",
name);
753 if (!strncmp(
name,
"FREQACxx", 6)) {
755 ret = snprintf(
buf, 512,
"Average/actual frequency for this processor, Core %d based on OCA data", tgt);
757 else if (!strncmp(
name,
"FREQA", 5))
758 ret = snprintf(
buf, 512,
"Average of all core frequencies for Processor");
760 ret = snprintf(
buf, 512,
"[FREQUENCY] Unexpected: %s",
name);
764 ret = snprintf(
buf, 512,
"[TIME] Unexpected: %s",
name);
769 if (!strncmp(
name,
"MEMSPSTATM", 10)) {
771 ret = snprintf(
buf, 512,
"Static Memory throttle level setting for MCA %d when not in a memory throttle condition", tgt);
773 else if (!strncmp(
name,
"MEMSPM", 6)) {
775 ret = snprintf(
buf, 512,
"Current Memory throttle level setting for MCA %d", tgt);
777 else if (!strncmp(
name,
"NUTILC", 6)) {
779 ret = snprintf(
buf, 512,
"Normalized average utilization, rolling average of this Processor's Core %d", tgt);
781 else if (!strncmp(
name,
"UTILC", 5)) {
783 ret = snprintf(
buf, 512,
"Utilization of this Processor's Core %d (where 100%% means fully utilized): NOTE: per thread HW counters are combined as appropriate to give this core level utilization sensor", tgt);
785 else if (!strncmp(
name,
"UTIL", 4))
786 ret = snprintf(
buf, 512,
"Average of all Cores UTILC[yy] sensor");
788 ret = snprintf(
buf, 512,
"[UTILIZATION] Unexpected: %s",
name);
793 if (!strncmp(
name,
"TEMPNEST", 8))
794 ret = snprintf(
buf, 512,
"Average temperature of nest DTS sensors");
795 else if (!strncmp(
name,
"TEMPVDD", 7))
796 ret = snprintf(
buf, 512,
"VRM Vdd temperature");
797 else if (!strncmp(
name,
"TEMPPROCTHRMCxx", 13)) {
799 ret = snprintf(
buf, 512,
"The combined weighted core/quad temperature for processor core %d", tgt);
801 else if (!strncmp(
name,
"TEMPDIMMvv", 8)) {
803 ret = snprintf(
buf, 512,
"DIMM temperature for DIMM %d", tgt);
805 else if (!strncmp(
name,
"TEMPGPUz", 7)) {
806 char z[] = {
name[7],
'\0'};
809 if (!strncmp(
name,
"TEMPGPUzMEM", 11))
810 ret = snprintf(
buf, 512,
"GPU %d hottest HBM temperature (individual memory temperatures are not available)", tgt);
811 else if (!strncmp(
name,
"TEMPGPUz", 8))
812 ret = snprintf(
buf, 512,
"GPU %d board temperature", tgt);
814 ret = snprintf(
buf, 512,
"[TEMPERATURE] Unexpected: GPU-%d %s", tgt,
name);
817 ret = snprintf(
buf, 512,
"[TEMPERATURE] Unexpected: %s",
name);
822 if (!strncmp(
name,
"VOLTVDDS", 8))
823 ret = snprintf(
buf, 512,
"Vdn Voltage at the remote sense. (AVS reading adjusted for loadline)");
824 else if (!strncmp(
name,
"VOLTVDNS", 8))
825 ret = snprintf(
buf, 512,
"Vdd Voltage at the remote sense. (AVS reading adjusted for loadline)");
826 else if (!strncmp(
name,
"VOLTVDD", 7))
827 ret = snprintf(
buf, 512,
"Processor Vdd Voltage (read from AVSBus)");
828 else if (!strncmp(
name,
"VOLTVDN", 7))
829 ret = snprintf(
buf, 512,
"Processor Vdn Voltage (read from AVSBus)");
830 else if (!strncmp(
name,
"VOLTDROOPCNTC", 13)) {
832 ret = snprintf(
buf, 512,
"Small voltage droop count for core %d", tgt);
834 else if (!strncmp(
name,
"VOLTDROOPCNTQ", 13)) {
836 ret = snprintf(
buf, 512,
"Small voltage droop count for core %d", tgt);
839 ret = snprintf(
buf, 512,
"[VOLTAGE] Unexpected: %s",
name);
844 if (!strncmp(
name,
"CURVDN", 6))
845 ret = snprintf(
buf, 512,
"Processor Vdn Current (read from AVSBus)");
846 else if (!strncmp(
name,
"CURVDD", 6))
847 ret = snprintf(
buf, 512,
"Processor Vdd Current (read from AVSBus)");
849 ret = snprintf(
buf, 512,
"[CURRENT] Unexpected: %s",
name);
854 ret = snprintf(
buf, 512,
"[GENERIC] Unexpected: %s",
name);
858 if (ret <= 0 || 512 <= ret)
862 if (ret <= 0 || 512 <= ret)
865 ret = snprintf(
buf+strlen(
buf), 512,
"Sampling period: %lfs", 1./
freq);
866 if (ret <= 0 || 512 <= ret)
877 .
name =
"sensors_ppc",
878 .short_name =
"sensors_ppc",
879 .description =
"Linux sensors_ppc energy measurements",
int open(const char *pathname, int flags, mode_t mode)
off_t lseek(int fd, off_t offset, int whence)
ssize_t read(int fd, void *buf, size_t count)
const char * names[NUM_EVENTS]
static const PAPI_hw_info_t * hw_info
Get real time counter value in nanoseconds.
struct papi_vectors * _papi_hwd[]
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
#define PAPI_DATATYPE_INT64
char events[MAX_EVENTS][BUFSIZ]
static double c[MATRIX_SIZE][MATRIX_SIZE]
static int _sensors_ppc_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
#define DESC_LINE_SIZE_ALLOWED
static int _sensors_ppc_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _sensors_ppc_set_domain(hwd_control_state_t *ctl, int domain)
static long long read_sensors_ppc_record(int s, int gidx, int midx)
static int _sensors_ppc_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _sensors_ppc_shutdown_component(void)
static int _sensors_ppc_ntv_code_to_name(unsigned int EventCode, char *name, int len)
static long long read_sensors_ppc_counter(int s, int gidx)
static int _sensors_ppc_init_component(int cidx)
static int _sensors_ppc_is_counter(int index)
static void refresh_data(int occ_id, int forced)
Refresh_data locks in write and update ping and pong at the same time for OCC occ_id....
static char * _local_strlcpy(char *dst, const char *src, size_t size)
static int _sensors_ppc_shutdown_thread(hwd_context_t *ctx)
static int _sensors_ppc_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
static int _sensors_ppc_ntv_code_to_info(unsigned int EventCode, PAPI_event_info_t *info)
static int _sensors_ppc_ntv_enum_events(unsigned int *EventCode, int modifier)
static double _pow(int x, int y)
static int _sensors_ppc_reset(hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _sensors_ppc_init_thread(hwd_context_t *ctx)
static int _sensors_ppc_init_control_state(hwd_control_state_t *ctl)
static int _sensors_ppc_read(hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
static long long read_sensors_ppc_value(int index)
papi_vector_t _sensors_ppc_vector
static void _space_padding(char *buf, size_t max)
#define HANDLE_STRING_ERROR
OCC Inband Sensors component for PowerPC This file contains the source code for a component that enab...
static char * pkg_sys_name
#define OCC_SENSOR_DATA_BLOCK_SIZE
static const char * sensors_ppc_fake_qualifiers[]
#define papi_sensors_ppc_lock()
uint32_t reading_pong_offset
#define OCC_SENSOR_READING_COUNTER
static mode_t pkg_sys_flag
static long long last_refresh[MAX_OCCS]
struct occ_sensor_data_header_s * occ_hdr[MAX_OCCS]
@ OCC_SENSOR_TYPE_GENERIC
@ OCC_SENSOR_TYPE_VOLTAGE
@ OCC_SENSOR_TYPE_FREQUENCY
@ OCC_SENSOR_TYPE_UTILIZATION
@ OCC_SENSOR_TYPE_TEMPERATURE
@ OCC_SENSOR_TYPE_CURRENT
@ OCC_SENSOR_TYPE_PERFORMANCE
uint32_t reading_ping_offset
static uint32_t * double_pong[MAX_OCCS]
#define SENSORS_PPC_MAX_COUNTERS
#define OCC_PING_DATA_BLOCK_SIZE
@ OCC_SENSORS_ACCUMULATOR_TAG
static const char * sensors_ppc_fake_qualif_desc[]
static int occ_num_events[MAX_OCCS+1]
#define OCC_SENSOR_READING_FULL
struct occ_sensor_name_s * occ_names[MAX_OCCS]
static uint32_t * pong[MAX_OCCS]
#define papi_sensors_ppc_unlock()
static uint32_t * ping[MAX_OCCS]
static uint32_t * double_ping[MAX_OCCS]
#define PAPI_NATIVE_AND_MASK
#define SUBDBG(format, args...)
papi_mdi_t _papi_hwi_system_info
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]
char units[PAPI_MIN_STR_LEN]
char symbol[PAPI_HUGE_STR_LEN]
char long_descr[PAPI_HUGE_STR_LEN]
long long start_value[SENSORS_PPC_MAX_COUNTERS]
long long count[SENSORS_PPC_MAX_COUNTERS]
long long which_counter[SENSORS_PPC_MAX_COUNTERS]
char units[MAX_CHARS_SENSOR_UNIT]
PAPI_component_info_t cmp_info