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

commit d375a09c0a4f6189ea7559273d0c00b4f55a0ccb
Author: yinshengkai <[email protected]>
AuthorDate: Wed Aug 14 17:40:28 2024 +0800

    libs: add gprof arm64 support
    
    Signed-off-by: yinshengkai <[email protected]>
---
 arch/arm64/src/Toolchain.defs        |  4 +++
 arch/arm64/src/cmake/Toolchain.cmake |  4 +++
 include/sys/gmon.h                   | 10 ++++++
 libs/libc/machine/arm64/gnu/mcount.c | 63 ++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+)

diff --git a/arch/arm64/src/Toolchain.defs b/arch/arm64/src/Toolchain.defs
index b785e1d403..58970f4fa5 100644
--- a/arch/arm64/src/Toolchain.defs
+++ b/arch/arm64/src/Toolchain.defs
@@ -88,6 +88,10 @@ ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y)
   ARCHOPTIMIZATION += -finstrument-functions
 endif
 
+ifeq ($(CONFIG_SCHED_GPROF_ALL),y)
+  ARCHOPTIMIZATION += -pg
+endif
+
 ifeq ($(CONFIG_ARCH_FPU),y)
   ARCHCXXFLAGS += -D_LDBL_EQ_DBL
   ARCHCFLAGS   += -D_LDBL_EQ_DBL
diff --git a/arch/arm64/src/cmake/Toolchain.cmake 
b/arch/arm64/src/cmake/Toolchain.cmake
index c1f08d46e3..a8f9838ed1 100644
--- a/arch/arm64/src/cmake/Toolchain.cmake
+++ b/arch/arm64/src/cmake/Toolchain.cmake
@@ -135,6 +135,10 @@ if(CONFIG_ARCH_INSTRUMENT_ALL)
   add_compile_options(-finstrument-functions)
 endif()
 
+if(CONFIG_SCHED_GPROF_ALL)
+  add_compile_options(-pg)
+endif()
+
 if(CONFIG_ARCH_FPU)
   add_compile_options(-D_LDBL_EQ_DBL)
 endif()
diff --git a/include/sys/gmon.h b/include/sys/gmon.h
index b98deef88d..5ad1601271 100644
--- a/include/sys/gmon.h
+++ b/include/sys/gmon.h
@@ -21,6 +21,13 @@
 #ifndef __INCLUDE_SYS_GMON_H
 #define __INCLUDE_SYS_GMON_H
 
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/compiler.h>
+#include <stdint.h>
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -46,6 +53,9 @@ void monstartup(unsigned long lowpc, unsigned long highpc);
 
 void _mcleanup(void);
 
+noinstrument_function
+void mcount_internal(uintptr_t frompc, uintptr_t selfpc);
+
 #undef EXTERN
 #if defined(__cplusplus)
 }
diff --git a/libs/libc/machine/arm64/gnu/mcount.c 
b/libs/libc/machine/arm64/gnu/mcount.c
new file mode 100644
index 0000000000..31e08fa363
--- /dev/null
+++ b/libs/libc/machine/arm64/gnu/mcount.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * libs/libc/machine/arm64/gnu/mcount.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 <sys/gmon.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static inline noinstrument_function void *strip_pac(void *p)
+{
+  register void *ra asm ("x30") = (p);
+  asm ("hint 7 // xpaclri" : "+r"(ra));
+  return ra;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: _mcount
+ *
+ * Description:
+ *   This is the ARM64 mcount function.  It is called by the profiling
+ *   logic to record the call.
+ *
+ * Input Parameters:
+ *   frompc - The address of the calling instruction
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+noinstrument_function
+void _mcount(void *frompc)
+{
+  mcount_internal((uintptr_t)strip_pac(frompc),
+                  (uintptr_t)return_address(0));
+}
+

Reply via email to