Skip to content

Commit 347cc61

Browse files
authored
dynamic tracing compiler cpp handle API (#284)
* annotation update for preemption restore asm Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> * dtrace cpp handle API; drop config struct Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> * address copilot comments Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com> --------- Signed-off-by: advanaik <AdvaitHemant.Naik@amd.com>
1 parent 3a1a1a7 commit 347cc61

12 files changed

Lines changed: 54 additions & 89 deletions

File tree

specification/aie4/preemption_asm/aie4_restore_1c.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ MASK_POLL_32 0x149ed0, 0x1f8003c, 0x0
1919
MASK_POLL_32 0x149ed4, 0x1f8003c, 0x0
2020
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
2121
END_JOB
22-
23-
START_JOB 1
24-
LOAD_LAST_PDI
25-
END_JOB
2622
.section annotation
2723
id: 3
2824
name: end_restore
2925
description: end restore
3026

27+
START_JOB 1
28+
LOAD_LAST_PDI
29+
END_JOB
30+
3131
EOF
3232

3333
;

specification/aie4/preemption_asm/aie4_restore_1c0.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ MASK_POLL_32 0x149ed0, 0x1f8003c, 0x0
2020
MASK_POLL_32 0x149ed4, 0x1f8003c, 0x0
2121
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
2222
END_JOB
23-
24-
START_JOB 1
25-
LOAD_LAST_PDI
26-
END_JOB
2723
.section annotation
2824
id: 3
2925
name: end_restore_1c0
3026
description: end restore 1c0
3127

28+
START_JOB 1
29+
LOAD_LAST_PDI
30+
END_JOB
3231

3332
EOF
3433

specification/aie4/preemption_asm/aie4_restore_1c1.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ MASK_POLL_32 0x2149ed0, 0x1f8003c, 0x0
2020
MASK_POLL_32 0x2149ed4, 0x1f8003c, 0x0
2121
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
2222
END_JOB
23-
24-
START_JOB 1
25-
LOAD_LAST_PDI
26-
END_JOB
2723
.section annotation
2824
id: 7
2925
name: end_restore_1c1
3026
description: end restore 1c1
3127

28+
START_JOB 1
29+
LOAD_LAST_PDI
30+
END_JOB
31+
3232
EOF
3333

3434
;

specification/aie4/preemption_asm/aie4_restore_1c2.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ MASK_POLL_32 0x4149ed0, 0x1f8003c, 0x0
2020
MASK_POLL_32 0x4149ed4, 0x1f8003c, 0x0
2121
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
2222
END_JOB
23-
24-
START_JOB 1
25-
LOAD_LAST_PDI
26-
END_JOB
2723
.section annotation
2824
id: 11
2925
name: end_restore_1c2
3026
description: end restore 1c2
3127

28+
START_JOB 1
29+
LOAD_LAST_PDI
30+
END_JOB
31+
3232
EOF
3333

3434
;

specification/aie4/preemption_asm/aie4_restore_2c.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ MASK_POLL_32 0x2149ed0, 0x1f8003c, 0x0
2828
MASK_POLL_32 0x2149ed4, 0x1f8003c, 0x0
2929
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
3030
END_JOB
31-
32-
START_JOB 1
33-
LOAD_LAST_PDI
34-
END_JOB
3531
.section annotation
3632
id: 3
3733
name: end_restore
3834
description: end restore
3935

36+
START_JOB 1
37+
LOAD_LAST_PDI
38+
END_JOB
4039

4140
EOF
4241

specification/aie4/preemption_asm/aie4_restore_3c.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ MASK_POLL_32 0x4149ed0, 0x1f8003c, 0x0
3636
MASK_POLL_32 0x4149ed4, 0x1f8003c, 0x0
3737
UC_DMA_WRITE_DES_SYNC @UCBD_label_3
3838
END_JOB
39-
40-
START_JOB 1
41-
LOAD_LAST_PDI
42-
END_JOB
4339
.section annotation
4440
id: 3
4541
name: end_restore
4642
description: end restore
4743

44+
START_JOB 1
45+
LOAD_LAST_PDI
46+
END_JOB
4847

4948
EOF
5049

src/cpp/dtrace/control/control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dtrace_log_level g_current_log_level = dtrace_log_level::dtrace_error; // NOLIN
3636
* file, and setting up control and memory buffers based on the parsed data.
3737
*/
3838
control::
39-
control(std::string script_file, const std::string& map_data)
39+
control(const std::string& script_file, const std::string& map_data)
4040
: m_pager(true)
4141
, m_parser(map_data)
4242
, m_output_format(dtrace::get_output_format())

src/cpp/dtrace/control/control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class control
4242
dtrace::dtrace_output_format m_output_format;
4343

4444
public:
45-
control(std::string script_file, const std::string& map_data);
45+
control(const std::string& script_file, const std::string& map_data);
4646
uint32_t m_num_uCs;
4747
std::set<uint32_t> m_control_uC_indices;
4848
bool m_mem_action_present;

src/cpp/dtrace/dtrace.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <memory>
1313
#include <stdexcept>
1414

15-
extern "C" {
16-
1715
/**
1816
* @struct dtrace_buffer_info
1917
*
@@ -49,35 +47,32 @@ struct dtrace_command_handle {
4947
};
5048

5149
dtrace_handle_t
52-
create_dtrace_handle(const dtrace_config_t* config)
50+
create_dtrace_handle(const std::string& script_file, const std::string& map_data, uint32_t log_level,
51+
uint32_t output_fmt)
5352
{
5453
try
5554
{
56-
// Validate dtrace config
57-
if (!config)
55+
// Validate script file path and map data
56+
if (script_file.empty())
5857
{
59-
std::cerr << "[DTRACE] [ERROR] : Invalid dtrace config";
58+
std::cerr << "[DTRACE] [ERROR] : Invalid dtrace config script data";
6059
return nullptr;
6160
}
6261

63-
// Validate script file path and map data
64-
if (!config->script_file || !config->map_data)
62+
if (map_data.empty())
6563
{
66-
std::cerr << "[DTRACE] [ERROR] : Invalid dtrace config data";
64+
std::cerr << "[DTRACE] [ERROR] : Invalid dtrace config map data";
6765
return nullptr;
6866
}
6967

7068
// Create new dtrace handle
7169
auto handle = std::make_unique<dtrace_command_handle>();
7270

73-
// Set the log level and output format
74-
dtrace::set_log_level(config->log_level);
75-
dtrace::set_output_format(config->output_fmt);
71+
dtrace::set_log_level(log_level);
72+
dtrace::set_output_format(output_fmt);
7673

7774
// Initialize the memory host address map and dtrace compiler control object
78-
handle->g_control = std::make_unique<dtrace::control>(
79-
config->script_file, config->map_data
80-
);
75+
handle->g_control = std::make_unique<dtrace::control>(script_file, map_data);
8176

8277
// Returns an opaque raw handle.
8378
// Transfer ownership to caller; caller must call destroy_dtrace_handle().
@@ -222,8 +217,8 @@ populate_dtrace_buffer(dtrace_handle_t dtrace_handle, uint32_t* dtrace_buffer,
222217
}
223218
}
224219

225-
void
226-
get_dtrace_result_file(dtrace_handle_t dtrace_handle, const char* result_file)
220+
void
221+
get_dtrace_result_file(dtrace_handle_t dtrace_handle, const std::string& result_file)
227222
{
228223
try
229224
{
@@ -306,5 +301,3 @@ destroy_dtrace_handle(dtrace_handle_t dtrace_handle)
306301
std::cerr << e.what();
307302
}
308303
}
309-
310-
}

src/cpp/dtrace/dtrace.h

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,27 @@
1919
#define DTRACE_EXPORT __attribute__((visibility("default")))
2020
#endif
2121

22-
#ifdef __cplusplus
23-
extern "C" {
24-
#endif
25-
26-
//---------------------------dtrace c---------------------------
2722
/*!
2823
* handle to a dynamic tracing context.
2924
* Each handle represents an independent dynamic tracing instance for a command.
3025
*/
31-
typedef void* dtrace_handle_t; // NOLINT
32-
33-
/*!
34-
* @struct dtrace_config_t
35-
*
36-
* @brief Configuration for creating a dtrace handle.
37-
*
38-
* @details
39-
* This structure contains configuration parameters for dtrace operation.
40-
*/
41-
typedef struct { // NOLINT
42-
const char* script_file; // Script file containing the probe and action details
43-
const char* map_data; // Map data containing details of control code
44-
uint32_t log_level; // Log level for debugging (default: dtrace_error)
45-
uint32_t output_fmt; // Output format for result file (default: python)
46-
} dtrace_config_t;
26+
using dtrace_handle_t = void*; // NOLINT
4727

4828
/*!
4929
* create_dtrace_handle() - Creates a handle to the dynamic tracing context.
5030
*
51-
* @config: Configuration structure containing dtrace parameters.
31+
* @script_file: Path to script file containing probe and action details.
32+
* @map_data: Map JSON string with details of control code.
33+
* @log_level: Log level for debugging.
34+
* @output_fmt: Output format for result file.
5235
*
5336
* @return Opaque raw handle to the dynamic tracing context owned by the caller, or NULL on failure.
5437
* @note The caller must release this handle by calling destroy_dtrace_handle().
5538
*/
5639
DTRACE_EXPORT
5740
dtrace_handle_t
58-
create_dtrace_handle(const dtrace_config_t* config);
41+
create_dtrace_handle(const std::string& script_file, const std::string& map_data, uint32_t log_level,
42+
uint32_t output_fmt);
5943

6044
/*!
6145
* get_dtrace_col_numbers() - Retrieves the buffer sizes required for dynamic tracing.
@@ -110,8 +94,8 @@ populate_dtrace_buffer(dtrace_handle_t dtrace_handle, uint32_t* dtrace_buffer,
11094
* and writes the output to the specified result file.
11195
*/
11296
DTRACE_EXPORT
113-
void
114-
get_dtrace_result_file(dtrace_handle_t dtrace_handle, const char* result_file);
97+
void
98+
get_dtrace_result_file(dtrace_handle_t dtrace_handle, const std::string& result_file);
11599

116100
/*!
117101
* destroy_dtrace_handle() - Destroys a dynamic tracing context.
@@ -125,8 +109,4 @@ DTRACE_EXPORT
125109
void
126110
destroy_dtrace_handle(dtrace_handle_t dtrace_handle);
127111

128-
#ifdef __cplusplus
129-
}
130-
#endif
131-
132112
#endif // TRACE_H

0 commit comments

Comments
 (0)