armv8_pmu_cycle_counter_el0 icon indicating copy to clipboard operation
armv8_pmu_cycle_counter_el0 copied to clipboard

`cat /dev/pmuctl` not work

Open axiqia opened this issue 3 years ago • 2 comments

I try to read from the /dev/pmuctl deivce with cat, but it do NOT work.

$ cat /dev/pmuctl
cat: /dev/pmuctl: Argument list too long

I also try to read with read system call, the result is as bellow:

    int fd;
    fd = open("/dev/pmuctl", O_RDWR);

    char buffer[100];
    read(fd, &buffer, 100);
    printf("%s", buffer);
    return 0;   

// output:
// PMCCNTR=1
// K���#    

Any feedback would be greatly appreciated. Thank you :).

axiqia avatar Apr 27 '21 09:04 axiqia

In my case, the count and PAGE_SIZE are 131072, 4096, separately. https://github.com/jerinjacobk/armv8_pmu_cycle_counter_el0/blob/81fbd86cd3e168b76c6bdad29f280a5744207740/pmu_el0_cycle_counter.c#L137

My platform is kernel 5.10 on aarch64.

axiqia avatar Apr 28 '21 02:04 axiqia

The main loop of GNU cat, in the simplest case is (function simple_cat from cat.c):

while (true)
    {
        /* Read a block of input. */
        n_read = safe_read (input_desc, buf, bufsize);

        /* ... */
    }

Then the question becomes "how is bufsize set?" The answer is it's using io_blksize (insize = io_blksize (stat_buf)), which is defined as follows:

io_blksize (struct stat sb)
{
  return MAX (IO_BUFSIZE, ST_BLKSIZE (sb));
}

where ST_BLKSIZE gives the operating system's idea of the file system's preferred I/O block size (as accessed using stat), and IO_BUFSIZE is defined as 128*1024 (128KB).

It seems that GNU cat will read in blocks of 128KB or the file system's recommended I/O block size, whichever is larger.

ref: https://unix.stackexchange.com/a/245507/343633

$ stat -f -c %s /dev/pmuctl
4096

Therefore, the count here is 128KB(131072 Byte).

Is it necessary to limit it to one page? @jerinjacobk

axiqia avatar Apr 28 '21 06:04 axiqia