about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2024-06-01 16:34:50 +0200
committerGitHub <noreply@github.com>2024-06-01 16:34:50 +0200
commitca55858aa7ecb1a4cd420e3c325fe604a5b5c30d (patch)
tree34bb1853847ce6ee80ffe57c3ce581195be3238f
parente13dc9b7e63c72ec4eca9a7baa8f226a15d3a040 (diff)
parente639521b01e2abf33a7713f21787cc3e7f9f8df0 (diff)
downloadafl++-ca55858aa7ecb1a4cd420e3c325fe604a5b5c30d.tar.gz
Merge pull request #2107 from AFLplusplus/reg
fix regression
-rw-r--r--docs/Changelog.md3
-rw-r--r--src/afl-common.c45
2 files changed, 11 insertions, 37 deletions
diff --git a/docs/Changelog.md b/docs/Changelog.md
index 058e42af..ba7eb6a3 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -5,6 +5,9 @@
 
 ### Version ++4.21a (dev)
   * afl-fuzz
+    - fixed a regression in afl-fuzz that resulted in a 5-10% performace loss
+      do a switch from gettimeofday() to clock_gettime() which should be rather
+      three times faster. The reason for this is unknown.
     - added AFL_DISABLE_REDUNDANT for huge queues
     - fix AFL_PERSISTENT_RECORD
     - run custom_post_process after standard trimming
diff --git a/src/afl-common.c b/src/afl-common.c
index 8af49e19..efdb5d60 100644
--- a/src/afl-common.c
+++ b/src/afl-common.c
@@ -59,27 +59,6 @@ u8  last_intr = 0;
   #define AFL_PATH "/usr/local/lib/afl/"
 #endif
 
-/* - Some BSD (i.e.: FreeBSD) offer the FAST clock source as
- *   equivalent to Linux COARSE clock source. Aliasing COARSE to
- *   FAST on such systems when COARSE is not already defined.
- * - macOS has no support of CLOCK_MONOTONIC_COARSE clock type.
- */
-#if defined(OS_DARWIN) || defined(OS_SUNOS) || defined(__APPLE__) || \
-    defined(__sun) || defined(__NetBSD__)
-  #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
-#elif defined(OS_FREEBSD)
-  #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
-#endif
-
-/* Convert seconds to milliseconds. */
-#define SEC_TO_MS(sec) ((sec) * 1000)
-/* Convert seconds to microseconds. */
-#define SEC_TO_US(sec) ((sec) * 1000000)
-/* Convert nanoseconds to milliseconds. */
-#define NS_TO_MS(ns) ((ns) / 1000000)
-/* Convert nanoseconds to microseconds. */
-#define NS_TO_US(ns) ((ns) / 1000)
-
 void *afl_memmem(const void *haystack, size_t haystacklen, const void *needle,
                  size_t needlelen) {
 
@@ -997,16 +976,12 @@ void read_bitmap(u8 *fname, u8 *map, size_t len) {
 
 inline u64 get_cur_time(void) {
 
-  struct timespec ts;
-  int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
-  if (unlikely(rc == -1)) {
+  struct timeval  tv;
+  struct timezone tz;
 
-    PFATAL("Failed to obtain timestamp (errno = %i: %s)\n", errno,
-           strerror(errno));
+  gettimeofday(&tv, &tz);
 
-  }
-
-  return SEC_TO_MS((uint64_t)ts.tv_sec) + NS_TO_MS((uint64_t)ts.tv_nsec);
+  return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000);
 
 }
 
@@ -1014,16 +989,12 @@ inline u64 get_cur_time(void) {
 
 inline u64 get_cur_time_us(void) {
 
-  struct timespec ts;
-  int             rc = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
-  if (unlikely(rc == -1)) {
+  struct timeval  tv;
+  struct timezone tz;
 
-    PFATAL("Failed to obtain timestamp (errno = %i: %s)\n", errno,
-           strerror(errno));
-
-  }
+  gettimeofday(&tv, &tz);
 
-  return SEC_TO_US((uint64_t)ts.tv_sec) + NS_TO_US((uint64_t)ts.tv_nsec);
+  return (tv.tv_sec * 1000000ULL) + tv.tv_usec;
 
 }