arch/x86_64:Add perf tool

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
This commit is contained in:
liwenxiang1 2024-10-10 10:05:34 +08:00 committed by Xiang Xiao
parent f81c7dbc93
commit 2448e8a59e
4 changed files with 78 additions and 0 deletions

View file

@ -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.

View file

@ -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()

View file

@ -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

View file

@ -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