clock: replace all up_perf_xx with perf_xx

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
yinshengkai 2023-09-28 16:37:27 +08:00 committed by Mateusz Szafoni
parent b99820744c
commit ddb87d3b86
17 changed files with 86 additions and 148 deletions

View File

@ -234,20 +234,13 @@ static void note_common(FAR struct tcb_s *tcb,
FAR struct note_common_s *note,
uint8_t length, uint8_t type)
{
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
struct timespec perftime;
#endif
struct timespec ts;
clock_systime_timespec(&ts);
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
up_perf_convert(up_perf_gettime(), &perftime);
ts.tv_nsec = perftime.tv_nsec;
#endif
perf_convert(perf_gettime(), &ts);
/* Save all of the common fields */
note->nc_length = length;
note->nc_type = type;
note->nc_length = length;
note->nc_type = type;
if (tcb == NULL)
{

View File

@ -41,11 +41,7 @@ struct notesnap_chunk_s
uint8_t cpu;
#endif
pid_t pid;
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
unsigned long count;
#else
struct timespec time;
#endif
clock_t count;
uintptr_t args;
};
@ -216,11 +212,7 @@ static inline void notesnap_common(FAR struct note_driver_s *drv,
#ifdef CONFIG_SMP
note->cpu = tcb->cpu;
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
note->count = up_perf_gettime();
#else
clock_systime_timespec(&note->time);
#endif
note->count = perf_gettime();
note->pid = tcb->pid;
note->args = args;
}
@ -379,14 +371,11 @@ void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
{
size_t i;
size_t index = g_notesnap.index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS;
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
uint32_t lastcount = g_notesnap.buffer[index].count;
clock_t lastcount = g_notesnap.buffer[index].count;
struct timespec lasttime =
{
0
};
#endif
/* Stop recording while dumping */
@ -397,15 +386,13 @@ void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
{
FAR struct notesnap_chunk_s *note = &g_notesnap.buffer[i];
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
struct timespec time;
unsigned long elapsed = note->count < lastcount ?
note->count + UINT32_MAX - lastcount :
note->count - lastcount;
up_perf_convert(elapsed, &time);
clock_t elapsed = note->count < lastcount ?
note->count + CLOCK_MAX - lastcount :
note->count - lastcount;
perf_convert(elapsed, &time);
clock_timespec_add(&lasttime, &time, &lasttime);
lastcount = note->count;
#endif
lib_sprintf(stream,
"snapshoot: [%u.%09u] "
@ -413,12 +400,8 @@ void notesnap_dump_with_stream(FAR struct lib_outstream_s *stream)
"[CPU%d] "
#endif
"[%d] %-16s %#" PRIxPTR "\n",
#ifdef CONFIG_SCHED_INSTRUMENTATION_PERFCOUNT
(unsigned)lasttime.tv_sec,
(unsigned)lasttime.tv_nsec,
#else
(unsigned)note->time.tv_sec, (unsigned)note->time.tv_nsec,
#endif
#ifdef CONFIG_SMP
note->cpu,
#endif

View File

@ -28,6 +28,7 @@
#include <inttypes.h>
#include <string.h>
#include <sys/param.h>
#include <time.h>
#include "rptun.h"
@ -121,11 +122,11 @@ static int rptun_ping_once(FAR struct rpmsg_endpoint *ept,
return ret;
}
static void rptun_ping_logout(FAR const char *s, unsigned long value)
static void rptun_ping_logout(FAR const char *s, clock_t value)
{
struct timespec ts;
up_perf_convert(value, &ts);
perf_convert(value, &ts);
#ifdef CONFIG_SYSTEM_TIME64
syslog(LOG_INFO, "%s: s %" PRIu64 ", ns %ld\n", s, ts.tv_sec, ts.tv_nsec);
@ -141,8 +142,8 @@ static void rptun_ping_logout(FAR const char *s, unsigned long value)
int rptun_ping(FAR struct rpmsg_endpoint *ept,
FAR const struct rptun_ping_s *ping)
{
unsigned long min = ULONG_MAX;
unsigned long max = 0;
clock_t min = ULONG_MAX;
clock_t max = 0;
uint64_t total = 0;
int i;
@ -153,7 +154,7 @@ int rptun_ping(FAR struct rpmsg_endpoint *ept,
for (i = 0; i < ping->times; i++)
{
unsigned long tm = up_perf_gettime();
clock_t tm = perf_gettime();
int ret = rptun_ping_once(ept, ping->len, ping->ack);
if (ret < 0)
@ -161,7 +162,7 @@ int rptun_ping(FAR struct rpmsg_endpoint *ept,
return ret;
}
tm = up_perf_gettime() - tm;
tm = perf_gettime() - tm;
min = MIN(min, tm);
max = MAX(max, tm);
total += tm;
@ -169,8 +170,7 @@ int rptun_ping(FAR struct rpmsg_endpoint *ept,
usleep(ping->sleep * USEC_PER_MSEC);
}
syslog(LOG_INFO, "current CPU freq: %lu, ping times: %d\n",
up_perf_getfreq(), ping->times);
syslog(LOG_INFO, "ping times: %d\n", ping->times);
rptun_ping_logout("avg", total / ping->times);
rptun_ping_logout("min", min);

View File

@ -350,7 +350,7 @@ unsigned int note_sysview_get_interrupt_id(void)
unsigned long note_sysview_get_timestamp(void)
{
return up_perf_gettime();
return perf_gettime();
}
/****************************************************************************
@ -369,7 +369,7 @@ unsigned long note_sysview_get_timestamp(void)
int note_sysview_initialize(void)
{
unsigned long freq = up_perf_getfreq();
unsigned long freq = perf_getfreq();
int ret;
static const SEGGER_SYSVIEW_OS_API g_sysview_trace_api =

View File

@ -191,7 +191,7 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
if (g_premp_max[cpu] > 0)
{
up_perf_convert(g_premp_max[cpu], &maxtime);
perf_convert(g_premp_max[cpu], &maxtime);
}
else
{
@ -222,7 +222,7 @@ static ssize_t critmon_read_cpu(FAR struct critmon_file_s *attr,
if (g_crit_max[cpu] > 0)
{
up_perf_convert(g_crit_max[cpu], &maxtime);
perf_convert(g_crit_max[cpu], &maxtime);
}
else
{

View File

@ -775,7 +775,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
if (tcb->premp_max > 0)
{
up_perf_convert(tcb->premp_max, &maxtime);
perf_convert(tcb->premp_max, &maxtime);
}
else
{
@ -808,7 +808,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
if (tcb->crit_max > 0)
{
up_perf_convert(tcb->crit_max, &maxtime);
perf_convert(tcb->crit_max, &maxtime);
}
else
{
@ -841,7 +841,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
if (tcb->run_max > 0)
{
up_perf_convert(tcb->run_max, &maxtime);
perf_convert(tcb->run_max, &maxtime);
}
else
{
@ -852,7 +852,7 @@ static ssize_t proc_critmon(FAR struct proc_file_s *procfile,
/* Reset the maximum */
tcb->run_max = 0;
up_perf_convert(tcb->run_time, &runtime);
perf_convert(tcb->run_time, &runtime);
/* Output the maximum time the thread has run and
* the total time the thread has run

View File

@ -232,6 +232,12 @@
#define TIMER_MAX _POSIX_TIMER_MAX
#define CLOCKRES_MIN _POSIX_CLOCKRES_MIN
#ifdef CONFIG_SYSTEM_TIME64
# define CLOCK_MAX UINT64_MAX
#else
# define CLOCK_MAX UINT32_MAX
#endif
/* Other invariant values */
/* CHARCLASS_NAME_MAX

View File

@ -631,13 +631,13 @@ struct tcb_s
/* Pre-emption monitor support ********************************************/
#ifdef CONFIG_SCHED_CRITMONITOR
unsigned long premp_start; /* Time when preemption disabled */
unsigned long premp_max; /* Max time preemption disabled */
unsigned long crit_start; /* Time critical section entered */
unsigned long crit_max; /* Max time in critical section */
unsigned long run_start; /* Time when thread begin run */
unsigned long run_max; /* Max time thread run */
unsigned long run_time; /* Total time thread run */
clock_t premp_start; /* Time when preemption disabled */
clock_t premp_max; /* Max time preemption disabled */
clock_t crit_start; /* Time critical section entered */
clock_t crit_max; /* Max time in critical section */
clock_t run_start; /* Time when thread begin run */
clock_t run_max; /* Max time thread run */
clock_t run_time; /* Total time thread run */
#endif
/* State save areas *******************************************************/
@ -762,8 +762,8 @@ extern "C"
#ifdef CONFIG_SCHED_CRITMONITOR
/* Maximum time with pre-emption disabled or within critical section. */
EXTERN unsigned long g_premp_max[CONFIG_SMP_NCPUS];
EXTERN unsigned long g_crit_max[CONFIG_SMP_NCPUS];
EXTERN clock_t g_premp_max[CONFIG_SMP_NCPUS];
EXTERN clock_t g_crit_max[CONFIG_SMP_NCPUS];
#endif /* CONFIG_SCHED_CRITMONITOR */
EXTERN const struct tcbinfo_s g_tcbinfo;

View File

@ -1080,14 +1080,6 @@ config SCHED_INSTRUMENTATION_CPUSET
---help---
Monitor only CPUs in the bitset. Bit 0=CPU0, Bit1=CPU1, etc.
config SCHED_INSTRUMENTATION_PERFCOUNT
bool "Use perf count for instrumentation"
default n
---help---
Enabling this option will use perfcount as the clock source for tv_nsec
to achieve higher precision time.
This requires calling up_perf_init at system startup.
config SCHED_INSTRUMENTATION_FILTER
bool "Instrumentation filter"
default n

View File

@ -155,7 +155,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
if (tcb != NULL)
{
up_perf_convert(tcb->run_time, tp);
perf_convert(tcb->run_time, tp);
}
else
{
@ -197,7 +197,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
}
leave_critical_section(flags);
up_perf_convert(runtime, tp);
perf_convert(runtime, tp);
}
else
{

View File

@ -60,13 +60,8 @@ struct irq_info_s
FAR void *arg; /* The argument provided to the interrupt handler. */
#ifdef CONFIG_SCHED_IRQMONITOR
clock_t start; /* Time interrupt attached */
#ifdef CONFIG_HAVE_LONG_LONG
uint64_t count; /* Number of interrupts on this IRQ */
#else
uint32_t mscount; /* Number of interrupts on this IRQ (MS) */
uint32_t lscount; /* Number of interrupts on this IRQ (LS) */
#endif
uint32_t time; /* Maximum execution time on this IRQ */
clock_t time; /* Maximum execution time on this IRQ */
uint32_t count; /* Number of interrupts on this IRQ */
#endif
};

View File

@ -117,12 +117,8 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
g_irqvector[ndx].arg = arg;
#ifdef CONFIG_SCHED_IRQMONITOR
g_irqvector[ndx].start = clock_systime_ticks();
#ifdef CONFIG_HAVE_LONG_LONG
g_irqvector[ndx].time = 0;
g_irqvector[ndx].count = 0;
#else
g_irqvector[ndx].mscount = 0;
g_irqvector[ndx].lscount = 0;
#endif
#endif
leave_critical_section(flags);

View File

@ -45,29 +45,6 @@
# define NUSER_IRQS NR_IRQS
#endif
/* INCR_COUNT - Increment the count of interrupts taken on this IRQ number */
#ifndef CONFIG_SCHED_IRQMONITOR
# define INCR_COUNT(ndx)
#elif defined(CONFIG_HAVE_LONG_LONG)
# define INCR_COUNT(ndx) \
do \
{ \
g_irqvector[ndx].count++; \
} \
while (0)
#else
# define INCR_COUNT(ndx) \
do \
{ \
if (++g_irqvector[ndx].lscount == 0) \
{ \
g_irqvector[ndx].mscount++; \
} \
} \
while (0)
#endif
/* CALL_VECTOR - Call the interrupt service routine attached to this
* interrupt request
*/
@ -80,14 +57,14 @@
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
do \
{ \
unsigned long start; \
unsigned long elapsed; \
start = up_perf_gettime(); \
clock_t start; \
clock_t elapsed; \
start = perf_gettime(); \
vector(irq, context, arg); \
elapsed = up_perf_gettime() - start; \
elapsed = perf_gettime() - start; \
if (ndx < NUSER_IRQS) \
{ \
INCR_COUNT(ndx); \
g_irqvector[ndx].count++; \
if (elapsed > g_irqvector[ndx].time) \
{ \
g_irqvector[ndx].time = elapsed; \
@ -96,8 +73,8 @@
if (CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ > 0 && \
elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ) \
{ \
CRITMONITOR_PANIC("IRQ %d(%p), execute time too long %lu\n", \
irq, vector, elapsed); \
CRITMONITOR_PANIC("IRQ %d(%p), execute time too long %ju\n", \
irq, vector, (uintmax_t)elapsed); \
} \
} \
while (0)

View File

@ -159,15 +159,10 @@ static int irq_callback(int irq, FAR struct irq_info_s *info,
flags = enter_critical_section();
memcpy(&copy, info, sizeof(struct irq_info_s));
now = clock_systime_ticks();
info->start = now;
#ifdef CONFIG_HAVE_LONG_LONG
info->count = 0;
#else
info->mscount = 0;
info->lscount = 0;
#endif
info->time = 0;
now = clock_systime_ticks();
info->start = now;
info->time = 0;
info->count = 0;
leave_critical_section(flags);
/* Don't bother if count == 0.
@ -201,7 +196,7 @@ static int irq_callback(int irq, FAR struct irq_info_s *info,
*/
elapsed = now - copy.start;
up_perf_convert(copy.time, &delta);
perf_convert(copy.time, &delta);
#ifdef CONFIG_HAVE_LONG_LONG
/* elapsed = <current-time> - <start-time>, units=clock ticks

View File

@ -28,6 +28,7 @@
#include <sched.h>
#include <assert.h>
#include <debug.h>
#include <time.h>
#include "sched/sched.h"
@ -103,8 +104,8 @@
/* Start time when pre-emption disabled or critical section entered. */
static unsigned long g_premp_start[CONFIG_SMP_NCPUS];
static unsigned long g_crit_start[CONFIG_SMP_NCPUS];
static clock_t g_premp_start[CONFIG_SMP_NCPUS];
static clock_t g_crit_start[CONFIG_SMP_NCPUS];
/****************************************************************************
* Public Data
@ -112,8 +113,8 @@ static unsigned long g_crit_start[CONFIG_SMP_NCPUS];
/* Maximum time with pre-emption disabled or within critical section. */
unsigned long g_premp_max[CONFIG_SMP_NCPUS];
unsigned long g_crit_max[CONFIG_SMP_NCPUS];
clock_t g_premp_max[CONFIG_SMP_NCPUS];
clock_t g_crit_max[CONFIG_SMP_NCPUS];
/****************************************************************************
* Public Functions
@ -141,15 +142,15 @@ void nxsched_critmon_preemption(FAR struct tcb_s *tcb, bool state)
{
/* Disabling.. Save the thread start time */
tcb->premp_start = up_perf_gettime();
tcb->premp_start = perf_gettime();
g_premp_start[cpu] = tcb->premp_start;
}
else
{
/* Re-enabling.. Check for the max elapsed time */
unsigned long now = up_perf_gettime();
unsigned long elapsed = now - tcb->premp_start;
clock_t now = perf_gettime();
clock_t elapsed = now - tcb->premp_start;
if (elapsed > tcb->premp_max)
{
@ -189,15 +190,15 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state)
{
/* Entering... Save the start time. */
tcb->crit_start = up_perf_gettime();
tcb->crit_start = perf_gettime();
g_crit_start[cpu] = tcb->crit_start;
}
else
{
/* Leaving .. Check for the max elapsed time */
unsigned long now = up_perf_gettime();
unsigned long elapsed = now - tcb->crit_start;
clock_t now = perf_gettime();
clock_t elapsed = now - tcb->crit_start;
if (elapsed > tcb->crit_max)
{
@ -230,9 +231,9 @@ void nxsched_critmon_csection(FAR struct tcb_s *tcb, bool state)
void nxsched_resume_critmon(FAR struct tcb_s *tcb)
{
unsigned long current = up_perf_gettime();
clock_t current = perf_gettime();
int cpu = this_cpu();
unsigned long elapsed;
clock_t elapsed;
tcb->run_start = current;
@ -294,11 +295,11 @@ void nxsched_resume_critmon(FAR struct tcb_s *tcb)
void nxsched_suspend_critmon(FAR struct tcb_s *tcb)
{
unsigned long current = up_perf_gettime();
unsigned long elapsed = current - tcb->run_start;
clock_t current = perf_gettime();
clock_t elapsed = current - tcb->run_start;
#ifdef CONFIG_SCHED_CPULOAD_CRITMONITOR
unsigned long tick = elapsed * CLOCKS_PER_SEC / up_perf_getfreq();
clock_t tick = elapsed * CLOCKS_PER_SEC / perf_getfreq();
nxsched_process_taskload_ticks(tcb, tick);
#endif

View File

@ -52,16 +52,16 @@
# define CALL_FUNC(func, arg) \
do \
{ \
unsigned long start; \
unsigned long elapsed; \
start = up_perf_gettime(); \
clock_t start; \
clock_t elapsed; \
start = perf_gettime(); \
func(arg); \
elapsed = up_perf_gettime() - start; \
elapsed = perf_gettime() - start; \
if (elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_WDOG) \
{ \
CRITMONITOR_PANIC("WDOG %p, %s IRQ, execute too long %lu\n", \
CRITMONITOR_PANIC("WDOG %p, %s IRQ, execute too long %ju\n", \
func, up_interrupt_context() ? \
"IN" : "NOT", elapsed); \
"IN" : "NOT", (uintmax_t)elapsed); \
} \
} \
while (0)

View File

@ -55,15 +55,15 @@
# define CALL_WORKER(worker, arg) \
do \
{ \
unsigned long start; \
unsigned long elapsed; \
start = up_perf_gettime(); \
clock_t start; \
clock_t elapsed; \
start = perf_gettime(); \
worker(arg); \
elapsed = up_perf_gettime() - start; \
elapsed = perf_gettime() - start; \
if (elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_WQUEUE) \
{ \
CRITMONITOR_PANIC("WORKER %p execute too long %lu\n", \
worker, elapsed); \
CRITMONITOR_PANIC("WORKER %p execute too long %ju\n", \
worker, (uintmax_t)elapsed); \
} \
} \
while (0)