---
name: "pmc_read"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/pmc_read"
---

# pmc\_read(3)

read and write hardware performance counters

## NAME

**pmc\_read**, **pmc\_rw**, **pmc\_write** – read and write hardware performance counters

## LIBRARY

library “libpmc”

## SYNOPSIS

**#include \<pmc.h\>**

*int*\

**pmc\_read**(*pmc\_id\_t pmc*, *pmc\_value\_t \*value*);

*int*\

**pmc\_rw**(*pmc\_id\_t pmc*, *pmc\_value\_t newvalue*, *pmc\_value\_t \*oldvaluep*);

*int*\

**pmc\_write**(*pmc\_id\_t pmc*, *pmc\_value\_t value*);

## DESCRIPTION

These functions read and write the current value of a PMC.

Function **pmc\_read**() will read the current value of the PMC specified by argument *pmc* and write it to the location specified by argument *value*.

Function **pmc\_write**() will set the current value of the PMC specified by argument *pmc* to the value specified by argument *value*.

Function **pmc\_rw**() combines a read and a write into a single atomic operation.

For write operations the PMC should be a quiescent state.

## RETURN VALUES

The **pmc\_read()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

A call to these functions may fail with the following errors:

- \[EBUSY\]

  A write operation specified a currently running PMC.

- \[EINVAL\]

  Argument *pmc* specified a PMC not in a readable state.

- \[EINVAL\]

  The PMC specified by argument *pmc* was not owned by the current process.

## SEE ALSO

[pmc(3)](/pmc/3.md), [hwpmc(4)](/hwpmc/4.md)
