Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Nov 2024 10:23:24 GMT
From:      Robert Clausecker <fuz@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 05515f175902 - main - benchmarks/libcpucycles: report actual CPU frequency if supported
Message-ID:  <202411251023.4APANObg012570@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by fuz:

URL: https://cgit.FreeBSD.org/ports/commit/?id=05515f1759027c2a2b9bb4ca9e20641a048188ba

commit 05515f1759027c2a2b9bb4ca9e20641a048188ba
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2024-11-20 12:44:21 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2024-11-25 10:22:04 +0000

    benchmarks/libcpucycles: report actual CPU frequency if supported
    
    This uses sched_getcpu(2) to find the CPU we are scheduled on and then
    cpufreq(4) to find the frequency of that CPU.  The caller is responsible
    for pinning the thread to one CPU and/or disabling frequency scaling if
    a consistent result is required.
---
 benchmarks/libcpucycles/Makefile                   |  2 +-
 .../libcpucycles/files/patch-cpucycles_wrapper.c   | 47 +++++++++++++++++++++-
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/benchmarks/libcpucycles/Makefile b/benchmarks/libcpucycles/Makefile
index 4ed732450f6e..d77797b1a73b 100644
--- a/benchmarks/libcpucycles/Makefile
+++ b/benchmarks/libcpucycles/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	libcpucycles
 DISTVERSION=	20240318
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	benchmarks devel
 MASTER_SITES=	https://cpucycles.cr.yp.to/
 
diff --git a/benchmarks/libcpucycles/files/patch-cpucycles_wrapper.c b/benchmarks/libcpucycles/files/patch-cpucycles_wrapper.c
index 40c74c029cd0..703b4a0763c3 100644
--- a/benchmarks/libcpucycles/files/patch-cpucycles_wrapper.c
+++ b/benchmarks/libcpucycles/files/patch-cpucycles_wrapper.c
@@ -1,6 +1,19 @@
---- cpucycles/wrapper.c.orig	2024-10-29 18:59:34 UTC
+--- cpucycles/wrapper.c.orig	2024-03-18 00:15:33 UTC
 +++ cpucycles/wrapper.c
-@@ -26,7 +26,7 @@ void cpucycles_tracesetup(void)
+@@ -16,6 +16,12 @@
+ #include <inttypes.h>
+ #include <signal.h>
+ #include <setjmp.h>
++
++#ifdef __FreeBSD__
++#include <sched.h>
++#include <sys/sysctl.h>
++#endif
++
+ #include "cpucycles.h"
+ #include "cpucycles_internal.h"
+ 
+@@ -26,7 +32,7 @@ void cpucycles_tracesetup(void)
    tracesetup = 1;
  }
  
@@ -9,3 +22,33 @@
  
  static void crash(int s)
  {
+@@ -81,6 +87,21 @@ static double osfreq(void)
+     if (s > 0) return result;
+   }
+ 
++#ifdef __FreeBSD__
++  {
++    int freq;
++    size_t len = sizeof freq;
++    char *freqctl;
++
++    if (asprintf(&freqctl, "dev.cpu.%d.freq", sched_getcpu())) {
++      if (sysctlbyname(freqctl, &freq, &len, NULL, 0) == 0) {
++        free(freqctl);
++        return 1e6 * freq;
++      } else
++        free(freqctl);
++    }
++  }
++#else
+   f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "r");
+   if (f) {
+     s = fscanf(f,"%lf",&result);
+@@ -163,6 +184,7 @@ static double osfreq(void)
+     pclose(f);
+     if (result) return 1000000.0 * result;
+   }
++#endif /* defined(__FreeBSD__) */
+ 
+   x = getenv("cpucyclespersecond");
+   if (x) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202411251023.4APANObg012570>