Skip to content

Commit

Permalink
Intel Vtune Markers for EventLoop and InputStream Read (#596)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Graeb <[email protected]>
  • Loading branch information
waahm7 and graebm authored Aug 28, 2023
1 parent 248e39a commit b4aa873
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/proof-alarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Check
run: |
TMPFILE=$(mktemp)
echo "59be2f2fbbd5ff4a374589cfe408609f source/linux/epoll_event_loop.c" > $TMPFILE
echo "c624a28de5af7f851a240a1e65a26c01 source/linux/epoll_event_loop.c" > $TMPFILE
md5sum --check $TMPFILE
# No further steps if successful
Expand All @@ -26,4 +26,5 @@ jobs:
run: |
echo "The VCC proofs are based on a snapshot of epoll_event_loop.c.
This push updates this file so the proofs must be rechecked to ensure they remain valid.
Please contact Nathan Chong."
Please contact Nathan Chong.
You can also update md5sum value by running `md5sum source/linux/epoll_event_loop.c` if the changes are trivial."
22 changes: 22 additions & 0 deletions include/aws/io/private/tracing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef AWS_IO_TRACING_H
#define AWS_IO_TRACING_H

/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/external/ittnotify.h>
#include <aws/io/io.h>

extern __itt_domain *io_tracing_domain;
extern __itt_string_handle *tracing_input_stream_read;
extern __itt_string_handle *tracing_event_loop_run_tasks;
extern __itt_string_handle *tracing_event_loop_event;
extern __itt_string_handle *tracing_event_loop_events;

AWS_EXTERN_C_BEGIN

void aws_io_tracing_init(void);

AWS_EXTERN_C_END
#endif /* AWS_IO_TRACING_H */
2 changes: 2 additions & 0 deletions source/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <aws/io/logging.h>

#include <aws/cal/cal.h>
#include <aws/io/private/tracing.h>

#define AWS_DEFINE_ERROR_INFO_IO(CODE, STR) [(CODE)-0x0400] = AWS_DEFINE_ERROR_INFO(CODE, STR, "aws-c-io")

Expand Down Expand Up @@ -360,6 +361,7 @@ void aws_io_library_init(struct aws_allocator *allocator) {
aws_register_error_info(&s_list);
aws_register_log_subject_info_list(&s_io_log_subject_list);
aws_tls_init_static_state(allocator);
aws_io_tracing_init();
}
}

Expand Down
8 changes: 8 additions & 0 deletions source/linux/epoll_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <aws/common/mutex.h>
#include <aws/common/task_scheduler.h>
#include <aws/common/thread.h>
#include <aws/io/private/tracing.h>

#include <aws/io/logging.h>

Expand Down Expand Up @@ -615,6 +616,8 @@ static void aws_event_loop_thread(void *args) {

AWS_LOGF_TRACE(
AWS_LS_IO_EVENT_LOOP, "id=%p: wake up with %d events to process.", (void *)event_loop, event_count);

__itt_task_begin(io_tracing_domain, __itt_null, __itt_null, tracing_event_loop_events);
for (int i = 0; i < event_count; ++i) {
struct epoll_event_data *event_data = (struct epoll_event_data *)events[i].data.ptr;

Expand Down Expand Up @@ -645,9 +648,12 @@ static void aws_event_loop_thread(void *args) {
"id=%p: activity on fd %d, invoking handler.",
(void *)event_loop,
event_data->handle->data.fd);
__itt_task_begin(io_tracing_domain, __itt_null, __itt_null, tracing_event_loop_event);
event_data->on_event(event_loop, event_data->handle, event_mask, event_data->user_data);
__itt_task_end(io_tracing_domain);
}
}
__itt_task_end(io_tracing_domain);

/* run scheduled tasks */
s_process_task_pre_queue(event_loop);
Expand All @@ -656,7 +662,9 @@ static void aws_event_loop_thread(void *args) {
event_loop->clock(&now_ns); /* if clock fails, now_ns will be 0 and tasks scheduled for a specific time
will not be run. That's ok, we'll handle them next time around. */
AWS_LOGF_TRACE(AWS_LS_IO_EVENT_LOOP, "id=%p: running scheduled tasks.", (void *)event_loop);
__itt_task_begin(io_tracing_domain, __itt_null, __itt_null, tracing_event_loop_run_tasks);
aws_task_scheduler_run_all(&epoll_loop->scheduler, now_ns);
__itt_task_end(io_tracing_domain);

/* set timeout for next epoll_wait() call.
* if clock fails, or scheduler has no tasks, use default timeout */
Expand Down
3 changes: 3 additions & 0 deletions source/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <aws/common/file.h>
#include <aws/io/file_utils.h>
#include <aws/io/private/tracing.h>

#include <errno.h>

Expand All @@ -32,7 +33,9 @@ int aws_input_stream_read(struct aws_input_stream *stream, struct aws_byte_buf *
const size_t safe_buf_capacity = dest->capacity - dest->len;
struct aws_byte_buf safe_buf = aws_byte_buf_from_empty_array(safe_buf_start, safe_buf_capacity);

__itt_task_begin(io_tracing_domain, __itt_null, __itt_null, tracing_input_stream_read);
int read_result = stream->vtable->read(stream, &safe_buf);
__itt_task_end(io_tracing_domain);

/* Ensure the implementation did not commit forbidden acts upon the buffer */
AWS_FATAL_ASSERT(
Expand Down
20 changes: 20 additions & 0 deletions source/tracing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/io/private/tracing.h>

__itt_domain *io_tracing_domain;
__itt_string_handle *tracing_input_stream_read;
__itt_string_handle *tracing_event_loop_run_tasks;
__itt_string_handle *tracing_event_loop_event;
__itt_string_handle *tracing_event_loop_events;

void aws_io_tracing_init() {
io_tracing_domain = __itt_domain_create("aws.c.io");
tracing_input_stream_read = __itt_string_handle_create("Read:InputStream");
tracing_event_loop_run_tasks = __itt_string_handle_create("RunTasks:EventLoop");
tracing_event_loop_event = __itt_string_handle_create("IOEvent:EventLoop");
tracing_event_loop_events = __itt_string_handle_create("IOEvents:EventLoop");
}

0 comments on commit b4aa873

Please sign in to comment.