Skip to content

Add TSAN annotations to pool_scalable #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/pool/pool_scalable.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand All @@ -24,6 +24,7 @@
#include <tbb/scalable_allocator.h>

#include "utils_common.h"
#include "utils_sanitizers.h"

typedef void *(*raw_alloc_tbb_type)(intptr_t, size_t *);
typedef void (*raw_free_tbb_type)(intptr_t, void *, size_t);
Expand Down Expand Up @@ -179,6 +180,7 @@ static void *tbb_malloc(void *pool, size_t size) {
}
return NULL;
}
utils_annotate_acquire(pool);
return ptr;
}

Expand All @@ -205,6 +207,7 @@ static void *tbb_realloc(void *pool, void *ptr, size_t size) {
}
return NULL;
}
utils_annotate_acquire(pool);
return new_ptr;
}

Expand All @@ -219,6 +222,7 @@ static void *tbb_aligned_malloc(void *pool, size_t size, size_t alignment) {
}
return NULL;
}
utils_annotate_acquire(pool);
return ptr;
}

Expand All @@ -229,6 +233,12 @@ static umf_result_t tbb_free(void *pool, void *ptr) {

TLS_last_free_error = UMF_RESULT_SUCCESS;

// Establishes happens-before order with tbb_*alloc functions.
// Makes sure that writes to the memory pointed to by 'ptr'
// are not reported as data races whenever 'ptr' reused by
// other threads.
utils_annotate_release(pool);

struct tbb_memory_pool *pool_data = (struct tbb_memory_pool *)pool;
if (g_tbb_ops.pool_free(pool_data->tbb_pool, ptr)) {
return UMF_RESULT_SUCCESS;
Expand Down
36 changes: 36 additions & 0 deletions src/utils/utils_sanitizers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

#if __SANITIZE_THREAD__
#include <sanitizer/tsan_interface.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

void utils_annotate_acquire(void *ptr) {
#if __SANITIZE_THREAD__
__tsan_acquire(ptr);
#else
(void)ptr;
#endif
}

void utils_annotate_release(void *ptr) {
#if __SANITIZE_THREAD__
__tsan_release(ptr);
#else
(void)ptr;
#endif
}

#ifdef __cplusplus
}
#endif