Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177713475
D61373.1795108444.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
19 KB
Referenced Files
None
Subscribers
None
D61373.1795108444.diff
View Options
diff --git a/UPDATING b/UPDATING
--- a/UPDATING
+++ b/UPDATING
@@ -35,6 +35,20 @@
__FreeBSD_version has been bumped to 1600030 for ports that need to
detect these changes.
+20261022:
+ The hwpmc(4) PMCLOG_TYPE_DROPNOTIFY log record now has a payload
+ with the PMC ID, the CPU, the reason and the number of dropped
+ samples. PMC_VERSION_MINOR is now 4. An older libpmc(3) reads
+ the new record but ignores the payload. Rebuild libpmc and
+ pmcstat(8) to see the counts. The new libpmc reads logs from older
+ kernels.
+
+ The kernel and the hwpmc module must have the same PMC_VERSION, so
+ rebuild both. A module of a different version does not load. A
+ new libpmc that runs against an older hwpmc module gets
+ EPROGMISMATCH from pmc_init(3). Thus build and install world and
+ kernel together.
+
20261018:
The FreeBSD-base repository is now enabled in /etc/pkg/FreeBSD.conf.
To disable it, edit that file or put "FreeBSD-base: { enabled: no }"
diff --git a/lib/libpmc/pmclog.h b/lib/libpmc/pmclog.h
--- a/lib/libpmc/pmclog.h
+++ b/lib/libpmc/pmclog.h
@@ -54,6 +54,10 @@
};
struct pmclog_ev_dropnotify {
+ uint32_t pl_pmcid;
+ uint32_t pl_cpu;
+ uint32_t pl_flags; /* PMCLOG_DROP_* */
+ uint32_t pl_count;
};
struct pmclog_ev_closelog {
diff --git a/lib/libpmc/pmclog.3 b/lib/libpmc/pmclog.3
--- a/lib/libpmc/pmclog.3
+++ b/lib/libpmc/pmclog.3
@@ -85,7 +85,7 @@
union { /* log entry data */
struct pmclog_ev_callchain pl_cc;
struct pmclog_ev_closelog pl_cl;
- struct pmclog_ev_dropnotify pl_d;
+ struct pmclog_ev_dropnotify pl_dn;
struct pmclog_ev_initialize pl_i;
struct pmclog_ev_map_in pl_mi;
struct pmclog_ev_map_out pl_mo;
@@ -173,9 +173,37 @@
A marker indicating a successful close of a log file.
This record will be the last record of a log file.
.It Dv PMCLOG_TYPE_DROPNOTIFY
-A marker indicating that
+A record that reports samples that
.Xr hwpmc 4
-had to drop data due to a resource constraint.
+dropped for one PMC on one CPU since the previous record.
+Field
+.Va pl_u.pl_dn.pl_pmcid
+contains the PMC ID,
+.Va pl_u.pl_dn.pl_cpu
+contains the CPU, and
+.Va pl_u.pl_dn.pl_count
+contains the number of dropped samples.
+Field
+.Va pl_u.pl_dn.pl_flags
+contains one or more of these flags:
+.Bl -tag -width ".Dv PMCLOG_DROP_BUFFERFULL"
+.It Dv PMCLOG_DROP_BUFFERFULL
+The per-CPU sample buffer was full.
+.It Dv PMCLOG_DROP_THROTTLED
+The PMC was at the
+.Va kern.hwpmc.max_sample_rate
+limit.
+The count is the number of times that the driver stopped the PMC.
+While the PMC is stopped, it takes no samples, and the driver does not
+count these lost samples.
+.It Dv PMCLOG_DROP_USERCC
+The user callchain of a sample was not available in time.
+.El
+.Pp
+Logs from kernels before
+.Dv PMC_VERSION_MINOR
+4 contain no payload in this record.
+For these records, all fields are zero.
.It Dv PMCLOG_TYPE_INITIALIZE
An initialization record.
This is the first record in a log file.
diff --git a/lib/libpmc/pmclog.c b/lib/libpmc/pmclog.c
--- a/lib/libpmc/pmclog.c
+++ b/lib/libpmc/pmclog.c
@@ -320,7 +320,15 @@
ev->pl_state = PMCLOG_EOF;
return (-1);
case PMCLOG_TYPE_DROPNOTIFY:
- /* nothing to do */
+ /* Old records have no payload. */
+ if (evlen < (int)sizeof(struct pmclog_dropnotify)) {
+ memset(&ev->pl_u.pl_dn, 0, sizeof(ev->pl_u.pl_dn));
+ break;
+ }
+ PMCLOG_READ32(le, ev->pl_u.pl_dn.pl_pmcid);
+ PMCLOG_READ32(le, ev->pl_u.pl_dn.pl_cpu);
+ PMCLOG_READ32(le, ev->pl_u.pl_dn.pl_flags);
+ PMCLOG_READ32(le, ev->pl_u.pl_dn.pl_count);
break;
case PMCLOG_TYPE_INITIALIZE:
PMCLOG_READ32(le,ev->pl_u.pl_i.pl_version);
diff --git a/lib/libpmcstat/libpmcstat.h b/lib/libpmcstat/libpmcstat.h
--- a/lib/libpmcstat/libpmcstat.h
+++ b/lib/libpmcstat/libpmcstat.h
@@ -313,6 +313,7 @@
int ps_samples_indeterminable; /* #samples in indeterminable images */
int ps_samples_unknown_function;/* #samples with unknown function at offset */
int ps_callchain_dubious_frames;/* #dubious frame pointers seen */
+ int ps_samples_dropped; /* Dropped samples. */
};
__BEGIN_DECLS
diff --git a/lib/libpmcstat/libpmcstat_logging.c b/lib/libpmcstat/libpmcstat_logging.c
--- a/lib/libpmcstat/libpmcstat_logging.c
+++ b/lib/libpmcstat/libpmcstat_logging.c
@@ -265,6 +265,11 @@
ev.pl_u.pl_mo.pl_end);
break;
+ case PMCLOG_TYPE_DROPNOTIFY:
+ pmcstat_stats->ps_samples_dropped +=
+ ev.pl_u.pl_dn.pl_count;
+ break;
+
case PMCLOG_TYPE_CALLCHAIN:
pmcstat_stats->ps_samples_total++;
*ps_samples_period += 1;
@@ -671,6 +676,7 @@
PRINT("#exec/unknown", exec_indeterminable);
PRINT("#exec handling errors", exec_errors);
PRINT("#samples/total", samples_total);
+ PRINT("#samples/dropped", samples_dropped);
PRINT("#samples/unclaimed", samples_unknown_offset);
PRINT("#samples/unknown-object", samples_indeterminable);
PRINT("#samples/unknown-function", samples_unknown_function);
diff --git a/sys/dev/hwpmc/hwpmc_logging.c b/sys/dev/hwpmc/hwpmc_logging.c
--- a/sys/dev/hwpmc/hwpmc_logging.c
+++ b/sys/dev/hwpmc/hwpmc_logging.c
@@ -192,7 +192,7 @@
CTASSERT(sizeof(struct pmclog_callchain) == 7*4 + TSDELTA +
PMC_CALLCHAIN_DEPTH_MAX*sizeof(uintfptr_t));
CTASSERT(sizeof(struct pmclog_closelog) == 3*4 + TSDELTA);
-CTASSERT(sizeof(struct pmclog_dropnotify) == 3*4 + TSDELTA);
+CTASSERT(sizeof(struct pmclog_dropnotify) == 7 * 4 + TSDELTA);
CTASSERT(sizeof(struct pmclog_map_in) == PATH_MAX + TSDELTA +
5*4 + sizeof(uintfptr_t));
CTASSERT(offsetof(struct pmclog_map_in,pl_pathname) ==
@@ -1002,12 +1002,23 @@
spinlock_exit();
}
-void
-pmclog_process_dropnotify(struct pmc_owner *po)
+/* Log drops. Return ENOMEM if full. */
+int
+pmclog_process_dropnotify(struct pmc *pm, int cpu, uint32_t flags,
+ uint32_t count)
{
- PMCLOG_RESERVE(po, PMCLOG_TYPE_DROPNOTIFY,
- sizeof(struct pmclog_dropnotify));
- PMCLOG_DESPATCH(po);
+ struct pmc_owner *po;
+
+ po = pm->pm_owner;
+ _PMCLOG_RESERVE_SAFE(po, PMCLOG_TYPE_DROPNOTIFY,
+ sizeof(struct pmclog_dropnotify), return (ENOMEM), pmc_rdtsc());
+ PMCLOG_EMIT32(pm->pm_id);
+ PMCLOG_EMIT32(cpu);
+ PMCLOG_EMIT32(flags);
+ PMCLOG_EMIT32(count);
+ /* Wake the log thread after unlock. */
+ PMCLOG_DESPATCH_SCHED_LOCK(po);
+ return (0);
}
void
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -244,8 +244,11 @@
struct pmc_process *pp);
static void pmc_log_all_process_mappings(struct pmc_owner *po);
static void pmc_log_kernel_mappings(struct pmc *pm);
+static void pmc_log_lost(struct pmc *pm, int cpu);
+static void pmc_log_lost_off_cpu(struct pmc *pm, int cpu);
static void pmc_log_process_mappings(struct pmc_owner *po, struct proc *p);
static void pmc_maybe_remove_owner(struct pmc_owner *po);
+static void pmc_note_lost(struct pmc *pm, int cpu, u_int flag);
static void pmc_post_callchain_callback(void);
static void pmc_process_allproc(struct pmc *pm);
static void pmc_process_csw_in(struct thread *td);
@@ -1822,6 +1825,10 @@
}
}
+ /* Log drops here, not in hardclock. */
+ spinlock_enter();
+ pmc_log_lost(pm, cpu);
+ spinlock_exit();
counter_u64_add(pm->pm_runcount, -1);
(void)pcd->pcd_config_pmc(cpu, adjri, NULL);
}
@@ -1914,6 +1921,9 @@
("[pmc,%d] pm=%p runcount %ju", __LINE__, pm,
(uintmax_t)counter_u64_fetch(pm->pm_runcount)));
+ /* Log drops before CPU exit. */
+ pmc_log_lost(pm, cpu);
+
/* reduce this PMC's runcount */
counter_u64_add(pm->pm_runcount, -1);
@@ -3070,7 +3080,10 @@
PMCDBG2(PMC,REL,2, "decfg cpu=%d ri=%d", cpu, ri);
+ spinlock_enter();
+ pmc_log_lost(pm, cpu);
(void)pcd->pcd_config_pmc(cpu, adjri, NULL);
+ spinlock_exit();
/* adjust the global and process count of SS mode PMCs */
if (mode == PMC_MODE_SS && pm->pm_state == PMC_STATE_RUNNING) {
@@ -3535,6 +3548,11 @@
}
critical_exit();
+ /* Log stop drops here, not in hardclock. */
+ spinlock_enter();
+ pmc_log_lost(pm, cpu);
+ spinlock_exit();
+
pmc_restore_cpu_binding(&pb);
/* Remove this owner from the global list of SS PMC owners. */
@@ -5062,6 +5080,7 @@
ps = PMC_PROD_SAMPLE(psb);
if (psb->ps_considx != psb->ps_prodidx &&
ps->ps_nsamples) { /* in use, reader hasn't caught up */
+ pmc_note_lost(pm, cpu, PMCLOG_DROP_BUFFERFULL);
pm->pm_pcpu_state[cpu].pps_stalled = 1;
counter_u64_add(pmc_stats.pm_intr_bufferfull, 1);
PMCDBG6(SAM,INT,1,"(spc) cpu=%d pm=%p tf=%p um=%d wr=%d rd=%d",
@@ -5166,7 +5185,7 @@
pps->pps_intr_count = 0;
}
if (++pps->pps_intr_count > limit) {
- DPCPU_SET(pmc_throttled, 1);
+ pmc_note_lost(pm, curcpu, PMCLOG_DROP_THROTTLED);
pps->pps_stalled = 1;
counter_u64_add(pmc_stats.pm_intr_throttled, 1);
DPCPU_SET(pmc_sampled, 1);
@@ -5358,6 +5377,8 @@
* for long running system calls.
*/
counter_u64_add(pmc_stats.pm_overwrites, 1);
+ pmc_note_lost(pm, cpu, PMCLOG_DROP_USERCC);
+ pmc_log_lost_off_cpu(pm, cpu);
goto entrydone;
}
/* Need a rescan at a later time. */
@@ -5407,6 +5428,72 @@
pmc_restart_stalled(cpu);
}
+/* Drop count and flags share one word. */
+#define PMC_LOST_FLAG_SHIFT 29
+#define PMC_LOST_COUNT_MASK ((1U << PMC_LOST_FLAG_SHIFT) - 1)
+CTASSERT(((PMCLOG_DROP_BUFFERFULL | PMCLOG_DROP_THROTTLED |
+ PMCLOG_DROP_USERCC) >> (32 - PMC_LOST_FLAG_SHIFT)) == 0);
+
+/* Count drops for hardclock. NMI-safe. */
+static void
+pmc_note_lost(struct pmc *pm, int cpu, u_int flag)
+{
+ struct pmc_pcpu_state *pps;
+ u_int old;
+
+ pps = &pm->pm_pcpu_state[cpu];
+ do {
+ old = atomic_load_int(&pps->pps_lost);
+ if ((old & PMC_LOST_COUNT_MASK) == PMC_LOST_COUNT_MASK)
+ break;
+ } while (atomic_cmpset_int(&pps->pps_lost, old,
+ (old | flag << PMC_LOST_FLAG_SHIFT) + 1) == 0);
+ DPCPU_SET(pmc_throttled, 1);
+}
+
+/* Log per-PMC drops. */
+static void
+pmc_log_lost(struct pmc *pm, int cpu)
+{
+ struct pmc_pcpu_state *pps;
+ u_int count, new, old, v;
+
+ pps = &pm->pm_pcpu_state[cpu];
+ if (atomic_load_int(&pps->pps_lost) == 0)
+ return;
+ v = atomic_readandclear_int(&pps->pps_lost);
+ if ((pm->pm_flags & PMC_F_ATTACHED_TO_OWNER) != 0 ||
+ (pm->pm_owner->po_flags & PMC_PO_OWNS_LOGFILE) == 0)
+ return;
+ if (pmclog_process_dropnotify(pm, cpu, v >> PMC_LOST_FLAG_SHIFT,
+ v & PMC_LOST_COUNT_MASK) == 0)
+ return;
+
+ /* Keep drops while the log is full. */
+ do {
+ old = atomic_load_int(&pps->pps_lost);
+ count = (old & PMC_LOST_COUNT_MASK) + (v & PMC_LOST_COUNT_MASK);
+ if (count > PMC_LOST_COUNT_MASK)
+ count = PMC_LOST_COUNT_MASK;
+ new = ((old | v) & ~PMC_LOST_COUNT_MASK) | count;
+ } while (atomic_cmpset_int(&pps->pps_lost, old, new) == 0);
+ DPCPU_ID_SET(cpu, pmc_throttled, 1);
+}
+
+/* Log drops after this PMC leaves the CPU. */
+static void
+pmc_log_lost_off_cpu(struct pmc *pm, int cpu)
+{
+ struct pmc_classdep *pcd;
+ struct pmc *phw_pm;
+ int adjri;
+
+ pcd = pmc_ri_to_classdep(md, PMC_TO_ROWINDEX(pm), &adjri);
+ phw_pm = NULL;
+ (void)(*pcd->pcd_get_config)(cpu, adjri, &phw_pm);
+ if (phw_pm != pm)
+ pmc_log_lost(pm, cpu);
+}
/* Check the tick limit. */
static bool
@@ -5441,6 +5528,8 @@
!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) /* !sampling */
continue;
+ pmc_log_lost(pm, cpu);
+
if (!pm->pm_pcpu_state[cpu].pps_cpustate || /* !desired */
!pm->pm_pcpu_state[cpu].pps_stalled) /* !stalled */
continue;
@@ -5598,6 +5687,10 @@
KASSERT(counter_u64_fetch(pm->pm_runcount) > 0,
("[pmc,%d] runcount is %d", __LINE__, ri));
+ /* Log drops before CPU exit. */
+ spinlock_enter();
+ pmc_log_lost(pm, cpu);
+ spinlock_exit();
counter_u64_add(pm->pm_runcount, -1);
(void)pcd->pcd_config_pmc(cpu, adjri, NULL);
}
diff --git a/sys/sys/pmc.h b/sys/sys/pmc.h
--- a/sys/sys/pmc.h
+++ b/sys/sys/pmc.h
@@ -60,7 +60,7 @@
* The patch version is incremented for every bug fix.
*/
#define PMC_VERSION_MAJOR 0x0A
-#define PMC_VERSION_MINOR 0x03
+#define PMC_VERSION_MINOR 0x04
#define PMC_VERSION_PATCH 0x0000
#define PMC_VERSION (PMC_VERSION_MAJOR << 24 | \
@@ -753,6 +753,7 @@
uint32_t pps_overflowcnt; /* count overflow interrupts */
int pps_intr_tick; /* Tick number. */
u_int pps_intr_count; /* Interrupts per tick. */
+ u_int pps_lost; /* Drop flags and count. */
uint8_t pps_stalled;
uint8_t pps_cpustate;
} __aligned(CACHE_LINE_SIZE);
diff --git a/sys/sys/pmclog.h b/sys/sys/pmclog.h
--- a/sys/sys/pmclog.h
+++ b/sys/sys/pmclog.h
@@ -143,10 +143,20 @@
PMCLOG_ENTRY_HEADER
};
+/* Per-PMC, per-CPU drops since the last record. */
struct pmclog_dropnotify {
PMCLOG_ENTRY_HEADER
+ uint32_t pl_pmcid;
+ uint32_t pl_cpu;
+ uint32_t pl_flags; /* PMCLOG_DROP_* */
+ uint32_t pl_count; /* Drop count. */
};
+#define PMCLOG_DROP_BUFFERFULL 0x0001 /* Sample ring full. */
+#define PMCLOG_DROP_THROTTLED 0x0002 /* Sample rate limit. */
+#define PMCLOG_DROP_USERCC 0x0004 /* Late user callchain. */
+/* pps_lost uses 3 flag bits. */
+
struct pmclog_initialize {
PMCLOG_ENTRY_HEADER
uint32_t pl_version; /* driver version */
@@ -324,7 +334,8 @@
void pmclog_proc_ignite(void *handle, struct pmc_owner *po);
void pmclog_process_callchain(struct pmc *_pm, struct pmc_sample *_ps);
void pmclog_process_closelog(struct pmc_owner *po);
-void pmclog_process_dropnotify(struct pmc_owner *po);
+int pmclog_process_dropnotify(struct pmc *_pm, int _cpu, uint32_t _flags,
+ uint32_t _count);
void pmclog_process_map_in(struct pmc_owner *po, pid_t pid,
uintfptr_t start, const char *path);
void pmclog_process_map_out(struct pmc_owner *po, pid_t pid,
diff --git a/tests/sys/pmc/pmc_throttle_test.c b/tests/sys/pmc/pmc_throttle_test.c
--- a/tests/sys/pmc/pmc_throttle_test.c
+++ b/tests/sys/pmc/pmc_throttle_test.c
@@ -390,6 +390,184 @@
sysctls_restore();
}
+/* Compare drop counts with throttle counts. */
+ATF_TC_WITH_CLEANUP(drop_records);
+ATF_TC_HEAD(drop_records, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+ATF_TC_BODY(drop_records, tc)
+{
+ struct pmclog_ev ev;
+ uint64_t throttled, dropped, nrec, other;
+ pmc_id_t id;
+ void *parser;
+ int fd;
+
+ (void)throttle_setup(10);
+
+ (void)measure_log(&throttled, "drop.log", &id);
+
+ sysctls_restore();
+
+ fd = open("drop.log", O_RDONLY);
+ ATF_REQUIRE(fd >= 0);
+ parser = pmclog_open(fd);
+ ATF_REQUIRE(parser != NULL);
+ dropped = nrec = other = 0;
+ while (pmclog_read(parser, &ev) == 0) {
+ if (ev.pl_type != PMCLOG_TYPE_DROPNOTIFY)
+ continue;
+ nrec++;
+ if (ev.pl_u.pl_dn.pl_pmcid != id ||
+ ev.pl_u.pl_dn.pl_cpu != TEST_CPU ||
+ (ev.pl_u.pl_dn.pl_flags & PMCLOG_DROP_THROTTLED) == 0) {
+ other++;
+ continue;
+ }
+ dropped += ev.pl_u.pl_dn.pl_count;
+ }
+ ATF_CHECK_MSG(ev.pl_state == PMCLOG_EOF, "log state %d",
+ ev.pl_state);
+ pmclog_close(parser);
+ close(fd);
+
+ printf("throttled %ju, records %ju, dropped %ju, other %ju\n",
+ (uintmax_t)throttled, (uintmax_t)nrec, (uintmax_t)dropped,
+ (uintmax_t)other);
+ ATF_CHECK_MSG(throttled > 0, "the PMC never reached the limit");
+ ATF_CHECK_MSG(nrec > 0, "no DROPNOTIFY record in the log");
+ ATF_CHECK_EQ_MSG(other, 0, "%ju records with wrong fields",
+ (uintmax_t)other);
+ /* Check stop-time drops. */
+ ATF_CHECK_MSG(dropped == throttled,
+ "dropped %ju, throttled %ju", (uintmax_t)dropped,
+ (uintmax_t)throttled);
+}
+
+ATF_TC_CLEANUP(drop_records, tc)
+{
+
+ sysctls_restore();
+}
+
+/* Sum throttle drops for this PMC. */
+static uint64_t
+log_drops(const char *logpath, pmc_id_t id, uint64_t *nrec)
+{
+ struct pmclog_ev ev;
+ uint64_t dropped;
+ void *parser;
+ int fd;
+
+ fd = open(logpath, O_RDONLY);
+ ATF_REQUIRE(fd >= 0);
+ parser = pmclog_open(fd);
+ ATF_REQUIRE(parser != NULL);
+ dropped = *nrec = 0;
+ while (pmclog_read(parser, &ev) == 0) {
+ if (ev.pl_type != PMCLOG_TYPE_DROPNOTIFY ||
+ ev.pl_u.pl_dn.pl_pmcid != id ||
+ (ev.pl_u.pl_dn.pl_flags & PMCLOG_DROP_THROTTLED) == 0)
+ continue;
+ (*nrec)++;
+ dropped += ev.pl_u.pl_dn.pl_count;
+ }
+ ATF_CHECK_MSG(ev.pl_state == PMCLOG_EOF, "log state %d",
+ ev.pl_state);
+ pmclog_close(parser);
+ close(fd);
+ return (dropped);
+}
+
+/* Check drops at switch and exit. */
+ATF_TC_WITH_CLEANUP(drop_records_process);
+ATF_TC_HEAD(drop_records_process, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "timeout", "30");
+}
+ATF_TC_BODY(drop_records_process, tc)
+{
+ struct timespec t, t0;
+ volatile uint64_t x;
+ uint64_t dropped, nrec, th0, th1;
+ pmc_id_t id;
+ pid_t pid;
+ int fd, i, pfd[2], status;
+ char c;
+
+ (void)throttle_setup(10);
+
+ ATF_REQUIRE(pipe(pfd) == 0);
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+ if (pid == 0) {
+ /* 300 bursts of 2 ms, with 1 ms sleeps. */
+ pin(TEST_CPU);
+ if (read(pfd[0], &c, 1) != 1)
+ _exit(1);
+ x = 1;
+ for (i = 0; i < 300; i++) {
+ clock_gettime(CLOCK_MONOTONIC, &t0);
+ do {
+ x = x * 6364136223846793005ULL + 1;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ } while ((t.tv_sec - t0.tv_sec) * 1000000000L +
+ (t.tv_nsec - t0.tv_nsec) < 2000000L);
+ usleep(1000);
+ }
+ _exit(0);
+ }
+
+ for (i = 0; i < (int)nitems(cycle_events); i++) {
+ if (pmc_allocate(cycle_events[i], PMC_MODE_TS, 0, PMC_CPU_ANY,
+ &id, TEST_PERIOD) == 0)
+ break;
+ }
+ if (i == (int)nitems(cycle_events)) {
+ (void)kill(pid, SIGKILL);
+ (void)waitpid(pid, NULL, 0);
+ atf_tc_skip("no cycle event for a process sampling PMC");
+ }
+ fd = open("dropp.log", O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ ATF_REQUIRE(fd >= 0);
+ ATF_REQUIRE(pmc_configure_logfile(fd) == 0);
+ ATF_REQUIRE(pmc_attach(id, pid) == 0);
+ th0 = stat_get("intr_throttled");
+ ATF_REQUIRE(pmc_start(id) == 0);
+ ATF_REQUIRE(write(pfd[1], "g", 1) == 1);
+ ATF_REQUIRE(waitpid(pid, &status, 0) == pid);
+ th1 = stat_get("intr_throttled");
+ (void)pmc_stop(id);
+ ATF_REQUIRE(pmc_release(id) == 0);
+ ATF_REQUIRE(pmc_close_logfile() == 0);
+ (void)pmc_configure_logfile(-1);
+ close(fd);
+ close(pfd[0]);
+ close(pfd[1]);
+
+ sysctls_restore();
+
+ dropped = log_drops("dropp.log", id, &nrec);
+ printf("throttled %ju, records %ju, dropped %ju\n",
+ (uintmax_t)(th1 - th0), (uintmax_t)nrec, (uintmax_t)dropped);
+ ATF_CHECK_MSG(WIFEXITED(status) && WEXITSTATUS(status) == 0,
+ "child status %d", status);
+ ATF_CHECK_MSG(th1 - th0 > 0, "the PMC never reached the limit");
+ /* One late NMI may add an unlogged drop. */
+ ATF_CHECK_MSG(dropped <= th1 - th0 && dropped + 1 >= th1 - th0,
+ "dropped %ju, throttled %ju", (uintmax_t)dropped,
+ (uintmax_t)(th1 - th0));
+}
+
+ATF_TC_CLEANUP(drop_records_process, tc)
+{
+
+ sysctls_restore();
+}
+
/* One throttle per tick. */
ATF_TC_WITH_CLEANUP(short_period);
ATF_TC_HEAD(short_period, tc)
@@ -464,6 +642,8 @@
ATF_TP_ADD_TC(tp, rate_limited);
ATF_TP_ADD_TC(tp, rate_unlimited);
ATF_TP_ADD_TC(tp, time_limited);
+ ATF_TP_ADD_TC(tp, drop_records);
+ ATF_TP_ADD_TC(tp, drop_records_process);
ATF_TP_ADD_TC(tp, short_period);
ATF_TP_ADD_TC(tp, flush_loop);
return (atf_no_error());
diff --git a/usr.sbin/pmcstat/pmcstat_log.c b/usr.sbin/pmcstat/pmcstat_log.c
--- a/usr.sbin/pmcstat/pmcstat_log.c
+++ b/usr.sbin/pmcstat/pmcstat_log.c
@@ -497,7 +497,7 @@
pmcstat_print_log(void)
{
struct pmclog_ev ev;
- uint32_t npc;
+ uint32_t dnf, npc;
while (pmclog_read(args.pa_logparser, &ev) == 0) {
assert(ev.pl_state == PMCLOG_OK);
@@ -524,7 +524,17 @@
PMCSTAT_PRINT_ENTRY("closelog",);
break;
case PMCLOG_TYPE_DROPNOTIFY:
- PMCSTAT_PRINT_ENTRY("drop",);
+ dnf = ev.pl_u.pl_dn.pl_flags;
+ PMCSTAT_PRINT_ENTRY("drop",
+ "0x%x cpu=%u count=%u%s%s%s",
+ ev.pl_u.pl_dn.pl_pmcid, ev.pl_u.pl_dn.pl_cpu,
+ ev.pl_u.pl_dn.pl_count,
+ (dnf & PMCLOG_DROP_BUFFERFULL) != 0 ?
+ " bufferfull" : "",
+ (dnf & PMCLOG_DROP_THROTTLED) != 0 ?
+ " throttled" : "",
+ (dnf & PMCLOG_DROP_USERCC) != 0 ?
+ " usercallchain" : "");
break;
case PMCLOG_TYPE_INITIALIZE:
PMCSTAT_PRINT_ENTRY("initlog",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 19, 5:14 PM (22 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41845988
Default Alt Text
D61373.1795108444.diff (19 KB)
Attached To
Mode
D61373: hwpmc: log sample drops
Attached
Detach File
Event Timeline