Obtaining counter data through an API
Applications can access the CPU-measurement counters through ioctls.
For example, the lshwc tool uses these ioctls.Application programmers: This information is intended for programmers
who want to write applications that extract data from CPU-measurement counters.
Name | Structure passed | Description |
---|---|---|
S390_HWCTR_START | s390_ctrset_start | Start counter sets on CPUs. |
S390_HWCTR_READ | s390_ctrset_read | Read counter sets on CPUs. |
S390_HWCTR_STOP | n/a | Stop counter sets on CPUs. |
For details about the calls and structures, see the arch/s390/include/uapi/asm/hwctrset.h header file in the Linux® kernel source.
Issue the ioctls on the misc character device /dev/hwctr. You must first open this device node in read/write mode.
Sample program
unsigned long cpumask[1];
struct s390_hwctr_start start;
struct s390_hwctr_read read;
int fd, rc;
/* Open device */
fd = open(S390_HWCTR_DEVICE, O_RDWR);
/* Start counter sets */
cpumask[0] = 0xffff; /* Use CPUs 0-15 */
start.version = 1;
start.counter_sets = S390_HWCTR_ALL;
start.cpumask_len = sizeof(cpumask);
start.cpumask = cpumask;
rc = ioctl(fd, S390_HWCTR_START, &start);
/* Read counter sets */
read.data = malloc(start.data_bytes + sizeof(*read));
rc = ioctl(fd, S390_HWCTR_READ, &read);
/* Stop counter sets */
rc = ioctl(fd, S390_HWCTR_STOP, 0);
/* Close device */
close(fd);