Page MenuHomeFreeBSD

D61770.1795200846.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D61770.1795200846.diff

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
@@ -545,7 +545,7 @@
static uint32_t *
pmclog_reserve(struct pmc_owner *po, int length)
{
- uintptr_t newptr, oldptr __diagused;
+ uintptr_t newptr, oldptr;
struct pmclog_buffer *plb, **pplb;
PMCDBG2(LOG,ALL,1, "po=%p len=%d", po, length);
@@ -608,7 +608,13 @@
__LINE__, po, plb->plb_ptr, plb->plb_base,
plb->plb_fence));
+ /* Claim the space in the fresh buffer, as above. */
oldptr = (uintptr_t) plb->plb_ptr;
+ newptr = oldptr + length;
+ KASSERT(newptr <= (uintptr_t) plb->plb_fence,
+ ("[pmclog,%d] po=%p record of %d bytes exceeds a buffer",
+ __LINE__, po, length));
+ plb->plb_ptr = (char *) newptr;
done:
return ((uint32_t *) oldptr);
diff --git a/tests/sys/pmc/pmc_log_test.c b/tests/sys/pmc/pmc_log_test.c
--- a/tests/sys/pmc/pmc_log_test.c
+++ b/tests/sys/pmc/pmc_log_test.c
@@ -49,12 +49,16 @@
*/
#include <sys/param.h>
+#include <sys/cpuset.h>
#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <pmc.h>
+#include <pmclog.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
@@ -436,6 +440,87 @@
ATF_CHECK(pmc_release(id) == 0);
}
+#define SPAN_MARKER 0x53500000U
+#define SPAN_INDEX 0x000fffffU
+
+/**
+ * @internal
+ * Write records on one CPU until they fill more than three log buffers.
+ * A record that does not fit the end of a buffer starts the next buffer.
+ * The record after it must not overwrite it.
+ */
+ATF_TC_WITHOUT_HEAD(records_span_buffers);
+ATF_TC_BODY(records_span_buffers, tc)
+{
+ struct pmclog_ev ev;
+ struct stat sb;
+ cpuset_t set;
+ void *parser;
+ size_t len;
+ off_t min;
+ int bufkb, cpu, fd, i, n, seen;
+
+ require_hwpmc();
+ len = sizeof(bufkb);
+ ATF_REQUIRE_MSG(sysctlbyname("kern.hwpmc.logbuffersize", &bufkb,
+ &len, NULL, 0) == 0, "kern.hwpmc.logbuffersize: %s",
+ strerror(errno));
+ n = 3 * bufkb * 1024 / (int)sizeof(struct pmclog_userdata) + 1;
+ ATF_REQUIRE(n <= (int)SPAN_INDEX);
+
+ /* Each CPU has its own buffer: keep all writes on one CPU. */
+ ATF_REQUIRE(cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1,
+ sizeof(set), &set) == 0);
+ cpu = CPU_FFS(&set) - 1;
+ ATF_REQUIRE(cpu >= 0);
+ CPU_SETOF(cpu, &set);
+ ATF_REQUIRE_MSG(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ -1, sizeof(set), &set) == 0, "cannot pin to CPU %d: %s", cpu,
+ strerror(errno));
+
+ fd = work_file("span.pmclog");
+ ATF_REQUIRE_MSG(pmc_configure_logfile(fd) == 0,
+ "pmc_configure_logfile: %s", strerror(errno));
+ for (i = 0; i < n; i++)
+ ATF_REQUIRE_MSG(pmc_writelog(SPAN_MARKER | i) == 0,
+ "pmc_writelog(%d): %s", i, strerror(errno));
+ ATF_REQUIRE_MSG(pmc_close_logfile() == 0, "pmc_close_logfile: %s",
+ strerror(errno));
+ /*
+ * Let the writer write all the queued buffers before the log stops.
+ * If records are lost, the file stays short and the wait ends at the
+ * deadline.
+ */
+ min = (off_t)n * sizeof(struct pmclog_userdata) +
+ sizeof(struct pmclog_closelog);
+ for (i = 0; i < 500; i++) {
+ ATF_REQUIRE(fstat(fd, &sb) == 0);
+ if (sb.st_size >= min)
+ break;
+ (void)usleep(10000);
+ }
+ ATF_REQUIRE_MSG(pmc_configure_logfile(-1) == 0,
+ "pmc_configure_logfile(-1): %s", strerror(errno));
+
+ ATF_REQUIRE(lseek(fd, 0, SEEK_SET) == 0);
+ ATF_REQUIRE((parser = pmclog_open(fd)) != NULL);
+ seen = 0;
+ while (pmclog_read(parser, &ev) == 0) {
+ if (ev.pl_type != PMCLOG_TYPE_USERDATA ||
+ (ev.pl_u.pl_u.pl_userdata & ~SPAN_INDEX) != SPAN_MARKER)
+ continue;
+ ATF_CHECK_MSG((int)(ev.pl_u.pl_u.pl_userdata & SPAN_INDEX) ==
+ seen, "record %d is missing", seen);
+ seen = (ev.pl_u.pl_u.pl_userdata & SPAN_INDEX) + 1;
+ }
+ ATF_CHECK_MSG(ev.pl_state == PMCLOG_EOF,
+ "log parse ended in state %d", ev.pl_state);
+ pmclog_close(parser);
+ (void)close(fd);
+ ATF_CHECK_MSG(seen == n, "the last record seen is %d of %d",
+ seen, n);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -448,6 +533,7 @@
ATF_TP_ADD_TC(tp, log_survives_userland_closing_the_fd);
ATF_TP_ADD_TC(tp, log_write_error_is_reported);
ATF_TP_ADD_TC(tp, owner_exit_with_log_and_running_pmc);
+ ATF_TP_ADD_TC(tp, records_span_buffers);
return (atf_no_error());
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 20, 6:54 PM (14 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41873931
Default Alt Text
D61770.1795200846.diff (4 KB)

Event Timeline