perf: The new configuration supports hardware performance counting

Adding the CONFIG_ARCH_PERF_EVENTS configuration to enable
hardware performance counting,solve the problem that some platform
hardware counting support is not perfect, you can choose to use
software interface.

This is configured using CONFIG_ARCH_PERF_EVENTS, so weak_functions
are removed to prevent confusion

To use hardware performance counting, must:
1. Configure CONFIG_ARCH_PERF_EVENTS, default selection
2. Call up_perf_init for initialization

Signed-off-by: wangming9 <wangming9@xiaomi.com>
This commit is contained in:
wangming9 2023-08-08 11:12:41 +08:00 committed by Xiang Xiao
parent d0613fa165
commit c928acc9ff
22 changed files with 53 additions and 25 deletions

View File

@ -487,6 +487,13 @@ config ARCH_HAVE_BACKTRACE
config ARCH_HAVE_PERF_EVENTS
bool
default n
---help---
The architecture supports hardware performance counting.
config ARCH_PERF_EVENTS
bool "Configure hardware performance counting"
default y
depends on ARCH_HAVE_PERF_EVENTS
---help---
Enable hardware performance counter support for perf events. If
disabled, perf events will use software events only.

View File

@ -47,9 +47,12 @@ list(
arm_syscall.c
arm_tcbinfo.c
arm_undefinedinsn.c
arm_perf.c
cp15_cacheops.c)
if(CONFIG_ARCH_PERF_EVENTS)
list(APPEND SRCS arm_perf.c)
endif()
if(CONFIG_ARMV7A_HAVE_PTM)
list(APPEND SRCS arm_timer.c)
endif()

View File

@ -28,6 +28,8 @@
#include "arm_internal.h"
#include "sctlr.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
@ -85,3 +87,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
#endif

View File

@ -31,7 +31,6 @@ set(SRCS
arm_initialstate.c
arm_itm.c
arm_memfault.c
arm_perf.c
arm_schedulesigaction.c
arm_sigdeliver.c
arm_svcall.c
@ -41,6 +40,10 @@ set(SRCS
arm_usagefault.c
arm_vectors.c)
if(CONFIG_ARCH_PERF_EVENTS)
list(APPEND SRCS arm_perf.c)
endif()
if(CONFIG_ARMV7M_SYSTICK)
list(APPEND SRCS arm_systick.c)
endif()

View File

@ -30,6 +30,8 @@
#include "itm.h"
#include "nvic.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
@ -74,3 +76,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
#endif

View File

@ -28,6 +28,8 @@
#include "arm_internal.h"
#include "sctlr.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
@ -85,3 +87,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
#endif

View File

@ -29,7 +29,6 @@ set(SRCS
arm_initialstate.c
arm_itm.c
arm_memfault.c
arm_perf.c
arm_sau.c
arm_schedulesigaction.c
arm_securefault.c
@ -42,6 +41,10 @@ set(SRCS
arm_usagefault.c
arm_vectors.c)
if(CONFIG_ARCH_PERF_EVENTS)
list(APPEND SRCS arm_perf.c)
endif()
if(CONFIG_ARMV8M_SYSTICK)
list(APPEND SRCS arm_systick.c)
endif()

View File

@ -30,6 +30,8 @@
#include "itm.h"
#include "nvic.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
@ -74,3 +76,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
#endif

View File

@ -26,6 +26,8 @@
#include "arm64_pmu.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Public Functions
****************************************************************************/
@ -58,3 +60,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * left / cpu_freq;
}
#endif

View File

@ -33,6 +33,8 @@
#include "hardware/esp32c3_system.h"
#include "esp32c3_clockconfig.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -82,3 +84,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
elapsed -= ts->tv_sec * CYCLE_PER_SEC;
ts->tv_nsec = elapsed * NSEC_PER_CYCLE;
}
#endif

View File

@ -28,6 +28,8 @@
#include "xtensa_counter.h"
#include "xtensa.h"
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
@ -61,3 +63,4 @@ void up_perf_convert(unsigned long elapsed, struct timespec *ts)
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq;
}
#endif

View File

@ -74,7 +74,6 @@ CONFIG_SYSTEM_SPITOOL=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -77,7 +77,6 @@ CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_TLS_NELEM=4
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128

View File

@ -69,7 +69,6 @@ CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -69,7 +69,6 @@ CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -70,7 +70,6 @@ CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -67,7 +67,6 @@ CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -71,7 +71,6 @@ CONFIG_SYSTEM_SPITOOL=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -70,7 +70,6 @@ CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -75,7 +75,6 @@ CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=12
CONFIG_TESTING_GETPRIME=y
CONFIG_TIMER=y
CONFIG_TIMER_ARCH=y
CONFIG_UART0_BAUD=2000000
CONFIG_UART0_RXBUFSIZE=128
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -356,13 +356,13 @@ int weak_function up_alarm_tick_start(clock_t ticks)
* units.
****************************************************************************/
#ifndef CONFIG_ARCH_HAVE_PERF_EVENTS
void weak_function up_perf_init(FAR void *arg)
#ifndef CONFIG_ARCH_PERF_EVENTS
void up_perf_init(FAR void *arg)
{
UNUSED(arg);
}
unsigned long weak_function up_perf_gettime(void)
unsigned long up_perf_gettime(void)
{
unsigned long ret = 0;
@ -377,17 +377,17 @@ unsigned long weak_function up_perf_gettime(void)
return ret;
}
unsigned long weak_function up_perf_getfreq(void)
unsigned long up_perf_getfreq(void)
{
return USEC_PER_SEC;
}
void weak_function up_perf_convert(unsigned long elapsed,
void up_perf_convert(unsigned long elapsed,
FAR struct timespec *ts)
{
timespec_from_usec(ts, elapsed);
}
#endif /* CONFIG_ARCH_HAVE_PERF_EVENTS */
#endif /* CONFIG_ARCH_PERF_EVENTS */
/****************************************************************************
* Name: up_mdelay

View File

@ -395,13 +395,13 @@ int weak_function up_timer_tick_start(clock_t ticks)
* units.
****************************************************************************/
#ifndef CONFIG_ARCH_HAVE_PERF_EVENTS
void weak_function up_perf_init(FAR void *arg)
#ifndef CONFIG_ARCH_PERF_EVENTS
void up_perf_init(FAR void *arg)
{
UNUSED(arg);
}
unsigned long weak_function up_perf_gettime(void)
unsigned long up_perf_gettime(void)
{
unsigned long ret = 0;
@ -413,17 +413,17 @@ unsigned long weak_function up_perf_gettime(void)
return ret;
}
unsigned long weak_function up_perf_getfreq(void)
unsigned long up_perf_getfreq(void)
{
return USEC_PER_SEC;
}
void weak_function up_perf_convert(unsigned long elapsed,
FAR struct timespec *ts)
void up_perf_convert(unsigned long elapsed,
FAR struct timespec *ts)
{
timespec_from_usec(ts, elapsed);
}
#endif /* CONFIG_ARCH_HAVE_PERF_EVENTS */
#endif /* CONFIG_ARCH_PERF_EVENTS */
/****************************************************************************
* Name: up_mdelay