This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2448e8a59e arch/x86_64:Add perf tool
2448e8a59e is described below

commit 2448e8a59e2dc7e96713ca3916ab2b8b4f262fdc
Author: liwenxiang1 <liwenxia...@xiaomi.com>
AuthorDate: Thu Oct 10 10:05:34 2024 +0800

    arch/x86_64:Add perf tool
    
    Signed-off-by: liwenxiang1 <liwenxia...@xiaomi.com>
---
 arch/Kconfig                           |  1 +
 arch/x86_64/src/intel64/CMakeLists.txt |  4 ++
 arch/x86_64/src/intel64/Make.defs      |  5 +++
 arch/x86_64/src/intel64/intel64_perf.c | 68 ++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index d1fd94c5dd..2d0af2d6d6 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -145,6 +145,7 @@ config ARCH_X86_64
        select ARCH_HAVE_BACKTRACE
        select ARCH_HAVE_FORK
        select ARCH_HAVE_SETJMP
+       select ARCH_HAVE_PERF_EVENTS
        ---help---
                x86-64 architectures.
 
diff --git a/arch/x86_64/src/intel64/CMakeLists.txt 
b/arch/x86_64/src/intel64/CMakeLists.txt
index 956e0ac57a..c575aa92d8 100644
--- a/arch/x86_64/src/intel64/CMakeLists.txt
+++ b/arch/x86_64/src/intel64/CMakeLists.txt
@@ -56,6 +56,10 @@ if(CONFIG_STACK_COLORATION)
   list(APPEND SRCS intel64_checkstack.c)
 endif()
 
+if(CONFIG_ARCH_PERF_EVENTS)
+  list(APPEND SRCS intel64_perf.c)
+endif()
+
 if(CONFIG_MM_PGALLOC)
   list(APPEND SRCS intel64_pgalloc.c)
 endif()
diff --git a/arch/x86_64/src/intel64/Make.defs 
b/arch/x86_64/src/intel64/Make.defs
index 7a8bd25817..52cf364ea3 100644
--- a/arch/x86_64/src/intel64/Make.defs
+++ b/arch/x86_64/src/intel64/Make.defs
@@ -37,10 +37,15 @@ CHIP_CSRCS += intel64_cpu.c
 ifeq ($(CONFIG_x86_64_UNWINDER_FRAME_POINTER),y)
   CMN_CSRCS += intel64_backtrace_fp.c
 endif
+
 ifeq ($(CONFIG_STACK_COLORATION),y)
   CMN_CSRCS += intel64_checkstack.c
 endif
 
+#ifdef CONFIG_ARCH_PERF_EVENTS
+  CMN_CSRCS += intel64_perf.c
+#endif
+
 ifeq ($(CONFIG_MM_PGALLOC),y)
 CHIP_CSRCS += intel64_pgalloc.c
 endif
diff --git a/arch/x86_64/src/intel64/intel64_perf.c 
b/arch/x86_64/src/intel64/intel64_perf.c
new file mode 100644
index 0000000000..55fd8e8a85
--- /dev/null
+++ b/arch/x86_64/src/intel64/intel64_perf.c
@@ -0,0 +1,68 @@
+/****************************************************************************
+ * arch/x86_64/src/intel64/intel64_perf.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+
+#include "x86_64_internal.h"
+
+#ifdef CONFIG_ARCH_PERF_EVENTS
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+extern unsigned long g_x86_64_timer_freq;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void up_perf_init(void *arg)
+{
+  /* The default tsc will be turned on when the system starts */
+
+  UNUSED(arg);
+}
+
+unsigned long up_perf_getfreq(void)
+{
+  return g_x86_64_timer_freq;
+}
+
+clock_t up_perf_gettime(void)
+{
+  return rdtscp();
+}
+
+void up_perf_convert(clock_t elapsed, struct timespec *ts)
+{
+  clock_t left;
+
+  ts->tv_sec  = elapsed / g_x86_64_timer_freq;
+  left        = elapsed - ts->tv_sec * g_x86_64_timer_freq;
+  ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_x86_64_timer_freq;
+}
+#endif
+

Reply via email to