Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add KCOV_LOAD() and KCOV_STORE() - new helper macros
details: https://anonhg.NetBSD.org/src/rev/cc23cca166ff
branches: trunk
changeset: 839544:cc23cca166ff
user: kamil <kamil%NetBSD.org@localhost>
date: Sun Feb 24 21:14:43 2019 +0000
description:
Add KCOV_LOAD() and KCOV_STORE() - new helper macros
New macros prefer 64-bit atomic operations whenever accessible.
As a fallback they use volatile move operations that are not known
to have negative effect in KCOV even if interrupted in the middle of
operation.
Enable kcov_basic and kcov_thread tests on targets without
__HAVE_ATOMIC64_OPS.
diffstat:
sys/sys/kcov.h | 21 ++++++++++++++++++++-
tests/modules/t_kcov.c | 10 ++++------
2 files changed, 24 insertions(+), 7 deletions(-)
diffs (78 lines):
diff -r 8752d341afe4 -r cc23cca166ff sys/sys/kcov.h
--- a/sys/sys/kcov.h Sun Feb 24 21:07:59 2019 +0000
+++ b/sys/sys/kcov.h Sun Feb 24 21:14:43 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kcov.h,v 1.1 2019/02/23 03:10:06 kamil Exp $ */
+/* $NetBSD: kcov.h,v 1.2 2019/02/24 21:14:43 kamil Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -32,6 +32,10 @@
#ifndef _SYS_KCOV_H_
#define _SYS_KCOV_H_
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/atomic.h>
+
#define KCOV_IOC_SETBUFSIZE _IOW('K', 1, uint64_t)
#define KCOV_IOC_ENABLE _IO('K', 2)
#define KCOV_IOC_DISABLE _IO('K', 3)
@@ -39,4 +43,19 @@
typedef volatile uint64_t kcov_int_t;
#define KCOV_ENTRY_SIZE sizeof(kcov_int_t)
+/*
+ * Always prefer 64-bit atomic operations whenever accessible.
+ *
+ * As a fallback keep regular volatile move operation that it's not known
+ * to have negative effect in KCOV even if interrupted in the middle of
+ * operation.
+ */
+#ifdef __HAVE_ATOMIC64_OPS
+#define KCOV_STORE(x,v) __atomic_store_n(&(x), (v), __ATOMIC_RELAXED)
+#define KCOV_LOAD(x) __atomic_load_n(&(x), __ATOMIC_RELAXED)
+#else
+#define KCOV_STORE(x,v) (x) = (y)
+#define KCOV_LOAD(x) (x)
+#endif
+
#endif /* !_SYS_KCOV_H_ */
diff -r 8752d341afe4 -r cc23cca166ff tests/modules/t_kcov.c
--- a/tests/modules/t_kcov.c Sun Feb 24 21:07:59 2019 +0000
+++ b/tests/modules/t_kcov.c Sun Feb 24 21:14:43 2019 +0000
@@ -254,10 +254,10 @@
ATF_REQUIRE_MSG(ioctl(fd, KCOV_IOC_ENABLE) == 0,
"Unable to enable kcov ");
- __atomic_store_n(&buf[0], 0 , __ATOMIC_RELAXED);
+ KCOV_STORE(&buf[0], 0);
sleep(0);
- ATF_REQUIRE_MSG(__atomic_load_n(&buf[0], __ATOMIC_RELAXED) != 0, "No records found");
+ ATF_REQUIRE_MSG(KCOV_LOAD(&buf[0]) != 0, "No records found");
ATF_REQUIRE_MSG(ioctl(fd, KCOV_IOC_DISABLE) == 0,
"Unable to disable kcov");
@@ -270,9 +270,9 @@
{
kcov_int_t *buf = ptr;
- __atomic_store_n(&buf[0], 0, __ATOMIC_RELAXED);
+ KCOV_STORE(&buf[0], 0);
sleep(0);
- ATF_REQUIRE_MSG(__atomic_load_n(&buf[0], __ATOMIC_RELAXED) == 0,
+ ATF_REQUIRE_MSG(KCOV_LOAD(&buf[0]) == 0,
"Records changed in blocked thread");
return NULL;
@@ -311,9 +311,7 @@
ATF_TP_ADD_TC(tp, kcov_enable_no_disable);
ATF_TP_ADD_TC(tp, kcov_enable_no_disable_no_close);
ATF_TP_ADD_TC(tp, kcov_mmap_enable_thread_close);
-#ifdef __HAVE_ATOMIC64_OPS
ATF_TP_ADD_TC(tp, kcov_basic);
ATF_TP_ADD_TC(tp, kcov_thread);
-#endif
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index