Skip to content

Commit 3d9c8e7

Browse files
hsharma35facebook-github-bot
authored andcommitted
Xtensa ISS PAL layer for logging/timing. (#7311)
Summary: Overrides for `et_pal*` weak symbols for logging/timing with xtensa ISS. Reviewed By: zonglinpeng Differential Revision: D67128599
1 parent 9b4a784 commit 3d9c8e7

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

backends/cadence/runtime/TARGETS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load(":targets.bzl", "define_common_targets")
12
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
23

34
oncall("odai_jarvis")
@@ -22,3 +23,5 @@ python_library(
2223
"//executorch/exir:lib",
2324
],
2425
)
26+
27+
define_common_targets()

backends/cadence/runtime/et_pal.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#if defined(XTENSA)
10+
11+
#include <stdio.h>
12+
#include <sys/times.h>
13+
14+
#include <xtensa/sim.h>
15+
16+
#include <executorch/runtime/platform/platform.h>
17+
18+
#define ET_LOG_OUTPUT_FILE stdout
19+
20+
void et_pal_emit_log_message(
21+
et_timestamp_t timestamp,
22+
et_pal_log_level_t level,
23+
const char* filename,
24+
ET_UNUSED const char* function,
25+
size_t line,
26+
const char* message,
27+
ET_UNUSED size_t length) {
28+
// Not all platforms have ticks == nanoseconds, but this one does.
29+
timestamp /= 1000; // To microseconds
30+
int us = timestamp % 1000000;
31+
timestamp /= 1000000; // To seconds
32+
int sec = timestamp % 60;
33+
timestamp /= 60; // To minutes
34+
int min = timestamp % 60;
35+
timestamp /= 60; // To hours
36+
int hour = timestamp;
37+
38+
fprintf(
39+
ET_LOG_OUTPUT_FILE,
40+
"%c %02d:%02d:%02d.%06d executorch:%s:%d] %s\n",
41+
static_cast<char>(level),
42+
hour,
43+
min,
44+
sec,
45+
us,
46+
filename,
47+
static_cast<int>(line),
48+
message);
49+
fflush(ET_LOG_OUTPUT_FILE);
50+
}
51+
52+
et_timestamp_t et_pal_current_ticks(void) {
53+
struct tms curr_time;
54+
times(&curr_time);
55+
return curr_time.tms_utime;
56+
}
57+
58+
void et_pal_init(void) {
59+
xt_iss_client_command("all", "enable");
60+
}
61+
62+
#else
63+
64+
#include <time.h>
65+
66+
#include <cstdio>
67+
#include <cstdlib>
68+
69+
#include <executorch/runtime/platform/platform.h>
70+
71+
#define ET_LOG_OUTPUT_FILE stderr
72+
73+
#define NSEC_PER_USEC 1000UL
74+
#define USEC_IN_SEC 1000000UL
75+
#define NSEC_IN_USEC 1000UL
76+
#define NSEC_IN_SEC (NSEC_IN_USEC * USEC_IN_SEC)
77+
78+
et_timestamp_t et_pal_current_ticks(void) {
79+
struct timespec ts;
80+
auto ret = clock_gettime(CLOCK_REALTIME, &ts);
81+
if (ret != 0) {
82+
fprintf(ET_LOG_OUTPUT_FILE, "Could not get time\n");
83+
fflush(ET_LOG_OUTPUT_FILE);
84+
std::abort();
85+
}
86+
87+
return ((ts.tv_sec * NSEC_IN_SEC) + (ts.tv_nsec));
88+
}
89+
90+
#endif

backends/cadence/runtime/targets.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
3+
def define_common_targets():
4+
runtime.cxx_library(
5+
name = "et_pal",
6+
srcs = ["et_pal.cpp"],
7+
link_whole = True,
8+
visibility = [
9+
"//executorch/backends/cadence/...",
10+
"@EXECUTORCH_CLIENTS"
11+
],
12+
exported_deps = [
13+
"//executorch/runtime/platform:platform",
14+
],
15+
)

0 commit comments

Comments
 (0)